blob: 757e14e0497fe23347176da952f8f842f91ef984 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
jbauch555604a2016-04-26 03:13:22 -070011#include <memory>
kwiberg0eb15ed2015-12-17 03:04:15 -080012#include <utility>
deadbeefcbecd352015-09-23 11:50:27 -070013#include <vector>
14
Henrik Kjellander15583c12016-02-10 10:53:12 +010015#include "webrtc/api/fakemetricsobserver.h"
16#include "webrtc/api/jsepicecandidate.h"
17#include "webrtc/api/jsepsessiondescription.h"
nissec80e7412017-01-11 05:56:46 -080018#include "webrtc/base/checks.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000019#include "webrtc/base/fakenetwork.h"
20#include "webrtc/base/firewallsocketserver.h"
21#include "webrtc/base/gunit.h"
22#include "webrtc/base/logging.h"
23#include "webrtc/base/network.h"
24#include "webrtc/base/physicalsocketserver.h"
25#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020026#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000027#include "webrtc/base/sslstreamadapter.h"
28#include "webrtc/base/stringutils.h"
29#include "webrtc/base/thread.h"
30#include "webrtc/base/virtualsocketserver.h"
skvlad11a9cbf2016-10-07 11:53:05 -070031#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
kjellandera96e2d72016-02-04 23:52:28 -080032#include "webrtc/media/base/fakemediaengine.h"
33#include "webrtc/media/base/fakevideorenderer.h"
34#include "webrtc/media/base/mediachannel.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010035#include "webrtc/media/engine/fakewebrtccall.h"
deadbeef953c2ce2017-01-09 14:53:41 -080036#include "webrtc/media/sctp/sctptransportinternal.h"
deadbeef5bd5ca32017-02-10 11:31:50 -080037#include "webrtc/p2p/base/packettransportinternal.h"
kjellandera96e2d72016-02-04 23:52:28 -080038#include "webrtc/p2p/base/stunserver.h"
39#include "webrtc/p2p/base/teststunserver.h"
40#include "webrtc/p2p/base/testturnserver.h"
kjellandera96e2d72016-02-04 23:52:28 -080041#include "webrtc/p2p/client/basicportallocator.h"
ossu7bb87ee2017-01-23 04:56:25 -080042#include "webrtc/pc/audiotrack.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010043#include "webrtc/pc/channelmanager.h"
ossu7bb87ee2017-01-23 04:56:25 -080044#include "webrtc/pc/fakemediacontroller.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010045#include "webrtc/pc/mediasession.h"
ossu7bb87ee2017-01-23 04:56:25 -080046#include "webrtc/pc/peerconnection.h"
47#include "webrtc/pc/sctputils.h"
48#include "webrtc/pc/test/fakertccertificategenerator.h"
49#include "webrtc/pc/videotrack.h"
50#include "webrtc/pc/webrtcsession.h"
51#include "webrtc/pc/webrtcsessiondescriptionfactory.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000052
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000054using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000055using rtc::SocketAddress;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000056using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000058using webrtc::CreateSessionDescriptionObserver;
59using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070060using webrtc::DataChannel;
jbauchac8869e2015-07-03 01:36:14 -070061using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070063using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064using webrtc::JsepIceCandidate;
65using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000066using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067using webrtc::PeerConnectionInterface;
68using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070069using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000071using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000072using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000073using webrtc::kCreateChannelFailed;
74using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000076using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000077using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000078using webrtc::kSdpWithoutDtlsFingerprint;
79using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000081using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000082using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +000084typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
85
wu@webrtc.org364f2042013-11-20 21:49:41 +000086static const int kClientAddrPort = 0;
87static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +000088static const char kClientIPv6AddrHost1[] =
89 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +000090static const char kClientAddrHost2[] = "22.22.22.22";
91static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +000092static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
93static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +000094static const char kTurnUsername[] = "test";
95static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096
97static const char kSessionVersion[] = "1";
98
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099// Media index of candidates belonging to the first media content.
100static const int kMediaContentIndex0 = 0;
101static const char kMediaContentName0[] = "audio";
102
103// Media index of candidates belonging to the second media content.
104static const int kMediaContentIndex1 = 1;
105static const char kMediaContentName1[] = "video";
106
deadbeef953c2ce2017-01-09 14:53:41 -0800107static const int kDefaultTimeout = 10000; // 10 seconds.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108static const int kIceCandidatesTimeout = 10000;
109
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000110static const char kFakeDtlsFingerprint[] =
111 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
112 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
113
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000114static const char kTooLongIceUfragPwd[] =
115 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
116 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
117 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
118 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
119
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000120static const char kSdpWithRtx[] =
121 "v=0\r\n"
122 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
123 "s=-\r\n"
124 "t=0 0\r\n"
125 "a=msid-semantic: WMS stream1\r\n"
126 "m=video 9 RTP/SAVPF 0 96\r\n"
127 "c=IN IP4 0.0.0.0\r\n"
128 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
129 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
130 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
131 "a=mid:video\r\n"
132 "a=sendrecv\r\n"
133 "a=rtcp-mux\r\n"
134 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
135 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
136 "a=rtpmap:0 fake_video_codec/90000\r\n"
137 "a=rtpmap:96 rtx/90000\r\n"
138 "a=fmtp:96 apt=0\r\n";
139
deadbeefab9b2d12015-10-14 11:33:11 -0700140static const char kStream1[] = "stream1";
141static const char kVideoTrack1[] = "video1";
142static const char kAudioTrack1[] = "audio1";
143
144static const char kStream2[] = "stream2";
145static const char kVideoTrack2[] = "video2";
146static const char kAudioTrack2[] = "audio2";
147
Henrik Boström87713d02015-08-25 09:53:21 +0200148enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
149
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150class MockIceObserver : public webrtc::IceObserver {
151 public:
152 MockIceObserver()
153 : oncandidatesready_(false),
154 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
155 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
156 }
157
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200158 virtual ~MockIceObserver() = default;
159
zstein6dfd53a2017-03-06 13:49:03 -0800160 void OnIceConnectionStateChange(
perkjdfb769d2016-02-09 03:09:43 -0800161 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000162 ice_connection_state_ = new_state;
skvlad6c87a672016-05-17 17:49:52 -0700163 ice_connection_state_history_.push_back(new_state);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164 }
perkjdfb769d2016-02-09 03:09:43 -0800165 void OnIceGatheringChange(
166 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167 // We can never transition back to "new".
168 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
169 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800170 oncandidatesready_ =
171 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172 }
173
174 // Found a new candidate.
jbauch81bf7b02017-03-25 08:31:12 -0700175 void OnIceCandidate(
176 std::unique_ptr<webrtc::IceCandidateInterface> candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000177 switch (candidate->sdp_mline_index()) {
178 case kMediaContentIndex0:
179 mline_0_candidates_.push_back(candidate->candidate());
180 break;
181 case kMediaContentIndex1:
182 mline_1_candidates_.push_back(candidate->candidate());
183 break;
184 default:
nissec80e7412017-01-11 05:56:46 -0800185 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000186 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000187
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000188 // The ICE gathering state should always be Gathering when a candidate is
189 // received (or possibly Completed in the case of the final candidate).
190 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
191 }
192
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700193 // Some local candidates are removed.
194 void OnIceCandidatesRemoved(
nisseef8b61e2016-04-29 06:09:15 -0700195 const std::vector<cricket::Candidate>& candidates) override {
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700196 num_candidates_removed_ += candidates.size();
197 }
198
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000199 bool oncandidatesready_;
200 std::vector<cricket::Candidate> mline_0_candidates_;
201 std::vector<cricket::Candidate> mline_1_candidates_;
202 PeerConnectionInterface::IceConnectionState ice_connection_state_;
203 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
skvlad6c87a672016-05-17 17:49:52 -0700204 std::vector<PeerConnectionInterface::IceConnectionState>
205 ice_connection_state_history_;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700206 size_t num_candidates_removed_ = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207};
208
deadbeef953c2ce2017-01-09 14:53:41 -0800209// Used for tests in this file to verify that WebRtcSession responds to signals
210// from the SctpTransport correctly, and calls Start with the correct
211// local/remote ports.
212class FakeSctpTransport : public cricket::SctpTransportInternal {
213 public:
deadbeef5bd5ca32017-02-10 11:31:50 -0800214 void SetTransportChannel(rtc::PacketTransportInternal* channel) override {}
deadbeef953c2ce2017-01-09 14:53:41 -0800215 bool Start(int local_port, int remote_port) override {
216 local_port_ = local_port;
217 remote_port_ = remote_port;
218 return true;
219 }
220 bool OpenStream(int sid) override { return true; }
221 bool ResetStream(int sid) override { return true; }
222 bool SendData(const cricket::SendDataParams& params,
223 const rtc::CopyOnWriteBuffer& payload,
224 cricket::SendDataResult* result = nullptr) override {
225 return true;
226 }
227 bool ReadyToSendData() override { return true; }
228 void set_debug_name_for_testing(const char* debug_name) override {}
229
230 int local_port() const { return local_port_; }
231 int remote_port() const { return remote_port_; }
232
233 private:
234 int local_port_ = -1;
235 int remote_port_ = -1;
236};
237
238class FakeSctpTransportFactory : public cricket::SctpTransportInternalFactory {
239 public:
240 std::unique_ptr<cricket::SctpTransportInternal> CreateSctpTransport(
deadbeef5bd5ca32017-02-10 11:31:50 -0800241 rtc::PacketTransportInternal*) override {
deadbeef953c2ce2017-01-09 14:53:41 -0800242 last_fake_sctp_transport_ = new FakeSctpTransport();
243 return std::unique_ptr<cricket::SctpTransportInternal>(
244 last_fake_sctp_transport_);
245 }
246
247 FakeSctpTransport* last_fake_sctp_transport() {
248 return last_fake_sctp_transport_;
249 }
250
251 private:
252 FakeSctpTransport* last_fake_sctp_transport_ = nullptr;
253};
254
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255class WebRtcSessionForTest : public webrtc::WebRtcSession {
256 public:
zhihuang29ff8442016-07-27 11:07:25 -0700257 WebRtcSessionForTest(
258 webrtc::MediaControllerInterface* media_controller,
259 rtc::Thread* network_thread,
260 rtc::Thread* worker_thread,
261 rtc::Thread* signaling_thread,
262 cricket::PortAllocator* port_allocator,
263 webrtc::IceObserver* ice_observer,
deadbeef953c2ce2017-01-09 14:53:41 -0800264 std::unique_ptr<cricket::TransportController> transport_controller,
265 std::unique_ptr<FakeSctpTransportFactory> sctp_factory)
stefanc1aeaf02015-10-15 07:26:07 -0700266 : WebRtcSession(media_controller,
danilchape9021a32016-05-17 01:52:02 -0700267 network_thread,
stefanc1aeaf02015-10-15 07:26:07 -0700268 worker_thread,
danilchape9021a32016-05-17 01:52:02 -0700269 signaling_thread,
zhihuang29ff8442016-07-27 11:07:25 -0700270 port_allocator,
deadbeef953c2ce2017-01-09 14:53:41 -0800271 std::move(transport_controller),
272 std::move(sctp_factory)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000273 RegisterIceObserver(ice_observer);
274 }
275 virtual ~WebRtcSessionForTest() {}
276
deadbeefcbecd352015-09-23 11:50:27 -0700277 // Note that these methods are only safe to use if the signaling thread
278 // is the same as the worker thread
deadbeef5bd5ca32017-02-10 11:31:50 -0800279 rtc::PacketTransportInternal* voice_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700280 return rtp_transport_channel(voice_channel());
281 }
282
deadbeef5bd5ca32017-02-10 11:31:50 -0800283 rtc::PacketTransportInternal* voice_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700284 return rtcp_transport_channel(voice_channel());
285 }
286
deadbeef5bd5ca32017-02-10 11:31:50 -0800287 rtc::PacketTransportInternal* video_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700288 return rtp_transport_channel(video_channel());
289 }
290
deadbeef5bd5ca32017-02-10 11:31:50 -0800291 rtc::PacketTransportInternal* video_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700292 return rtcp_transport_channel(video_channel());
293 }
294
deadbeefcbecd352015-09-23 11:50:27 -0700295 private:
deadbeef5bd5ca32017-02-10 11:31:50 -0800296 rtc::PacketTransportInternal* rtp_transport_channel(
johan669d69b2016-11-08 14:14:08 -0800297 cricket::BaseChannel* ch) {
deadbeefcbecd352015-09-23 11:50:27 -0700298 if (!ch) {
299 return nullptr;
300 }
zhihuangb2cdd932017-01-19 16:54:25 -0800301 return ch->rtp_dtls_transport();
deadbeefcbecd352015-09-23 11:50:27 -0700302 }
303
deadbeef5bd5ca32017-02-10 11:31:50 -0800304 rtc::PacketTransportInternal* rtcp_transport_channel(
johan669d69b2016-11-08 14:14:08 -0800305 cricket::BaseChannel* ch) {
deadbeefcbecd352015-09-23 11:50:27 -0700306 if (!ch) {
307 return nullptr;
308 }
zhihuangb2cdd932017-01-19 16:54:25 -0800309 return ch->rtcp_dtls_transport();
deadbeefcbecd352015-09-23 11:50:27 -0700310 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311};
312
wu@webrtc.org91053e72013-08-10 07:18:04 +0000313class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000314 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000315 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000316 enum State {
317 kInit,
318 kFailed,
319 kSucceeded,
320 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000321 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000322
323 // CreateSessionDescriptionObserver implementation.
324 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000325 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000326 state_ = kSucceeded;
327 }
328 virtual void OnFailure(const std::string& error) {
329 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330 }
331
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000332 SessionDescriptionInterface* description() { return description_.get(); }
333
334 SessionDescriptionInterface* ReleaseDescription() {
335 return description_.release();
336 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000337
wu@webrtc.org91053e72013-08-10 07:18:04 +0000338 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000339
wu@webrtc.org91053e72013-08-10 07:18:04 +0000340 protected:
341 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000342
343 private:
kwibergd1fe2812016-04-27 06:47:29 -0700344 std::unique_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000345 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000346};
347
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800348class FakeAudioSource : public cricket::AudioSource {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000349 public:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800350 FakeAudioSource() : sink_(NULL) {}
351 virtual ~FakeAudioSource() {
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000352 if (sink_)
353 sink_->OnClose();
354 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000355
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000356 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000357
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800358 const cricket::AudioSource::Sink* sink() const { return sink_; }
359
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000360 private:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800361 cricket::AudioSource::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000362};
363
Henrik Boström87713d02015-08-25 09:53:21 +0200364class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700365 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
366 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000367 protected:
368 // TODO Investigate why ChannelManager crashes, if it's created
369 // after stun_server.
370 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700371 : media_engine_(new cricket::FakeMediaEngine()),
372 data_engine_(new cricket::FakeDataEngine()),
deadbeef112b2e92017-02-10 20:13:37 -0800373 channel_manager_(new cricket::ChannelManager(
374 std::unique_ptr<cricket::MediaEngineInterface>(media_engine_),
375 std::unique_ptr<cricket::DataEngineInterface>(data_engine_),
376 rtc::Thread::Current())),
skvlad11a9cbf2016-10-07 11:53:05 -0700377 fake_call_(webrtc::Call::Config(&event_log_)),
stefanc1aeaf02015-10-15 07:26:07 -0700378 media_controller_(
nisse51542be2016-02-12 02:27:06 -0800379 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
380 rtc::Thread::Current(),
skvlad11a9cbf2016-10-07 11:53:05 -0700381 channel_manager_.get(),
382 &event_log_)),
stefanc1aeaf02015-10-15 07:26:07 -0700383 tdesc_factory_(new cricket::TransportDescriptionFactory()),
384 desc_factory_(
385 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
386 tdesc_factory_.get())),
387 pss_(new rtc::PhysicalSocketServer),
388 vss_(new rtc::VirtualSocketServer(pss_.get())),
389 fss_(new rtc::FirewallSocketServer(vss_.get())),
390 ss_scope_(fss_.get()),
391 stun_socket_addr_(
392 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
393 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
394 stun_socket_addr_)),
395 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
396 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000397 cricket::ServerAddresses stun_servers;
398 stun_servers.insert(stun_socket_addr_);
399 allocator_.reset(new cricket::BasicPortAllocator(
400 &network_manager_,
401 stun_servers,
402 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000403 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700404 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000405 EXPECT_TRUE(channel_manager_->Init());
406 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000407 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000408 }
409
410 void AddInterface(const SocketAddress& addr) {
411 network_manager_.AddInterface(addr);
412 }
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700413 void RemoveInterface(const SocketAddress& addr) {
414 network_manager_.RemoveInterface(addr);
415 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000416
Henrik Boströmd79599d2016-06-01 13:58:50 +0200417 // If |cert_generator| != null or |rtc_configuration| contains |certificates|
418 // then DTLS will be enabled unless explicitly disabled by |rtc_configuration|
419 // options. When DTLS is enabled a certificate will be used if provided,
420 // otherwise one will be generated using the |cert_generator|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000421 void Init(
zhihuang4dfb8ce2016-11-23 10:30:12 -0800422 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
deadbeef7914b8c2017-04-21 03:23:33 -0700423 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy,
424 const rtc::CryptoOptions& crypto_options) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000425 ASSERT_TRUE(session_.get() == NULL);
deadbeef953c2ce2017-01-09 14:53:41 -0800426 fake_sctp_transport_factory_ = new FakeSctpTransportFactory();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000427 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700428 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
zhihuang29ff8442016-07-27 11:07:25 -0700429 rtc::Thread::Current(), allocator_.get(), &observer_,
430 std::unique_ptr<cricket::TransportController>(
deadbeef7914b8c2017-04-21 03:23:33 -0700431 new cricket::TransportController(
432 rtc::Thread::Current(), rtc::Thread::Current(),
433 allocator_.get(),
434 /*redetermine_role_on_ice_restart=*/true, crypto_options)),
deadbeef953c2ce2017-01-09 14:53:41 -0800435 std::unique_ptr<FakeSctpTransportFactory>(
436 fake_sctp_transport_factory_)));
deadbeefab9b2d12015-10-14 11:33:11 -0700437 session_->SignalDataChannelOpenMessage.connect(
438 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000439
zhihuang4dfb8ce2016-11-23 10:30:12 -0800440 configuration_.rtcp_mux_policy = rtcp_mux_policy;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000441 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
442 observer_.ice_connection_state_);
443 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
444 observer_.ice_gathering_state_);
445
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200446 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator),
htaa2a49d92016-03-04 02:51:39 -0800447 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700448 session_->set_metrics_observer(metrics_observer_);
deadbeef7914b8c2017-04-21 03:23:33 -0700449 crypto_options_ = crypto_options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000450 }
451
deadbeefab9b2d12015-10-14 11:33:11 -0700452 void OnDataChannelOpenMessage(const std::string& label,
453 const InternalDataChannelInit& config) {
454 last_data_channel_label_ = label;
455 last_data_channel_config_ = config;
456 }
457
zhihuang4dfb8ce2016-11-23 10:30:12 -0800458 void Init() {
deadbeef7914b8c2017-04-21 03:23:33 -0700459 Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate,
460 rtc::CryptoOptions());
zhihuang4dfb8ce2016-11-23 10:30:12 -0800461 }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000462
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000463 void InitWithBundlePolicy(
464 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800465 configuration_.bundle_policy = bundle_policy;
466 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700467 }
468
469 void InitWithRtcpMuxPolicy(
470 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
471 PeerConnectionInterface::RTCConfiguration configuration;
deadbeef7914b8c2017-04-21 03:23:33 -0700472 Init(nullptr, rtcp_mux_policy, rtc::CryptoOptions());
473 }
474
475 void InitWithCryptoOptions(const rtc::CryptoOptions& crypto_options) {
476 Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate,
477 crypto_options);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000478 }
479
Henrik Boström87713d02015-08-25 09:53:21 +0200480 // Successfully init with DTLS; with a certificate generated and supplied or
481 // with a store that generates it for us.
482 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200483 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator;
Henrik Boström87713d02015-08-25 09:53:21 +0200484 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800485 configuration_.certificates.push_back(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200486 FakeRTCCertificateGenerator::GenerateCertificate());
Henrik Boström87713d02015-08-25 09:53:21 +0200487 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200488 cert_generator.reset(new FakeRTCCertificateGenerator());
489 cert_generator->set_should_fail(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200490 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700491 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200492 }
zhihuang4dfb8ce2016-11-23 10:30:12 -0800493 Init(std::move(cert_generator),
deadbeef7914b8c2017-04-21 03:23:33 -0700494 PeerConnectionInterface::kRtcpMuxPolicyNegotiate,
495 rtc::CryptoOptions());
Henrik Boström87713d02015-08-25 09:53:21 +0200496 }
497
498 // Init with DTLS with a store that will fail to generate a certificate.
499 void InitWithDtlsIdentityGenFail() {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200500 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
501 new FakeRTCCertificateGenerator());
502 cert_generator->set_should_fail(true);
zhihuang4dfb8ce2016-11-23 10:30:12 -0800503 Init(std::move(cert_generator),
deadbeef7914b8c2017-04-21 03:23:33 -0700504 PeerConnectionInterface::kRtcpMuxPolicyNegotiate,
505 rtc::CryptoOptions());
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000506 }
507
jbauchcb560652016-08-04 05:20:32 -0700508 void InitWithGcm() {
509 rtc::CryptoOptions crypto_options;
510 crypto_options.enable_gcm_crypto_suites = true;
deadbeef7914b8c2017-04-21 03:23:33 -0700511 InitWithCryptoOptions(crypto_options);
jbauchcb560652016-08-04 05:20:32 -0700512 }
513
deadbeefab9b2d12015-10-14 11:33:11 -0700514 void SendAudioVideoStream1() {
515 send_stream_1_ = true;
516 send_stream_2_ = false;
517 send_audio_ = true;
518 send_video_ = true;
519 }
520
521 void SendAudioVideoStream2() {
522 send_stream_1_ = false;
523 send_stream_2_ = true;
524 send_audio_ = true;
525 send_video_ = true;
526 }
527
528 void SendAudioVideoStream1And2() {
529 send_stream_1_ = true;
530 send_stream_2_ = true;
531 send_audio_ = true;
532 send_video_ = true;
533 }
534
535 void SendNothing() {
536 send_stream_1_ = false;
537 send_stream_2_ = false;
538 send_audio_ = false;
539 send_video_ = false;
540 }
541
542 void SendAudioOnlyStream2() {
543 send_stream_1_ = false;
544 send_stream_2_ = true;
545 send_audio_ = true;
546 send_video_ = false;
547 }
548
549 void SendVideoOnlyStream2() {
550 send_stream_1_ = false;
551 send_stream_2_ = true;
552 send_audio_ = false;
553 send_video_ = true;
554 }
555
556 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
557 if (send_stream_1_ && send_audio_) {
558 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
559 kStream1);
560 }
561 if (send_stream_1_ && send_video_) {
562 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
563 kStream1);
564 }
565 if (send_stream_2_ && send_audio_) {
566 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
567 kStream2);
568 }
569 if (send_stream_2_ && send_video_) {
570 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
571 kStream2);
572 }
573 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
574 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
575 data_channel_->label(),
576 data_channel_->label());
577 }
578 }
579
580 void GetOptionsForOffer(
581 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
582 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800583 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700584
deadbeefc80741f2015-10-22 13:14:45 -0700585 AddStreamsToOptions(session_options);
586 if (rtc_options.offer_to_receive_audio ==
587 RTCOfferAnswerOptions::kUndefined) {
588 session_options->recv_audio =
589 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
590 }
591 if (rtc_options.offer_to_receive_video ==
592 RTCOfferAnswerOptions::kUndefined) {
593 session_options->recv_video =
594 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
595 }
596 session_options->bundle_enabled =
597 session_options->bundle_enabled &&
598 (session_options->has_audio() || session_options->has_video() ||
599 session_options->has_data());
600
deadbeefab9b2d12015-10-14 11:33:11 -0700601 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
602 session_options->data_channel_type = cricket::DCT_SCTP;
zhihuang9763d562016-08-05 11:14:50 -0700603 } else if (session_->data_channel_type() == cricket::DCT_QUIC) {
604 session_options->data_channel_type = cricket::DCT_QUIC;
deadbeefab9b2d12015-10-14 11:33:11 -0700605 }
jbauchcb560652016-08-04 05:20:32 -0700606
deadbeef7914b8c2017-04-21 03:23:33 -0700607 session_options->crypto_options = crypto_options_;
deadbeefab9b2d12015-10-14 11:33:11 -0700608 }
609
htaa2a49d92016-03-04 02:51:39 -0800610 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
611 // ParseConstraintsForAnswer is used to set some defaults.
612 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700613
deadbeefc80741f2015-10-22 13:14:45 -0700614 AddStreamsToOptions(session_options);
615 session_options->bundle_enabled =
616 session_options->bundle_enabled &&
617 (session_options->has_audio() || session_options->has_video() ||
618 session_options->has_data());
619
zhihuang9763d562016-08-05 11:14:50 -0700620 if (session_->data_channel_type() != cricket::DCT_RTP) {
621 session_options->data_channel_type = session_->data_channel_type();
deadbeef907abe42016-08-04 12:22:18 -0700622 }
jbauchcb560652016-08-04 05:20:32 -0700623
deadbeef7914b8c2017-04-21 03:23:33 -0700624 session_options->crypto_options = crypto_options_;
deadbeefab9b2d12015-10-14 11:33:11 -0700625 }
626
627 // Creates a local offer and applies it. Starts ICE.
628 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000629 // to decide which streams to create.
630 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000631 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000632 SetLocalDescriptionWithoutError(offer);
633 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
634 observer_.ice_gathering_state_,
635 kIceCandidatesTimeout);
636 }
637
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000638 SessionDescriptionInterface* CreateOffer() {
639 PeerConnectionInterface::RTCOfferAnswerOptions options;
640 options.offer_to_receive_audio =
641 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
642
643 return CreateOffer(options);
644 }
645
wu@webrtc.org91053e72013-08-10 07:18:04 +0000646 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800647 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000648 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000649 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700650 cricket::MediaSessionOptions session_options;
651 GetOptionsForOffer(options, &session_options);
652 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000653 EXPECT_TRUE_WAIT(
654 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000655 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000656 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000657 }
658
659 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800660 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000661 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000662 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800663 cricket::MediaSessionOptions session_options = options;
664 GetOptionsForAnswer(&session_options);
665 // Overwrite recv_audio and recv_video with passed-in values.
666 session_options.recv_video = options.recv_video;
667 session_options.recv_audio = options.recv_audio;
668 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000669 EXPECT_TRUE_WAIT(
670 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000671 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000672 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000673 }
674
htaa2a49d92016-03-04 02:51:39 -0800675 SessionDescriptionInterface* CreateAnswer() {
676 cricket::MediaSessionOptions options;
677 options.recv_video = true;
678 options.recv_audio = true;
679 return CreateAnswer(options);
680 }
681
wu@webrtc.org364f2042013-11-20 21:49:41 +0000682 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000683 return (session_->voice_channel() != NULL &&
684 session_->video_channel() != NULL);
685 }
686
jbauchcb560652016-08-04 05:20:32 -0700687 void VerifyCryptoParams(const cricket::SessionDescription* sdp,
688 bool gcm_enabled = false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000689 ASSERT_TRUE(session_.get() != NULL);
690 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
691 ASSERT_TRUE(content != NULL);
692 const cricket::AudioContentDescription* audio_content =
693 static_cast<const cricket::AudioContentDescription*>(
694 content->description);
695 ASSERT_TRUE(audio_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700696 if (!gcm_enabled) {
697 ASSERT_EQ(1U, audio_content->cryptos().size());
698 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
699 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
700 audio_content->cryptos()[0].cipher_suite);
701 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
702 audio_content->protocol());
703 } else {
704 // The offer contains 3 possible crypto suites, the answer 1.
705 EXPECT_LE(1U, audio_content->cryptos().size());
706 EXPECT_NE(2U, audio_content->cryptos().size());
707 EXPECT_GE(3U, audio_content->cryptos().size());
708 ASSERT_EQ(67U, audio_content->cryptos()[0].key_params.size());
709 ASSERT_EQ("AEAD_AES_256_GCM",
710 audio_content->cryptos()[0].cipher_suite);
711 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
712 audio_content->protocol());
713 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000714
715 content = cricket::GetFirstVideoContent(sdp);
716 ASSERT_TRUE(content != NULL);
717 const cricket::VideoContentDescription* video_content =
718 static_cast<const cricket::VideoContentDescription*>(
719 content->description);
720 ASSERT_TRUE(video_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700721 if (!gcm_enabled) {
722 ASSERT_EQ(1U, video_content->cryptos().size());
723 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
724 video_content->cryptos()[0].cipher_suite);
725 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
726 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
727 video_content->protocol());
728 } else {
729 // The offer contains 3 possible crypto suites, the answer 1.
730 EXPECT_LE(1U, video_content->cryptos().size());
731 EXPECT_NE(2U, video_content->cryptos().size());
732 EXPECT_GE(3U, video_content->cryptos().size());
733 ASSERT_EQ("AEAD_AES_256_GCM",
734 video_content->cryptos()[0].cipher_suite);
735 ASSERT_EQ(67U, video_content->cryptos()[0].key_params.size());
736 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
737 video_content->protocol());
738 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000739 }
740
741 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
742 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
743 ASSERT_TRUE(content != NULL);
744 const cricket::AudioContentDescription* audio_content =
745 static_cast<const cricket::AudioContentDescription*>(
746 content->description);
747 ASSERT_TRUE(audio_content != NULL);
748 ASSERT_EQ(0U, audio_content->cryptos().size());
749
750 content = cricket::GetFirstVideoContent(sdp);
751 ASSERT_TRUE(content != NULL);
752 const cricket::VideoContentDescription* video_content =
753 static_cast<const cricket::VideoContentDescription*>(
754 content->description);
755 ASSERT_TRUE(video_content != NULL);
756 ASSERT_EQ(0U, video_content->cryptos().size());
757
758 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700759 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700761 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762 video_content->protocol());
763 } else {
764 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
765 audio_content->protocol());
766 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
767 video_content->protocol());
768 }
769 }
770
771 // Set the internal fake description factories to do DTLS-SRTP.
772 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000773 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000774 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000775 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200776 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800777 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700778 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800779 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000780 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
781 }
782
783 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
784 bool expected) {
785 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
786 ASSERT_TRUE(audio != NULL);
787 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 const TransportInfo* video = sdp->GetTransportInfoByName("video");
789 ASSERT_TRUE(video != NULL);
790 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791 }
792
793 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000794 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000796 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000797 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000799 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000801 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
802 offer);
htaa2a49d92016-03-04 02:51:39 -0800803 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 // Answer should be NULL as no crypto params in offer.
805 ASSERT_TRUE(answer == NULL);
806 }
807
808 void VerifyAnswerFromCryptoOffer() {
809 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000810 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000811 options.bundle_enabled = true;
kwibergd1fe2812016-04-27 06:47:29 -0700812 std::unique_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000813 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
814 ASSERT_TRUE(offer.get() != NULL);
815 VerifyCryptoParams(offer->description());
816 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -0700817 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818 ASSERT_TRUE(answer.get() != NULL);
819 VerifyCryptoParams(answer->description());
820 }
821
deadbeef0ed85b22016-02-23 17:24:52 -0800822 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
823 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800825 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000826 }
827
828 const cricket::ContentInfos& contents = desc1->contents();
829 cricket::ContentInfos::const_iterator it = contents.begin();
830
831 for (; it != contents.end(); ++it) {
832 const cricket::TransportDescription* transport_desc1 =
833 desc1->GetTransportDescriptionByName(it->name);
834 const cricket::TransportDescription* transport_desc2 =
835 desc2->GetTransportDescriptionByName(it->name);
836 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800837 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 }
839 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
840 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800841 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000842 }
843 }
deadbeef0ed85b22016-02-23 17:24:52 -0800844 return true;
845 }
846
847 // Compares ufrag/password only for the specified |media_type|.
848 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
849 const cricket::SessionDescription* desc2,
850 cricket::MediaType media_type) {
851 if (desc1->contents().size() != desc2->contents().size()) {
852 return false;
853 }
854
855 const cricket::ContentInfo* cinfo =
856 cricket::GetFirstMediaContent(desc1->contents(), media_type);
857 const cricket::TransportDescription* transport_desc1 =
858 desc1->GetTransportDescriptionByName(cinfo->name);
859 const cricket::TransportDescription* transport_desc2 =
860 desc2->GetTransportDescriptionByName(cinfo->name);
861 if (!transport_desc1 || !transport_desc2) {
862 return false;
863 }
864 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
865 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
866 return false;
867 }
868 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000870
871 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
872 std::string *sdp) {
873 const cricket::SessionDescription* desc = current_desc->description();
874 EXPECT_TRUE(current_desc->ToString(sdp));
875
876 const cricket::ContentInfos& contents = desc->contents();
877 cricket::ContentInfos::const_iterator it = contents.begin();
878 // Replace ufrag and pwd lines with empty strings.
879 for (; it != contents.end(); ++it) {
880 const cricket::TransportDescription* transport_desc =
881 desc->GetTransportDescriptionByName(it->name);
882 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
883 + "\r\n";
884 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
885 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000886 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000887 "", 0,
888 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000889 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000890 "", 0,
891 sdp);
892 }
893 }
894
deadbeef0ed85b22016-02-23 17:24:52 -0800895 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
896 const std::string& ufrag,
897 const std::string& pwd) {
898 cricket::SessionDescription* desc = current_desc->description();
899 for (TransportInfo& transport_info : desc->transport_infos()) {
900 cricket::TransportDescription& transport_desc =
901 transport_info.description;
902 transport_desc.ice_ufrag = ufrag;
903 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000904 }
905 }
906
deadbeef0ed85b22016-02-23 17:24:52 -0800907 // Sets ufrag/pwd for specified |media_type|.
908 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
909 cricket::MediaType media_type,
910 const std::string& ufrag,
911 const std::string& pwd) {
912 cricket::SessionDescription* desc = current_desc->description();
913 const cricket::ContentInfo* cinfo =
914 cricket::GetFirstMediaContent(desc->contents(), media_type);
915 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
916 cricket::TransportDescription* transport_desc =
917 &transport_info->description;
918 transport_desc->ice_ufrag = ufrag;
919 transport_desc->ice_pwd = pwd;
920 }
921
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922 // Creates a remote offer and and applies it as a remote description,
923 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700924 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000925 // to decide which local and remote streams to create.
926 void CreateAndSetRemoteOfferAndLocalAnswer() {
927 SessionDescriptionInterface* offer = CreateRemoteOffer();
928 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800929 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000930 SetLocalDescriptionWithoutError(answer);
931 }
932 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
933 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700934 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000935 }
936 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700937 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000938 SetLocalDescriptionWithoutError(desc);
939 EXPECT_EQ(expected_state, session_->state());
940 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000941 void SetLocalDescriptionExpectError(const std::string& action,
942 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000943 SessionDescriptionInterface* desc) {
944 std::string error;
945 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000946 std::string sdp_type = "local ";
947 sdp_type.append(action);
948 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000949 EXPECT_NE(std::string::npos, error.find(expected_error));
950 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000951 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
952 SessionDescriptionInterface* desc) {
953 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
954 expected_error, desc);
955 }
956 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
957 SessionDescriptionInterface* desc) {
958 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
959 expected_error, desc);
960 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000961 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
962 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
963 }
964 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700965 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000966 SetRemoteDescriptionWithoutError(desc);
967 EXPECT_EQ(expected_state, session_->state());
968 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000969 void SetRemoteDescriptionExpectError(const std::string& action,
970 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000971 SessionDescriptionInterface* desc) {
972 std::string error;
973 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000974 std::string sdp_type = "remote ";
975 sdp_type.append(action);
976 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000977 EXPECT_NE(std::string::npos, error.find(expected_error));
978 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000979 void SetRemoteDescriptionOfferExpectError(
980 const std::string& expected_error, SessionDescriptionInterface* desc) {
981 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
982 expected_error, desc);
983 }
984 void SetRemoteDescriptionPranswerExpectError(
985 const std::string& expected_error, SessionDescriptionInterface* desc) {
986 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
987 expected_error, desc);
988 }
989 void SetRemoteDescriptionAnswerExpectError(
990 const std::string& expected_error, SessionDescriptionInterface* desc) {
991 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
992 expected_error, desc);
993 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000994
995 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
996 SessionDescriptionInterface** nocrypto_answer) {
997 // Create a SDP without Crypto.
998 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000999 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001000 options.bundle_enabled = true;
1001 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
1002 ASSERT_TRUE(*offer != NULL);
1003 VerifyCryptoParams((*offer)->description());
1004
1005 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
1006 cricket::SEC_DISABLED);
1007 EXPECT_TRUE(*nocrypto_answer != NULL);
1008 }
1009
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001010 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
1011 SessionDescriptionInterface** nodtls_answer) {
1012 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001013 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001014 options.bundle_enabled = true;
1015
kwibergd1fe2812016-04-27 06:47:29 -07001016 std::unique_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001017 CreateRemoteOffer(options, cricket::SEC_ENABLED));
1018
1019 *nodtls_answer =
1020 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
1021 EXPECT_TRUE(*nodtls_answer != NULL);
1022 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
1023 VerifyCryptoParams((*nodtls_answer)->description());
1024
1025 SetFactoryDtlsSrtp();
1026 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
1027 ASSERT_TRUE(*offer != NULL);
1028 VerifyFingerprintStatus((*offer)->description(), true);
1029 VerifyCryptoParams((*offer)->description());
1030 }
1031
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001032 JsepSessionDescription* CreateRemoteOfferWithVersion(
1033 cricket::MediaSessionOptions options,
1034 cricket::SecurePolicy secure_policy,
1035 const std::string& session_version,
1036 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001037 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001038 const cricket::SessionDescription* cricket_desc = NULL;
1039 if (current_desc) {
1040 cricket_desc = current_desc->description();
1041 session_id = current_desc->session_id();
1042 }
1043
1044 desc_factory_->set_secure(secure_policy);
1045 JsepSessionDescription* offer(
1046 new JsepSessionDescription(JsepSessionDescription::kOffer));
1047 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
1048 session_id, session_version)) {
1049 delete offer;
1050 offer = NULL;
1051 }
1052 return offer;
1053 }
1054 JsepSessionDescription* CreateRemoteOffer(
1055 cricket::MediaSessionOptions options) {
1056 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1057 kSessionVersion, NULL);
1058 }
1059 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001060 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
1061 return CreateRemoteOfferWithVersion(
1062 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 }
1064 JsepSessionDescription* CreateRemoteOffer(
1065 cricket::MediaSessionOptions options,
1066 const SessionDescriptionInterface* current_desc) {
1067 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1068 kSessionVersion, current_desc);
1069 }
1070
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001071 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
1072 const char* sctp_stream_name, int new_port,
1073 cricket::MediaSessionOptions options) {
1074 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001075 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
1076 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001077 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
1078 }
1079
1080 // Takes ownership of offer_basis (and deletes it).
1081 JsepSessionDescription* ChangeSDPSctpPort(
1082 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1083 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1084 // SessionDescription from the mutated string.
1085 const char* default_port_str = "5000";
1086 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001087 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001088 std::string offer_str;
1089 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001090 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001091 new_port_str, strlen(new_port_str),
1092 &offer_str);
1093 JsepSessionDescription* offer = new JsepSessionDescription(
1094 offer_basis->type());
1095 delete offer_basis;
1096 offer->Initialize(offer_str, NULL);
1097 return offer;
1098 }
1099
deadbeefab9b2d12015-10-14 11:33:11 -07001100 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001101 // before this function to decide which streams to create.
1102 JsepSessionDescription* CreateRemoteOffer() {
1103 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001104 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001105 return CreateRemoteOffer(options, session_->remote_description());
1106 }
1107
1108 JsepSessionDescription* CreateRemoteAnswer(
1109 const SessionDescriptionInterface* offer,
1110 cricket::MediaSessionOptions options,
1111 cricket::SecurePolicy policy) {
1112 desc_factory_->set_secure(policy);
1113 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001114 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001115 JsepSessionDescription* answer(
1116 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1117 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1118 options, NULL),
1119 session_id, kSessionVersion)) {
1120 delete answer;
1121 answer = NULL;
1122 }
1123 return answer;
1124 }
1125
1126 JsepSessionDescription* CreateRemoteAnswer(
1127 const SessionDescriptionInterface* offer,
1128 cricket::MediaSessionOptions options) {
1129 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1130 }
1131
deadbeefab9b2d12015-10-14 11:33:11 -07001132 // Creates an answer session description.
1133 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001134 // to decide which streams to create.
1135 JsepSessionDescription* CreateRemoteAnswer(
1136 const SessionDescriptionInterface* offer) {
1137 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001138 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001139 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1140 }
1141
1142 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001143 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001144 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001145 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001146
1147 PeerConnectionInterface::RTCOfferAnswerOptions options;
1148 options.use_rtp_mux = bundle;
1149
1150 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001151 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1152 // and answer.
1153 SetLocalDescriptionWithoutError(offer);
1154
kwibergd1fe2812016-04-27 06:47:29 -07001155 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001156 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001157 std::string sdp;
1158 EXPECT_TRUE(answer->ToString(&sdp));
1159
1160 size_t expected_candidate_num = 2;
1161 if (!rtcp_mux) {
1162 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1163 // for rtp and rtcp.
1164 expected_candidate_num = 4;
1165 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001166 const std::string kRtcpMux = "a=rtcp-mux";
1167 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001168 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001169 kXRtcpMux.c_str(), kXRtcpMux.length(),
1170 &sdp);
1171 }
1172
1173 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1174 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001175
1176 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001177 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001178 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1179 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001180 if (bundle) {
1181 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1182 } else {
1183 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001184 }
1185 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001186
zhihuang3a334652016-05-05 18:37:49 -07001187 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1188 const std::string& codec_name) {
1189 for (const auto& content : desc->description()->contents()) {
1190 if (static_cast<cricket::MediaContentDescription*>(content.description)
1191 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1192 const auto* mdesc =
1193 static_cast<cricket::VideoContentDescription*>(content.description);
1194 for (const auto& codec : mdesc->codecs()) {
1195 if (codec.name == codec_name) {
1196 return true;
1197 }
1198 }
1199 }
1200 }
1201 return false;
1202 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001203 // Helper class to configure loopback network and verify Best
1204 // Connection using right IP protocol for TestLoopbackCall
1205 // method. LoopbackNetworkManager applies firewall rules to block
1206 // all ping traffic once ICE completed, and remove them to observe
1207 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1208 // verifies the best connection is using the right IP protocol after
1209 // initial ICE convergences.
1210
1211 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001212 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001213 LoopbackNetworkConfiguration()
1214 : test_ipv6_network_(false),
1215 test_extra_ipv4_network_(false),
1216 best_connection_after_initial_ice_converged_(1, 0) {}
1217
1218 // Used to track the expected best connection count in each IP protocol.
1219 struct ExpectedBestConnection {
1220 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1221 : ipv4_count_(ipv4_count),
1222 ipv6_count_(ipv6_count) {}
1223
1224 int ipv4_count_;
1225 int ipv6_count_;
1226 };
1227
1228 bool test_ipv6_network_;
1229 bool test_extra_ipv4_network_;
1230 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1231
1232 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001233 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001234 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1235 }
1236
1237 private:
jbauchac8869e2015-07-03 01:36:14 -07001238 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001239 const ExpectedBestConnection& expected) const {
1240 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001241 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1242 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001243 expected.ipv4_count_);
1244 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001245 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1246 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001247 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001248 // This is used in the loopback call so there is only single host to host
1249 // candidate pair.
1250 EXPECT_EQ(metrics_observer->GetEnumCounter(
1251 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1252 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001253 0);
1254 EXPECT_EQ(metrics_observer->GetEnumCounter(
1255 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1256 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001257 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001258 }
1259 };
1260
1261 class LoopbackNetworkManager {
1262 public:
1263 LoopbackNetworkManager(WebRtcSessionTest* session,
1264 const LoopbackNetworkConfiguration& config)
1265 : config_(config) {
1266 session->AddInterface(
1267 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1268 if (config_.test_extra_ipv4_network_) {
1269 session->AddInterface(
1270 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1271 }
1272 if (config_.test_ipv6_network_) {
1273 session->AddInterface(
1274 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1275 }
1276 }
1277
1278 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1279 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1280 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1281 if (config_.test_extra_ipv4_network_) {
1282 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1283 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1284 }
1285 if (config_.test_ipv6_network_) {
1286 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1287 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1288 }
1289 }
1290
1291 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1292
1293 private:
1294 LoopbackNetworkConfiguration config_;
1295 };
1296
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001297 // The method sets up a call from the session to itself, in a loopback
1298 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001299 // disconnection, and then a permanent disconnection.
1300 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001301 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1302 // While running the call, this method also checks if the session goes through
1303 // the correct sequence of ICE states when a connection is established,
1304 // broken, and re-established.
1305 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001306 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1307 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001308 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001309
stefanc1aeaf02015-10-15 07:26:07 -07001310 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001311 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001312 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001313 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001314
1315 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1316 observer_.ice_gathering_state_);
1317 SetLocalDescriptionWithoutError(offer);
1318 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1319 observer_.ice_connection_state_);
1320 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001321 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001322 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1323 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001324 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001325
1326 std::string sdp;
1327 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001328 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1329 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001330 ASSERT_TRUE(desc != NULL);
1331 SetRemoteDescriptionWithoutError(desc);
1332
1333 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001334 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001335
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001336 // The ice connection state is "Connected" too briefly to catch in a test.
1337 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001338 observer_.ice_connection_state_, kIceCandidatesTimeout);
1339 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001340
stefanc1aeaf02015-10-15 07:26:07 -07001341 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1342 LoopbackNetworkManager loopback_network_manager(this, config);
1343 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001344 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001345 // Adding firewall rule to block ping requests, which should cause
1346 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001347
1348 loopback_network_manager.ApplyFirewallRules(fss_.get());
1349
1350 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001351 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1352 observer_.ice_connection_state_,
1353 kIceCandidatesTimeout);
1354
jbauchac8869e2015-07-03 01:36:14 -07001355 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001356
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001357 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001358 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001359
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001360 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001361 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001362 observer_.ice_connection_state_,
1363 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001364
1365 // Now we block ping requests and wait until the ICE connection transitions
1366 // to the Failed state. This will take at least 30 seconds because it must
1367 // wait for the Port to timeout.
1368 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001369
1370 loopback_network_manager.ApplyFirewallRules(fss_.get());
1371 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001372 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001373 observer_.ice_connection_state_,
1374 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001375 }
1376
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001377 void TestLoopbackCall() {
1378 LoopbackNetworkConfiguration config;
1379 TestLoopbackCall(config);
1380 }
1381
stefanc1aeaf02015-10-15 07:26:07 -07001382 void TestPacketOptions() {
1383 media_controller_.reset(
1384 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1385 LoopbackNetworkConfiguration config;
1386 LoopbackNetworkManager loopback_network_manager(this, config);
1387
1388 SetupLoopbackCall();
1389
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001390 // Wait for channel to be ready for sending.
1391 EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
stefanc1aeaf02015-10-15 07:26:07 -07001392 uint8_t test_packet[15] = {0};
1393 rtc::PacketOptions options;
1394 options.packet_id = 10;
1395 media_engine_->GetVideoChannel(0)
1396 ->SendRtp(test_packet, sizeof(test_packet), options);
1397
1398 const int kPacketTimeout = 2000;
deadbeef14461d42016-06-15 11:06:57 -07001399 EXPECT_EQ_WAIT(10, fake_call_.last_sent_nonnegative_packet_id(),
1400 kPacketTimeout);
stefanc1aeaf02015-10-15 07:26:07 -07001401 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1402 }
1403
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001404 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1405 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001406 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1407 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001408
1409 // Add kCNCodec for dtmf test.
ossudedfd282016-06-14 07:12:39 -07001410 std::vector<cricket::AudioCodec> codecs =
1411 media_engine_->audio_send_codecs();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001412 codecs.push_back(kCNCodec1);
1413 codecs.push_back(kCNCodec2);
1414 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -07001415 desc_factory_->set_audio_codecs(codecs, codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001416 }
1417
1418 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1419 const cricket::ContentDescription* description = content->description;
nissec8ee8822017-01-18 07:20:55 -08001420 RTC_CHECK(description != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001421 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001422 static_cast<const cricket::AudioContentDescription*>(description);
nissec8ee8822017-01-18 07:20:55 -08001423 RTC_CHECK(audio_content_desc != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001424 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1425 if (audio_content_desc->codecs()[i].name == "CN")
1426 return false;
1427 }
1428 return true;
1429 }
1430
deadbeefab9b2d12015-10-14 11:33:11 -07001431 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001432 webrtc::InternalDataChannelInit dci;
nissec8ee8822017-01-18 07:20:55 -08001433 RTC_CHECK(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001434 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1435 data_channel_ = DataChannel::Create(
1436 session_.get(), session_->data_channel_type(), "datachannel", dci);
1437 }
1438
1439 void SetLocalDescriptionWithDataChannel() {
1440 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001441 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001442 SetLocalDescriptionWithoutError(offer);
1443 }
1444
wu@webrtc.org91053e72013-08-10 07:18:04 +00001445 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001446 RTCCertificateGenerationMethod cert_gen_method,
1447 CreateSessionDescriptionRequest::Type type) {
1448 InitWithDtls(cert_gen_method);
1449 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1450 }
1451
1452 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1453 CreateSessionDescriptionRequest::Type type) {
1454 InitWithDtlsIdentityGenFail();
1455 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1456 }
1457
1458 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001459 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001460 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001461 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001462 if (type == CreateSessionDescriptionRequest::kAnswer) {
1463 cricket::MediaSessionOptions options;
kwibergd1fe2812016-04-27 06:47:29 -07001464 std::unique_ptr<JsepSessionDescription> offer(
1465 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001466 ASSERT_TRUE(offer.get() != NULL);
1467 SetRemoteDescriptionWithoutError(offer.release());
1468 }
1469
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001470 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001471 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001472 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001473 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001474 observers[kNumber];
1475 for (int i = 0; i < kNumber; ++i) {
1476 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1477 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001478 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001479 } else {
htaa2a49d92016-03-04 02:51:39 -08001480 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001481 }
1482 }
1483
1484 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1485 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1486 WebRtcSessionCreateSDPObserverForTest::kFailed;
1487
1488 for (int i = 0; i < kNumber; ++i) {
1489 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1490 if (success) {
1491 EXPECT_TRUE(observers[i]->description() != NULL);
1492 } else {
1493 EXPECT_TRUE(observers[i]->description() == NULL);
1494 }
1495 }
1496 }
1497
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001498 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001499 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001500 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001501 turn_server.credentials = credentials;
1502 turn_server.ports.push_back(
hnsl277b2502016-12-13 05:17:23 -08001503 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP));
deadbeef653b8e02015-11-11 12:55:10 -08001504 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001505 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001506 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001507 }
1508
skvlad11a9cbf2016-10-07 11:53:05 -07001509 webrtc::RtcEventLogNullImpl event_log_;
deadbeef112b2e92017-02-10 20:13:37 -08001510 // |media_engine_| and |data_engine_| are actually owned by
1511 // |channel_manager_|.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001512 cricket::FakeMediaEngine* media_engine_;
1513 cricket::FakeDataEngine* data_engine_;
deadbeef953c2ce2017-01-09 14:53:41 -08001514 // Actually owned by session_.
1515 FakeSctpTransportFactory* fake_sctp_transport_factory_ = nullptr;
kwibergd1fe2812016-04-27 06:47:29 -07001516 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001517 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001518 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_;
1519 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1520 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1521 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1522 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1523 std::unique_ptr<rtc::FirewallSocketServer> fss_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001524 rtc::SocketServerScope ss_scope_;
1525 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001526 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001527 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001528 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001529 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001530 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001531 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001532 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001533 MockIceObserver observer_;
1534 cricket::FakeVideoMediaChannel* video_channel_;
1535 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001536 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001537 // The following flags affect options created for CreateOffer/CreateAnswer.
1538 bool send_stream_1_ = false;
1539 bool send_stream_2_ = false;
1540 bool send_audio_ = false;
1541 bool send_video_ = false;
1542 rtc::scoped_refptr<DataChannel> data_channel_;
1543 // Last values received from data channel creation signal.
1544 std::string last_data_channel_label_;
1545 InternalDataChannelInit last_data_channel_config_;
deadbeef7914b8c2017-04-21 03:23:33 -07001546 rtc::CryptoOptions crypto_options_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001547};
1548
Henrik Boström87713d02015-08-25 09:53:21 +02001549TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1550 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001551 // SDES is disabled when DTLS is on.
1552 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001553}
1554
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001555TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001556 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001557 // SDES is required if DTLS is off.
1558 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001559}
1560
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001561TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1562 TestSessionCandidatesWithBundleRtcpMux(false, false);
1563}
1564
1565// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1566// with rtcp-mux and/or bundle.
1567TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1568 TestSessionCandidatesWithBundleRtcpMux(false, true);
1569}
1570
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001571TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1572 TestSessionCandidatesWithBundleRtcpMux(true, true);
1573}
1574
1575TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001576 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1577 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001578 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001579 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001580 InitiateCall();
1581 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1582 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1583 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1584}
1585
deadbeeff5f03e82016-06-06 11:16:06 -07001586TEST_F(WebRtcSessionTest, TestStunError) {
1587 rtc::ScopedFakeClock clock;
1588
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001589 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1590 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001591 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001592 rtc::FP_UDP,
1593 rtc::FD_ANY,
1594 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001595 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001596 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001597 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001598 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
pthatcher94a2f212017-02-08 14:42:22 -08001599 EXPECT_TRUE_SIMULATED_WAIT(observer_.oncandidatesready_,
1600 cricket::STUN_TOTAL_TIMEOUT, clock);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1602 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
deadbeeff5f03e82016-06-06 11:16:06 -07001603 // Destroy session before scoped fake clock goes out of scope to avoid TSan
1604 // warning.
1605 session_->Close();
1606 session_.reset(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607}
1608
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001609TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001610 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001611 SessionDescriptionInterface* offer = NULL;
1612 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1613 std::string unknown_action;
1614 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1615 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1616}
1617
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001618// Test creating offers and receive answers and make sure the
1619// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001620TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001621 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001622 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001623 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001624 const std::string session_id_orig = offer->session_id();
1625 const std::string session_version_orig = offer->session_version();
1626 SetLocalDescriptionWithoutError(offer);
1627
deadbeefab9b2d12015-10-14 11:33:11 -07001628 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001629 SessionDescriptionInterface* answer =
1630 CreateRemoteAnswer(session_->local_description());
1631 SetRemoteDescriptionWithoutError(answer);
1632
1633 video_channel_ = media_engine_->GetVideoChannel(0);
1634 voice_channel_ = media_engine_->GetVoiceChannel(0);
1635
1636 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1637 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1638
1639 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1640 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1641
1642 ASSERT_EQ(1u, video_channel_->send_streams().size());
1643 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1644 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1645 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1646
1647 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001648 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001649 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001650
1651 // Verify the session id is the same and the session version is
1652 // increased.
1653 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001654 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1655 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001656
1657 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001658 EXPECT_EQ(0u, video_channel_->send_streams().size());
1659 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001660
deadbeefab9b2d12015-10-14 11:33:11 -07001661 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001662 answer = CreateRemoteAnswer(session_->local_description());
1663 SetRemoteDescriptionWithoutError(answer);
1664
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001665 // Make sure the receive streams have not changed.
1666 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1667 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1668 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1669 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1670}
1671
1672// Test receiving offers and creating answers and make sure the
1673// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001674TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001675 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001676 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001677 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001678 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001679 SetRemoteDescriptionWithoutError(offer);
1680
deadbeefab9b2d12015-10-14 11:33:11 -07001681 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001682 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001683 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001684 SetLocalDescriptionWithoutError(answer);
1685
1686 const std::string session_id_orig = answer->session_id();
1687 const std::string session_version_orig = answer->session_version();
1688
1689 video_channel_ = media_engine_->GetVideoChannel(0);
1690 voice_channel_ = media_engine_->GetVoiceChannel(0);
1691
htaa2a49d92016-03-04 02:51:39 -08001692 ASSERT_TRUE(video_channel_);
1693 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001694 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1695 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1696
1697 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1698 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1699
1700 ASSERT_EQ(1u, video_channel_->send_streams().size());
1701 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1702 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1703 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1704
deadbeefab9b2d12015-10-14 11:33:11 -07001705 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001706 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001707 SetRemoteDescriptionWithoutError(offer);
1708
1709 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001710 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001711 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001712
1713 // Verify the session id is the same and the session version is
1714 // increased.
1715 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001716 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1717 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001718 SetLocalDescriptionWithoutError(answer);
1719
1720 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1721 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1722 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1723 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1724 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1725 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1726
1727 // Make sure we have no send streams.
1728 EXPECT_EQ(0u, video_channel_->send_streams().size());
1729 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1730}
1731
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001732TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001733 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001734 media_engine_->set_fail_create_channel(true);
1735
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001736 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001737 ASSERT_TRUE(offer != NULL);
1738 // SetRemoteDescription and SetLocalDescription will take the ownership of
1739 // the offer.
1740 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001741 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001742 ASSERT_TRUE(offer != NULL);
1743 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1744}
1745
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001746//
1747// Tests for creating/setting SDP under different SDES/DTLS polices:
1748//
1749// --DTLS off and SDES on
1750// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1751// set local/remote offer/answer with crypto --> success
1752// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1753// failure
1754// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1755// failure
1756// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1757// failure
1758//
1759// --DTLS on and SDES off
1760// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1761// set local/remote offer/answer with DTLS fingerprint --> success
1762// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1763// fingerprint --> failure
1764// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1765// --> failure
1766// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1767// --> failure
1768//
1769// --Encryption disabled: DTLS off and SDES off
1770// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1771// answer without SDES or DTLS --> success
1772// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1773// answer without SDES or DTLS --> success
1774//
1775
1776// Test that we return a failure when applying a remote/local offer that doesn't
1777// have cryptos enabled when DTLS is off.
1778TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001779 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001780 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001781 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782 JsepSessionDescription* offer = CreateRemoteOffer(
1783 options, cricket::SEC_DISABLED);
1784 ASSERT_TRUE(offer != NULL);
1785 VerifyNoCryptoParams(offer->description(), false);
1786 // SetRemoteDescription and SetLocalDescription will take the ownership of
1787 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001788 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001789 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1790 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001791 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792}
1793
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001794// Test that we return a failure when applying a local answer that doesn't have
1795// cryptos enabled when DTLS is off.
1796TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001797 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798 SessionDescriptionInterface* offer = NULL;
1799 SessionDescriptionInterface* answer = NULL;
1800 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1801 // SetRemoteDescription and SetLocalDescription will take the ownership of
1802 // the offer.
1803 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001804 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001805}
1806
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001807// Test we will return fail when apply an remote answer that doesn't have
1808// crypto enabled when DTLS is off.
1809TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001810 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001811 SessionDescriptionInterface* offer = NULL;
1812 SessionDescriptionInterface* answer = NULL;
1813 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1814 // SetRemoteDescription and SetLocalDescription will take the ownership of
1815 // the offer.
1816 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001817 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001818}
1819
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001820// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1821// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001822TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001823 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001824 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825 SetFactoryDtlsSrtp();
1826 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001827 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001828 JsepSessionDescription* offer =
1829 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001830 ASSERT_TRUE(offer != NULL);
1831 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001832 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001833
1834 // SetRemoteDescription will take the ownership of the offer.
1835 SetRemoteDescriptionWithoutError(offer);
1836
1837 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001838 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001839 ASSERT_TRUE(answer != NULL);
1840 VerifyFingerprintStatus(answer->description(), true);
1841 // Check that we don't have an a=crypto line in the answer.
1842 VerifyNoCryptoParams(answer->description(), true);
1843
1844 // Now set the local description, which should work, even without a=crypto.
1845 SetLocalDescriptionWithoutError(answer);
1846}
1847
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001848// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1849// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001850TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001851 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001852 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001853 SetFactoryDtlsSrtp();
1854
1855 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001856 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001857 ASSERT_TRUE(offer != NULL);
1858 VerifyFingerprintStatus(offer->description(), true);
1859 // Check that we don't have an a=crypto line in the offer.
1860 VerifyNoCryptoParams(offer->description(), true);
1861
1862 // Now set the local description, which should work, even without a=crypto.
1863 SetLocalDescriptionWithoutError(offer);
1864
1865 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001866 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001867 JsepSessionDescription* answer =
1868 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1869 ASSERT_TRUE(answer != NULL);
1870 VerifyFingerprintStatus(answer->description(), true);
1871 VerifyNoCryptoParams(answer->description(), true);
1872
1873 // SetRemoteDescription will take the ownership of the answer.
1874 SetRemoteDescriptionWithoutError(answer);
1875}
1876
1877// Test that if we support DTLS and the other side didn't offer a fingerprint,
1878// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001879TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02001880 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001881 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001882 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001883 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001884 JsepSessionDescription* offer = CreateRemoteOffer(
1885 options, cricket::SEC_REQUIRED);
1886 ASSERT_TRUE(offer != NULL);
1887 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001888 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001889
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001890 // SetRemoteDescription will take the ownership of the offer.
1891 SetRemoteDescriptionOfferExpectError(
1892 kSdpWithoutDtlsFingerprint, offer);
1893
1894 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1895 // SetLocalDescription will take the ownership of the offer.
1896 SetLocalDescriptionOfferExpectError(
1897 kSdpWithoutDtlsFingerprint, offer);
1898}
1899
1900// Test that we return a failure when applying a local answer that doesn't have
1901// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001902TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02001903 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001904 SessionDescriptionInterface* offer = NULL;
1905 SessionDescriptionInterface* answer = NULL;
1906 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1907
1908 // SetRemoteDescription and SetLocalDescription will take the ownership of
1909 // the offer and answer.
1910 SetRemoteDescriptionWithoutError(offer);
1911 SetLocalDescriptionAnswerExpectError(
1912 kSdpWithoutDtlsFingerprint, answer);
1913}
1914
1915// Test that we return a failure when applying a remote answer that doesn't have
1916// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001917TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02001918 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001919 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001920 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001921 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07001922 std::unique_ptr<SessionDescriptionInterface> temp_offer(
deadbeefcbecd352015-09-23 11:50:27 -07001923 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001924 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001925 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001926
1927 // SetRemoteDescription and SetLocalDescription will take the ownership of
1928 // the offer and answer.
1929 SetLocalDescriptionWithoutError(offer);
1930 SetRemoteDescriptionAnswerExpectError(
1931 kSdpWithoutDtlsFingerprint, answer);
1932}
1933
1934// Test that we create a local offer without SDES or DTLS and accept a remote
1935// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001936TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001937 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001938 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001939 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001940
1941 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001942 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001943 ASSERT_TRUE(offer != NULL);
1944 VerifyFingerprintStatus(offer->description(), false);
1945 // Check that we don't have an a=crypto line in the offer.
1946 VerifyNoCryptoParams(offer->description(), false);
1947
1948 // Now set the local description, which should work, even without a=crypto.
1949 SetLocalDescriptionWithoutError(offer);
1950
1951 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001952 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001953 JsepSessionDescription* answer =
1954 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1955 ASSERT_TRUE(answer != NULL);
1956 VerifyFingerprintStatus(answer->description(), false);
1957 VerifyNoCryptoParams(answer->description(), false);
1958
1959 // SetRemoteDescription will take the ownership of the answer.
1960 SetRemoteDescriptionWithoutError(answer);
1961}
1962
1963// Test that we create a local answer without SDES or DTLS and accept a remote
1964// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001965TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001966 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001967 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001968
1969 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001970 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001971 JsepSessionDescription* offer =
1972 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1973 ASSERT_TRUE(offer != NULL);
1974 VerifyFingerprintStatus(offer->description(), false);
1975 VerifyNoCryptoParams(offer->description(), false);
1976
1977 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001978 SetRemoteDescriptionWithoutError(offer);
1979
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001980 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001981 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001982 ASSERT_TRUE(answer != NULL);
1983 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001984 // Check that we don't have an a=crypto line in the answer.
1985 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001986
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001987 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001988 SetLocalDescriptionWithoutError(answer);
1989}
1990
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001991// Test that we can create and set an answer correctly when different
1992// SSL roles have been negotiated for different transports.
1993// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1994TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1995 SendAudioVideoStream1();
1996 InitWithDtls(GetParam());
1997 SetFactoryDtlsSrtp();
1998
1999 SessionDescriptionInterface* offer = CreateOffer();
2000 SetLocalDescriptionWithoutError(offer);
2001
2002 cricket::MediaSessionOptions options;
2003 options.recv_video = true;
2004
2005 // First, negotiate different SSL roles.
2006 SessionDescriptionInterface* answer =
2007 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
2008 TransportInfo* audio_transport_info =
2009 answer->description()->GetTransportInfoByName("audio");
2010 audio_transport_info->description.connection_role =
2011 cricket::CONNECTIONROLE_ACTIVE;
2012 TransportInfo* video_transport_info =
2013 answer->description()->GetTransportInfoByName("video");
2014 video_transport_info->description.connection_role =
2015 cricket::CONNECTIONROLE_PASSIVE;
2016 SetRemoteDescriptionWithoutError(answer);
2017
2018 // Now create an offer in the reverse direction, and ensure the initial
2019 // offerer responds with an answer with correct SSL roles.
2020 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2021 kSessionVersion,
2022 session_->remote_description());
2023 SetRemoteDescriptionWithoutError(offer);
2024
htaa2a49d92016-03-04 02:51:39 -08002025 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002026 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2027 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2028 audio_transport_info->description.connection_role);
2029 video_transport_info = answer->description()->GetTransportInfoByName("video");
2030 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
2031 video_transport_info->description.connection_role);
2032 SetLocalDescriptionWithoutError(answer);
2033
2034 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
2035 // audio is transferred over to video in the answer that completes the BUNDLE
2036 // negotiation.
2037 options.bundle_enabled = true;
2038 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2039 kSessionVersion,
2040 session_->remote_description());
2041 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08002042 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002043 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2044 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2045 audio_transport_info->description.connection_role);
2046 video_transport_info = answer->description()->GetTransportInfoByName("video");
2047 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2048 video_transport_info->description.connection_role);
2049 SetLocalDescriptionWithoutError(answer);
2050}
2051
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002052TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002053 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002054 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002055 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002056 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002057 SetLocalDescriptionWithoutError(offer);
2058
2059 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002060 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002061 SetLocalDescriptionWithoutError(offer2);
2062}
2063
2064TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002065 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002066 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002067 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002068 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002069 SetRemoteDescriptionWithoutError(offer);
2070
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002071 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072 SetRemoteDescriptionWithoutError(offer2);
2073}
2074
2075TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002076 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002077 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002078 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002080 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002081 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2082 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002083}
2084
2085TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002086 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002087 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002088 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002089 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002090 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002091 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002092 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093}
2094
2095TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002096 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002097 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002098 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002099 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002100
htaa2a49d92016-03-04 02:51:39 -08002101 JsepSessionDescription* pranswer =
2102 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002104 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002105
deadbeefab9b2d12015-10-14 11:33:11 -07002106 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002107 JsepSessionDescription* pranswer2 =
2108 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002109 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2110
deadbeefd59daf82015-10-14 15:02:44 -07002111 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002112
deadbeefab9b2d12015-10-14 11:33:11 -07002113 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002114 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002115 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002116}
2117
2118TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002119 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002120 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002121 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002122 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002123
2124 JsepSessionDescription* pranswer =
2125 CreateRemoteAnswer(session_->local_description());
2126 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2127
2128 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002129 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002130
deadbeefab9b2d12015-10-14 11:33:11 -07002131 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002132 JsepSessionDescription* pranswer2 =
2133 CreateRemoteAnswer(session_->local_description());
2134 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2135
2136 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002137 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138
deadbeefab9b2d12015-10-14 11:33:11 -07002139 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140 SessionDescriptionInterface* answer =
2141 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002142 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002143}
2144
2145TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002146 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002147 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002148 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002149
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002150 SessionDescriptionInterface* answer =
2151 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002152 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2153 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154}
2155
2156TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002157 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002158 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002159 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002160
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002161 SessionDescriptionInterface* answer =
2162 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002163 SetRemoteDescriptionAnswerExpectError(
2164 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002165}
2166
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002167// Tests that the remote candidates are added and removed successfully.
2168TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002169 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002170 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002171
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002172 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
zhihuang38989e52017-03-21 11:04:53 -07002173 "", "", "local", 0, "");
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002174 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002175 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2176
deadbeefd59daf82015-10-14 15:02:44 -07002177 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002178 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2179
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002180 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002181 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002182
2183 // Fail since we have not set a remote description.
2184 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002185
2186 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2187 session_->local_description());
2188 SetRemoteDescriptionWithoutError(answer);
2189
deadbeefd59daf82015-10-14 15:02:44 -07002190 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2191 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002192 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002193 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2194 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2195
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002196 // Verifying the candidates are copied properly from internal vector.
2197 const SessionDescriptionInterface* remote_desc =
2198 session_->remote_description();
2199 ASSERT_TRUE(remote_desc != NULL);
2200 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2201 const IceCandidateCollection* candidates =
2202 remote_desc->candidates(kMediaContentIndex0);
2203 ASSERT_EQ(2u, candidates->count());
2204 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2205 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2206 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2207 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2208
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002209 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2210 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002211 candidate.set_component(2);
2212 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2213 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002214 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002215
2216 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2217 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002218
2219 // Remove candidate1 and candidate2
2220 std::vector<cricket::Candidate> remote_candidates;
2221 remote_candidates.push_back(ice_candidate1.candidate());
2222 remote_candidates.push_back(ice_candidate2.candidate());
2223 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2224 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002225}
2226
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002227// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002228// that it is retained if the remote session description is changed.
2229TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002230 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002231 cricket::Candidate candidate1;
2232 candidate1.set_component(1);
2233 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2234 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002235 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002236 CreateAndSetRemoteOfferAndLocalAnswer();
2237
2238 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2239 const SessionDescriptionInterface* remote_desc =
2240 session_->remote_description();
2241 ASSERT_TRUE(remote_desc != NULL);
2242 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2243 const IceCandidateCollection* candidates =
2244 remote_desc->candidates(kMediaContentIndex0);
2245 ASSERT_EQ(1u, candidates->count());
2246 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2247
2248 // Update the RemoteSessionDescription with a new session description and
2249 // a candidate and check that the new remote session description contains both
2250 // candidates.
2251 SessionDescriptionInterface* offer = CreateRemoteOffer();
2252 cricket::Candidate candidate2;
2253 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2254 candidate2);
2255 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2256 SetRemoteDescriptionWithoutError(offer);
2257
2258 remote_desc = session_->remote_description();
2259 ASSERT_TRUE(remote_desc != NULL);
2260 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2261 candidates = remote_desc->candidates(kMediaContentIndex0);
2262 ASSERT_EQ(2u, candidates->count());
2263 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2264 // Username and password have be updated with the TransportInfo of the
2265 // SessionDescription, won't be equal to the original one.
2266 candidate2.set_username(candidates->at(0)->candidate().username());
2267 candidate2.set_password(candidates->at(0)->candidate().password());
2268 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2269 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2270 // No need to verify the username and password.
2271 candidate1.set_username(candidates->at(1)->candidate().username());
2272 candidate1.set_password(candidates->at(1)->candidate().password());
2273 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2274
2275 // Test that the candidate is ignored if we can add the same candidate again.
2276 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2277}
2278
2279// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002280// that they are retained if the local session description is changed. And if
2281// continual gathering is enabled, they are removed from the local session
2282// description when the network is down.
2283TEST_F(WebRtcSessionTest,
2284 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002285 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002286 Init();
deadbeefb60a8192016-08-24 15:15:00 -07002287 // Enable Continual Gathering.
2288 cricket::IceConfig config;
2289 config.continual_gathering_policy = cricket::GATHER_CONTINUALLY;
2290 session_->SetIceConfig(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002291 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002292 CreateAndSetRemoteOfferAndLocalAnswer();
2293
2294 const SessionDescriptionInterface* local_desc = session_->local_description();
2295 const IceCandidateCollection* candidates =
2296 local_desc->candidates(kMediaContentIndex0);
2297 ASSERT_TRUE(candidates != NULL);
2298 EXPECT_EQ(0u, candidates->count());
2299
deadbeefb60a8192016-08-24 15:15:00 -07002300 // Since we're using continual gathering, we won't get "gathering done".
2301 EXPECT_EQ_WAIT(2u, candidates->count(), kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002302
2303 local_desc = session_->local_description();
2304 candidates = local_desc->candidates(kMediaContentIndex0);
2305 ASSERT_TRUE(candidates != NULL);
2306 EXPECT_LT(0u, candidates->count());
2307 candidates = local_desc->candidates(1);
2308 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002309 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002310
2311 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002312 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002313 CreateAndSetRemoteOfferAndLocalAnswer();
2314
2315 local_desc = session_->local_description();
2316 candidates = local_desc->candidates(kMediaContentIndex0);
2317 ASSERT_TRUE(candidates != NULL);
2318 EXPECT_LT(0u, candidates->count());
2319 candidates = local_desc->candidates(1);
2320 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002321 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002322
2323 candidates = local_desc->candidates(kMediaContentIndex0);
2324 size_t num_local_candidates = candidates->count();
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002325 // Bring down the network interface to trigger candidate removals.
2326 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2327 // Verify that all local candidates are removed.
2328 EXPECT_EQ(0, observer_.num_candidates_removed_);
2329 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2330 kIceCandidatesTimeout);
2331 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2332}
2333
2334// Tests that if continual gathering is disabled, local candidates won't be
2335// removed when the interface is turned down.
2336TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2337 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2338 Init();
2339 SendAudioVideoStream1();
2340 CreateAndSetRemoteOfferAndLocalAnswer();
2341
2342 const SessionDescriptionInterface* local_desc = session_->local_description();
2343 const IceCandidateCollection* candidates =
2344 local_desc->candidates(kMediaContentIndex0);
2345 ASSERT_TRUE(candidates != NULL);
2346 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2347
2348 size_t num_local_candidates = candidates->count();
2349 EXPECT_LT(0u, num_local_candidates);
2350 // By default, Continual Gathering is disabled.
2351 // Bring down the network interface.
2352 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2353 // Verify that the local candidates are not removed.
2354 rtc::Thread::Current()->ProcessMessages(1000);
2355 EXPECT_EQ(0, observer_.num_candidates_removed_);
2356 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002357}
2358
2359// Test that we can set a remote session description with remote candidates.
2360TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002361 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002362
2363 cricket::Candidate candidate1;
2364 candidate1.set_component(1);
2365 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2366 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002367 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002368 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369
2370 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2371 SetRemoteDescriptionWithoutError(offer);
2372
2373 const SessionDescriptionInterface* remote_desc =
2374 session_->remote_description();
2375 ASSERT_TRUE(remote_desc != NULL);
2376 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2377 const IceCandidateCollection* candidates =
2378 remote_desc->candidates(kMediaContentIndex0);
2379 ASSERT_EQ(1u, candidates->count());
2380 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2381
htaa2a49d92016-03-04 02:51:39 -08002382 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002383 SetLocalDescriptionWithoutError(answer);
2384}
2385
2386// Test that offers and answers contains ice candidates when Ice candidates have
2387// been gathered.
2388TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002389 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002390 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002391 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002392 // Ice is started but candidates are not provided until SetLocalDescription
2393 // is called.
2394 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2395 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2396 CreateAndSetRemoteOfferAndLocalAnswer();
2397 // Wait until at least one local candidate has been collected.
2398 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2399 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002400
kwibergd1fe2812016-04-27 06:47:29 -07002401 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002402
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002403 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2404 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002405
2406 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2407 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002408 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2410 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002411 SetLocalDescriptionWithoutError(answer);
2412}
2413
2414// Verifies TransportProxy and media channels are created with content names
2415// present in the SessionDescription.
2416TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002417 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002418 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002419 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002420
2421 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002422 // "video". Goal is to modify these content names and verify transport
2423 // channels
2424 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002425 // present in SDP.
2426 std::string sdp;
2427 EXPECT_TRUE(offer->ToString(&sdp));
2428 const std::string kAudioMid = "a=mid:audio";
2429 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2430 const std::string kVideoMid = "a=mid:video";
2431 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2432
2433 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002434 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002435 kAudioMidReplaceStr.c_str(),
2436 kAudioMidReplaceStr.length(),
2437 &sdp);
2438 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002439 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002440 kVideoMidReplaceStr.c_str(),
2441 kVideoMidReplaceStr.length(),
2442 &sdp);
2443
2444 SessionDescriptionInterface* modified_offer =
2445 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2446
2447 SetRemoteDescriptionWithoutError(modified_offer);
2448
htaa2a49d92016-03-04 02:51:39 -08002449 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002450 SetLocalDescriptionWithoutError(answer);
2451
deadbeef5bd5ca32017-02-10 11:31:50 -08002452 rtc::PacketTransportInternal* voice_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002453 session_->voice_rtp_transport_channel();
2454 EXPECT_TRUE(voice_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002455 EXPECT_EQ(voice_transport_channel->debug_name(),
2456 "audio_content_name " +
2457 std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
deadbeef5bd5ca32017-02-10 11:31:50 -08002458 rtc::PacketTransportInternal* video_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002459 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002460 ASSERT_TRUE(video_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002461 EXPECT_EQ(video_transport_channel->debug_name(),
2462 "video_content_name " +
2463 std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002464 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2465 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2466}
2467
2468// Test that an offer contains the correct media content descriptions based on
2469// the send streams when no constraints have been set.
2470TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002471 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002472 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002473
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002474 ASSERT_TRUE(offer != NULL);
2475 const cricket::ContentInfo* content =
2476 cricket::GetFirstAudioContent(offer->description());
2477 EXPECT_TRUE(content != NULL);
2478 content = cricket::GetFirstVideoContent(offer->description());
2479 EXPECT_TRUE(content == NULL);
2480}
2481
2482// Test that an offer contains the correct media content descriptions based on
2483// the send streams when no constraints have been set.
2484TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002485 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002486 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002487 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002488 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002489
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002490 const cricket::ContentInfo* content =
2491 cricket::GetFirstAudioContent(offer->description());
2492 EXPECT_TRUE(content != NULL);
2493 content = cricket::GetFirstVideoContent(offer->description());
2494 EXPECT_TRUE(content == NULL);
2495
2496 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002497 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002498 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002499 content = cricket::GetFirstAudioContent(offer->description());
2500 EXPECT_TRUE(content != NULL);
2501 content = cricket::GetFirstVideoContent(offer->description());
2502 EXPECT_TRUE(content != NULL);
2503}
2504
2505// Test that an offer contains no media content descriptions if
2506// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2507TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002508 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002509 PeerConnectionInterface::RTCOfferAnswerOptions options;
2510 options.offer_to_receive_audio = 0;
2511 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002512
kwibergd1fe2812016-04-27 06:47:29 -07002513 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002514
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002515 ASSERT_TRUE(offer != NULL);
2516 const cricket::ContentInfo* content =
2517 cricket::GetFirstAudioContent(offer->description());
2518 EXPECT_TRUE(content == NULL);
2519 content = cricket::GetFirstVideoContent(offer->description());
2520 EXPECT_TRUE(content == NULL);
2521}
2522
2523// Test that an offer contains only audio media content descriptions if
2524// kOfferToReceiveAudio constraints are set to true.
2525TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002526 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002527 PeerConnectionInterface::RTCOfferAnswerOptions options;
2528 options.offer_to_receive_audio =
2529 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2530
kwibergd1fe2812016-04-27 06:47:29 -07002531 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002532
2533 const cricket::ContentInfo* content =
2534 cricket::GetFirstAudioContent(offer->description());
2535 EXPECT_TRUE(content != NULL);
2536 content = cricket::GetFirstVideoContent(offer->description());
2537 EXPECT_TRUE(content == NULL);
2538}
2539
2540// Test that an offer contains audio and video media content descriptions if
2541// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2542TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002543 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002544 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002545 PeerConnectionInterface::RTCOfferAnswerOptions options;
2546 options.offer_to_receive_audio =
2547 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2548 options.offer_to_receive_video =
2549 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2550
kwibergd1fe2812016-04-27 06:47:29 -07002551 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002552
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002553 const cricket::ContentInfo* content =
2554 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002555 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002556
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002557 content = cricket::GetFirstVideoContent(offer->description());
2558 EXPECT_TRUE(content != NULL);
2559
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002560 // Sets constraints to false and verifies that audio/video contents are
2561 // removed.
2562 options.offer_to_receive_audio = 0;
2563 options.offer_to_receive_video = 0;
2564 offer.reset(CreateOffer(options));
2565
2566 content = cricket::GetFirstAudioContent(offer->description());
2567 EXPECT_TRUE(content == NULL);
2568 content = cricket::GetFirstVideoContent(offer->description());
2569 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002570}
2571
2572// Test that an answer can not be created if the last remote description is not
2573// an offer.
2574TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002575 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002576 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002577 SetLocalDescriptionWithoutError(offer);
2578 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2579 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002580 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002581}
2582
2583// Test that an answer contains the correct media content descriptions when no
2584// constraints have been set.
2585TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002586 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002587 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002588 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002589 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002590 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002591 const cricket::ContentInfo* content =
2592 cricket::GetFirstAudioContent(answer->description());
2593 ASSERT_TRUE(content != NULL);
2594 EXPECT_FALSE(content->rejected);
2595
2596 content = cricket::GetFirstVideoContent(answer->description());
2597 ASSERT_TRUE(content != NULL);
2598 EXPECT_FALSE(content->rejected);
2599}
2600
2601// Test that an answer contains the correct media content descriptions when no
2602// constraints have been set and the offer only contain audio.
2603TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002604 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002605 // Create a remote offer with audio only.
2606 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002607
kwibergd1fe2812016-04-27 06:47:29 -07002608 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002609 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2610 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2611
2612 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002613 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002614 const cricket::ContentInfo* content =
2615 cricket::GetFirstAudioContent(answer->description());
2616 ASSERT_TRUE(content != NULL);
2617 EXPECT_FALSE(content->rejected);
2618
2619 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2620}
2621
2622// Test that an answer contains the correct media content descriptions when no
2623// constraints have been set.
2624TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002625 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002626 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002627 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002628 SetRemoteDescriptionWithoutError(offer.release());
2629 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002630 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002631 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002632 const cricket::ContentInfo* content =
2633 cricket::GetFirstAudioContent(answer->description());
2634 ASSERT_TRUE(content != NULL);
2635 EXPECT_FALSE(content->rejected);
2636
2637 content = cricket::GetFirstVideoContent(answer->description());
2638 ASSERT_TRUE(content != NULL);
2639 EXPECT_FALSE(content->rejected);
2640}
2641
2642// Test that an answer contains the correct media content descriptions when
2643// constraints have been set but no stream is sent.
2644TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002645 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002646 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002647 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002648 SetRemoteDescriptionWithoutError(offer.release());
2649
htaa2a49d92016-03-04 02:51:39 -08002650 cricket::MediaSessionOptions session_options;
2651 session_options.recv_audio = false;
2652 session_options.recv_video = false;
kwibergd1fe2812016-04-27 06:47:29 -07002653 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002654 CreateAnswer(session_options));
2655
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002656 const cricket::ContentInfo* content =
2657 cricket::GetFirstAudioContent(answer->description());
2658 ASSERT_TRUE(content != NULL);
2659 EXPECT_TRUE(content->rejected);
2660
2661 content = cricket::GetFirstVideoContent(answer->description());
2662 ASSERT_TRUE(content != NULL);
2663 EXPECT_TRUE(content->rejected);
2664}
2665
2666// Test that an answer contains the correct media content descriptions when
2667// constraints have been set and streams are sent.
2668TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002669 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002670 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002671 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002672 SetRemoteDescriptionWithoutError(offer.release());
2673
htaa2a49d92016-03-04 02:51:39 -08002674 cricket::MediaSessionOptions options;
2675 options.recv_audio = false;
2676 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002677
2678 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002679 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002680 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002681
2682 // TODO(perkj): Should the direction be set to SEND_ONLY?
2683 const cricket::ContentInfo* content =
2684 cricket::GetFirstAudioContent(answer->description());
2685 ASSERT_TRUE(content != NULL);
2686 EXPECT_FALSE(content->rejected);
2687
2688 // TODO(perkj): Should the direction be set to SEND_ONLY?
2689 content = cricket::GetFirstVideoContent(answer->description());
2690 ASSERT_TRUE(content != NULL);
2691 EXPECT_FALSE(content->rejected);
2692}
2693
2694TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2695 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002696 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002697 PeerConnectionInterface::RTCOfferAnswerOptions options;
2698 options.offer_to_receive_audio =
2699 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2700 options.voice_activity_detection = false;
2701
kwibergd1fe2812016-04-27 06:47:29 -07002702 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002703
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002704 const cricket::ContentInfo* content =
2705 cricket::GetFirstAudioContent(offer->description());
2706 EXPECT_TRUE(content != NULL);
2707 EXPECT_TRUE(VerifyNoCNCodecs(content));
2708}
2709
2710TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2711 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002712 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002713 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002714 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002715 SetRemoteDescriptionWithoutError(offer.release());
2716
htaa2a49d92016-03-04 02:51:39 -08002717 cricket::MediaSessionOptions options;
2718 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002719 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002720 const cricket::ContentInfo* content =
2721 cricket::GetFirstAudioContent(answer->description());
2722 ASSERT_TRUE(content != NULL);
2723 EXPECT_TRUE(VerifyNoCNCodecs(content));
2724}
2725
2726// This test verifies the call setup when remote answer with audio only and
2727// later updates with video.
2728TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002729 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002730 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2731 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2732
deadbeefab9b2d12015-10-14 11:33:11 -07002733 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002734 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002735
2736 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002737 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2738
2739 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2740 // and answer;
2741 SetLocalDescriptionWithoutError(offer);
2742 SetRemoteDescriptionWithoutError(answer);
2743
2744 video_channel_ = media_engine_->GetVideoChannel(0);
2745 voice_channel_ = media_engine_->GetVoiceChannel(0);
2746
2747 ASSERT_TRUE(video_channel_ == NULL);
2748
2749 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2750 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2751 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2752
2753 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002754 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002755 CreateAndSetRemoteOfferAndLocalAnswer();
2756
2757 video_channel_ = media_engine_->GetVideoChannel(0);
2758 voice_channel_ = media_engine_->GetVoiceChannel(0);
2759
2760 ASSERT_TRUE(video_channel_ != NULL);
2761 ASSERT_TRUE(voice_channel_ != NULL);
2762
2763 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2764 ASSERT_EQ(1u, video_channel_->send_streams().size());
2765 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2766 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2767 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2768 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2769 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2770 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2771
2772 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002773 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002774 CreateAndSetRemoteOfferAndLocalAnswer();
2775
2776 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2777 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2778 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2779 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2780 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2781}
2782
2783// This test verifies the call setup when remote answer with video only and
2784// later updates with audio.
2785TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002786 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002787 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2788 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002789 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002790 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002791
2792 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002793 options.recv_audio = false;
2794 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002795 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2796 offer, options, cricket::SEC_ENABLED);
2797
2798 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2799 // and answer.
2800 SetLocalDescriptionWithoutError(offer);
2801 SetRemoteDescriptionWithoutError(answer);
2802
2803 video_channel_ = media_engine_->GetVideoChannel(0);
2804 voice_channel_ = media_engine_->GetVoiceChannel(0);
2805
2806 ASSERT_TRUE(voice_channel_ == NULL);
2807 ASSERT_TRUE(video_channel_ != NULL);
2808
2809 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2810 ASSERT_EQ(1u, video_channel_->send_streams().size());
2811 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2812
2813 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002814 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002815 CreateAndSetRemoteOfferAndLocalAnswer();
2816
2817 voice_channel_ = media_engine_->GetVoiceChannel(0);
2818 ASSERT_TRUE(voice_channel_ != NULL);
2819
2820 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2821 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2822 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2823 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2824
2825 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002826 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002827 CreateAndSetRemoteOfferAndLocalAnswer();
2828
2829 video_channel_ = media_engine_->GetVideoChannel(0);
2830 voice_channel_ = media_engine_->GetVoiceChannel(0);
2831
2832 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2833 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2834 ASSERT_EQ(1u, video_channel_->send_streams().size());
2835 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2836}
2837
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002838TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002839 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002840 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002841 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002842 VerifyCryptoParams(offer->description());
2843 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002844 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002845 VerifyCryptoParams(answer->description());
2846}
2847
jbauchcb560652016-08-04 05:20:32 -07002848TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDPGcm) {
2849 InitWithGcm();
2850 SendAudioVideoStream1();
2851 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
2852 VerifyCryptoParams(offer->description(), true);
2853 SetRemoteDescriptionWithoutError(offer.release());
2854 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
2855 VerifyCryptoParams(answer->description(), true);
2856}
2857
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002858TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002859 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002860 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002861 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002862 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002863 VerifyNoCryptoParams(offer->description(), false);
2864}
2865
2866TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002867 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002868 VerifyAnswerFromNonCryptoOffer();
2869}
2870
2871TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002872 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002873 VerifyAnswerFromCryptoOffer();
2874}
2875
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002876// This test verifies that setLocalDescription fails if
2877// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2878TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002879 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002880 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002881 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002882
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002883 std::string sdp;
2884 RemoveIceUfragPwdLines(offer.get(), &sdp);
2885 SessionDescriptionInterface* modified_offer =
2886 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002887 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002888}
2889
2890// This test verifies that setRemoteDescription fails if
2891// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2892TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002893 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002894 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002895 std::string sdp;
2896 RemoveIceUfragPwdLines(offer.get(), &sdp);
2897 SessionDescriptionInterface* modified_offer =
2898 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002899 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002900}
2901
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002902// This test verifies that setLocalDescription fails if local offer has
2903// too short ice ufrag and pwd strings.
2904TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002905 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002906 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002907 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002908 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2909 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002910 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002911 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002912 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002913
2914 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002915 offer.reset(CreateOffer());
2916 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2917 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002918}
2919
2920// This test verifies that setRemoteDescription fails if remote offer has
2921// too short ice ufrag and pwd strings.
2922TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002923 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002924 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002925 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2926 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002927 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002928 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002929 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002930
deadbeef0ed85b22016-02-23 17:24:52 -08002931 offer.reset(CreateRemoteOffer());
2932 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2933 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002934}
2935
Honghai Zhang04e91462015-12-11 14:26:22 -08002936// Test that if the remote offer indicates the peer requested ICE restart (via
2937// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2938TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002939 Init();
honghaiz503726c2015-07-31 12:37:38 -07002940
2941 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07002942 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08002943 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002944 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2945 0, "", "", "relay", 0, "");
2946 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2947 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002948 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2949 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002950 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2951
2952 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002953 offer.reset(CreateRemoteOffer());
2954 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002955 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2956 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2957 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002958 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2959 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002960 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2961
2962 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002963 offer.reset(CreateRemoteOffer());
2964 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002965 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2966 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2967 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002968 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2969 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002970 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2971
2972 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002973 offer.reset(CreateRemoteOffer());
2974 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2975 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002976 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2977}
2978
Honghai Zhang04e91462015-12-11 14:26:22 -08002979// Test that if the remote answer indicates the peer requested ICE restart (via
2980// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2981TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2982 Init();
2983 SessionDescriptionInterface* offer = CreateOffer();
2984 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002985
2986 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07002987 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08002988 answer->set_type(JsepSessionDescription::kPrAnswer);
2989 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002990 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2991 0, "", "", "relay", 0, "");
2992 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2993 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002994 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2995 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002996 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2997
2998 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002999 answer.reset(CreateRemoteAnswer(offer));
3000 answer->set_type(JsepSessionDescription::kPrAnswer);
3001 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08003002 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3003 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3004 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003005 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
3006 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003007 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
3008
3009 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08003010 answer.reset(CreateRemoteAnswer(offer));
3011 answer->set_type(JsepSessionDescription::kPrAnswer);
3012 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08003013 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
3014 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
3015 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003016 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
3017 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003018 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
3019
3020 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08003021 answer.reset(CreateRemoteAnswer(offer));
3022 answer->set_type(JsepSessionDescription::kPrAnswer);
3023 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
3024 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003025 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
3026}
3027
Donald Curtisd4f769d2015-05-28 09:48:21 -07003028// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07003029// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07003030TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
3031 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
3032
3033 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003034 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003035
3036 PeerConnectionInterface::RTCOfferAnswerOptions options;
3037 options.use_rtp_mux = true;
3038
3039 SessionDescriptionInterface* offer = CreateRemoteOffer();
3040 SetRemoteDescriptionWithoutError(offer);
3041
htaa2a49d92016-03-04 02:51:39 -08003042 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003043 SetLocalDescriptionWithoutError(answer);
3044
deadbeefcbecd352015-09-23 11:50:27 -07003045 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3046 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07003047
deadbeefcbecd352015-09-23 11:50:27 -07003048 cricket::BaseChannel* voice_channel = session_->voice_channel();
nissec8ee8822017-01-18 07:20:55 -08003049 ASSERT_TRUE(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003050
3051 // Checks if one of the transport channels contains a connection using a given
3052 // port.
deadbeefcbecd352015-09-23 11:50:27 -07003053 auto connection_with_remote_port = [this, voice_channel](int port) {
hbosdf6075a2016-12-19 04:58:02 -08003054 std::unique_ptr<webrtc::SessionStats> stats = session_->GetStats_s();
3055 for (auto& kv : stats->transport_stats) {
deadbeefcbecd352015-09-23 11:50:27 -07003056 for (auto& chan_stat : kv.second.channel_stats) {
3057 for (auto& conn_info : chan_stat.connection_infos) {
3058 if (conn_info.remote_candidate.address().port() == port) {
3059 return true;
3060 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07003061 }
3062 }
3063 }
3064 return false;
3065 };
3066
3067 EXPECT_FALSE(connection_with_remote_port(5000));
3068 EXPECT_FALSE(connection_with_remote_port(5001));
3069 EXPECT_FALSE(connection_with_remote_port(6000));
3070
3071 // The way the *_WAIT checks work is they only wait if the condition fails,
3072 // which does not help in the case where state is not changing. This is
3073 // problematic in this test since we want to verify that adding a video
3074 // candidate does _not_ change state. So we interleave candidates and assume
3075 // that messages are executed in the order they were posted.
3076
3077 // First audio candidate.
3078 cricket::Candidate candidate0;
3079 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3080 candidate0.set_component(1);
3081 candidate0.set_protocol("udp");
zhihuang38989e52017-03-21 11:04:53 -07003082 candidate0.set_type("local");
Donald Curtisd4f769d2015-05-28 09:48:21 -07003083 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3084 candidate0);
3085 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3086
3087 // Video candidate.
3088 cricket::Candidate candidate1;
3089 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3090 candidate1.set_component(1);
3091 candidate1.set_protocol("udp");
zhihuang38989e52017-03-21 11:04:53 -07003092 candidate1.set_type("local");
Donald Curtisd4f769d2015-05-28 09:48:21 -07003093 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3094 candidate1);
3095 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3096
3097 // Second audio candidate.
3098 cricket::Candidate candidate2;
3099 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3100 candidate2.set_component(1);
3101 candidate2.set_protocol("udp");
zhihuang38989e52017-03-21 11:04:53 -07003102 candidate2.set_type("local");
Donald Curtisd4f769d2015-05-28 09:48:21 -07003103 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3104 candidate2);
3105 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3106
3107 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3108 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3109
3110 // No need here for a _WAIT check since we are checking that state hasn't
3111 // changed: if this is false we would be doing waits for nothing and if this
3112 // is true then there will be no messages processed anyways.
3113 EXPECT_FALSE(connection_with_remote_port(6000));
3114}
3115
deadbeefcbecd352015-09-23 11:50:27 -07003116// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003117TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3118 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003119 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003120
3121 PeerConnectionInterface::RTCOfferAnswerOptions options;
3122 options.use_rtp_mux = true;
3123
3124 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003125 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003126
deadbeefcbecd352015-09-23 11:50:27 -07003127 EXPECT_NE(session_->voice_rtp_transport_channel(),
3128 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003129
deadbeefab9b2d12015-10-14 11:33:11 -07003130 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003131 SessionDescriptionInterface* answer =
3132 CreateRemoteAnswer(session_->local_description());
3133 SetRemoteDescriptionWithoutError(answer);
3134
deadbeefcbecd352015-09-23 11:50:27 -07003135 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3136 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003137}
3138
deadbeefcbecd352015-09-23 11:50:27 -07003139// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003140TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3141 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003142 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003143
Donald Curtis0e209b02015-03-24 09:29:54 -07003144 PeerConnectionInterface::RTCOfferAnswerOptions options;
3145 options.use_rtp_mux = true;
3146
3147 SessionDescriptionInterface* offer = CreateOffer(options);
3148 SetLocalDescriptionWithoutError(offer);
3149
deadbeefcbecd352015-09-23 11:50:27 -07003150 EXPECT_NE(session_->voice_rtp_transport_channel(),
3151 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003152
deadbeefab9b2d12015-10-14 11:33:11 -07003153 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003154
3155 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003156 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003157 CreateRemoteAnswer(session_->local_description()));
3158 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3159 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3160 JsepSessionDescription* modified_answer =
3161 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3162 modified_answer->Initialize(answer_copy, "1", "1");
3163 SetRemoteDescriptionWithoutError(modified_answer); //
3164
deadbeefcbecd352015-09-23 11:50:27 -07003165 EXPECT_NE(session_->voice_rtp_transport_channel(),
3166 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003167}
3168
3169// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3170TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3171 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003172 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003173
3174 PeerConnectionInterface::RTCOfferAnswerOptions options;
3175 options.use_rtp_mux = true;
3176
3177 SessionDescriptionInterface* offer = CreateOffer(options);
3178 SetLocalDescriptionWithoutError(offer);
3179
deadbeefcbecd352015-09-23 11:50:27 -07003180 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3181 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003182
deadbeefab9b2d12015-10-14 11:33:11 -07003183 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003184 SessionDescriptionInterface* answer =
3185 CreateRemoteAnswer(session_->local_description());
3186 SetRemoteDescriptionWithoutError(answer);
3187
deadbeefcbecd352015-09-23 11:50:27 -07003188 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3189 session_->video_rtp_transport_channel());
3190}
3191
3192// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3193// audio content in the answer.
3194TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3195 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003196 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003197
3198 PeerConnectionInterface::RTCOfferAnswerOptions options;
3199 options.use_rtp_mux = true;
3200
3201 SessionDescriptionInterface* offer = CreateOffer(options);
3202 SetLocalDescriptionWithoutError(offer);
3203
3204 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3205 session_->video_rtp_transport_channel());
3206
deadbeefab9b2d12015-10-14 11:33:11 -07003207 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003208 cricket::MediaSessionOptions recv_options;
3209 recv_options.recv_audio = false;
3210 recv_options.recv_video = true;
3211 SessionDescriptionInterface* answer =
3212 CreateRemoteAnswer(session_->local_description(), recv_options);
3213 SetRemoteDescriptionWithoutError(answer);
3214
deadbeefd59daf82015-10-14 15:02:44 -07003215 EXPECT_TRUE(nullptr == session_->voice_channel());
3216 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003217
deadbeefd59daf82015-10-14 15:02:44 -07003218 session_->Close();
3219 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3220 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3221 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3222 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003223}
3224
3225// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3226TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3227 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003228 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003229
Donald Curtis0e209b02015-03-24 09:29:54 -07003230 PeerConnectionInterface::RTCOfferAnswerOptions options;
3231 options.use_rtp_mux = true;
3232
3233 SessionDescriptionInterface* offer = CreateOffer(options);
3234 SetLocalDescriptionWithoutError(offer);
3235
deadbeefcbecd352015-09-23 11:50:27 -07003236 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3237 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003238
deadbeefab9b2d12015-10-14 11:33:11 -07003239 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003240
3241 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003242 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003243 CreateRemoteAnswer(session_->local_description()));
3244 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3245 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3246 JsepSessionDescription* modified_answer =
3247 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3248 modified_answer->Initialize(answer_copy, "1", "1");
3249 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003250
deadbeefcbecd352015-09-23 11:50:27 -07003251 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3252 session_->video_rtp_transport_channel());
3253}
3254
3255// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3256TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3257 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003258 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003259
3260 SessionDescriptionInterface* offer = CreateRemoteOffer();
3261 SetRemoteDescriptionWithoutError(offer);
3262
3263 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3264 session_->video_rtp_transport_channel());
3265
deadbeefab9b2d12015-10-14 11:33:11 -07003266 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003267 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003268 SetLocalDescriptionWithoutError(answer);
3269
3270 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3271 session_->video_rtp_transport_channel());
3272}
3273
3274// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3275TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3276 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003277 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003278
3279 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003280 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003281 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3282 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3283 JsepSessionDescription* modified_offer =
3284 new JsepSessionDescription(JsepSessionDescription::kOffer);
3285 modified_offer->Initialize(offer_copy, "1", "1");
3286
3287 // Expect an error when applying the remote description
3288 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3289 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003290}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003291
Peter Thatcher4eddf182015-04-30 10:55:59 -07003292// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003293TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3294 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003295 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003296
Donald Curtis0e209b02015-03-24 09:29:54 -07003297 PeerConnectionInterface::RTCOfferAnswerOptions options;
3298 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003299
Donald Curtis0e209b02015-03-24 09:29:54 -07003300 SessionDescriptionInterface* offer = CreateOffer(options);
3301 SetLocalDescriptionWithoutError(offer);
3302
deadbeefcbecd352015-09-23 11:50:27 -07003303 EXPECT_NE(session_->voice_rtp_transport_channel(),
3304 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003305
deadbeefab9b2d12015-10-14 11:33:11 -07003306 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003307 SessionDescriptionInterface* answer =
3308 CreateRemoteAnswer(session_->local_description());
3309 SetRemoteDescriptionWithoutError(answer);
3310
3311 // This should lead to an audio-only call but isn't implemented
3312 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003313 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3314 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003315}
3316
deadbeefcbecd352015-09-23 11:50:27 -07003317// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003318TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3319 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003320 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003321 PeerConnectionInterface::RTCOfferAnswerOptions options;
3322 options.use_rtp_mux = true;
3323
3324 SessionDescriptionInterface* offer = CreateOffer(options);
3325 SetLocalDescriptionWithoutError(offer);
3326
deadbeefcbecd352015-09-23 11:50:27 -07003327 EXPECT_NE(session_->voice_rtp_transport_channel(),
3328 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003329
deadbeefab9b2d12015-10-14 11:33:11 -07003330 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003331
3332 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003333 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003334 CreateRemoteAnswer(session_->local_description()));
3335 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3336 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3337 JsepSessionDescription* modified_answer =
3338 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3339 modified_answer->Initialize(answer_copy, "1", "1");
3340 SetRemoteDescriptionWithoutError(modified_answer); //
3341
deadbeefcbecd352015-09-23 11:50:27 -07003342 EXPECT_NE(session_->voice_rtp_transport_channel(),
3343 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003344}
3345
Peter Thatcher4eddf182015-04-30 10:55:59 -07003346// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3347TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3348 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003349 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003350
3351 PeerConnectionInterface::RTCOfferAnswerOptions options;
3352 options.use_rtp_mux = true;
3353
3354 SessionDescriptionInterface* offer = CreateOffer(options);
3355 SetRemoteDescriptionWithoutError(offer);
3356
deadbeefcbecd352015-09-23 11:50:27 -07003357 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3358 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003359}
3360
skvlad6c87a672016-05-17 17:49:52 -07003361// Adding a new channel to a BUNDLE which is already connected should directly
3362// assign the bundle transport to the channel, without first setting a
3363// disconnected non-bundle transport and then replacing it. The application
3364// should not receive any changes in the ICE state.
3365TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) {
3366 LoopbackNetworkConfiguration config;
3367 LoopbackNetworkManager loopback_network_manager(this, config);
3368 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain
3369 // connected. Disabling either of these two means that we need to wait for the
3370 // answer to find out if more transports are needed.
3371 configuration_.bundle_policy =
3372 PeerConnectionInterface::kBundlePolicyMaxBundle;
skvlad6c87a672016-05-17 17:49:52 -07003373 options_.disable_encryption = true;
deadbeef7914b8c2017-04-21 03:23:33 -07003374 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
skvlad6c87a672016-05-17 17:49:52 -07003375
3376 // Negotiate an audio channel with MAX_BUNDLE enabled.
3377 SendAudioOnlyStream2();
3378 SessionDescriptionInterface* offer = CreateOffer();
3379 SetLocalDescriptionWithoutError(offer);
3380 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
3381 observer_.ice_gathering_state_, kIceCandidatesTimeout);
3382 std::string sdp;
3383 offer->ToString(&sdp);
3384 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription(
3385 JsepSessionDescription::kAnswer, sdp, nullptr);
3386 ASSERT_TRUE(answer != NULL);
3387 SetRemoteDescriptionWithoutError(answer);
3388
3389 // Wait for the ICE state to stabilize.
3390 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3391 observer_.ice_connection_state_, kIceCandidatesTimeout);
3392 observer_.ice_connection_state_history_.clear();
3393
3394 // Now add a video channel which should be using the same bundle transport.
3395 SendAudioVideoStream2();
3396 offer = CreateOffer();
3397 offer->ToString(&sdp);
3398 SetLocalDescriptionWithoutError(offer);
3399 answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer,
3400 sdp, nullptr);
3401 ASSERT_TRUE(answer != NULL);
3402 SetRemoteDescriptionWithoutError(answer);
3403
3404 // Wait for ICE state to stabilize
3405 rtc::Thread::Current()->ProcessMessages(0);
3406 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3407 observer_.ice_connection_state_, kIceCandidatesTimeout);
3408
3409 // No ICE state changes are expected to happen.
3410 EXPECT_EQ(0, observer_.ice_connection_state_history_.size());
3411}
3412
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003413TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3414 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003415 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003416
3417 PeerConnectionInterface::RTCOfferAnswerOptions options;
3418 SessionDescriptionInterface* offer = CreateOffer(options);
3419 SetLocalDescriptionWithoutError(offer);
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
deadbeefab9b2d12015-10-14 11:33:11 -07003424 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003425 SessionDescriptionInterface* answer =
3426 CreateRemoteAnswer(session_->local_description());
3427 SetRemoteDescriptionWithoutError(answer);
3428
deadbeefcbecd352015-09-23 11:50:27 -07003429 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3430 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003431}
3432
3433TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3434 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003435 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003436
3437 PeerConnectionInterface::RTCOfferAnswerOptions options;
3438 SessionDescriptionInterface* offer = CreateOffer(options);
3439 SetLocalDescriptionWithoutError(offer);
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
deadbeefab9b2d12015-10-14 11:33:11 -07003444 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003445 SessionDescriptionInterface* answer =
3446 CreateRemoteAnswer(session_->local_description());
3447 SetRemoteDescriptionWithoutError(answer);
3448
deadbeefcbecd352015-09-23 11:50:27 -07003449 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3450 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003451}
3452
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003453// This test verifies that SetLocalDescription and SetRemoteDescription fails
3454// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3455TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003456 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003457 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003458
3459 PeerConnectionInterface::RTCOfferAnswerOptions options;
3460 options.use_rtp_mux = true;
3461
3462 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003463 std::string offer_str;
3464 offer->ToString(&offer_str);
3465 // Disable rtcp-mux
3466 const std::string rtcp_mux = "rtcp-mux";
3467 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003468 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003469 xrtcp_mux.c_str(), xrtcp_mux.length(),
3470 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003471 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003472 new JsepSessionDescription(JsepSessionDescription::kOffer);
3473 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003474 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003475 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003476 new JsepSessionDescription(JsepSessionDescription::kOffer);
3477 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003478 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003479 // Trying unmodified SDP.
3480 SetLocalDescriptionWithoutError(offer);
3481}
3482
jbauchcb560652016-08-04 05:20:32 -07003483TEST_F(WebRtcSessionTest, SetSetupGcm) {
3484 InitWithGcm();
3485 SendAudioVideoStream1();
3486 CreateAndSetRemoteOfferAndLocalAnswer();
3487}
3488
deadbeefd59daf82015-10-14 15:02:44 -07003489// This test verifies the |initial_offerer| flag when session initiates the
3490// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003491TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003492 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003493 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003494 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003495 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3496 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003497 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003498 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003499 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003500}
3501
deadbeefd59daf82015-10-14 15:02:44 -07003502// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003503TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003504 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003505 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003506 SessionDescriptionInterface* offer = CreateRemoteOffer();
3507 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003508 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003509
deadbeefd59daf82015-10-14 15:02:44 -07003510 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003511 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003512 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003513}
3514
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003515// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3516TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003517 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003518 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003519 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003520 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003521 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003522 CreateRemoteAnswer(session_->local_description()));
3523
3524 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3525 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003526 JsepSessionDescription* modified_answer =
3527 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003528
3529 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3530 answer->session_id(),
3531 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003532 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003533
wu@webrtc.org4e393072014-04-07 17:04:35 +00003534 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003535 std::string sdp;
3536 EXPECT_TRUE(answer->ToString(&sdp));
3537 const std::string kAudioMid = "a=mid:audio";
3538 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003539 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003540 kAudioMidReplaceStr.c_str(),
3541 kAudioMidReplaceStr.length(),
3542 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003543 SessionDescriptionInterface* modified_answer1 =
3544 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003545 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003546
wu@webrtc.org4e393072014-04-07 17:04:35 +00003547 // Different media types.
3548 EXPECT_TRUE(answer->ToString(&sdp));
3549 const std::string kAudioMline = "m=audio";
3550 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003551 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003552 kAudioMlineReplaceStr.c_str(),
3553 kAudioMlineReplaceStr.length(),
3554 &sdp);
3555 SessionDescriptionInterface* modified_answer2 =
3556 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3557 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3558
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003559 SetRemoteDescriptionWithoutError(answer.release());
3560}
3561
3562// Verifying remote offer and local answer have matching m-lines as per
3563// RFC 3264.
3564TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003565 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003566 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003567 SessionDescriptionInterface* offer = CreateRemoteOffer();
3568 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003569 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003570
3571 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3572 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003573 JsepSessionDescription* modified_answer =
3574 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003575
3576 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3577 answer->session_id(),
3578 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003579 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003580 SetLocalDescriptionWithoutError(answer);
3581}
3582
3583// This test verifies that WebRtcSession does not start candidate allocation
3584// before SetLocalDescription is called.
3585TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003586 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003587 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003588 SessionDescriptionInterface* offer = CreateRemoteOffer();
3589 cricket::Candidate candidate;
3590 candidate.set_component(1);
3591 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3592 candidate);
3593 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3594 cricket::Candidate candidate1;
3595 candidate1.set_component(1);
3596 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3597 candidate1);
3598 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3599 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003600 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3601 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003602
3603 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003604 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003605 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3606 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3607
htaa2a49d92016-03-04 02:51:39 -08003608 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003609 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003610 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3611}
3612
3613// This test verifies that crypto parameter is updated in local session
3614// description as per security policy set in MediaSessionDescriptionFactory.
3615TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003616 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003617 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003618 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003619
3620 // Making sure SetLocalDescription correctly sets crypto value in
3621 // SessionDescription object after de-serialization of sdp string. The value
3622 // will be set as per MediaSessionDescriptionFactory.
3623 std::string offer_str;
3624 offer->ToString(&offer_str);
3625 SessionDescriptionInterface* jsep_offer_str =
3626 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3627 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003628 EXPECT_TRUE(session_->voice_channel()->srtp_required_for_testing());
3629 EXPECT_TRUE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003630}
3631
3632// This test verifies the crypto parameter when security is disabled.
3633TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003634 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003635 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003636 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003637 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003638
3639 // Making sure SetLocalDescription correctly sets crypto value in
3640 // SessionDescription object after de-serialization of sdp string. The value
3641 // will be set as per MediaSessionDescriptionFactory.
3642 std::string offer_str;
3643 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003644 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003645 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3646 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003647 EXPECT_FALSE(session_->voice_channel()->srtp_required_for_testing());
3648 EXPECT_FALSE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003649}
3650
3651// This test verifies that an answer contains new ufrag and password if an offer
3652// with new ufrag and password is received.
3653TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003654 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003655 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003656 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003657 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003658 SetRemoteDescriptionWithoutError(offer.release());
3659
deadbeefab9b2d12015-10-14 11:33:11 -07003660 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003661 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003662 SetLocalDescriptionWithoutError(answer.release());
3663
3664 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003665 for (const cricket::ContentInfo& content :
3666 session_->local_description()->description()->contents()) {
3667 options.transport_options[content.name].ice_restart = true;
3668 }
kwibergd1fe2812016-04-27 06:47:29 -07003669 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003670 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003671 SetRemoteDescriptionWithoutError(updated_offer1.release());
3672
kwibergd1fe2812016-04-27 06:47:29 -07003673 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003674
deadbeef0ed85b22016-02-23 17:24:52 -08003675 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3676 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003677
deadbeef0ed85b22016-02-23 17:24:52 -08003678 // Even a second answer (created before the description is set) should have
3679 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003680 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003681
3682 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3683 session_->local_description()->description()));
3684
3685 SetLocalDescriptionWithoutError(updated_answer2.release());
3686}
3687
3688// This test verifies that an answer contains new ufrag and password if an offer
3689// that changes either the ufrag or password (but not both) is received.
3690// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3691// a=ice-pwd attributes compared to the previous SDP from the peer, it
3692// indicates that ICE is restarting for this media stream."
3693TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3694 Init();
3695 cricket::MediaSessionOptions options;
3696 options.recv_audio = true;
3697 options.recv_video = true;
3698 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003699 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003700 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3701 SetRemoteDescriptionWithoutError(offer.release());
3702
3703 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003704 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003705 SetLocalDescriptionWithoutError(answer.release());
3706
3707 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003708 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003709 CreateRemoteOffer(options, session_->remote_description()));
3710 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3711 "original_password12345");
3712 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3713
kwibergd1fe2812016-04-27 06:47:29 -07003714 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003715 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3716 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003717 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003718
3719 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003720 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003721 CreateRemoteOffer(options, session_->remote_description()));
3722 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3723 "modified_password12345");
3724 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3725
kwibergd1fe2812016-04-27 06:47:29 -07003726 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003727 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3728 session_->local_description()->description()));
3729 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003730}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003731
wu@webrtc.org91053e72013-08-10 07:18:04 +00003732// This test verifies that an answer contains old ufrag and password if an offer
3733// with old ufrag and password is received.
3734TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003735 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003736 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003737 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003738 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003739 SetRemoteDescriptionWithoutError(offer.release());
3740
deadbeefab9b2d12015-10-14 11:33:11 -07003741 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003742 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003743 SetLocalDescriptionWithoutError(answer.release());
3744
3745 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003746 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003747 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003748 SetRemoteDescriptionWithoutError(updated_offer2.release());
3749
kwibergd1fe2812016-04-27 06:47:29 -07003750 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003751
deadbeef0ed85b22016-02-23 17:24:52 -08003752 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3753 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003754
3755 SetLocalDescriptionWithoutError(updated_answer2.release());
3756}
3757
deadbeef0ed85b22016-02-23 17:24:52 -08003758// This test verifies that if an offer does an ICE restart on some, but not all
3759// media sections, the answer will change the ufrag/password in the correct
3760// media sections.
3761TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3762 Init();
3763 cricket::MediaSessionOptions options;
3764 options.recv_video = true;
3765 options.recv_audio = true;
3766 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003767 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003768
3769 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3770 "aaaaaaaaaaaaaaaaaaaaaa");
3771 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3772 "bbbbbbbbbbbbbbbbbbbbbb");
3773 SetRemoteDescriptionWithoutError(offer.release());
3774
3775 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003776 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003777 SetLocalDescriptionWithoutError(answer.release());
3778
3779 // Receive an offer with new ufrag and password, but only for the video media
3780 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003781 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003782 CreateRemoteOffer(options, session_->remote_description()));
3783 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3784 "cccccccccccccccccccccc");
3785 SetRemoteDescriptionWithoutError(updated_offer.release());
3786
kwibergd1fe2812016-04-27 06:47:29 -07003787 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003788
3789 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3790 session_->local_description()->description(),
3791 cricket::MEDIA_TYPE_AUDIO));
3792
3793 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3794 session_->local_description()->description(),
3795 cricket::MEDIA_TYPE_VIDEO));
3796
3797 SetLocalDescriptionWithoutError(updated_answer.release());
3798}
3799
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003800TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003801 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003802 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003803 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003804 const std::string session_id_orig = offer->session_id();
3805 const std::string session_version_orig = offer->session_version();
3806 SetLocalDescriptionWithoutError(offer);
3807
3808 video_channel_ = media_engine_->GetVideoChannel(0);
3809 video_channel_->set_fail_set_send_codecs(true);
3810
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003811 SessionDescriptionInterface* answer =
3812 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003813 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003814
3815 // Test that after a content error, setting any description will
3816 // result in an error.
3817 video_channel_->set_fail_set_send_codecs(false);
3818 answer = CreateRemoteAnswer(session_->local_description());
3819 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3820 offer = CreateRemoteOffer();
3821 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003822}
3823
3824// Runs the loopback call test with BUNDLE and STUN disabled.
3825TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3826 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003827 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003828 cricket::PORTALLOCATOR_DISABLE_STUN |
3829 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003830 TestLoopbackCall();
3831}
3832
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003833TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003834 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003835 cricket::PORTALLOCATOR_DISABLE_STUN |
3836 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3837 cricket::PORTALLOCATOR_DISABLE_RELAY);
3838
3839 // best connection is IPv6 since it has higher network preference.
3840 LoopbackNetworkConfiguration config;
3841 config.test_ipv6_network_ = true;
3842 config.best_connection_after_initial_ice_converged_ =
3843 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3844
3845 TestLoopbackCall(config);
3846}
3847
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003848// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003849TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003850 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3851 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003852 TestLoopbackCall();
3853}
3854
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003855TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003856 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003857 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003858 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003859 ASSERT_TRUE(data_engine_);
deadbeef953c2ce2017-01-09 14:53:41 -08003860 EXPECT_NE(nullptr, data_engine_->GetChannel(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003861}
3862
Henrik Boström87713d02015-08-25 09:53:21 +02003863TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
htaa2a49d92016-03-04 02:51:39 -08003864 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003865 options_.disable_sctp_data_channels = false;
3866
Henrik Boström87713d02015-08-25 09:53:21 +02003867 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003868
3869 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003870 EXPECT_NE(nullptr, data_engine_->GetChannel(0));
3871}
3872
3873// Test that sctp_content_name/sctp_transport_name (used for stats) are correct
3874// before and after BUNDLE is negotiated.
3875TEST_P(WebRtcSessionTest, SctpContentAndTransportName) {
deadbeef953c2ce2017-01-09 14:53:41 -08003876 SetFactoryDtlsSrtp();
3877 InitWithDtls(GetParam());
3878
3879 // Initially these fields should be empty.
3880 EXPECT_FALSE(session_->sctp_content_name());
3881 EXPECT_FALSE(session_->sctp_transport_name());
3882
3883 // Create offer with audio/video/data.
3884 // Default bundle policy is "balanced", so data should be using its own
3885 // transport.
3886 SendAudioVideoStream1();
3887 CreateDataChannel();
3888 InitiateCall();
3889 ASSERT_TRUE(session_->sctp_content_name());
3890 ASSERT_TRUE(session_->sctp_transport_name());
3891 EXPECT_EQ("data", *session_->sctp_content_name());
3892 EXPECT_EQ("data", *session_->sctp_transport_name());
3893
3894 // Create answer that finishes BUNDLE negotiation, which means everything
3895 // should be bundled on the first transport (audio).
3896 cricket::MediaSessionOptions answer_options;
3897 answer_options.recv_video = true;
3898 answer_options.bundle_enabled = true;
3899 answer_options.data_channel_type = cricket::DCT_SCTP;
3900 SetRemoteDescriptionWithoutError(CreateRemoteAnswer(
3901 session_->local_description(), answer_options, cricket::SEC_DISABLED));
3902 ASSERT_TRUE(session_->sctp_content_name());
3903 ASSERT_TRUE(session_->sctp_transport_name());
3904 EXPECT_EQ("data", *session_->sctp_content_name());
3905 EXPECT_EQ("audio", *session_->sctp_transport_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003906}
3907
Henrik Boström87713d02015-08-25 09:53:21 +02003908TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
Henrik Boström87713d02015-08-25 09:53:21 +02003909 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003910
kwibergd1fe2812016-04-27 06:47:29 -07003911 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003912 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003913 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3914}
3915
Henrik Boström87713d02015-08-25 09:53:21 +02003916TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003917 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003918 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003919
3920 // Create remote offer with SCTP.
3921 cricket::MediaSessionOptions options;
3922 options.data_channel_type = cricket::DCT_SCTP;
3923 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003924 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003925 SetRemoteDescriptionWithoutError(offer);
3926
3927 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07003928 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003929 EXPECT_TRUE(answer != NULL);
3930 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3931 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003932}
3933
deadbeef953c2ce2017-01-09 14:53:41 -08003934// Test that if DTLS is disabled, we don't end up with an SctpTransport
3935// created (or an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02003936TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003937 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003938 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003939
3940 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003941 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
3942 EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003943}
3944
deadbeef953c2ce2017-01-09 14:53:41 -08003945// Test that if DTLS is enabled, we end up with an SctpTransport created
3946// (and not an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02003947TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
Henrik Boström87713d02015-08-25 09:53:21 +02003948 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003949
3950 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003951 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
3952 EXPECT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003953}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003954
deadbeef953c2ce2017-01-09 14:53:41 -08003955// Test that if SCTP is disabled, we don't end up with an SctpTransport
3956// created (or an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02003957TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003958 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003959 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003960
3961 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003962 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
3963 EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003964}
3965
Henrik Boström87713d02015-08-25 09:53:21 +02003966TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003967 const int new_send_port = 9998;
3968 const int new_recv_port = 7775;
3969
Henrik Boström87713d02015-08-25 09:53:21 +02003970 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003971 SetFactoryDtlsSrtp();
3972
3973 // By default, don't actually add the codecs to desc_factory_; they don't
3974 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3975 // let the session description get parsed. That'll get the proper codecs
3976 // into the stream.
3977 cricket::MediaSessionOptions options;
3978 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3979 "stream1", new_send_port, options);
3980
3981 // SetRemoteDescription will take the ownership of the offer.
3982 SetRemoteDescriptionWithoutError(offer);
3983
htaa2a49d92016-03-04 02:51:39 -08003984 SessionDescriptionInterface* answer =
3985 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003986 ASSERT_TRUE(answer != NULL);
3987
3988 // Now set the local description, which'll take ownership of the answer.
3989 SetLocalDescriptionWithoutError(answer);
3990
3991 // TEST PLAN: Set the port number to something new, set it in the SDP,
3992 // and pass it all the way down.
deadbeef953c2ce2017-01-09 14:53:41 -08003993 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003994 CreateDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003995 ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
3996 EXPECT_EQ(
3997 new_recv_port,
3998 fake_sctp_transport_factory_->last_fake_sctp_transport()->local_port());
3999 EXPECT_EQ(
4000 new_send_port,
4001 fake_sctp_transport_factory_->last_fake_sctp_transport()->remote_port());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004002}
4003
deadbeef953c2ce2017-01-09 14:53:41 -08004004// Verifies that when a session's SctpTransport receives an OPEN message,
4005// WebRtcSession signals the SctpTransport creation request with the expected
deadbeefab9b2d12015-10-14 11:33:11 -07004006// config.
4007TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
deadbeefab9b2d12015-10-14 11:33:11 -07004008 InitWithDtls(GetParam());
4009
4010 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004011 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4012 ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
deadbeefab9b2d12015-10-14 11:33:11 -07004013
deadbeef953c2ce2017-01-09 14:53:41 -08004014 // Make the fake SCTP transport pretend it received an OPEN message.
deadbeefab9b2d12015-10-14 11:33:11 -07004015 webrtc::DataChannelInit config;
4016 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07004017 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07004018 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4019 cricket::ReceiveDataParams params;
4020 params.ssrc = config.id;
4021 params.type = cricket::DMT_CONTROL;
deadbeef953c2ce2017-01-09 14:53:41 -08004022 fake_sctp_transport_factory_->last_fake_sctp_transport()->SignalDataReceived(
4023 params, payload);
deadbeefab9b2d12015-10-14 11:33:11 -07004024
deadbeef953c2ce2017-01-09 14:53:41 -08004025 EXPECT_EQ_WAIT("a", last_data_channel_label_, kDefaultTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07004026 EXPECT_EQ(config.id, last_data_channel_config_.id);
4027 EXPECT_FALSE(last_data_channel_config_.negotiated);
4028 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4029 last_data_channel_config_.open_handshake_role);
4030}
4031
4032TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004033 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
Henrik Boströmd79599d2016-06-01 13:58:50 +02004034 FakeRTCCertificateGenerator::GenerateCertificate();
Henrik Boströmd8281982015-08-27 10:12:24 +02004035
htaa2a49d92016-03-04 02:51:39 -08004036 configuration_.certificates.push_back(certificate);
4037 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004038 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4039
4040 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4041}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004042
Henrik Boström87713d02015-08-25 09:53:21 +02004043// Verifies that CreateOffer succeeds when CreateOffer is called before async
4044// identity generation is finished (even if a certificate is provided this is
4045// an async op).
4046TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004047 InitWithDtls(GetParam());
4048
Henrik Boströmd8281982015-08-27 10:12:24 +02004049 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004050 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07004051 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004052
wu@webrtc.org91053e72013-08-10 07:18:04 +00004053 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004054 VerifyNoCryptoParams(offer->description(), true);
4055 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004056}
4057
4058// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004059// identity generation is finished (even if a certificate is provided this is
4060// an async op).
4061TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004062 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004063 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004064
4065 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004066 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07004067 std::unique_ptr<JsepSessionDescription> offer(
4068 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004069 ASSERT_TRUE(offer.get() != NULL);
4070 SetRemoteDescriptionWithoutError(offer.release());
4071
kwibergd1fe2812016-04-27 06:47:29 -07004072 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004073 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004074 VerifyNoCryptoParams(answer->description(), true);
4075 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004076}
4077
4078// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004079// identity generation is finished (even if a certificate is provided this is
4080// an async op).
4081TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004082 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004083
Henrik Boströmd8281982015-08-27 10:12:24 +02004084 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004085
kwibergd1fe2812016-04-27 06:47:29 -07004086 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004087 EXPECT_TRUE(offer != NULL);
4088}
4089
4090// Verifies that CreateOffer fails when CreateOffer is called after async
4091// identity generation fails.
4092TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004093 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004094
Henrik Boströmd8281982015-08-27 10:12:24 +02004095 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004096
kwibergd1fe2812016-04-27 06:47:29 -07004097 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004098 EXPECT_TRUE(offer == NULL);
4099}
4100
4101// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4102// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004103TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004104 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
deadbeefcbecd352015-09-23 11:50:27 -07004105 VerifyMultipleAsyncCreateDescription(GetParam(),
4106 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004107}
4108
4109// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4110// before async identity generation fails.
4111TEST_F(WebRtcSessionTest,
4112 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004113 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4114 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004115}
4116
4117// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4118// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004119TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004120 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00004121 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004122 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004123}
4124
4125// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4126// before async identity generation fails.
4127TEST_F(WebRtcSessionTest,
4128 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004129 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4130 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004131}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004132
4133// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4134// offer has no SDES crypto but only DTLS fingerprint.
4135TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4136 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004137 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004138 // Create a remote offer with secured transport disabled.
4139 cricket::MediaSessionOptions options;
4140 JsepSessionDescription* offer(CreateRemoteOffer(
4141 options, cricket::SEC_DISABLED));
4142 // Adds a DTLS fingerprint to the remote offer.
4143 cricket::SessionDescription* sdp = offer->description();
4144 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4145 ASSERT_TRUE(audio != NULL);
4146 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4147 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004148 rtc::SSLFingerprint::CreateFromRfc4572(
4149 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004150 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004151 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004152}
4153
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004154TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004155 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004156 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004157 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004158 SessionDescriptionInterface* offer = CreateOffer();
4159
4160 SetLocalDescriptionWithoutError(offer);
4161
4162 voice_channel_ = media_engine_->GetVoiceChannel(0);
4163
4164 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004165 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004166 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004167}
4168
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004169// Tests that we can renegotiate new media content with ICE candidates in the
4170// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004171TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
Henrik Boström87713d02015-08-25 09:53:21 +02004172 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004173 SetFactoryDtlsSrtp();
4174
deadbeefab9b2d12015-10-14 11:33:11 -07004175 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004176 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004177 SetLocalDescriptionWithoutError(offer);
4178
4179 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4180 SetRemoteDescriptionWithoutError(answer);
4181
4182 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004183 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004184 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4185
4186 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004187 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004188 candidate1.set_component(1);
4189 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4190 candidate1);
4191 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4192 SetRemoteDescriptionWithoutError(offer);
4193
htaa2a49d92016-03-04 02:51:39 -08004194 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004195 SetLocalDescriptionWithoutError(answer);
4196}
4197
4198// Tests that we can renegotiate new media content with ICE candidates separated
4199// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004200TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
Henrik Boström87713d02015-08-25 09:53:21 +02004201 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004202 SetFactoryDtlsSrtp();
4203
deadbeefab9b2d12015-10-14 11:33:11 -07004204 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004205 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004206 SetLocalDescriptionWithoutError(offer);
4207
4208 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4209 SetRemoteDescriptionWithoutError(answer);
4210
4211 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004212 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004213 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4214 SetRemoteDescriptionWithoutError(offer);
4215
4216 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004217 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004218 candidate1.set_component(1);
4219 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4220 candidate1);
4221 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4222
htaa2a49d92016-03-04 02:51:39 -08004223 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004224 SetLocalDescriptionWithoutError(answer);
4225}
honghaiz7f777492016-02-02 21:54:01 -08004226
zhihuang9763d562016-08-05 11:14:50 -07004227#ifdef HAVE_QUIC
4228TEST_P(WebRtcSessionTest, TestNegotiateQuic) {
4229 configuration_.enable_quic = true;
4230 InitWithDtls(GetParam());
4231 EXPECT_TRUE(session_->data_channel_type() == cricket::DCT_QUIC);
4232 SessionDescriptionInterface* offer = CreateOffer();
4233 ASSERT_TRUE(offer);
4234 ASSERT_TRUE(offer->description());
4235 SetLocalDescriptionWithoutError(offer);
4236 cricket::MediaSessionOptions options;
4237 options.recv_audio = true;
4238 options.recv_video = true;
4239 SessionDescriptionInterface* answer =
4240 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
4241 ASSERT_TRUE(answer);
4242 ASSERT_TRUE(answer->description());
4243 SetRemoteDescriptionWithoutError(answer);
4244}
4245#endif // HAVE_QUIC
4246
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004247// Tests that RTX codec is removed from the answer when it isn't supported
4248// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004249TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004250 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004251 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004252 std::string offer_sdp(kSdpWithRtx);
4253
4254 SessionDescriptionInterface* offer =
4255 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4256 EXPECT_TRUE(offer->ToString(&offer_sdp));
4257
4258 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004259 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004260 SetRemoteDescriptionWithoutError(offer);
4261
htaa2a49d92016-03-04 02:51:39 -08004262 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004263 // Answer SDP does not contain the RTX codec.
4264 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004265 SetLocalDescriptionWithoutError(answer);
4266}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004267
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004268// This verifies that the voice channel after bundle has both options from video
4269// and voice channels.
4270TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4271 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004272 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004273
4274 PeerConnectionInterface::RTCOfferAnswerOptions options;
4275 options.use_rtp_mux = true;
4276
4277 SessionDescriptionInterface* offer = CreateOffer(options);
4278 SetLocalDescriptionWithoutError(offer);
4279
4280 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4281 rtc::Socket::Option::OPT_SNDBUF, 4000);
4282
4283 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4284 rtc::Socket::Option::OPT_RCVBUF, 8000);
4285
4286 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004287 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004288 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4289 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004290 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004291 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4292
deadbeefcbecd352015-09-23 11:50:27 -07004293 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004294 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4295 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004296 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004297 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4298
deadbeefcbecd352015-09-23 11:50:27 -07004299 EXPECT_NE(session_->voice_rtp_transport_channel(),
4300 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004301
deadbeefab9b2d12015-10-14 11:33:11 -07004302 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004303 SessionDescriptionInterface* answer =
4304 CreateRemoteAnswer(session_->local_description());
4305 SetRemoteDescriptionWithoutError(answer);
4306
deadbeefcbecd352015-09-23 11:50:27 -07004307 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004308 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4309 EXPECT_EQ(4000, option_val);
4310
deadbeefcbecd352015-09-23 11:50:27 -07004311 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004312 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4313 EXPECT_EQ(8000, option_val);
4314}
4315
tommi0f620f42015-07-09 03:25:02 -07004316// Test creating a session, request multiple offers, destroy the session
4317// and make sure we got success/failure callbacks for all of the requests.
4318// Background: crbug.com/507307
4319TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4320 Init();
4321
4322 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4323 PeerConnectionInterface::RTCOfferAnswerOptions options;
4324 options.offer_to_receive_audio =
4325 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004326 cricket::MediaSessionOptions session_options;
4327 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004328
4329 for (auto& o : observers) {
4330 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004331 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004332 }
4333
4334 session_.reset();
4335
tommi0f620f42015-07-09 03:25:02 -07004336 for (auto& o : observers) {
4337 // We expect to have received a notification now even if the session was
4338 // terminated. The offer creation may or may not have succeeded, but we
4339 // must have received a notification which, so the only invalid state
4340 // is kInit.
4341 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4342 }
4343}
4344
stefanc1aeaf02015-10-15 07:26:07 -07004345TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4346 TestPacketOptions();
4347}
4348
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004349// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4350// currently fails because upon disconnection and reconnection OnIceComplete is
4351// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004352
deadbeefcbecd352015-09-23 11:50:27 -07004353INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4354 WebRtcSessionTest,
4355 testing::Values(ALREADY_GENERATED,
4356 DTLS_IDENTITY_STORE));