blob: 79e2055dec86163063e78079f4d0de955e16fee7 [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"
johan669d69b2016-11-08 14:14:08 -080037#include "webrtc/p2p/base/packettransportinterface.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
perkjdfb769d2016-02-09 03:09:43 -0800160 void OnIceConnectionChange(
161 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:
zhihuangb2cdd932017-01-19 16:54:25 -0800213 void SetTransportChannel(rtc::PacketTransportInterface* 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(
zhihuangb2cdd932017-01-19 16:54:25 -0800240 rtc::PacketTransportInterface*) 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
johan669d69b2016-11-08 14:14:08 -0800278 rtc::PacketTransportInterface* voice_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700279 return rtp_transport_channel(voice_channel());
280 }
281
johan669d69b2016-11-08 14:14:08 -0800282 rtc::PacketTransportInterface* voice_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700283 return rtcp_transport_channel(voice_channel());
284 }
285
johan669d69b2016-11-08 14:14:08 -0800286 rtc::PacketTransportInterface* video_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700287 return rtp_transport_channel(video_channel());
288 }
289
johan669d69b2016-11-08 14:14:08 -0800290 rtc::PacketTransportInterface* 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:
johan669d69b2016-11-08 14:14:08 -0800295 rtc::PacketTransportInterface* rtp_transport_channel(
296 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
johan669d69b2016-11-08 14:14:08 -0800303 rtc::PacketTransportInterface* rtcp_transport_channel(
304 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()),
skvlad11a9cbf2016-10-07 11:53:05 -0700372 channel_manager_(new cricket::ChannelManager(media_engine_,
373 data_engine_,
374 rtc::Thread::Current())),
375 fake_call_(webrtc::Call::Config(&event_log_)),
stefanc1aeaf02015-10-15 07:26:07 -0700376 media_controller_(
nisse51542be2016-02-12 02:27:06 -0800377 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
378 rtc::Thread::Current(),
skvlad11a9cbf2016-10-07 11:53:05 -0700379 channel_manager_.get(),
380 &event_log_)),
stefanc1aeaf02015-10-15 07:26:07 -0700381 tdesc_factory_(new cricket::TransportDescriptionFactory()),
382 desc_factory_(
383 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
384 tdesc_factory_.get())),
385 pss_(new rtc::PhysicalSocketServer),
386 vss_(new rtc::VirtualSocketServer(pss_.get())),
387 fss_(new rtc::FirewallSocketServer(vss_.get())),
388 ss_scope_(fss_.get()),
389 stun_socket_addr_(
390 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
391 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
392 stun_socket_addr_)),
393 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
394 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000395 cricket::ServerAddresses stun_servers;
396 stun_servers.insert(stun_socket_addr_);
397 allocator_.reset(new cricket::BasicPortAllocator(
398 &network_manager_,
399 stun_servers,
400 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000401 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700402 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000403 EXPECT_TRUE(channel_manager_->Init());
404 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000405 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000406 }
407
408 void AddInterface(const SocketAddress& addr) {
409 network_manager_.AddInterface(addr);
410 }
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700411 void RemoveInterface(const SocketAddress& addr) {
412 network_manager_.RemoveInterface(addr);
413 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000414
Henrik Boströmd79599d2016-06-01 13:58:50 +0200415 // If |cert_generator| != null or |rtc_configuration| contains |certificates|
416 // then DTLS will be enabled unless explicitly disabled by |rtc_configuration|
417 // options. When DTLS is enabled a certificate will be used if provided,
418 // otherwise one will be generated using the |cert_generator|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000419 void Init(
zhihuang4dfb8ce2016-11-23 10:30:12 -0800420 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
421 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000422 ASSERT_TRUE(session_.get() == NULL);
deadbeef953c2ce2017-01-09 14:53:41 -0800423 fake_sctp_transport_factory_ = new FakeSctpTransportFactory();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000424 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700425 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
zhihuang29ff8442016-07-27 11:07:25 -0700426 rtc::Thread::Current(), allocator_.get(), &observer_,
427 std::unique_ptr<cricket::TransportController>(
428 new cricket::TransportController(rtc::Thread::Current(),
429 rtc::Thread::Current(),
deadbeef953c2ce2017-01-09 14:53:41 -0800430 allocator_.get())),
431 std::unique_ptr<FakeSctpTransportFactory>(
432 fake_sctp_transport_factory_)));
deadbeefab9b2d12015-10-14 11:33:11 -0700433 session_->SignalDataChannelOpenMessage.connect(
434 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000435
zhihuang4dfb8ce2016-11-23 10:30:12 -0800436 configuration_.rtcp_mux_policy = rtcp_mux_policy;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000437 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
438 observer_.ice_connection_state_);
439 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
440 observer_.ice_gathering_state_);
441
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200442 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator),
htaa2a49d92016-03-04 02:51:39 -0800443 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700444 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000445 }
446
deadbeefab9b2d12015-10-14 11:33:11 -0700447 void OnDataChannelOpenMessage(const std::string& label,
448 const InternalDataChannelInit& config) {
449 last_data_channel_label_ = label;
450 last_data_channel_config_ = config;
451 }
452
zhihuang4dfb8ce2016-11-23 10:30:12 -0800453 void Init() {
454 Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
455 }
456
457 void Init(PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
458 Init(nullptr, rtcp_mux_policy);
459 }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000460
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000461 void InitWithBundlePolicy(
462 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800463 configuration_.bundle_policy = bundle_policy;
464 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700465 }
466
467 void InitWithRtcpMuxPolicy(
468 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
469 PeerConnectionInterface::RTCConfiguration configuration;
zhihuang4dfb8ce2016-11-23 10:30:12 -0800470 Init(rtcp_mux_policy);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000471 }
472
Henrik Boström87713d02015-08-25 09:53:21 +0200473 // Successfully init with DTLS; with a certificate generated and supplied or
474 // with a store that generates it for us.
475 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200476 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator;
Henrik Boström87713d02015-08-25 09:53:21 +0200477 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800478 configuration_.certificates.push_back(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200479 FakeRTCCertificateGenerator::GenerateCertificate());
Henrik Boström87713d02015-08-25 09:53:21 +0200480 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200481 cert_generator.reset(new FakeRTCCertificateGenerator());
482 cert_generator->set_should_fail(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200483 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700484 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200485 }
zhihuang4dfb8ce2016-11-23 10:30:12 -0800486 Init(std::move(cert_generator),
487 PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
Henrik Boström87713d02015-08-25 09:53:21 +0200488 }
489
490 // Init with DTLS with a store that will fail to generate a certificate.
491 void InitWithDtlsIdentityGenFail() {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200492 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
493 new FakeRTCCertificateGenerator());
494 cert_generator->set_should_fail(true);
zhihuang4dfb8ce2016-11-23 10:30:12 -0800495 Init(std::move(cert_generator),
496 PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000497 }
498
jbauchcb560652016-08-04 05:20:32 -0700499 void InitWithGcm() {
500 rtc::CryptoOptions crypto_options;
501 crypto_options.enable_gcm_crypto_suites = true;
502 channel_manager_->SetCryptoOptions(crypto_options);
503 with_gcm_ = true;
504 Init();
505 }
506
deadbeefab9b2d12015-10-14 11:33:11 -0700507 void SendAudioVideoStream1() {
508 send_stream_1_ = true;
509 send_stream_2_ = false;
510 send_audio_ = true;
511 send_video_ = true;
512 }
513
514 void SendAudioVideoStream2() {
515 send_stream_1_ = false;
516 send_stream_2_ = true;
517 send_audio_ = true;
518 send_video_ = true;
519 }
520
521 void SendAudioVideoStream1And2() {
522 send_stream_1_ = true;
523 send_stream_2_ = true;
524 send_audio_ = true;
525 send_video_ = true;
526 }
527
528 void SendNothing() {
529 send_stream_1_ = false;
530 send_stream_2_ = false;
531 send_audio_ = false;
532 send_video_ = false;
533 }
534
535 void SendAudioOnlyStream2() {
536 send_stream_1_ = false;
537 send_stream_2_ = true;
538 send_audio_ = true;
539 send_video_ = false;
540 }
541
542 void SendVideoOnlyStream2() {
543 send_stream_1_ = false;
544 send_stream_2_ = true;
545 send_audio_ = false;
546 send_video_ = true;
547 }
548
549 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
550 if (send_stream_1_ && send_audio_) {
551 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
552 kStream1);
553 }
554 if (send_stream_1_ && send_video_) {
555 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
556 kStream1);
557 }
558 if (send_stream_2_ && send_audio_) {
559 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
560 kStream2);
561 }
562 if (send_stream_2_ && send_video_) {
563 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
564 kStream2);
565 }
566 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
567 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
568 data_channel_->label(),
569 data_channel_->label());
570 }
571 }
572
573 void GetOptionsForOffer(
574 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
575 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800576 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700577
deadbeefc80741f2015-10-22 13:14:45 -0700578 AddStreamsToOptions(session_options);
579 if (rtc_options.offer_to_receive_audio ==
580 RTCOfferAnswerOptions::kUndefined) {
581 session_options->recv_audio =
582 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
583 }
584 if (rtc_options.offer_to_receive_video ==
585 RTCOfferAnswerOptions::kUndefined) {
586 session_options->recv_video =
587 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
588 }
589 session_options->bundle_enabled =
590 session_options->bundle_enabled &&
591 (session_options->has_audio() || session_options->has_video() ||
592 session_options->has_data());
593
deadbeefab9b2d12015-10-14 11:33:11 -0700594 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
595 session_options->data_channel_type = cricket::DCT_SCTP;
zhihuang9763d562016-08-05 11:14:50 -0700596 } else if (session_->data_channel_type() == cricket::DCT_QUIC) {
597 session_options->data_channel_type = cricket::DCT_QUIC;
deadbeefab9b2d12015-10-14 11:33:11 -0700598 }
jbauchcb560652016-08-04 05:20:32 -0700599
600 if (with_gcm_) {
601 session_options->crypto_options.enable_gcm_crypto_suites = true;
602 }
deadbeefab9b2d12015-10-14 11:33:11 -0700603 }
604
htaa2a49d92016-03-04 02:51:39 -0800605 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
606 // ParseConstraintsForAnswer is used to set some defaults.
607 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700608
deadbeefc80741f2015-10-22 13:14:45 -0700609 AddStreamsToOptions(session_options);
610 session_options->bundle_enabled =
611 session_options->bundle_enabled &&
612 (session_options->has_audio() || session_options->has_video() ||
613 session_options->has_data());
614
zhihuang9763d562016-08-05 11:14:50 -0700615 if (session_->data_channel_type() != cricket::DCT_RTP) {
616 session_options->data_channel_type = session_->data_channel_type();
deadbeef907abe42016-08-04 12:22:18 -0700617 }
jbauchcb560652016-08-04 05:20:32 -0700618
619 if (with_gcm_) {
620 session_options->crypto_options.enable_gcm_crypto_suites = true;
621 }
deadbeefab9b2d12015-10-14 11:33:11 -0700622 }
623
624 // Creates a local offer and applies it. Starts ICE.
625 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000626 // to decide which streams to create.
627 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000628 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000629 SetLocalDescriptionWithoutError(offer);
630 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
631 observer_.ice_gathering_state_,
632 kIceCandidatesTimeout);
633 }
634
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000635 SessionDescriptionInterface* CreateOffer() {
636 PeerConnectionInterface::RTCOfferAnswerOptions options;
637 options.offer_to_receive_audio =
638 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
639
640 return CreateOffer(options);
641 }
642
wu@webrtc.org91053e72013-08-10 07:18:04 +0000643 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800644 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000645 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000646 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700647 cricket::MediaSessionOptions session_options;
648 GetOptionsForOffer(options, &session_options);
649 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000650 EXPECT_TRUE_WAIT(
651 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000652 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000653 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000654 }
655
656 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800657 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000658 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000659 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800660 cricket::MediaSessionOptions session_options = options;
661 GetOptionsForAnswer(&session_options);
662 // Overwrite recv_audio and recv_video with passed-in values.
663 session_options.recv_video = options.recv_video;
664 session_options.recv_audio = options.recv_audio;
665 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000666 EXPECT_TRUE_WAIT(
667 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000668 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000669 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000670 }
671
htaa2a49d92016-03-04 02:51:39 -0800672 SessionDescriptionInterface* CreateAnswer() {
673 cricket::MediaSessionOptions options;
674 options.recv_video = true;
675 options.recv_audio = true;
676 return CreateAnswer(options);
677 }
678
wu@webrtc.org364f2042013-11-20 21:49:41 +0000679 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000680 return (session_->voice_channel() != NULL &&
681 session_->video_channel() != NULL);
682 }
683
jbauchcb560652016-08-04 05:20:32 -0700684 void VerifyCryptoParams(const cricket::SessionDescription* sdp,
685 bool gcm_enabled = false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000686 ASSERT_TRUE(session_.get() != NULL);
687 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
688 ASSERT_TRUE(content != NULL);
689 const cricket::AudioContentDescription* audio_content =
690 static_cast<const cricket::AudioContentDescription*>(
691 content->description);
692 ASSERT_TRUE(audio_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700693 if (!gcm_enabled) {
694 ASSERT_EQ(1U, audio_content->cryptos().size());
695 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
696 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
697 audio_content->cryptos()[0].cipher_suite);
698 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
699 audio_content->protocol());
700 } else {
701 // The offer contains 3 possible crypto suites, the answer 1.
702 EXPECT_LE(1U, audio_content->cryptos().size());
703 EXPECT_NE(2U, audio_content->cryptos().size());
704 EXPECT_GE(3U, audio_content->cryptos().size());
705 ASSERT_EQ(67U, audio_content->cryptos()[0].key_params.size());
706 ASSERT_EQ("AEAD_AES_256_GCM",
707 audio_content->cryptos()[0].cipher_suite);
708 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
709 audio_content->protocol());
710 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000711
712 content = cricket::GetFirstVideoContent(sdp);
713 ASSERT_TRUE(content != NULL);
714 const cricket::VideoContentDescription* video_content =
715 static_cast<const cricket::VideoContentDescription*>(
716 content->description);
717 ASSERT_TRUE(video_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700718 if (!gcm_enabled) {
719 ASSERT_EQ(1U, video_content->cryptos().size());
720 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
721 video_content->cryptos()[0].cipher_suite);
722 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
723 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
724 video_content->protocol());
725 } else {
726 // The offer contains 3 possible crypto suites, the answer 1.
727 EXPECT_LE(1U, video_content->cryptos().size());
728 EXPECT_NE(2U, video_content->cryptos().size());
729 EXPECT_GE(3U, video_content->cryptos().size());
730 ASSERT_EQ("AEAD_AES_256_GCM",
731 video_content->cryptos()[0].cipher_suite);
732 ASSERT_EQ(67U, video_content->cryptos()[0].key_params.size());
733 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
734 video_content->protocol());
735 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000736 }
737
738 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
739 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
740 ASSERT_TRUE(content != NULL);
741 const cricket::AudioContentDescription* audio_content =
742 static_cast<const cricket::AudioContentDescription*>(
743 content->description);
744 ASSERT_TRUE(audio_content != NULL);
745 ASSERT_EQ(0U, audio_content->cryptos().size());
746
747 content = cricket::GetFirstVideoContent(sdp);
748 ASSERT_TRUE(content != NULL);
749 const cricket::VideoContentDescription* video_content =
750 static_cast<const cricket::VideoContentDescription*>(
751 content->description);
752 ASSERT_TRUE(video_content != NULL);
753 ASSERT_EQ(0U, video_content->cryptos().size());
754
755 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700756 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000757 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700758 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759 video_content->protocol());
760 } else {
761 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
762 audio_content->protocol());
763 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
764 video_content->protocol());
765 }
766 }
767
768 // Set the internal fake description factories to do DTLS-SRTP.
769 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000770 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000771 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000772 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200773 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800774 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700775 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800776 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000777 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
778 }
779
780 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
781 bool expected) {
782 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
783 ASSERT_TRUE(audio != NULL);
784 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785 const TransportInfo* video = sdp->GetTransportInfoByName("video");
786 ASSERT_TRUE(video != NULL);
787 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 }
789
790 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000791 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000793 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000794 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000796 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000798 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
799 offer);
htaa2a49d92016-03-04 02:51:39 -0800800 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 // Answer should be NULL as no crypto params in offer.
802 ASSERT_TRUE(answer == NULL);
803 }
804
805 void VerifyAnswerFromCryptoOffer() {
806 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000807 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808 options.bundle_enabled = true;
kwibergd1fe2812016-04-27 06:47:29 -0700809 std::unique_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000810 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
811 ASSERT_TRUE(offer.get() != NULL);
812 VerifyCryptoParams(offer->description());
813 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -0700814 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815 ASSERT_TRUE(answer.get() != NULL);
816 VerifyCryptoParams(answer->description());
817 }
818
deadbeef0ed85b22016-02-23 17:24:52 -0800819 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
820 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000821 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800822 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823 }
824
825 const cricket::ContentInfos& contents = desc1->contents();
826 cricket::ContentInfos::const_iterator it = contents.begin();
827
828 for (; it != contents.end(); ++it) {
829 const cricket::TransportDescription* transport_desc1 =
830 desc1->GetTransportDescriptionByName(it->name);
831 const cricket::TransportDescription* transport_desc2 =
832 desc2->GetTransportDescriptionByName(it->name);
833 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800834 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835 }
836 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
837 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800838 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839 }
840 }
deadbeef0ed85b22016-02-23 17:24:52 -0800841 return true;
842 }
843
844 // Compares ufrag/password only for the specified |media_type|.
845 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
846 const cricket::SessionDescription* desc2,
847 cricket::MediaType media_type) {
848 if (desc1->contents().size() != desc2->contents().size()) {
849 return false;
850 }
851
852 const cricket::ContentInfo* cinfo =
853 cricket::GetFirstMediaContent(desc1->contents(), media_type);
854 const cricket::TransportDescription* transport_desc1 =
855 desc1->GetTransportDescriptionByName(cinfo->name);
856 const cricket::TransportDescription* transport_desc2 =
857 desc2->GetTransportDescriptionByName(cinfo->name);
858 if (!transport_desc1 || !transport_desc2) {
859 return false;
860 }
861 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
862 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
863 return false;
864 }
865 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000867
868 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
869 std::string *sdp) {
870 const cricket::SessionDescription* desc = current_desc->description();
871 EXPECT_TRUE(current_desc->ToString(sdp));
872
873 const cricket::ContentInfos& contents = desc->contents();
874 cricket::ContentInfos::const_iterator it = contents.begin();
875 // Replace ufrag and pwd lines with empty strings.
876 for (; it != contents.end(); ++it) {
877 const cricket::TransportDescription* transport_desc =
878 desc->GetTransportDescriptionByName(it->name);
879 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
880 + "\r\n";
881 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
882 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000883 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000884 "", 0,
885 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000886 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000887 "", 0,
888 sdp);
889 }
890 }
891
deadbeef0ed85b22016-02-23 17:24:52 -0800892 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
893 const std::string& ufrag,
894 const std::string& pwd) {
895 cricket::SessionDescription* desc = current_desc->description();
896 for (TransportInfo& transport_info : desc->transport_infos()) {
897 cricket::TransportDescription& transport_desc =
898 transport_info.description;
899 transport_desc.ice_ufrag = ufrag;
900 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000901 }
902 }
903
deadbeef0ed85b22016-02-23 17:24:52 -0800904 // Sets ufrag/pwd for specified |media_type|.
905 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
906 cricket::MediaType media_type,
907 const std::string& ufrag,
908 const std::string& pwd) {
909 cricket::SessionDescription* desc = current_desc->description();
910 const cricket::ContentInfo* cinfo =
911 cricket::GetFirstMediaContent(desc->contents(), media_type);
912 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
913 cricket::TransportDescription* transport_desc =
914 &transport_info->description;
915 transport_desc->ice_ufrag = ufrag;
916 transport_desc->ice_pwd = pwd;
917 }
918
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 // Creates a remote offer and and applies it as a remote description,
920 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700921 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922 // to decide which local and remote streams to create.
923 void CreateAndSetRemoteOfferAndLocalAnswer() {
924 SessionDescriptionInterface* offer = CreateRemoteOffer();
925 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800926 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927 SetLocalDescriptionWithoutError(answer);
928 }
929 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
930 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700931 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000932 }
933 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700934 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000935 SetLocalDescriptionWithoutError(desc);
936 EXPECT_EQ(expected_state, session_->state());
937 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000938 void SetLocalDescriptionExpectError(const std::string& action,
939 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000940 SessionDescriptionInterface* desc) {
941 std::string error;
942 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000943 std::string sdp_type = "local ";
944 sdp_type.append(action);
945 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000946 EXPECT_NE(std::string::npos, error.find(expected_error));
947 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000948 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
949 SessionDescriptionInterface* desc) {
950 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
951 expected_error, desc);
952 }
953 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
954 SessionDescriptionInterface* desc) {
955 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
956 expected_error, desc);
957 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000958 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
959 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
960 }
961 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700962 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000963 SetRemoteDescriptionWithoutError(desc);
964 EXPECT_EQ(expected_state, session_->state());
965 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000966 void SetRemoteDescriptionExpectError(const std::string& action,
967 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000968 SessionDescriptionInterface* desc) {
969 std::string error;
970 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000971 std::string sdp_type = "remote ";
972 sdp_type.append(action);
973 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000974 EXPECT_NE(std::string::npos, error.find(expected_error));
975 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000976 void SetRemoteDescriptionOfferExpectError(
977 const std::string& expected_error, SessionDescriptionInterface* desc) {
978 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
979 expected_error, desc);
980 }
981 void SetRemoteDescriptionPranswerExpectError(
982 const std::string& expected_error, SessionDescriptionInterface* desc) {
983 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
984 expected_error, desc);
985 }
986 void SetRemoteDescriptionAnswerExpectError(
987 const std::string& expected_error, SessionDescriptionInterface* desc) {
988 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
989 expected_error, desc);
990 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991
992 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
993 SessionDescriptionInterface** nocrypto_answer) {
994 // Create a SDP without Crypto.
995 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000996 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000997 options.bundle_enabled = true;
998 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
999 ASSERT_TRUE(*offer != NULL);
1000 VerifyCryptoParams((*offer)->description());
1001
1002 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
1003 cricket::SEC_DISABLED);
1004 EXPECT_TRUE(*nocrypto_answer != NULL);
1005 }
1006
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001007 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
1008 SessionDescriptionInterface** nodtls_answer) {
1009 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001010 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001011 options.bundle_enabled = true;
1012
kwibergd1fe2812016-04-27 06:47:29 -07001013 std::unique_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001014 CreateRemoteOffer(options, cricket::SEC_ENABLED));
1015
1016 *nodtls_answer =
1017 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
1018 EXPECT_TRUE(*nodtls_answer != NULL);
1019 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
1020 VerifyCryptoParams((*nodtls_answer)->description());
1021
1022 SetFactoryDtlsSrtp();
1023 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
1024 ASSERT_TRUE(*offer != NULL);
1025 VerifyFingerprintStatus((*offer)->description(), true);
1026 VerifyCryptoParams((*offer)->description());
1027 }
1028
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001029 JsepSessionDescription* CreateRemoteOfferWithVersion(
1030 cricket::MediaSessionOptions options,
1031 cricket::SecurePolicy secure_policy,
1032 const std::string& session_version,
1033 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001034 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001035 const cricket::SessionDescription* cricket_desc = NULL;
1036 if (current_desc) {
1037 cricket_desc = current_desc->description();
1038 session_id = current_desc->session_id();
1039 }
1040
1041 desc_factory_->set_secure(secure_policy);
1042 JsepSessionDescription* offer(
1043 new JsepSessionDescription(JsepSessionDescription::kOffer));
1044 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
1045 session_id, session_version)) {
1046 delete offer;
1047 offer = NULL;
1048 }
1049 return offer;
1050 }
1051 JsepSessionDescription* CreateRemoteOffer(
1052 cricket::MediaSessionOptions options) {
1053 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1054 kSessionVersion, NULL);
1055 }
1056 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001057 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
1058 return CreateRemoteOfferWithVersion(
1059 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001060 }
1061 JsepSessionDescription* CreateRemoteOffer(
1062 cricket::MediaSessionOptions options,
1063 const SessionDescriptionInterface* current_desc) {
1064 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1065 kSessionVersion, current_desc);
1066 }
1067
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001068 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
1069 const char* sctp_stream_name, int new_port,
1070 cricket::MediaSessionOptions options) {
1071 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001072 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
1073 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001074 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
1075 }
1076
1077 // Takes ownership of offer_basis (and deletes it).
1078 JsepSessionDescription* ChangeSDPSctpPort(
1079 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1080 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1081 // SessionDescription from the mutated string.
1082 const char* default_port_str = "5000";
1083 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001084 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001085 std::string offer_str;
1086 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001087 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001088 new_port_str, strlen(new_port_str),
1089 &offer_str);
1090 JsepSessionDescription* offer = new JsepSessionDescription(
1091 offer_basis->type());
1092 delete offer_basis;
1093 offer->Initialize(offer_str, NULL);
1094 return offer;
1095 }
1096
deadbeefab9b2d12015-10-14 11:33:11 -07001097 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001098 // before this function to decide which streams to create.
1099 JsepSessionDescription* CreateRemoteOffer() {
1100 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001101 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001102 return CreateRemoteOffer(options, session_->remote_description());
1103 }
1104
1105 JsepSessionDescription* CreateRemoteAnswer(
1106 const SessionDescriptionInterface* offer,
1107 cricket::MediaSessionOptions options,
1108 cricket::SecurePolicy policy) {
1109 desc_factory_->set_secure(policy);
1110 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001111 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001112 JsepSessionDescription* answer(
1113 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1114 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1115 options, NULL),
1116 session_id, kSessionVersion)) {
1117 delete answer;
1118 answer = NULL;
1119 }
1120 return answer;
1121 }
1122
1123 JsepSessionDescription* CreateRemoteAnswer(
1124 const SessionDescriptionInterface* offer,
1125 cricket::MediaSessionOptions options) {
1126 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1127 }
1128
deadbeefab9b2d12015-10-14 11:33:11 -07001129 // Creates an answer session description.
1130 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001131 // to decide which streams to create.
1132 JsepSessionDescription* CreateRemoteAnswer(
1133 const SessionDescriptionInterface* offer) {
1134 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001135 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001136 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1137 }
1138
1139 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001140 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001141 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001142 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001143
1144 PeerConnectionInterface::RTCOfferAnswerOptions options;
1145 options.use_rtp_mux = bundle;
1146
1147 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001148 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1149 // and answer.
1150 SetLocalDescriptionWithoutError(offer);
1151
kwibergd1fe2812016-04-27 06:47:29 -07001152 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001153 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001154 std::string sdp;
1155 EXPECT_TRUE(answer->ToString(&sdp));
1156
1157 size_t expected_candidate_num = 2;
1158 if (!rtcp_mux) {
1159 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1160 // for rtp and rtcp.
1161 expected_candidate_num = 4;
1162 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001163 const std::string kRtcpMux = "a=rtcp-mux";
1164 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001165 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001166 kXRtcpMux.c_str(), kXRtcpMux.length(),
1167 &sdp);
1168 }
1169
1170 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1171 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001172
1173 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001174 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001175 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1176 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001177 if (bundle) {
1178 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1179 } else {
1180 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001181 }
1182 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001183
zhihuang3a334652016-05-05 18:37:49 -07001184 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1185 const std::string& codec_name) {
1186 for (const auto& content : desc->description()->contents()) {
1187 if (static_cast<cricket::MediaContentDescription*>(content.description)
1188 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1189 const auto* mdesc =
1190 static_cast<cricket::VideoContentDescription*>(content.description);
1191 for (const auto& codec : mdesc->codecs()) {
1192 if (codec.name == codec_name) {
1193 return true;
1194 }
1195 }
1196 }
1197 }
1198 return false;
1199 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001200 // Helper class to configure loopback network and verify Best
1201 // Connection using right IP protocol for TestLoopbackCall
1202 // method. LoopbackNetworkManager applies firewall rules to block
1203 // all ping traffic once ICE completed, and remove them to observe
1204 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1205 // verifies the best connection is using the right IP protocol after
1206 // initial ICE convergences.
1207
1208 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001209 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001210 LoopbackNetworkConfiguration()
1211 : test_ipv6_network_(false),
1212 test_extra_ipv4_network_(false),
1213 best_connection_after_initial_ice_converged_(1, 0) {}
1214
1215 // Used to track the expected best connection count in each IP protocol.
1216 struct ExpectedBestConnection {
1217 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1218 : ipv4_count_(ipv4_count),
1219 ipv6_count_(ipv6_count) {}
1220
1221 int ipv4_count_;
1222 int ipv6_count_;
1223 };
1224
1225 bool test_ipv6_network_;
1226 bool test_extra_ipv4_network_;
1227 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1228
1229 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001230 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001231 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1232 }
1233
1234 private:
jbauchac8869e2015-07-03 01:36:14 -07001235 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001236 const ExpectedBestConnection& expected) const {
1237 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001238 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1239 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001240 expected.ipv4_count_);
1241 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001242 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1243 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001244 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001245 // This is used in the loopback call so there is only single host to host
1246 // candidate pair.
1247 EXPECT_EQ(metrics_observer->GetEnumCounter(
1248 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1249 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001250 0);
1251 EXPECT_EQ(metrics_observer->GetEnumCounter(
1252 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1253 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001254 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001255 }
1256 };
1257
1258 class LoopbackNetworkManager {
1259 public:
1260 LoopbackNetworkManager(WebRtcSessionTest* session,
1261 const LoopbackNetworkConfiguration& config)
1262 : config_(config) {
1263 session->AddInterface(
1264 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1265 if (config_.test_extra_ipv4_network_) {
1266 session->AddInterface(
1267 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1268 }
1269 if (config_.test_ipv6_network_) {
1270 session->AddInterface(
1271 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1272 }
1273 }
1274
1275 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1276 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1277 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1278 if (config_.test_extra_ipv4_network_) {
1279 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1280 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1281 }
1282 if (config_.test_ipv6_network_) {
1283 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1284 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1285 }
1286 }
1287
1288 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1289
1290 private:
1291 LoopbackNetworkConfiguration config_;
1292 };
1293
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001294 // The method sets up a call from the session to itself, in a loopback
1295 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001296 // disconnection, and then a permanent disconnection.
1297 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001298 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1299 // While running the call, this method also checks if the session goes through
1300 // the correct sequence of ICE states when a connection is established,
1301 // broken, and re-established.
1302 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001303 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1304 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001305 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001306
stefanc1aeaf02015-10-15 07:26:07 -07001307 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001308 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001309 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001310 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001311
1312 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1313 observer_.ice_gathering_state_);
1314 SetLocalDescriptionWithoutError(offer);
1315 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1316 observer_.ice_connection_state_);
1317 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001318 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001319 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1320 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001321 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001322
1323 std::string sdp;
1324 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001325 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1326 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001327 ASSERT_TRUE(desc != NULL);
1328 SetRemoteDescriptionWithoutError(desc);
1329
1330 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001331 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001332
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001333 // The ice connection state is "Connected" too briefly to catch in a test.
1334 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001335 observer_.ice_connection_state_, kIceCandidatesTimeout);
1336 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001337
stefanc1aeaf02015-10-15 07:26:07 -07001338 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1339 LoopbackNetworkManager loopback_network_manager(this, config);
1340 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001341 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001342 // Adding firewall rule to block ping requests, which should cause
1343 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001344
1345 loopback_network_manager.ApplyFirewallRules(fss_.get());
1346
1347 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001348 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1349 observer_.ice_connection_state_,
1350 kIceCandidatesTimeout);
1351
jbauchac8869e2015-07-03 01:36:14 -07001352 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001353
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001354 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001355 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001356
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001357 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001358 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001359 observer_.ice_connection_state_,
1360 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001361
1362 // Now we block ping requests and wait until the ICE connection transitions
1363 // to the Failed state. This will take at least 30 seconds because it must
1364 // wait for the Port to timeout.
1365 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001366
1367 loopback_network_manager.ApplyFirewallRules(fss_.get());
1368 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001369 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001370 observer_.ice_connection_state_,
1371 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001372 }
1373
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001374 void TestLoopbackCall() {
1375 LoopbackNetworkConfiguration config;
1376 TestLoopbackCall(config);
1377 }
1378
stefanc1aeaf02015-10-15 07:26:07 -07001379 void TestPacketOptions() {
1380 media_controller_.reset(
1381 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1382 LoopbackNetworkConfiguration config;
1383 LoopbackNetworkManager loopback_network_manager(this, config);
1384
1385 SetupLoopbackCall();
1386
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001387 // Wait for channel to be ready for sending.
1388 EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
stefanc1aeaf02015-10-15 07:26:07 -07001389 uint8_t test_packet[15] = {0};
1390 rtc::PacketOptions options;
1391 options.packet_id = 10;
1392 media_engine_->GetVideoChannel(0)
1393 ->SendRtp(test_packet, sizeof(test_packet), options);
1394
1395 const int kPacketTimeout = 2000;
deadbeef14461d42016-06-15 11:06:57 -07001396 EXPECT_EQ_WAIT(10, fake_call_.last_sent_nonnegative_packet_id(),
1397 kPacketTimeout);
stefanc1aeaf02015-10-15 07:26:07 -07001398 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1399 }
1400
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001401 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1402 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001403 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1404 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001405
1406 // Add kCNCodec for dtmf test.
ossudedfd282016-06-14 07:12:39 -07001407 std::vector<cricket::AudioCodec> codecs =
1408 media_engine_->audio_send_codecs();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001409 codecs.push_back(kCNCodec1);
1410 codecs.push_back(kCNCodec2);
1411 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -07001412 desc_factory_->set_audio_codecs(codecs, codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001413 }
1414
1415 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1416 const cricket::ContentDescription* description = content->description;
nissec8ee8822017-01-18 07:20:55 -08001417 RTC_CHECK(description != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001418 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001419 static_cast<const cricket::AudioContentDescription*>(description);
nissec8ee8822017-01-18 07:20:55 -08001420 RTC_CHECK(audio_content_desc != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001421 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1422 if (audio_content_desc->codecs()[i].name == "CN")
1423 return false;
1424 }
1425 return true;
1426 }
1427
deadbeefab9b2d12015-10-14 11:33:11 -07001428 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001429 webrtc::InternalDataChannelInit dci;
nissec8ee8822017-01-18 07:20:55 -08001430 RTC_CHECK(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001431 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1432 data_channel_ = DataChannel::Create(
1433 session_.get(), session_->data_channel_type(), "datachannel", dci);
1434 }
1435
1436 void SetLocalDescriptionWithDataChannel() {
1437 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001438 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001439 SetLocalDescriptionWithoutError(offer);
1440 }
1441
wu@webrtc.org91053e72013-08-10 07:18:04 +00001442 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001443 RTCCertificateGenerationMethod cert_gen_method,
1444 CreateSessionDescriptionRequest::Type type) {
1445 InitWithDtls(cert_gen_method);
1446 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1447 }
1448
1449 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1450 CreateSessionDescriptionRequest::Type type) {
1451 InitWithDtlsIdentityGenFail();
1452 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1453 }
1454
1455 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001456 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001457 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001458 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001459 if (type == CreateSessionDescriptionRequest::kAnswer) {
1460 cricket::MediaSessionOptions options;
kwibergd1fe2812016-04-27 06:47:29 -07001461 std::unique_ptr<JsepSessionDescription> offer(
1462 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001463 ASSERT_TRUE(offer.get() != NULL);
1464 SetRemoteDescriptionWithoutError(offer.release());
1465 }
1466
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001467 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001468 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001469 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001470 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001471 observers[kNumber];
1472 for (int i = 0; i < kNumber; ++i) {
1473 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1474 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001475 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001476 } else {
htaa2a49d92016-03-04 02:51:39 -08001477 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001478 }
1479 }
1480
1481 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1482 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1483 WebRtcSessionCreateSDPObserverForTest::kFailed;
1484
1485 for (int i = 0; i < kNumber; ++i) {
1486 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1487 if (success) {
1488 EXPECT_TRUE(observers[i]->description() != NULL);
1489 } else {
1490 EXPECT_TRUE(observers[i]->description() == NULL);
1491 }
1492 }
1493 }
1494
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001495 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001496 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001497 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001498 turn_server.credentials = credentials;
1499 turn_server.ports.push_back(
hnsl277b2502016-12-13 05:17:23 -08001500 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP));
deadbeef653b8e02015-11-11 12:55:10 -08001501 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001502 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001503 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001504 }
1505
skvlad11a9cbf2016-10-07 11:53:05 -07001506 webrtc::RtcEventLogNullImpl event_log_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001507 cricket::FakeMediaEngine* media_engine_;
1508 cricket::FakeDataEngine* data_engine_;
deadbeef953c2ce2017-01-09 14:53:41 -08001509 // Actually owned by session_.
1510 FakeSctpTransportFactory* fake_sctp_transport_factory_ = nullptr;
kwibergd1fe2812016-04-27 06:47:29 -07001511 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001512 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001513 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_;
1514 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1515 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1516 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1517 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1518 std::unique_ptr<rtc::FirewallSocketServer> fss_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001519 rtc::SocketServerScope ss_scope_;
1520 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001521 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001522 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001523 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001524 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001525 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001526 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001527 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001528 MockIceObserver observer_;
1529 cricket::FakeVideoMediaChannel* video_channel_;
1530 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001531 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001532 // The following flags affect options created for CreateOffer/CreateAnswer.
1533 bool send_stream_1_ = false;
1534 bool send_stream_2_ = false;
1535 bool send_audio_ = false;
1536 bool send_video_ = false;
1537 rtc::scoped_refptr<DataChannel> data_channel_;
1538 // Last values received from data channel creation signal.
1539 std::string last_data_channel_label_;
1540 InternalDataChannelInit last_data_channel_config_;
jbauchcb560652016-08-04 05:20:32 -07001541 bool with_gcm_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001542};
1543
Henrik Boström87713d02015-08-25 09:53:21 +02001544TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1545 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001546 // SDES is disabled when DTLS is on.
1547 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001548}
1549
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001550TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001551 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001552 // SDES is required if DTLS is off.
1553 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001554}
1555
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001556TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1557 TestSessionCandidatesWithBundleRtcpMux(false, false);
1558}
1559
1560// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1561// with rtcp-mux and/or bundle.
1562TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1563 TestSessionCandidatesWithBundleRtcpMux(false, true);
1564}
1565
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001566TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1567 TestSessionCandidatesWithBundleRtcpMux(true, true);
1568}
1569
1570TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001571 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1572 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001573 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001574 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001575 InitiateCall();
1576 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1577 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1578 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1579}
1580
deadbeeff5f03e82016-06-06 11:16:06 -07001581TEST_F(WebRtcSessionTest, TestStunError) {
1582 rtc::ScopedFakeClock clock;
1583
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001584 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1585 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001586 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001587 rtc::FP_UDP,
1588 rtc::FD_ANY,
1589 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001590 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001591 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001592 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001593 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
pthatcher94a2f212017-02-08 14:42:22 -08001594 EXPECT_TRUE_SIMULATED_WAIT(observer_.oncandidatesready_,
1595 cricket::STUN_TOTAL_TIMEOUT, clock);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001596 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1597 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
deadbeeff5f03e82016-06-06 11:16:06 -07001598 // Destroy session before scoped fake clock goes out of scope to avoid TSan
1599 // warning.
1600 session_->Close();
1601 session_.reset(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001602}
1603
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001604TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001605 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001606 SessionDescriptionInterface* offer = NULL;
1607 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1608 std::string unknown_action;
1609 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1610 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1611}
1612
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001613// Test creating offers and receive answers and make sure the
1614// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001615TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001616 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001617 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001618 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619 const std::string session_id_orig = offer->session_id();
1620 const std::string session_version_orig = offer->session_version();
1621 SetLocalDescriptionWithoutError(offer);
1622
deadbeefab9b2d12015-10-14 11:33:11 -07001623 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001624 SessionDescriptionInterface* answer =
1625 CreateRemoteAnswer(session_->local_description());
1626 SetRemoteDescriptionWithoutError(answer);
1627
1628 video_channel_ = media_engine_->GetVideoChannel(0);
1629 voice_channel_ = media_engine_->GetVoiceChannel(0);
1630
1631 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1632 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1633
1634 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1635 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1636
1637 ASSERT_EQ(1u, video_channel_->send_streams().size());
1638 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1639 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1640 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1641
1642 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001643 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001644 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001645
1646 // Verify the session id is the same and the session version is
1647 // increased.
1648 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001649 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1650 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001651
1652 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001653 EXPECT_EQ(0u, video_channel_->send_streams().size());
1654 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001655
deadbeefab9b2d12015-10-14 11:33:11 -07001656 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001657 answer = CreateRemoteAnswer(session_->local_description());
1658 SetRemoteDescriptionWithoutError(answer);
1659
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001660 // Make sure the receive streams have not changed.
1661 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1662 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1663 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1664 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1665}
1666
1667// Test receiving offers and creating answers and make sure the
1668// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001669TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001670 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001671 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001672 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001673 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001674 SetRemoteDescriptionWithoutError(offer);
1675
deadbeefab9b2d12015-10-14 11:33:11 -07001676 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001677 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001678 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001679 SetLocalDescriptionWithoutError(answer);
1680
1681 const std::string session_id_orig = answer->session_id();
1682 const std::string session_version_orig = answer->session_version();
1683
1684 video_channel_ = media_engine_->GetVideoChannel(0);
1685 voice_channel_ = media_engine_->GetVoiceChannel(0);
1686
htaa2a49d92016-03-04 02:51:39 -08001687 ASSERT_TRUE(video_channel_);
1688 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001689 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1690 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1691
1692 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1693 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1694
1695 ASSERT_EQ(1u, video_channel_->send_streams().size());
1696 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1697 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1698 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1699
deadbeefab9b2d12015-10-14 11:33:11 -07001700 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001701 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001702 SetRemoteDescriptionWithoutError(offer);
1703
1704 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001705 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001706 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001707
1708 // Verify the session id is the same and the session version is
1709 // increased.
1710 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001711 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1712 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001713 SetLocalDescriptionWithoutError(answer);
1714
1715 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1716 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1717 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1718 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1719 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1720 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1721
1722 // Make sure we have no send streams.
1723 EXPECT_EQ(0u, video_channel_->send_streams().size());
1724 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1725}
1726
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001727TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001728 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001729 media_engine_->set_fail_create_channel(true);
1730
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001731 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001732 ASSERT_TRUE(offer != NULL);
1733 // SetRemoteDescription and SetLocalDescription will take the ownership of
1734 // the offer.
1735 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001736 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001737 ASSERT_TRUE(offer != NULL);
1738 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1739}
1740
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001741//
1742// Tests for creating/setting SDP under different SDES/DTLS polices:
1743//
1744// --DTLS off and SDES on
1745// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1746// set local/remote offer/answer with crypto --> success
1747// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1748// failure
1749// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1750// failure
1751// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1752// failure
1753//
1754// --DTLS on and SDES off
1755// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1756// set local/remote offer/answer with DTLS fingerprint --> success
1757// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1758// fingerprint --> failure
1759// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1760// --> failure
1761// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1762// --> failure
1763//
1764// --Encryption disabled: DTLS off and SDES off
1765// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1766// answer without SDES or DTLS --> success
1767// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1768// answer without SDES or DTLS --> success
1769//
1770
1771// Test that we return a failure when applying a remote/local offer that doesn't
1772// have cryptos enabled when DTLS is off.
1773TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001774 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001776 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001777 JsepSessionDescription* offer = CreateRemoteOffer(
1778 options, cricket::SEC_DISABLED);
1779 ASSERT_TRUE(offer != NULL);
1780 VerifyNoCryptoParams(offer->description(), false);
1781 // SetRemoteDescription and SetLocalDescription will take the ownership of
1782 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001783 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001784 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1785 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001786 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787}
1788
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001789// Test that we return a failure when applying a local answer that doesn't have
1790// cryptos enabled when DTLS is off.
1791TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001792 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001793 SessionDescriptionInterface* offer = NULL;
1794 SessionDescriptionInterface* answer = NULL;
1795 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1796 // SetRemoteDescription and SetLocalDescription will take the ownership of
1797 // the offer.
1798 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001799 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001800}
1801
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001802// Test we will return fail when apply an remote answer that doesn't have
1803// crypto enabled when DTLS is off.
1804TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001805 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001806 SessionDescriptionInterface* offer = NULL;
1807 SessionDescriptionInterface* answer = NULL;
1808 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1809 // SetRemoteDescription and SetLocalDescription will take the ownership of
1810 // the offer.
1811 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001812 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001813}
1814
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001815// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1816// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001817TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001818 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001819 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001820 SetFactoryDtlsSrtp();
1821 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001822 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001823 JsepSessionDescription* offer =
1824 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825 ASSERT_TRUE(offer != NULL);
1826 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001827 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001828
1829 // SetRemoteDescription will take the ownership of the offer.
1830 SetRemoteDescriptionWithoutError(offer);
1831
1832 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001833 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001834 ASSERT_TRUE(answer != NULL);
1835 VerifyFingerprintStatus(answer->description(), true);
1836 // Check that we don't have an a=crypto line in the answer.
1837 VerifyNoCryptoParams(answer->description(), true);
1838
1839 // Now set the local description, which should work, even without a=crypto.
1840 SetLocalDescriptionWithoutError(answer);
1841}
1842
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001843// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1844// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001845TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001846 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001847 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001848 SetFactoryDtlsSrtp();
1849
1850 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001851 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001852 ASSERT_TRUE(offer != NULL);
1853 VerifyFingerprintStatus(offer->description(), true);
1854 // Check that we don't have an a=crypto line in the offer.
1855 VerifyNoCryptoParams(offer->description(), true);
1856
1857 // Now set the local description, which should work, even without a=crypto.
1858 SetLocalDescriptionWithoutError(offer);
1859
1860 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001861 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001862 JsepSessionDescription* answer =
1863 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1864 ASSERT_TRUE(answer != NULL);
1865 VerifyFingerprintStatus(answer->description(), true);
1866 VerifyNoCryptoParams(answer->description(), true);
1867
1868 // SetRemoteDescription will take the ownership of the answer.
1869 SetRemoteDescriptionWithoutError(answer);
1870}
1871
1872// Test that if we support DTLS and the other side didn't offer a fingerprint,
1873// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001874TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02001875 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001876 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001877 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001878 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001879 JsepSessionDescription* offer = CreateRemoteOffer(
1880 options, cricket::SEC_REQUIRED);
1881 ASSERT_TRUE(offer != NULL);
1882 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001883 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001884
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001885 // SetRemoteDescription will take the ownership of the offer.
1886 SetRemoteDescriptionOfferExpectError(
1887 kSdpWithoutDtlsFingerprint, offer);
1888
1889 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1890 // SetLocalDescription will take the ownership of the offer.
1891 SetLocalDescriptionOfferExpectError(
1892 kSdpWithoutDtlsFingerprint, offer);
1893}
1894
1895// Test that we return a failure when applying a local answer that doesn't have
1896// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001897TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02001898 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001899 SessionDescriptionInterface* offer = NULL;
1900 SessionDescriptionInterface* answer = NULL;
1901 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1902
1903 // SetRemoteDescription and SetLocalDescription will take the ownership of
1904 // the offer and answer.
1905 SetRemoteDescriptionWithoutError(offer);
1906 SetLocalDescriptionAnswerExpectError(
1907 kSdpWithoutDtlsFingerprint, answer);
1908}
1909
1910// Test that we return a failure when applying a remote answer that doesn't have
1911// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001912TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02001913 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001914 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001915 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001916 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07001917 std::unique_ptr<SessionDescriptionInterface> temp_offer(
deadbeefcbecd352015-09-23 11:50:27 -07001918 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001919 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001920 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001921
1922 // SetRemoteDescription and SetLocalDescription will take the ownership of
1923 // the offer and answer.
1924 SetLocalDescriptionWithoutError(offer);
1925 SetRemoteDescriptionAnswerExpectError(
1926 kSdpWithoutDtlsFingerprint, answer);
1927}
1928
1929// Test that we create a local offer without SDES or DTLS and accept a remote
1930// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001931TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001932 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001933 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001934 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001935
1936 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001937 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001938 ASSERT_TRUE(offer != NULL);
1939 VerifyFingerprintStatus(offer->description(), false);
1940 // Check that we don't have an a=crypto line in the offer.
1941 VerifyNoCryptoParams(offer->description(), false);
1942
1943 // Now set the local description, which should work, even without a=crypto.
1944 SetLocalDescriptionWithoutError(offer);
1945
1946 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001947 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001948 JsepSessionDescription* answer =
1949 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1950 ASSERT_TRUE(answer != NULL);
1951 VerifyFingerprintStatus(answer->description(), false);
1952 VerifyNoCryptoParams(answer->description(), false);
1953
1954 // SetRemoteDescription will take the ownership of the answer.
1955 SetRemoteDescriptionWithoutError(answer);
1956}
1957
1958// Test that we create a local answer without SDES or DTLS and accept a remote
1959// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001960TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001961 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001962 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001963
1964 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001965 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001966 JsepSessionDescription* offer =
1967 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1968 ASSERT_TRUE(offer != NULL);
1969 VerifyFingerprintStatus(offer->description(), false);
1970 VerifyNoCryptoParams(offer->description(), false);
1971
1972 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001973 SetRemoteDescriptionWithoutError(offer);
1974
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001975 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001976 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001977 ASSERT_TRUE(answer != NULL);
1978 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001979 // Check that we don't have an a=crypto line in the answer.
1980 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001981
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001982 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001983 SetLocalDescriptionWithoutError(answer);
1984}
1985
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001986// Test that we can create and set an answer correctly when different
1987// SSL roles have been negotiated for different transports.
1988// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1989TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1990 SendAudioVideoStream1();
1991 InitWithDtls(GetParam());
1992 SetFactoryDtlsSrtp();
1993
1994 SessionDescriptionInterface* offer = CreateOffer();
1995 SetLocalDescriptionWithoutError(offer);
1996
1997 cricket::MediaSessionOptions options;
1998 options.recv_video = true;
1999
2000 // First, negotiate different SSL roles.
2001 SessionDescriptionInterface* answer =
2002 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
2003 TransportInfo* audio_transport_info =
2004 answer->description()->GetTransportInfoByName("audio");
2005 audio_transport_info->description.connection_role =
2006 cricket::CONNECTIONROLE_ACTIVE;
2007 TransportInfo* video_transport_info =
2008 answer->description()->GetTransportInfoByName("video");
2009 video_transport_info->description.connection_role =
2010 cricket::CONNECTIONROLE_PASSIVE;
2011 SetRemoteDescriptionWithoutError(answer);
2012
2013 // Now create an offer in the reverse direction, and ensure the initial
2014 // offerer responds with an answer with correct SSL roles.
2015 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2016 kSessionVersion,
2017 session_->remote_description());
2018 SetRemoteDescriptionWithoutError(offer);
2019
htaa2a49d92016-03-04 02:51:39 -08002020 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002021 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2022 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2023 audio_transport_info->description.connection_role);
2024 video_transport_info = answer->description()->GetTransportInfoByName("video");
2025 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
2026 video_transport_info->description.connection_role);
2027 SetLocalDescriptionWithoutError(answer);
2028
2029 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
2030 // audio is transferred over to video in the answer that completes the BUNDLE
2031 // negotiation.
2032 options.bundle_enabled = true;
2033 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2034 kSessionVersion,
2035 session_->remote_description());
2036 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08002037 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002038 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2039 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2040 audio_transport_info->description.connection_role);
2041 video_transport_info = answer->description()->GetTransportInfoByName("video");
2042 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2043 video_transport_info->description.connection_role);
2044 SetLocalDescriptionWithoutError(answer);
2045}
2046
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002047TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002048 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002049 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002050 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002051 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002052 SetLocalDescriptionWithoutError(offer);
2053
2054 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002055 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002056 SetLocalDescriptionWithoutError(offer2);
2057}
2058
2059TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002060 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002061 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002062 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002063 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002064 SetRemoteDescriptionWithoutError(offer);
2065
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002066 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002067 SetRemoteDescriptionWithoutError(offer2);
2068}
2069
2070TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002071 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002072 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002073 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002075 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002076 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2077 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002078}
2079
2080TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002081 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002082 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002083 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002085 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002086 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002087 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002088}
2089
2090TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002091 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002092 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002094 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095
htaa2a49d92016-03-04 02:51:39 -08002096 JsepSessionDescription* pranswer =
2097 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002098 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002099 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002100
deadbeefab9b2d12015-10-14 11:33:11 -07002101 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002102 JsepSessionDescription* pranswer2 =
2103 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002104 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2105
deadbeefd59daf82015-10-14 15:02:44 -07002106 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107
deadbeefab9b2d12015-10-14 11:33:11 -07002108 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002109 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002110 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002111}
2112
2113TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002114 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002115 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002116 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002117 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118
2119 JsepSessionDescription* pranswer =
2120 CreateRemoteAnswer(session_->local_description());
2121 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2122
2123 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002124 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002125
deadbeefab9b2d12015-10-14 11:33:11 -07002126 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002127 JsepSessionDescription* pranswer2 =
2128 CreateRemoteAnswer(session_->local_description());
2129 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2130
2131 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002132 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133
deadbeefab9b2d12015-10-14 11:33:11 -07002134 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002135 SessionDescriptionInterface* answer =
2136 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002137 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138}
2139
2140TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002141 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002142 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002143 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002144
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145 SessionDescriptionInterface* answer =
2146 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002147 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2148 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002149}
2150
2151TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002152 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002153 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002154 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002155
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002156 SessionDescriptionInterface* answer =
2157 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002158 SetRemoteDescriptionAnswerExpectError(
2159 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002160}
2161
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002162// Tests that the remote candidates are added and removed successfully.
2163TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002164 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002165 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002166
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002167 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
2168 "", "", "host", 0, "");
2169 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002170 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2171
deadbeefd59daf82015-10-14 15:02:44 -07002172 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002173 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2174
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002175 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002176 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002177
2178 // Fail since we have not set a remote description.
2179 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002180
2181 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2182 session_->local_description());
2183 SetRemoteDescriptionWithoutError(answer);
2184
deadbeefd59daf82015-10-14 15:02:44 -07002185 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2186 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002187 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002188 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2189 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2190
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002191 // Verifying the candidates are copied properly from internal vector.
2192 const SessionDescriptionInterface* remote_desc =
2193 session_->remote_description();
2194 ASSERT_TRUE(remote_desc != NULL);
2195 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2196 const IceCandidateCollection* candidates =
2197 remote_desc->candidates(kMediaContentIndex0);
2198 ASSERT_EQ(2u, candidates->count());
2199 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2200 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2201 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2202 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2203
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002204 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2205 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002206 candidate.set_component(2);
2207 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2208 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002209 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002210
2211 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2212 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002213
2214 // Remove candidate1 and candidate2
2215 std::vector<cricket::Candidate> remote_candidates;
2216 remote_candidates.push_back(ice_candidate1.candidate());
2217 remote_candidates.push_back(ice_candidate2.candidate());
2218 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2219 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002220}
2221
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002222// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002223// that it is retained if the remote session description is changed.
2224TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002225 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002226 cricket::Candidate candidate1;
2227 candidate1.set_component(1);
2228 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2229 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002230 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002231 CreateAndSetRemoteOfferAndLocalAnswer();
2232
2233 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2234 const SessionDescriptionInterface* remote_desc =
2235 session_->remote_description();
2236 ASSERT_TRUE(remote_desc != NULL);
2237 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2238 const IceCandidateCollection* candidates =
2239 remote_desc->candidates(kMediaContentIndex0);
2240 ASSERT_EQ(1u, candidates->count());
2241 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2242
2243 // Update the RemoteSessionDescription with a new session description and
2244 // a candidate and check that the new remote session description contains both
2245 // candidates.
2246 SessionDescriptionInterface* offer = CreateRemoteOffer();
2247 cricket::Candidate candidate2;
2248 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2249 candidate2);
2250 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2251 SetRemoteDescriptionWithoutError(offer);
2252
2253 remote_desc = session_->remote_description();
2254 ASSERT_TRUE(remote_desc != NULL);
2255 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2256 candidates = remote_desc->candidates(kMediaContentIndex0);
2257 ASSERT_EQ(2u, candidates->count());
2258 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2259 // Username and password have be updated with the TransportInfo of the
2260 // SessionDescription, won't be equal to the original one.
2261 candidate2.set_username(candidates->at(0)->candidate().username());
2262 candidate2.set_password(candidates->at(0)->candidate().password());
2263 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2264 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2265 // No need to verify the username and password.
2266 candidate1.set_username(candidates->at(1)->candidate().username());
2267 candidate1.set_password(candidates->at(1)->candidate().password());
2268 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2269
2270 // Test that the candidate is ignored if we can add the same candidate again.
2271 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2272}
2273
2274// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002275// that they are retained if the local session description is changed. And if
2276// continual gathering is enabled, they are removed from the local session
2277// description when the network is down.
2278TEST_F(WebRtcSessionTest,
2279 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002280 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002281 Init();
deadbeefb60a8192016-08-24 15:15:00 -07002282 // Enable Continual Gathering.
2283 cricket::IceConfig config;
2284 config.continual_gathering_policy = cricket::GATHER_CONTINUALLY;
2285 session_->SetIceConfig(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002286 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002287 CreateAndSetRemoteOfferAndLocalAnswer();
2288
2289 const SessionDescriptionInterface* local_desc = session_->local_description();
2290 const IceCandidateCollection* candidates =
2291 local_desc->candidates(kMediaContentIndex0);
2292 ASSERT_TRUE(candidates != NULL);
2293 EXPECT_EQ(0u, candidates->count());
2294
deadbeefb60a8192016-08-24 15:15:00 -07002295 // Since we're using continual gathering, we won't get "gathering done".
2296 EXPECT_EQ_WAIT(2u, candidates->count(), kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002297
2298 local_desc = session_->local_description();
2299 candidates = local_desc->candidates(kMediaContentIndex0);
2300 ASSERT_TRUE(candidates != NULL);
2301 EXPECT_LT(0u, candidates->count());
2302 candidates = local_desc->candidates(1);
2303 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002304 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002305
2306 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002307 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002308 CreateAndSetRemoteOfferAndLocalAnswer();
2309
2310 local_desc = session_->local_description();
2311 candidates = local_desc->candidates(kMediaContentIndex0);
2312 ASSERT_TRUE(candidates != NULL);
2313 EXPECT_LT(0u, candidates->count());
2314 candidates = local_desc->candidates(1);
2315 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002316 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002317
2318 candidates = local_desc->candidates(kMediaContentIndex0);
2319 size_t num_local_candidates = candidates->count();
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002320 // Bring down the network interface to trigger candidate removals.
2321 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2322 // Verify that all local candidates are removed.
2323 EXPECT_EQ(0, observer_.num_candidates_removed_);
2324 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2325 kIceCandidatesTimeout);
2326 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2327}
2328
2329// Tests that if continual gathering is disabled, local candidates won't be
2330// removed when the interface is turned down.
2331TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2332 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2333 Init();
2334 SendAudioVideoStream1();
2335 CreateAndSetRemoteOfferAndLocalAnswer();
2336
2337 const SessionDescriptionInterface* local_desc = session_->local_description();
2338 const IceCandidateCollection* candidates =
2339 local_desc->candidates(kMediaContentIndex0);
2340 ASSERT_TRUE(candidates != NULL);
2341 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2342
2343 size_t num_local_candidates = candidates->count();
2344 EXPECT_LT(0u, num_local_candidates);
2345 // By default, Continual Gathering is disabled.
2346 // Bring down the network interface.
2347 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2348 // Verify that the local candidates are not removed.
2349 rtc::Thread::Current()->ProcessMessages(1000);
2350 EXPECT_EQ(0, observer_.num_candidates_removed_);
2351 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002352}
2353
2354// Test that we can set a remote session description with remote candidates.
2355TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002356 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002357
2358 cricket::Candidate candidate1;
2359 candidate1.set_component(1);
2360 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2361 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002362 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002363 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002364
2365 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2366 SetRemoteDescriptionWithoutError(offer);
2367
2368 const SessionDescriptionInterface* remote_desc =
2369 session_->remote_description();
2370 ASSERT_TRUE(remote_desc != NULL);
2371 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2372 const IceCandidateCollection* candidates =
2373 remote_desc->candidates(kMediaContentIndex0);
2374 ASSERT_EQ(1u, candidates->count());
2375 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2376
htaa2a49d92016-03-04 02:51:39 -08002377 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002378 SetLocalDescriptionWithoutError(answer);
2379}
2380
2381// Test that offers and answers contains ice candidates when Ice candidates have
2382// been gathered.
2383TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002384 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002385 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002386 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002387 // Ice is started but candidates are not provided until SetLocalDescription
2388 // is called.
2389 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2390 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2391 CreateAndSetRemoteOfferAndLocalAnswer();
2392 // Wait until at least one local candidate has been collected.
2393 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2394 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002395
kwibergd1fe2812016-04-27 06:47:29 -07002396 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002397
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002398 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2399 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002400
2401 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2402 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002403 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002404 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2405 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002406 SetLocalDescriptionWithoutError(answer);
2407}
2408
2409// Verifies TransportProxy and media channels are created with content names
2410// present in the SessionDescription.
2411TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002412 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002413 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002414 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002415
2416 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002417 // "video". Goal is to modify these content names and verify transport
2418 // channels
2419 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002420 // present in SDP.
2421 std::string sdp;
2422 EXPECT_TRUE(offer->ToString(&sdp));
2423 const std::string kAudioMid = "a=mid:audio";
2424 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2425 const std::string kVideoMid = "a=mid:video";
2426 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2427
2428 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002429 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002430 kAudioMidReplaceStr.c_str(),
2431 kAudioMidReplaceStr.length(),
2432 &sdp);
2433 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002434 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002435 kVideoMidReplaceStr.c_str(),
2436 kVideoMidReplaceStr.length(),
2437 &sdp);
2438
2439 SessionDescriptionInterface* modified_offer =
2440 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2441
2442 SetRemoteDescriptionWithoutError(modified_offer);
2443
htaa2a49d92016-03-04 02:51:39 -08002444 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002445 SetLocalDescriptionWithoutError(answer);
2446
johan669d69b2016-11-08 14:14:08 -08002447 rtc::PacketTransportInterface* voice_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002448 session_->voice_rtp_transport_channel();
2449 EXPECT_TRUE(voice_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002450 EXPECT_EQ(voice_transport_channel->debug_name(),
2451 "audio_content_name " +
2452 std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
2453 rtc::PacketTransportInterface* video_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002454 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002455 ASSERT_TRUE(video_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002456 EXPECT_EQ(video_transport_channel->debug_name(),
2457 "video_content_name " +
2458 std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002459 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2460 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2461}
2462
2463// Test that an offer contains the correct media content descriptions based on
2464// the send streams when no constraints have been set.
2465TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002466 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002467 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002468
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002469 ASSERT_TRUE(offer != NULL);
2470 const cricket::ContentInfo* content =
2471 cricket::GetFirstAudioContent(offer->description());
2472 EXPECT_TRUE(content != NULL);
2473 content = cricket::GetFirstVideoContent(offer->description());
2474 EXPECT_TRUE(content == NULL);
2475}
2476
2477// Test that an offer contains the correct media content descriptions based on
2478// the send streams when no constraints have been set.
2479TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002480 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002481 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002482 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002483 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002484
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002485 const cricket::ContentInfo* content =
2486 cricket::GetFirstAudioContent(offer->description());
2487 EXPECT_TRUE(content != NULL);
2488 content = cricket::GetFirstVideoContent(offer->description());
2489 EXPECT_TRUE(content == NULL);
2490
2491 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002492 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002493 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002494 content = cricket::GetFirstAudioContent(offer->description());
2495 EXPECT_TRUE(content != NULL);
2496 content = cricket::GetFirstVideoContent(offer->description());
2497 EXPECT_TRUE(content != NULL);
2498}
2499
2500// Test that an offer contains no media content descriptions if
2501// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2502TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002503 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002504 PeerConnectionInterface::RTCOfferAnswerOptions options;
2505 options.offer_to_receive_audio = 0;
2506 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002507
kwibergd1fe2812016-04-27 06:47:29 -07002508 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002509
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002510 ASSERT_TRUE(offer != NULL);
2511 const cricket::ContentInfo* content =
2512 cricket::GetFirstAudioContent(offer->description());
2513 EXPECT_TRUE(content == NULL);
2514 content = cricket::GetFirstVideoContent(offer->description());
2515 EXPECT_TRUE(content == NULL);
2516}
2517
2518// Test that an offer contains only audio media content descriptions if
2519// kOfferToReceiveAudio constraints are set to true.
2520TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002521 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002522 PeerConnectionInterface::RTCOfferAnswerOptions options;
2523 options.offer_to_receive_audio =
2524 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2525
kwibergd1fe2812016-04-27 06:47:29 -07002526 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002527
2528 const cricket::ContentInfo* content =
2529 cricket::GetFirstAudioContent(offer->description());
2530 EXPECT_TRUE(content != NULL);
2531 content = cricket::GetFirstVideoContent(offer->description());
2532 EXPECT_TRUE(content == NULL);
2533}
2534
2535// Test that an offer contains audio and video media content descriptions if
2536// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2537TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002538 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002539 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002540 PeerConnectionInterface::RTCOfferAnswerOptions options;
2541 options.offer_to_receive_audio =
2542 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2543 options.offer_to_receive_video =
2544 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2545
kwibergd1fe2812016-04-27 06:47:29 -07002546 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002547
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002548 const cricket::ContentInfo* content =
2549 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002550 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002551
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002552 content = cricket::GetFirstVideoContent(offer->description());
2553 EXPECT_TRUE(content != NULL);
2554
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002555 // Sets constraints to false and verifies that audio/video contents are
2556 // removed.
2557 options.offer_to_receive_audio = 0;
2558 options.offer_to_receive_video = 0;
2559 offer.reset(CreateOffer(options));
2560
2561 content = cricket::GetFirstAudioContent(offer->description());
2562 EXPECT_TRUE(content == NULL);
2563 content = cricket::GetFirstVideoContent(offer->description());
2564 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002565}
2566
2567// Test that an answer can not be created if the last remote description is not
2568// an offer.
2569TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002570 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002571 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002572 SetLocalDescriptionWithoutError(offer);
2573 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2574 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002575 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002576}
2577
2578// Test that an answer contains the correct media content descriptions when no
2579// constraints have been set.
2580TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002581 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002582 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002583 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002584 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002585 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002586 const cricket::ContentInfo* content =
2587 cricket::GetFirstAudioContent(answer->description());
2588 ASSERT_TRUE(content != NULL);
2589 EXPECT_FALSE(content->rejected);
2590
2591 content = cricket::GetFirstVideoContent(answer->description());
2592 ASSERT_TRUE(content != NULL);
2593 EXPECT_FALSE(content->rejected);
2594}
2595
2596// Test that an answer contains the correct media content descriptions when no
2597// constraints have been set and the offer only contain audio.
2598TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002599 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002600 // Create a remote offer with audio only.
2601 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002602
kwibergd1fe2812016-04-27 06:47:29 -07002603 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002604 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2605 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2606
2607 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002608 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002609 const cricket::ContentInfo* content =
2610 cricket::GetFirstAudioContent(answer->description());
2611 ASSERT_TRUE(content != NULL);
2612 EXPECT_FALSE(content->rejected);
2613
2614 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2615}
2616
2617// Test that an answer contains the correct media content descriptions when no
2618// constraints have been set.
2619TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002620 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002621 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002622 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002623 SetRemoteDescriptionWithoutError(offer.release());
2624 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002625 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002626 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002627 const cricket::ContentInfo* content =
2628 cricket::GetFirstAudioContent(answer->description());
2629 ASSERT_TRUE(content != NULL);
2630 EXPECT_FALSE(content->rejected);
2631
2632 content = cricket::GetFirstVideoContent(answer->description());
2633 ASSERT_TRUE(content != NULL);
2634 EXPECT_FALSE(content->rejected);
2635}
2636
2637// Test that an answer contains the correct media content descriptions when
2638// constraints have been set but no stream is sent.
2639TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002640 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002641 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002642 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002643 SetRemoteDescriptionWithoutError(offer.release());
2644
htaa2a49d92016-03-04 02:51:39 -08002645 cricket::MediaSessionOptions session_options;
2646 session_options.recv_audio = false;
2647 session_options.recv_video = false;
kwibergd1fe2812016-04-27 06:47:29 -07002648 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002649 CreateAnswer(session_options));
2650
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002651 const cricket::ContentInfo* content =
2652 cricket::GetFirstAudioContent(answer->description());
2653 ASSERT_TRUE(content != NULL);
2654 EXPECT_TRUE(content->rejected);
2655
2656 content = cricket::GetFirstVideoContent(answer->description());
2657 ASSERT_TRUE(content != NULL);
2658 EXPECT_TRUE(content->rejected);
2659}
2660
2661// Test that an answer contains the correct media content descriptions when
2662// constraints have been set and streams are sent.
2663TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002664 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002665 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002666 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002667 SetRemoteDescriptionWithoutError(offer.release());
2668
htaa2a49d92016-03-04 02:51:39 -08002669 cricket::MediaSessionOptions options;
2670 options.recv_audio = false;
2671 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002672
2673 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002674 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002675 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002676
2677 // TODO(perkj): Should the direction be set to SEND_ONLY?
2678 const cricket::ContentInfo* content =
2679 cricket::GetFirstAudioContent(answer->description());
2680 ASSERT_TRUE(content != NULL);
2681 EXPECT_FALSE(content->rejected);
2682
2683 // TODO(perkj): Should the direction be set to SEND_ONLY?
2684 content = cricket::GetFirstVideoContent(answer->description());
2685 ASSERT_TRUE(content != NULL);
2686 EXPECT_FALSE(content->rejected);
2687}
2688
2689TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2690 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002691 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002692 PeerConnectionInterface::RTCOfferAnswerOptions options;
2693 options.offer_to_receive_audio =
2694 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2695 options.voice_activity_detection = false;
2696
kwibergd1fe2812016-04-27 06:47:29 -07002697 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002698
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002699 const cricket::ContentInfo* content =
2700 cricket::GetFirstAudioContent(offer->description());
2701 EXPECT_TRUE(content != NULL);
2702 EXPECT_TRUE(VerifyNoCNCodecs(content));
2703}
2704
2705TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2706 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002707 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002708 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002709 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002710 SetRemoteDescriptionWithoutError(offer.release());
2711
htaa2a49d92016-03-04 02:51:39 -08002712 cricket::MediaSessionOptions options;
2713 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002714 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002715 const cricket::ContentInfo* content =
2716 cricket::GetFirstAudioContent(answer->description());
2717 ASSERT_TRUE(content != NULL);
2718 EXPECT_TRUE(VerifyNoCNCodecs(content));
2719}
2720
2721// This test verifies the call setup when remote answer with audio only and
2722// later updates with video.
2723TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002724 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002725 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2726 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2727
deadbeefab9b2d12015-10-14 11:33:11 -07002728 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002729 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002730
2731 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002732 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2733
2734 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2735 // and answer;
2736 SetLocalDescriptionWithoutError(offer);
2737 SetRemoteDescriptionWithoutError(answer);
2738
2739 video_channel_ = media_engine_->GetVideoChannel(0);
2740 voice_channel_ = media_engine_->GetVoiceChannel(0);
2741
2742 ASSERT_TRUE(video_channel_ == NULL);
2743
2744 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2745 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2746 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2747
2748 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002749 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002750 CreateAndSetRemoteOfferAndLocalAnswer();
2751
2752 video_channel_ = media_engine_->GetVideoChannel(0);
2753 voice_channel_ = media_engine_->GetVoiceChannel(0);
2754
2755 ASSERT_TRUE(video_channel_ != NULL);
2756 ASSERT_TRUE(voice_channel_ != NULL);
2757
2758 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2759 ASSERT_EQ(1u, video_channel_->send_streams().size());
2760 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2761 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2762 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2763 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2764 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2765 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2766
2767 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002768 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002769 CreateAndSetRemoteOfferAndLocalAnswer();
2770
2771 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2772 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2773 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2774 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2775 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2776}
2777
2778// This test verifies the call setup when remote answer with video only and
2779// later updates with audio.
2780TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002781 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002782 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2783 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002784 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002785 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002786
2787 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002788 options.recv_audio = false;
2789 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002790 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2791 offer, options, cricket::SEC_ENABLED);
2792
2793 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2794 // and answer.
2795 SetLocalDescriptionWithoutError(offer);
2796 SetRemoteDescriptionWithoutError(answer);
2797
2798 video_channel_ = media_engine_->GetVideoChannel(0);
2799 voice_channel_ = media_engine_->GetVoiceChannel(0);
2800
2801 ASSERT_TRUE(voice_channel_ == NULL);
2802 ASSERT_TRUE(video_channel_ != NULL);
2803
2804 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2805 ASSERT_EQ(1u, video_channel_->send_streams().size());
2806 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2807
2808 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002809 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002810 CreateAndSetRemoteOfferAndLocalAnswer();
2811
2812 voice_channel_ = media_engine_->GetVoiceChannel(0);
2813 ASSERT_TRUE(voice_channel_ != NULL);
2814
2815 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2816 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2817 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2818 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2819
2820 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002821 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002822 CreateAndSetRemoteOfferAndLocalAnswer();
2823
2824 video_channel_ = media_engine_->GetVideoChannel(0);
2825 voice_channel_ = media_engine_->GetVoiceChannel(0);
2826
2827 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2828 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2829 ASSERT_EQ(1u, video_channel_->send_streams().size());
2830 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2831}
2832
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002833TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002834 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002835 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002836 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002837 VerifyCryptoParams(offer->description());
2838 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002839 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002840 VerifyCryptoParams(answer->description());
2841}
2842
jbauchcb560652016-08-04 05:20:32 -07002843TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDPGcm) {
2844 InitWithGcm();
2845 SendAudioVideoStream1();
2846 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
2847 VerifyCryptoParams(offer->description(), true);
2848 SetRemoteDescriptionWithoutError(offer.release());
2849 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
2850 VerifyCryptoParams(answer->description(), true);
2851}
2852
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002853TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002854 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002855 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002856 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002857 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002858 VerifyNoCryptoParams(offer->description(), false);
2859}
2860
2861TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002862 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002863 VerifyAnswerFromNonCryptoOffer();
2864}
2865
2866TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002867 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002868 VerifyAnswerFromCryptoOffer();
2869}
2870
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002871// This test verifies that setLocalDescription fails if
2872// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2873TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002874 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002875 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002876 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002877
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002878 std::string sdp;
2879 RemoveIceUfragPwdLines(offer.get(), &sdp);
2880 SessionDescriptionInterface* modified_offer =
2881 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002882 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002883}
2884
2885// This test verifies that setRemoteDescription fails if
2886// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2887TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002888 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002889 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002890 std::string sdp;
2891 RemoveIceUfragPwdLines(offer.get(), &sdp);
2892 SessionDescriptionInterface* modified_offer =
2893 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002894 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002895}
2896
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002897// This test verifies that setLocalDescription fails if local offer has
2898// too short ice ufrag and pwd strings.
2899TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002900 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002901 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002902 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002903 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2904 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002905 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002906 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002907 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002908
2909 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002910 offer.reset(CreateOffer());
2911 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2912 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002913}
2914
2915// This test verifies that setRemoteDescription fails if remote offer has
2916// too short ice ufrag and pwd strings.
2917TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002918 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002919 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002920 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2921 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002922 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002923 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002924 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002925
deadbeef0ed85b22016-02-23 17:24:52 -08002926 offer.reset(CreateRemoteOffer());
2927 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2928 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002929}
2930
Honghai Zhang04e91462015-12-11 14:26:22 -08002931// Test that if the remote offer indicates the peer requested ICE restart (via
2932// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2933TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002934 Init();
honghaiz503726c2015-07-31 12:37:38 -07002935
2936 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07002937 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08002938 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002939 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2940 0, "", "", "relay", 0, "");
2941 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2942 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002943 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2944 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002945 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2946
2947 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002948 offer.reset(CreateRemoteOffer());
2949 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002950 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2951 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2952 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002953 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2954 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002955 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2956
2957 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002958 offer.reset(CreateRemoteOffer());
2959 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002960 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2961 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2962 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002963 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2964 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002965 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2966
2967 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002968 offer.reset(CreateRemoteOffer());
2969 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2970 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002971 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2972}
2973
Honghai Zhang04e91462015-12-11 14:26:22 -08002974// Test that if the remote answer indicates the peer requested ICE restart (via
2975// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2976TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2977 Init();
2978 SessionDescriptionInterface* offer = CreateOffer();
2979 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002980
2981 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07002982 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08002983 answer->set_type(JsepSessionDescription::kPrAnswer);
2984 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002985 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2986 0, "", "", "relay", 0, "");
2987 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2988 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002989 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2990 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002991 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2992
2993 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002994 answer.reset(CreateRemoteAnswer(offer));
2995 answer->set_type(JsepSessionDescription::kPrAnswer);
2996 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002997 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2998 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2999 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003000 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
3001 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003002 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
3003
3004 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08003005 answer.reset(CreateRemoteAnswer(offer));
3006 answer->set_type(JsepSessionDescription::kPrAnswer);
3007 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08003008 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
3009 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
3010 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003011 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
3012 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003013 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
3014
3015 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08003016 answer.reset(CreateRemoteAnswer(offer));
3017 answer->set_type(JsepSessionDescription::kPrAnswer);
3018 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
3019 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003020 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
3021}
3022
Donald Curtisd4f769d2015-05-28 09:48:21 -07003023// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07003024// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07003025TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
3026 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
3027
3028 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003029 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003030
3031 PeerConnectionInterface::RTCOfferAnswerOptions options;
3032 options.use_rtp_mux = true;
3033
3034 SessionDescriptionInterface* offer = CreateRemoteOffer();
3035 SetRemoteDescriptionWithoutError(offer);
3036
htaa2a49d92016-03-04 02:51:39 -08003037 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003038 SetLocalDescriptionWithoutError(answer);
3039
deadbeefcbecd352015-09-23 11:50:27 -07003040 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3041 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07003042
deadbeefcbecd352015-09-23 11:50:27 -07003043 cricket::BaseChannel* voice_channel = session_->voice_channel();
nissec8ee8822017-01-18 07:20:55 -08003044 ASSERT_TRUE(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003045
3046 // Checks if one of the transport channels contains a connection using a given
3047 // port.
deadbeefcbecd352015-09-23 11:50:27 -07003048 auto connection_with_remote_port = [this, voice_channel](int port) {
hbosdf6075a2016-12-19 04:58:02 -08003049 std::unique_ptr<webrtc::SessionStats> stats = session_->GetStats_s();
3050 for (auto& kv : stats->transport_stats) {
deadbeefcbecd352015-09-23 11:50:27 -07003051 for (auto& chan_stat : kv.second.channel_stats) {
3052 for (auto& conn_info : chan_stat.connection_infos) {
3053 if (conn_info.remote_candidate.address().port() == port) {
3054 return true;
3055 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07003056 }
3057 }
3058 }
3059 return false;
3060 };
3061
3062 EXPECT_FALSE(connection_with_remote_port(5000));
3063 EXPECT_FALSE(connection_with_remote_port(5001));
3064 EXPECT_FALSE(connection_with_remote_port(6000));
3065
3066 // The way the *_WAIT checks work is they only wait if the condition fails,
3067 // which does not help in the case where state is not changing. This is
3068 // problematic in this test since we want to verify that adding a video
3069 // candidate does _not_ change state. So we interleave candidates and assume
3070 // that messages are executed in the order they were posted.
3071
3072 // First audio candidate.
3073 cricket::Candidate candidate0;
3074 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3075 candidate0.set_component(1);
3076 candidate0.set_protocol("udp");
3077 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3078 candidate0);
3079 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3080
3081 // Video candidate.
3082 cricket::Candidate candidate1;
3083 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3084 candidate1.set_component(1);
3085 candidate1.set_protocol("udp");
3086 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3087 candidate1);
3088 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3089
3090 // Second audio candidate.
3091 cricket::Candidate candidate2;
3092 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3093 candidate2.set_component(1);
3094 candidate2.set_protocol("udp");
3095 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3096 candidate2);
3097 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3098
3099 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3100 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3101
3102 // No need here for a _WAIT check since we are checking that state hasn't
3103 // changed: if this is false we would be doing waits for nothing and if this
3104 // is true then there will be no messages processed anyways.
3105 EXPECT_FALSE(connection_with_remote_port(6000));
3106}
3107
deadbeefcbecd352015-09-23 11:50:27 -07003108// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003109TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3110 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003111 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003112
3113 PeerConnectionInterface::RTCOfferAnswerOptions options;
3114 options.use_rtp_mux = true;
3115
3116 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003117 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003118
deadbeefcbecd352015-09-23 11:50:27 -07003119 EXPECT_NE(session_->voice_rtp_transport_channel(),
3120 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003121
deadbeefab9b2d12015-10-14 11:33:11 -07003122 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003123 SessionDescriptionInterface* answer =
3124 CreateRemoteAnswer(session_->local_description());
3125 SetRemoteDescriptionWithoutError(answer);
3126
deadbeefcbecd352015-09-23 11:50:27 -07003127 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3128 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003129}
3130
deadbeefcbecd352015-09-23 11:50:27 -07003131// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003132TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3133 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003134 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003135
Donald Curtis0e209b02015-03-24 09:29:54 -07003136 PeerConnectionInterface::RTCOfferAnswerOptions options;
3137 options.use_rtp_mux = true;
3138
3139 SessionDescriptionInterface* offer = CreateOffer(options);
3140 SetLocalDescriptionWithoutError(offer);
3141
deadbeefcbecd352015-09-23 11:50:27 -07003142 EXPECT_NE(session_->voice_rtp_transport_channel(),
3143 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003144
deadbeefab9b2d12015-10-14 11:33:11 -07003145 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003146
3147 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003148 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003149 CreateRemoteAnswer(session_->local_description()));
3150 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3151 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3152 JsepSessionDescription* modified_answer =
3153 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3154 modified_answer->Initialize(answer_copy, "1", "1");
3155 SetRemoteDescriptionWithoutError(modified_answer); //
3156
deadbeefcbecd352015-09-23 11:50:27 -07003157 EXPECT_NE(session_->voice_rtp_transport_channel(),
3158 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003159}
3160
3161// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3162TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3163 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003164 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003165
3166 PeerConnectionInterface::RTCOfferAnswerOptions options;
3167 options.use_rtp_mux = true;
3168
3169 SessionDescriptionInterface* offer = CreateOffer(options);
3170 SetLocalDescriptionWithoutError(offer);
3171
deadbeefcbecd352015-09-23 11:50:27 -07003172 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3173 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003174
deadbeefab9b2d12015-10-14 11:33:11 -07003175 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003176 SessionDescriptionInterface* answer =
3177 CreateRemoteAnswer(session_->local_description());
3178 SetRemoteDescriptionWithoutError(answer);
3179
deadbeefcbecd352015-09-23 11:50:27 -07003180 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3181 session_->video_rtp_transport_channel());
3182}
3183
3184// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3185// audio content in the answer.
3186TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3187 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003188 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003189
3190 PeerConnectionInterface::RTCOfferAnswerOptions options;
3191 options.use_rtp_mux = true;
3192
3193 SessionDescriptionInterface* offer = CreateOffer(options);
3194 SetLocalDescriptionWithoutError(offer);
3195
3196 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3197 session_->video_rtp_transport_channel());
3198
deadbeefab9b2d12015-10-14 11:33:11 -07003199 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003200 cricket::MediaSessionOptions recv_options;
3201 recv_options.recv_audio = false;
3202 recv_options.recv_video = true;
3203 SessionDescriptionInterface* answer =
3204 CreateRemoteAnswer(session_->local_description(), recv_options);
3205 SetRemoteDescriptionWithoutError(answer);
3206
deadbeefd59daf82015-10-14 15:02:44 -07003207 EXPECT_TRUE(nullptr == session_->voice_channel());
3208 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003209
deadbeefd59daf82015-10-14 15:02:44 -07003210 session_->Close();
3211 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3212 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3213 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3214 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003215}
3216
3217// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3218TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3219 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003220 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003221
Donald Curtis0e209b02015-03-24 09:29:54 -07003222 PeerConnectionInterface::RTCOfferAnswerOptions options;
3223 options.use_rtp_mux = true;
3224
3225 SessionDescriptionInterface* offer = CreateOffer(options);
3226 SetLocalDescriptionWithoutError(offer);
3227
deadbeefcbecd352015-09-23 11:50:27 -07003228 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3229 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003230
deadbeefab9b2d12015-10-14 11:33:11 -07003231 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003232
3233 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003234 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003235 CreateRemoteAnswer(session_->local_description()));
3236 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3237 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3238 JsepSessionDescription* modified_answer =
3239 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3240 modified_answer->Initialize(answer_copy, "1", "1");
3241 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003242
deadbeefcbecd352015-09-23 11:50:27 -07003243 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3244 session_->video_rtp_transport_channel());
3245}
3246
3247// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3248TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3249 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003250 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003251
3252 SessionDescriptionInterface* offer = CreateRemoteOffer();
3253 SetRemoteDescriptionWithoutError(offer);
3254
3255 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3256 session_->video_rtp_transport_channel());
3257
deadbeefab9b2d12015-10-14 11:33:11 -07003258 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003259 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003260 SetLocalDescriptionWithoutError(answer);
3261
3262 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3263 session_->video_rtp_transport_channel());
3264}
3265
3266// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3267TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3268 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003269 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003270
3271 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003272 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003273 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3274 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3275 JsepSessionDescription* modified_offer =
3276 new JsepSessionDescription(JsepSessionDescription::kOffer);
3277 modified_offer->Initialize(offer_copy, "1", "1");
3278
3279 // Expect an error when applying the remote description
3280 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3281 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003282}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003283
Peter Thatcher4eddf182015-04-30 10:55:59 -07003284// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003285TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3286 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003287 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003288
Donald Curtis0e209b02015-03-24 09:29:54 -07003289 PeerConnectionInterface::RTCOfferAnswerOptions options;
3290 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003291
Donald Curtis0e209b02015-03-24 09:29:54 -07003292 SessionDescriptionInterface* offer = CreateOffer(options);
3293 SetLocalDescriptionWithoutError(offer);
3294
deadbeefcbecd352015-09-23 11:50:27 -07003295 EXPECT_NE(session_->voice_rtp_transport_channel(),
3296 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003297
deadbeefab9b2d12015-10-14 11:33:11 -07003298 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003299 SessionDescriptionInterface* answer =
3300 CreateRemoteAnswer(session_->local_description());
3301 SetRemoteDescriptionWithoutError(answer);
3302
3303 // This should lead to an audio-only call but isn't implemented
3304 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003305 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3306 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003307}
3308
deadbeefcbecd352015-09-23 11:50:27 -07003309// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003310TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3311 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003312 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003313 PeerConnectionInterface::RTCOfferAnswerOptions options;
3314 options.use_rtp_mux = true;
3315
3316 SessionDescriptionInterface* offer = CreateOffer(options);
3317 SetLocalDescriptionWithoutError(offer);
3318
deadbeefcbecd352015-09-23 11:50:27 -07003319 EXPECT_NE(session_->voice_rtp_transport_channel(),
3320 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003321
deadbeefab9b2d12015-10-14 11:33:11 -07003322 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003323
3324 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003325 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003326 CreateRemoteAnswer(session_->local_description()));
3327 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3328 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3329 JsepSessionDescription* modified_answer =
3330 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3331 modified_answer->Initialize(answer_copy, "1", "1");
3332 SetRemoteDescriptionWithoutError(modified_answer); //
3333
deadbeefcbecd352015-09-23 11:50:27 -07003334 EXPECT_NE(session_->voice_rtp_transport_channel(),
3335 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003336}
3337
Peter Thatcher4eddf182015-04-30 10:55:59 -07003338// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3339TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3340 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003341 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003342
3343 PeerConnectionInterface::RTCOfferAnswerOptions options;
3344 options.use_rtp_mux = true;
3345
3346 SessionDescriptionInterface* offer = CreateOffer(options);
3347 SetRemoteDescriptionWithoutError(offer);
3348
deadbeefcbecd352015-09-23 11:50:27 -07003349 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3350 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003351}
3352
skvlad6c87a672016-05-17 17:49:52 -07003353// Adding a new channel to a BUNDLE which is already connected should directly
3354// assign the bundle transport to the channel, without first setting a
3355// disconnected non-bundle transport and then replacing it. The application
3356// should not receive any changes in the ICE state.
3357TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) {
3358 LoopbackNetworkConfiguration config;
3359 LoopbackNetworkManager loopback_network_manager(this, config);
3360 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain
3361 // connected. Disabling either of these two means that we need to wait for the
3362 // answer to find out if more transports are needed.
3363 configuration_.bundle_policy =
3364 PeerConnectionInterface::kBundlePolicyMaxBundle;
skvlad6c87a672016-05-17 17:49:52 -07003365 options_.disable_encryption = true;
zhihuang4dfb8ce2016-11-23 10:30:12 -08003366 Init(PeerConnectionInterface::kRtcpMuxPolicyRequire);
skvlad6c87a672016-05-17 17:49:52 -07003367
3368 // Negotiate an audio channel with MAX_BUNDLE enabled.
3369 SendAudioOnlyStream2();
3370 SessionDescriptionInterface* offer = CreateOffer();
3371 SetLocalDescriptionWithoutError(offer);
3372 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
3373 observer_.ice_gathering_state_, kIceCandidatesTimeout);
3374 std::string sdp;
3375 offer->ToString(&sdp);
3376 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription(
3377 JsepSessionDescription::kAnswer, sdp, nullptr);
3378 ASSERT_TRUE(answer != NULL);
3379 SetRemoteDescriptionWithoutError(answer);
3380
3381 // Wait for the ICE state to stabilize.
3382 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3383 observer_.ice_connection_state_, kIceCandidatesTimeout);
3384 observer_.ice_connection_state_history_.clear();
3385
3386 // Now add a video channel which should be using the same bundle transport.
3387 SendAudioVideoStream2();
3388 offer = CreateOffer();
3389 offer->ToString(&sdp);
3390 SetLocalDescriptionWithoutError(offer);
3391 answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer,
3392 sdp, nullptr);
3393 ASSERT_TRUE(answer != NULL);
3394 SetRemoteDescriptionWithoutError(answer);
3395
3396 // Wait for ICE state to stabilize
3397 rtc::Thread::Current()->ProcessMessages(0);
3398 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3399 observer_.ice_connection_state_, kIceCandidatesTimeout);
3400
3401 // No ICE state changes are expected to happen.
3402 EXPECT_EQ(0, observer_.ice_connection_state_history_.size());
3403}
3404
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003405TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3406 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003407 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003408
3409 PeerConnectionInterface::RTCOfferAnswerOptions options;
3410 SessionDescriptionInterface* offer = CreateOffer(options);
3411 SetLocalDescriptionWithoutError(offer);
3412
deadbeefcbecd352015-09-23 11:50:27 -07003413 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3414 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003415
deadbeefab9b2d12015-10-14 11:33:11 -07003416 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003417 SessionDescriptionInterface* answer =
3418 CreateRemoteAnswer(session_->local_description());
3419 SetRemoteDescriptionWithoutError(answer);
3420
deadbeefcbecd352015-09-23 11:50:27 -07003421 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3422 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003423}
3424
3425TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3426 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003427 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003428
3429 PeerConnectionInterface::RTCOfferAnswerOptions options;
3430 SessionDescriptionInterface* offer = CreateOffer(options);
3431 SetLocalDescriptionWithoutError(offer);
3432
deadbeefcbecd352015-09-23 11:50:27 -07003433 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3434 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003435
deadbeefab9b2d12015-10-14 11:33:11 -07003436 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003437 SessionDescriptionInterface* answer =
3438 CreateRemoteAnswer(session_->local_description());
3439 SetRemoteDescriptionWithoutError(answer);
3440
deadbeefcbecd352015-09-23 11:50:27 -07003441 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3442 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003443}
3444
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003445// This test verifies that SetLocalDescription and SetRemoteDescription fails
3446// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3447TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003448 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003449 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003450
3451 PeerConnectionInterface::RTCOfferAnswerOptions options;
3452 options.use_rtp_mux = true;
3453
3454 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003455 std::string offer_str;
3456 offer->ToString(&offer_str);
3457 // Disable rtcp-mux
3458 const std::string rtcp_mux = "rtcp-mux";
3459 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003460 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003461 xrtcp_mux.c_str(), xrtcp_mux.length(),
3462 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003463 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003464 new JsepSessionDescription(JsepSessionDescription::kOffer);
3465 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003466 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003467 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003468 new JsepSessionDescription(JsepSessionDescription::kOffer);
3469 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003470 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003471 // Trying unmodified SDP.
3472 SetLocalDescriptionWithoutError(offer);
3473}
3474
jbauchcb560652016-08-04 05:20:32 -07003475TEST_F(WebRtcSessionTest, SetSetupGcm) {
3476 InitWithGcm();
3477 SendAudioVideoStream1();
3478 CreateAndSetRemoteOfferAndLocalAnswer();
3479}
3480
deadbeefd59daf82015-10-14 15:02:44 -07003481// This test verifies the |initial_offerer| flag when session initiates the
3482// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003483TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003484 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003485 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003486 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003487 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3488 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003489 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003490 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003491 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003492}
3493
deadbeefd59daf82015-10-14 15:02:44 -07003494// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003495TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003496 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003497 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003498 SessionDescriptionInterface* offer = CreateRemoteOffer();
3499 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003500 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003501
deadbeefd59daf82015-10-14 15:02:44 -07003502 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003503 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003504 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003505}
3506
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003507// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3508TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003509 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003510 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003511 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003512 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003513 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003514 CreateRemoteAnswer(session_->local_description()));
3515
3516 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3517 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003518 JsepSessionDescription* modified_answer =
3519 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003520
3521 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3522 answer->session_id(),
3523 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003524 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003525
wu@webrtc.org4e393072014-04-07 17:04:35 +00003526 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003527 std::string sdp;
3528 EXPECT_TRUE(answer->ToString(&sdp));
3529 const std::string kAudioMid = "a=mid:audio";
3530 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003531 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003532 kAudioMidReplaceStr.c_str(),
3533 kAudioMidReplaceStr.length(),
3534 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003535 SessionDescriptionInterface* modified_answer1 =
3536 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003537 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003538
wu@webrtc.org4e393072014-04-07 17:04:35 +00003539 // Different media types.
3540 EXPECT_TRUE(answer->ToString(&sdp));
3541 const std::string kAudioMline = "m=audio";
3542 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003543 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003544 kAudioMlineReplaceStr.c_str(),
3545 kAudioMlineReplaceStr.length(),
3546 &sdp);
3547 SessionDescriptionInterface* modified_answer2 =
3548 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3549 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3550
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003551 SetRemoteDescriptionWithoutError(answer.release());
3552}
3553
3554// Verifying remote offer and local answer have matching m-lines as per
3555// RFC 3264.
3556TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003557 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003558 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003559 SessionDescriptionInterface* offer = CreateRemoteOffer();
3560 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003561 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003562
3563 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3564 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003565 JsepSessionDescription* modified_answer =
3566 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003567
3568 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3569 answer->session_id(),
3570 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003571 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003572 SetLocalDescriptionWithoutError(answer);
3573}
3574
3575// This test verifies that WebRtcSession does not start candidate allocation
3576// before SetLocalDescription is called.
3577TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003578 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003579 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003580 SessionDescriptionInterface* offer = CreateRemoteOffer();
3581 cricket::Candidate candidate;
3582 candidate.set_component(1);
3583 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3584 candidate);
3585 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3586 cricket::Candidate candidate1;
3587 candidate1.set_component(1);
3588 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3589 candidate1);
3590 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3591 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003592 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3593 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003594
3595 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003596 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003597 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3598 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3599
htaa2a49d92016-03-04 02:51:39 -08003600 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003601 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003602 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3603}
3604
3605// This test verifies that crypto parameter is updated in local session
3606// description as per security policy set in MediaSessionDescriptionFactory.
3607TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003608 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003609 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003610 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003611
3612 // Making sure SetLocalDescription correctly sets crypto value in
3613 // SessionDescription object after de-serialization of sdp string. The value
3614 // will be set as per MediaSessionDescriptionFactory.
3615 std::string offer_str;
3616 offer->ToString(&offer_str);
3617 SessionDescriptionInterface* jsep_offer_str =
3618 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3619 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003620 EXPECT_TRUE(session_->voice_channel()->srtp_required_for_testing());
3621 EXPECT_TRUE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003622}
3623
3624// This test verifies the crypto parameter when security is disabled.
3625TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003626 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003627 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003628 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003629 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003630
3631 // Making sure SetLocalDescription correctly sets crypto value in
3632 // SessionDescription object after de-serialization of sdp string. The value
3633 // will be set as per MediaSessionDescriptionFactory.
3634 std::string offer_str;
3635 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003636 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003637 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3638 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003639 EXPECT_FALSE(session_->voice_channel()->srtp_required_for_testing());
3640 EXPECT_FALSE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003641}
3642
3643// This test verifies that an answer contains new ufrag and password if an offer
3644// with new ufrag and password is received.
3645TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003646 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003647 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003648 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003649 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003650 SetRemoteDescriptionWithoutError(offer.release());
3651
deadbeefab9b2d12015-10-14 11:33:11 -07003652 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003653 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003654 SetLocalDescriptionWithoutError(answer.release());
3655
3656 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003657 for (const cricket::ContentInfo& content :
3658 session_->local_description()->description()->contents()) {
3659 options.transport_options[content.name].ice_restart = true;
3660 }
kwibergd1fe2812016-04-27 06:47:29 -07003661 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003662 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003663 SetRemoteDescriptionWithoutError(updated_offer1.release());
3664
kwibergd1fe2812016-04-27 06:47:29 -07003665 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003666
deadbeef0ed85b22016-02-23 17:24:52 -08003667 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3668 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003669
deadbeef0ed85b22016-02-23 17:24:52 -08003670 // Even a second answer (created before the description is set) should have
3671 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003672 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003673
3674 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3675 session_->local_description()->description()));
3676
3677 SetLocalDescriptionWithoutError(updated_answer2.release());
3678}
3679
3680// This test verifies that an answer contains new ufrag and password if an offer
3681// that changes either the ufrag or password (but not both) is received.
3682// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3683// a=ice-pwd attributes compared to the previous SDP from the peer, it
3684// indicates that ICE is restarting for this media stream."
3685TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3686 Init();
3687 cricket::MediaSessionOptions options;
3688 options.recv_audio = true;
3689 options.recv_video = true;
3690 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003691 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003692 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3693 SetRemoteDescriptionWithoutError(offer.release());
3694
3695 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003696 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003697 SetLocalDescriptionWithoutError(answer.release());
3698
3699 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003700 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003701 CreateRemoteOffer(options, session_->remote_description()));
3702 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3703 "original_password12345");
3704 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3705
kwibergd1fe2812016-04-27 06:47:29 -07003706 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003707 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3708 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003709 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003710
3711 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003712 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003713 CreateRemoteOffer(options, session_->remote_description()));
3714 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3715 "modified_password12345");
3716 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3717
kwibergd1fe2812016-04-27 06:47:29 -07003718 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003719 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3720 session_->local_description()->description()));
3721 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003722}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003723
wu@webrtc.org91053e72013-08-10 07:18:04 +00003724// This test verifies that an answer contains old ufrag and password if an offer
3725// with old ufrag and password is received.
3726TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003727 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003728 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003729 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003730 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003731 SetRemoteDescriptionWithoutError(offer.release());
3732
deadbeefab9b2d12015-10-14 11:33:11 -07003733 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003734 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003735 SetLocalDescriptionWithoutError(answer.release());
3736
3737 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003738 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003739 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003740 SetRemoteDescriptionWithoutError(updated_offer2.release());
3741
kwibergd1fe2812016-04-27 06:47:29 -07003742 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003743
deadbeef0ed85b22016-02-23 17:24:52 -08003744 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3745 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003746
3747 SetLocalDescriptionWithoutError(updated_answer2.release());
3748}
3749
deadbeef0ed85b22016-02-23 17:24:52 -08003750// This test verifies that if an offer does an ICE restart on some, but not all
3751// media sections, the answer will change the ufrag/password in the correct
3752// media sections.
3753TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3754 Init();
3755 cricket::MediaSessionOptions options;
3756 options.recv_video = true;
3757 options.recv_audio = true;
3758 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003759 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003760
3761 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3762 "aaaaaaaaaaaaaaaaaaaaaa");
3763 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3764 "bbbbbbbbbbbbbbbbbbbbbb");
3765 SetRemoteDescriptionWithoutError(offer.release());
3766
3767 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003768 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003769 SetLocalDescriptionWithoutError(answer.release());
3770
3771 // Receive an offer with new ufrag and password, but only for the video media
3772 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003773 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003774 CreateRemoteOffer(options, session_->remote_description()));
3775 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3776 "cccccccccccccccccccccc");
3777 SetRemoteDescriptionWithoutError(updated_offer.release());
3778
kwibergd1fe2812016-04-27 06:47:29 -07003779 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003780
3781 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3782 session_->local_description()->description(),
3783 cricket::MEDIA_TYPE_AUDIO));
3784
3785 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3786 session_->local_description()->description(),
3787 cricket::MEDIA_TYPE_VIDEO));
3788
3789 SetLocalDescriptionWithoutError(updated_answer.release());
3790}
3791
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003792TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003793 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003794 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003795 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003796 const std::string session_id_orig = offer->session_id();
3797 const std::string session_version_orig = offer->session_version();
3798 SetLocalDescriptionWithoutError(offer);
3799
3800 video_channel_ = media_engine_->GetVideoChannel(0);
3801 video_channel_->set_fail_set_send_codecs(true);
3802
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003803 SessionDescriptionInterface* answer =
3804 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003805 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003806
3807 // Test that after a content error, setting any description will
3808 // result in an error.
3809 video_channel_->set_fail_set_send_codecs(false);
3810 answer = CreateRemoteAnswer(session_->local_description());
3811 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3812 offer = CreateRemoteOffer();
3813 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003814}
3815
3816// Runs the loopback call test with BUNDLE and STUN disabled.
3817TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3818 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003819 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003820 cricket::PORTALLOCATOR_DISABLE_STUN |
3821 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003822 TestLoopbackCall();
3823}
3824
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003825TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003826 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003827 cricket::PORTALLOCATOR_DISABLE_STUN |
3828 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3829 cricket::PORTALLOCATOR_DISABLE_RELAY);
3830
3831 // best connection is IPv6 since it has higher network preference.
3832 LoopbackNetworkConfiguration config;
3833 config.test_ipv6_network_ = true;
3834 config.best_connection_after_initial_ice_converged_ =
3835 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3836
3837 TestLoopbackCall(config);
3838}
3839
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003840// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003841TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003842 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3843 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003844 TestLoopbackCall();
3845}
3846
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003847TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003848 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003849 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003850 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003851 ASSERT_TRUE(data_engine_);
deadbeef953c2ce2017-01-09 14:53:41 -08003852 EXPECT_NE(nullptr, data_engine_->GetChannel(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003853}
3854
Henrik Boström87713d02015-08-25 09:53:21 +02003855TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
htaa2a49d92016-03-04 02:51:39 -08003856 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003857 options_.disable_sctp_data_channels = false;
3858
Henrik Boström87713d02015-08-25 09:53:21 +02003859 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003860
3861 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003862 EXPECT_NE(nullptr, data_engine_->GetChannel(0));
3863}
3864
3865// Test that sctp_content_name/sctp_transport_name (used for stats) are correct
3866// before and after BUNDLE is negotiated.
3867TEST_P(WebRtcSessionTest, SctpContentAndTransportName) {
deadbeef953c2ce2017-01-09 14:53:41 -08003868 SetFactoryDtlsSrtp();
3869 InitWithDtls(GetParam());
3870
3871 // Initially these fields should be empty.
3872 EXPECT_FALSE(session_->sctp_content_name());
3873 EXPECT_FALSE(session_->sctp_transport_name());
3874
3875 // Create offer with audio/video/data.
3876 // Default bundle policy is "balanced", so data should be using its own
3877 // transport.
3878 SendAudioVideoStream1();
3879 CreateDataChannel();
3880 InitiateCall();
3881 ASSERT_TRUE(session_->sctp_content_name());
3882 ASSERT_TRUE(session_->sctp_transport_name());
3883 EXPECT_EQ("data", *session_->sctp_content_name());
3884 EXPECT_EQ("data", *session_->sctp_transport_name());
3885
3886 // Create answer that finishes BUNDLE negotiation, which means everything
3887 // should be bundled on the first transport (audio).
3888 cricket::MediaSessionOptions answer_options;
3889 answer_options.recv_video = true;
3890 answer_options.bundle_enabled = true;
3891 answer_options.data_channel_type = cricket::DCT_SCTP;
3892 SetRemoteDescriptionWithoutError(CreateRemoteAnswer(
3893 session_->local_description(), answer_options, cricket::SEC_DISABLED));
3894 ASSERT_TRUE(session_->sctp_content_name());
3895 ASSERT_TRUE(session_->sctp_transport_name());
3896 EXPECT_EQ("data", *session_->sctp_content_name());
3897 EXPECT_EQ("audio", *session_->sctp_transport_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003898}
3899
Henrik Boström87713d02015-08-25 09:53:21 +02003900TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
Henrik Boström87713d02015-08-25 09:53:21 +02003901 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003902
kwibergd1fe2812016-04-27 06:47:29 -07003903 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003904 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003905 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3906}
3907
Henrik Boström87713d02015-08-25 09:53:21 +02003908TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003909 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003910 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003911
3912 // Create remote offer with SCTP.
3913 cricket::MediaSessionOptions options;
3914 options.data_channel_type = cricket::DCT_SCTP;
3915 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003916 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003917 SetRemoteDescriptionWithoutError(offer);
3918
3919 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07003920 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003921 EXPECT_TRUE(answer != NULL);
3922 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3923 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003924}
3925
deadbeef953c2ce2017-01-09 14:53:41 -08003926// Test that if DTLS is disabled, we don't end up with an SctpTransport
3927// created (or an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02003928TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003929 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003930 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003931
3932 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003933 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
3934 EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003935}
3936
deadbeef953c2ce2017-01-09 14:53:41 -08003937// Test that if DTLS is enabled, we end up with an SctpTransport created
3938// (and not an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02003939TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
Henrik Boström87713d02015-08-25 09:53:21 +02003940 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003941
3942 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003943 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
3944 EXPECT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003945}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003946
deadbeef953c2ce2017-01-09 14:53:41 -08003947// Test that if SCTP is disabled, we don't end up with an SctpTransport
3948// created (or an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02003949TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003950 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003951 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003952
3953 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003954 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
3955 EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003956}
3957
Henrik Boström87713d02015-08-25 09:53:21 +02003958TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003959 const int new_send_port = 9998;
3960 const int new_recv_port = 7775;
3961
Henrik Boström87713d02015-08-25 09:53:21 +02003962 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003963 SetFactoryDtlsSrtp();
3964
3965 // By default, don't actually add the codecs to desc_factory_; they don't
3966 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3967 // let the session description get parsed. That'll get the proper codecs
3968 // into the stream.
3969 cricket::MediaSessionOptions options;
3970 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3971 "stream1", new_send_port, options);
3972
3973 // SetRemoteDescription will take the ownership of the offer.
3974 SetRemoteDescriptionWithoutError(offer);
3975
htaa2a49d92016-03-04 02:51:39 -08003976 SessionDescriptionInterface* answer =
3977 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003978 ASSERT_TRUE(answer != NULL);
3979
3980 // Now set the local description, which'll take ownership of the answer.
3981 SetLocalDescriptionWithoutError(answer);
3982
3983 // TEST PLAN: Set the port number to something new, set it in the SDP,
3984 // and pass it all the way down.
deadbeef953c2ce2017-01-09 14:53:41 -08003985 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003986 CreateDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003987 ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
3988 EXPECT_EQ(
3989 new_recv_port,
3990 fake_sctp_transport_factory_->last_fake_sctp_transport()->local_port());
3991 EXPECT_EQ(
3992 new_send_port,
3993 fake_sctp_transport_factory_->last_fake_sctp_transport()->remote_port());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003994}
3995
deadbeef953c2ce2017-01-09 14:53:41 -08003996// Verifies that when a session's SctpTransport receives an OPEN message,
3997// WebRtcSession signals the SctpTransport creation request with the expected
deadbeefab9b2d12015-10-14 11:33:11 -07003998// config.
3999TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
deadbeefab9b2d12015-10-14 11:33:11 -07004000 InitWithDtls(GetParam());
4001
4002 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004003 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4004 ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
deadbeefab9b2d12015-10-14 11:33:11 -07004005
deadbeef953c2ce2017-01-09 14:53:41 -08004006 // Make the fake SCTP transport pretend it received an OPEN message.
deadbeefab9b2d12015-10-14 11:33:11 -07004007 webrtc::DataChannelInit config;
4008 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07004009 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07004010 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4011 cricket::ReceiveDataParams params;
4012 params.ssrc = config.id;
4013 params.type = cricket::DMT_CONTROL;
deadbeef953c2ce2017-01-09 14:53:41 -08004014 fake_sctp_transport_factory_->last_fake_sctp_transport()->SignalDataReceived(
4015 params, payload);
deadbeefab9b2d12015-10-14 11:33:11 -07004016
deadbeef953c2ce2017-01-09 14:53:41 -08004017 EXPECT_EQ_WAIT("a", last_data_channel_label_, kDefaultTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07004018 EXPECT_EQ(config.id, last_data_channel_config_.id);
4019 EXPECT_FALSE(last_data_channel_config_.negotiated);
4020 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4021 last_data_channel_config_.open_handshake_role);
4022}
4023
4024TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004025 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
Henrik Boströmd79599d2016-06-01 13:58:50 +02004026 FakeRTCCertificateGenerator::GenerateCertificate();
Henrik Boströmd8281982015-08-27 10:12:24 +02004027
htaa2a49d92016-03-04 02:51:39 -08004028 configuration_.certificates.push_back(certificate);
4029 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004030 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4031
4032 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4033}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004034
Henrik Boström87713d02015-08-25 09:53:21 +02004035// Verifies that CreateOffer succeeds when CreateOffer is called before async
4036// identity generation is finished (even if a certificate is provided this is
4037// an async op).
4038TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004039 InitWithDtls(GetParam());
4040
Henrik Boströmd8281982015-08-27 10:12:24 +02004041 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004042 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07004043 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004044
wu@webrtc.org91053e72013-08-10 07:18:04 +00004045 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004046 VerifyNoCryptoParams(offer->description(), true);
4047 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004048}
4049
4050// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004051// identity generation is finished (even if a certificate is provided this is
4052// an async op).
4053TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004054 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004055 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004056
4057 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004058 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07004059 std::unique_ptr<JsepSessionDescription> offer(
4060 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004061 ASSERT_TRUE(offer.get() != NULL);
4062 SetRemoteDescriptionWithoutError(offer.release());
4063
kwibergd1fe2812016-04-27 06:47:29 -07004064 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004065 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004066 VerifyNoCryptoParams(answer->description(), true);
4067 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004068}
4069
4070// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004071// identity generation is finished (even if a certificate is provided this is
4072// an async op).
4073TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004074 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004075
Henrik Boströmd8281982015-08-27 10:12:24 +02004076 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004077
kwibergd1fe2812016-04-27 06:47:29 -07004078 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004079 EXPECT_TRUE(offer != NULL);
4080}
4081
4082// Verifies that CreateOffer fails when CreateOffer is called after async
4083// identity generation fails.
4084TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004085 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004086
Henrik Boströmd8281982015-08-27 10:12:24 +02004087 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004088
kwibergd1fe2812016-04-27 06:47:29 -07004089 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004090 EXPECT_TRUE(offer == NULL);
4091}
4092
4093// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4094// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004095TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004096 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
deadbeefcbecd352015-09-23 11:50:27 -07004097 VerifyMultipleAsyncCreateDescription(GetParam(),
4098 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004099}
4100
4101// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4102// before async identity generation fails.
4103TEST_F(WebRtcSessionTest,
4104 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004105 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4106 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004107}
4108
4109// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4110// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004111TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004112 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00004113 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004114 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004115}
4116
4117// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4118// before async identity generation fails.
4119TEST_F(WebRtcSessionTest,
4120 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004121 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4122 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004123}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004124
4125// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4126// offer has no SDES crypto but only DTLS fingerprint.
4127TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4128 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004129 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004130 // Create a remote offer with secured transport disabled.
4131 cricket::MediaSessionOptions options;
4132 JsepSessionDescription* offer(CreateRemoteOffer(
4133 options, cricket::SEC_DISABLED));
4134 // Adds a DTLS fingerprint to the remote offer.
4135 cricket::SessionDescription* sdp = offer->description();
4136 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4137 ASSERT_TRUE(audio != NULL);
4138 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4139 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004140 rtc::SSLFingerprint::CreateFromRfc4572(
4141 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004142 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004143 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004144}
4145
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004146TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004147 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004148 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004149 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004150 SessionDescriptionInterface* offer = CreateOffer();
4151
4152 SetLocalDescriptionWithoutError(offer);
4153
4154 voice_channel_ = media_engine_->GetVoiceChannel(0);
4155
4156 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004157 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004158 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004159}
4160
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004161// Tests that we can renegotiate new media content with ICE candidates in the
4162// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004163TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
Henrik Boström87713d02015-08-25 09:53:21 +02004164 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004165 SetFactoryDtlsSrtp();
4166
deadbeefab9b2d12015-10-14 11:33:11 -07004167 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004168 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004169 SetLocalDescriptionWithoutError(offer);
4170
4171 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4172 SetRemoteDescriptionWithoutError(answer);
4173
4174 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004175 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004176 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4177
4178 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004179 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004180 candidate1.set_component(1);
4181 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4182 candidate1);
4183 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4184 SetRemoteDescriptionWithoutError(offer);
4185
htaa2a49d92016-03-04 02:51:39 -08004186 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004187 SetLocalDescriptionWithoutError(answer);
4188}
4189
4190// Tests that we can renegotiate new media content with ICE candidates separated
4191// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004192TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
Henrik Boström87713d02015-08-25 09:53:21 +02004193 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004194 SetFactoryDtlsSrtp();
4195
deadbeefab9b2d12015-10-14 11:33:11 -07004196 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004197 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004198 SetLocalDescriptionWithoutError(offer);
4199
4200 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4201 SetRemoteDescriptionWithoutError(answer);
4202
4203 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004204 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004205 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4206 SetRemoteDescriptionWithoutError(offer);
4207
4208 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004209 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004210 candidate1.set_component(1);
4211 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4212 candidate1);
4213 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4214
htaa2a49d92016-03-04 02:51:39 -08004215 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004216 SetLocalDescriptionWithoutError(answer);
4217}
honghaiz7f777492016-02-02 21:54:01 -08004218
zhihuang9763d562016-08-05 11:14:50 -07004219#ifdef HAVE_QUIC
4220TEST_P(WebRtcSessionTest, TestNegotiateQuic) {
4221 configuration_.enable_quic = true;
4222 InitWithDtls(GetParam());
4223 EXPECT_TRUE(session_->data_channel_type() == cricket::DCT_QUIC);
4224 SessionDescriptionInterface* offer = CreateOffer();
4225 ASSERT_TRUE(offer);
4226 ASSERT_TRUE(offer->description());
4227 SetLocalDescriptionWithoutError(offer);
4228 cricket::MediaSessionOptions options;
4229 options.recv_audio = true;
4230 options.recv_video = true;
4231 SessionDescriptionInterface* answer =
4232 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
4233 ASSERT_TRUE(answer);
4234 ASSERT_TRUE(answer->description());
4235 SetRemoteDescriptionWithoutError(answer);
4236}
4237#endif // HAVE_QUIC
4238
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004239// Tests that RTX codec is removed from the answer when it isn't supported
4240// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004241TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004242 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004243 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004244 std::string offer_sdp(kSdpWithRtx);
4245
4246 SessionDescriptionInterface* offer =
4247 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4248 EXPECT_TRUE(offer->ToString(&offer_sdp));
4249
4250 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004251 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004252 SetRemoteDescriptionWithoutError(offer);
4253
htaa2a49d92016-03-04 02:51:39 -08004254 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004255 // Answer SDP does not contain the RTX codec.
4256 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004257 SetLocalDescriptionWithoutError(answer);
4258}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004259
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004260// This verifies that the voice channel after bundle has both options from video
4261// and voice channels.
4262TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4263 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004264 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004265
4266 PeerConnectionInterface::RTCOfferAnswerOptions options;
4267 options.use_rtp_mux = true;
4268
4269 SessionDescriptionInterface* offer = CreateOffer(options);
4270 SetLocalDescriptionWithoutError(offer);
4271
4272 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4273 rtc::Socket::Option::OPT_SNDBUF, 4000);
4274
4275 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4276 rtc::Socket::Option::OPT_RCVBUF, 8000);
4277
4278 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004279 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004280 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4281 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004282 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004283 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4284
deadbeefcbecd352015-09-23 11:50:27 -07004285 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004286 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4287 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004288 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004289 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4290
deadbeefcbecd352015-09-23 11:50:27 -07004291 EXPECT_NE(session_->voice_rtp_transport_channel(),
4292 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004293
deadbeefab9b2d12015-10-14 11:33:11 -07004294 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004295 SessionDescriptionInterface* answer =
4296 CreateRemoteAnswer(session_->local_description());
4297 SetRemoteDescriptionWithoutError(answer);
4298
deadbeefcbecd352015-09-23 11:50:27 -07004299 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004300 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4301 EXPECT_EQ(4000, option_val);
4302
deadbeefcbecd352015-09-23 11:50:27 -07004303 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004304 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4305 EXPECT_EQ(8000, option_val);
4306}
4307
tommi0f620f42015-07-09 03:25:02 -07004308// Test creating a session, request multiple offers, destroy the session
4309// and make sure we got success/failure callbacks for all of the requests.
4310// Background: crbug.com/507307
4311TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4312 Init();
4313
4314 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4315 PeerConnectionInterface::RTCOfferAnswerOptions options;
4316 options.offer_to_receive_audio =
4317 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004318 cricket::MediaSessionOptions session_options;
4319 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004320
4321 for (auto& o : observers) {
4322 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004323 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004324 }
4325
4326 session_.reset();
4327
tommi0f620f42015-07-09 03:25:02 -07004328 for (auto& o : observers) {
4329 // We expect to have received a notification now even if the session was
4330 // terminated. The offer creation may or may not have succeeded, but we
4331 // must have received a notification which, so the only invalid state
4332 // is kInit.
4333 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4334 }
4335}
4336
stefanc1aeaf02015-10-15 07:26:07 -07004337TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4338 TestPacketOptions();
4339}
4340
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004341// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4342// currently fails because upon disconnection and reconnection OnIceComplete is
4343// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004344
deadbeefcbecd352015-09-23 11:50:27 -07004345INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4346 WebRtcSessionTest,
4347 testing::Values(ALREADY_GENERATED,
4348 DTLS_IDENTITY_STORE));