blob: 716ba25146227734ff927dba8e933da6f7e9deb4 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
jbauch555604a2016-04-26 03:13:22 -070011#include <memory>
kwiberg0eb15ed2015-12-17 03:04:15 -080012#include <utility>
deadbeefcbecd352015-09-23 11:50:27 -070013#include <vector>
14
Henrik Kjellander15583c12016-02-10 10:53:12 +010015#include "webrtc/api/fakemetricsobserver.h"
16#include "webrtc/api/jsepicecandidate.h"
17#include "webrtc/api/jsepsessiondescription.h"
nissec80e7412017-01-11 05:56:46 -080018#include "webrtc/base/checks.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000019#include "webrtc/base/fakenetwork.h"
20#include "webrtc/base/firewallsocketserver.h"
21#include "webrtc/base/gunit.h"
22#include "webrtc/base/logging.h"
23#include "webrtc/base/network.h"
24#include "webrtc/base/physicalsocketserver.h"
25#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020026#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000027#include "webrtc/base/sslstreamadapter.h"
28#include "webrtc/base/stringutils.h"
29#include "webrtc/base/thread.h"
30#include "webrtc/base/virtualsocketserver.h"
skvlad11a9cbf2016-10-07 11:53:05 -070031#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
kjellandera96e2d72016-02-04 23:52:28 -080032#include "webrtc/media/base/fakemediaengine.h"
33#include "webrtc/media/base/fakevideorenderer.h"
34#include "webrtc/media/base/mediachannel.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010035#include "webrtc/media/engine/fakewebrtccall.h"
deadbeef953c2ce2017-01-09 14:53:41 -080036#include "webrtc/media/sctp/sctptransportinternal.h"
johan669d69b2016-11-08 14:14:08 -080037#include "webrtc/p2p/base/packettransportinterface.h"
kjellandera96e2d72016-02-04 23:52:28 -080038#include "webrtc/p2p/base/stunserver.h"
39#include "webrtc/p2p/base/teststunserver.h"
40#include "webrtc/p2p/base/testturnserver.h"
kjellandera96e2d72016-02-04 23:52:28 -080041#include "webrtc/p2p/client/basicportallocator.h"
ossu7bb87ee2017-01-23 04:56:25 -080042#include "webrtc/pc/audiotrack.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010043#include "webrtc/pc/channelmanager.h"
ossu7bb87ee2017-01-23 04:56:25 -080044#include "webrtc/pc/fakemediacontroller.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010045#include "webrtc/pc/mediasession.h"
ossu7bb87ee2017-01-23 04:56:25 -080046#include "webrtc/pc/peerconnection.h"
47#include "webrtc/pc/sctputils.h"
48#include "webrtc/pc/test/fakertccertificategenerator.h"
49#include "webrtc/pc/videotrack.h"
50#include "webrtc/pc/webrtcsession.h"
51#include "webrtc/pc/webrtcsessiondescriptionfactory.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000052
henrike@webrtc.org28e20752013-07-10 00:45:36 +000053using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000054using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000055using rtc::SocketAddress;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000056using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000058using webrtc::CreateSessionDescriptionObserver;
59using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070060using webrtc::DataChannel;
jbauchac8869e2015-07-03 01:36:14 -070061using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070063using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000064using webrtc::JsepIceCandidate;
65using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000066using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067using webrtc::PeerConnectionInterface;
68using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070069using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000071using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000072using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000073using webrtc::kCreateChannelFailed;
74using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000076using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000077using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000078using webrtc::kSdpWithoutDtlsFingerprint;
79using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000081using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000082using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +000084typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
85
wu@webrtc.org364f2042013-11-20 21:49:41 +000086static const int kClientAddrPort = 0;
87static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +000088static const char kClientIPv6AddrHost1[] =
89 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +000090static const char kClientAddrHost2[] = "22.22.22.22";
91static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +000092static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
93static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +000094static const char kTurnUsername[] = "test";
95static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000096
97static const char kSessionVersion[] = "1";
98
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099// Media index of candidates belonging to the first media content.
100static const int kMediaContentIndex0 = 0;
101static const char kMediaContentName0[] = "audio";
102
103// Media index of candidates belonging to the second media content.
104static const int kMediaContentIndex1 = 1;
105static const char kMediaContentName1[] = "video";
106
deadbeef953c2ce2017-01-09 14:53:41 -0800107static const int kDefaultTimeout = 10000; // 10 seconds.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108static const int kIceCandidatesTimeout = 10000;
deadbeeff5f03e82016-06-06 11:16:06 -0700109// STUN timeout with all retransmissions is a total of 9500ms.
110static const int kStunTimeout = 9500;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000111
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000112static const char kFakeDtlsFingerprint[] =
113 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
114 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
115
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000116static const char kTooLongIceUfragPwd[] =
117 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
118 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
119 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
120 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
121
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000122static const char kSdpWithRtx[] =
123 "v=0\r\n"
124 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
125 "s=-\r\n"
126 "t=0 0\r\n"
127 "a=msid-semantic: WMS stream1\r\n"
128 "m=video 9 RTP/SAVPF 0 96\r\n"
129 "c=IN IP4 0.0.0.0\r\n"
130 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
131 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
132 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
133 "a=mid:video\r\n"
134 "a=sendrecv\r\n"
135 "a=rtcp-mux\r\n"
136 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
137 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
138 "a=rtpmap:0 fake_video_codec/90000\r\n"
139 "a=rtpmap:96 rtx/90000\r\n"
140 "a=fmtp:96 apt=0\r\n";
141
deadbeefab9b2d12015-10-14 11:33:11 -0700142static const char kStream1[] = "stream1";
143static const char kVideoTrack1[] = "video1";
144static const char kAudioTrack1[] = "audio1";
145
146static const char kStream2[] = "stream2";
147static const char kVideoTrack2[] = "video2";
148static const char kAudioTrack2[] = "audio2";
149
Henrik Boström87713d02015-08-25 09:53:21 +0200150enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
151
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000152class MockIceObserver : public webrtc::IceObserver {
153 public:
154 MockIceObserver()
155 : oncandidatesready_(false),
156 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
157 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
158 }
159
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200160 virtual ~MockIceObserver() = default;
161
perkjdfb769d2016-02-09 03:09:43 -0800162 void OnIceConnectionChange(
163 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164 ice_connection_state_ = new_state;
skvlad6c87a672016-05-17 17:49:52 -0700165 ice_connection_state_history_.push_back(new_state);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000166 }
perkjdfb769d2016-02-09 03:09:43 -0800167 void OnIceGatheringChange(
168 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000169 // We can never transition back to "new".
170 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
171 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800172 oncandidatesready_ =
173 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000174 }
175
176 // Found a new candidate.
perkjdfb769d2016-02-09 03:09:43 -0800177 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000178 switch (candidate->sdp_mline_index()) {
179 case kMediaContentIndex0:
180 mline_0_candidates_.push_back(candidate->candidate());
181 break;
182 case kMediaContentIndex1:
183 mline_1_candidates_.push_back(candidate->candidate());
184 break;
185 default:
nissec80e7412017-01-11 05:56:46 -0800186 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000187 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000188
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000189 // The ICE gathering state should always be Gathering when a candidate is
190 // received (or possibly Completed in the case of the final candidate).
191 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
192 }
193
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700194 // Some local candidates are removed.
195 void OnIceCandidatesRemoved(
nisseef8b61e2016-04-29 06:09:15 -0700196 const std::vector<cricket::Candidate>& candidates) override {
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700197 num_candidates_removed_ += candidates.size();
198 }
199
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000200 bool oncandidatesready_;
201 std::vector<cricket::Candidate> mline_0_candidates_;
202 std::vector<cricket::Candidate> mline_1_candidates_;
203 PeerConnectionInterface::IceConnectionState ice_connection_state_;
204 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
skvlad6c87a672016-05-17 17:49:52 -0700205 std::vector<PeerConnectionInterface::IceConnectionState>
206 ice_connection_state_history_;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700207 size_t num_candidates_removed_ = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208};
209
deadbeef953c2ce2017-01-09 14:53:41 -0800210// Used for tests in this file to verify that WebRtcSession responds to signals
211// from the SctpTransport correctly, and calls Start with the correct
212// local/remote ports.
213class FakeSctpTransport : public cricket::SctpTransportInternal {
214 public:
zhihuangb2cdd932017-01-19 16:54:25 -0800215 void SetTransportChannel(rtc::PacketTransportInterface* channel) override {}
deadbeef953c2ce2017-01-09 14:53:41 -0800216 bool Start(int local_port, int remote_port) override {
217 local_port_ = local_port;
218 remote_port_ = remote_port;
219 return true;
220 }
221 bool OpenStream(int sid) override { return true; }
222 bool ResetStream(int sid) override { return true; }
223 bool SendData(const cricket::SendDataParams& params,
224 const rtc::CopyOnWriteBuffer& payload,
225 cricket::SendDataResult* result = nullptr) override {
226 return true;
227 }
228 bool ReadyToSendData() override { return true; }
229 void set_debug_name_for_testing(const char* debug_name) override {}
230
231 int local_port() const { return local_port_; }
232 int remote_port() const { return remote_port_; }
233
234 private:
235 int local_port_ = -1;
236 int remote_port_ = -1;
237};
238
239class FakeSctpTransportFactory : public cricket::SctpTransportInternalFactory {
240 public:
241 std::unique_ptr<cricket::SctpTransportInternal> CreateSctpTransport(
zhihuangb2cdd932017-01-19 16:54:25 -0800242 rtc::PacketTransportInterface*) override {
deadbeef953c2ce2017-01-09 14:53:41 -0800243 last_fake_sctp_transport_ = new FakeSctpTransport();
244 return std::unique_ptr<cricket::SctpTransportInternal>(
245 last_fake_sctp_transport_);
246 }
247
248 FakeSctpTransport* last_fake_sctp_transport() {
249 return last_fake_sctp_transport_;
250 }
251
252 private:
253 FakeSctpTransport* last_fake_sctp_transport_ = nullptr;
254};
255
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256class WebRtcSessionForTest : public webrtc::WebRtcSession {
257 public:
zhihuang29ff8442016-07-27 11:07:25 -0700258 WebRtcSessionForTest(
259 webrtc::MediaControllerInterface* media_controller,
260 rtc::Thread* network_thread,
261 rtc::Thread* worker_thread,
262 rtc::Thread* signaling_thread,
263 cricket::PortAllocator* port_allocator,
264 webrtc::IceObserver* ice_observer,
deadbeef953c2ce2017-01-09 14:53:41 -0800265 std::unique_ptr<cricket::TransportController> transport_controller,
266 std::unique_ptr<FakeSctpTransportFactory> sctp_factory)
stefanc1aeaf02015-10-15 07:26:07 -0700267 : WebRtcSession(media_controller,
danilchape9021a32016-05-17 01:52:02 -0700268 network_thread,
stefanc1aeaf02015-10-15 07:26:07 -0700269 worker_thread,
danilchape9021a32016-05-17 01:52:02 -0700270 signaling_thread,
zhihuang29ff8442016-07-27 11:07:25 -0700271 port_allocator,
deadbeef953c2ce2017-01-09 14:53:41 -0800272 std::move(transport_controller),
273 std::move(sctp_factory)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000274 RegisterIceObserver(ice_observer);
275 }
276 virtual ~WebRtcSessionForTest() {}
277
deadbeefcbecd352015-09-23 11:50:27 -0700278 // Note that these methods are only safe to use if the signaling thread
279 // is the same as the worker thread
johan669d69b2016-11-08 14:14:08 -0800280 rtc::PacketTransportInterface* voice_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700281 return rtp_transport_channel(voice_channel());
282 }
283
johan669d69b2016-11-08 14:14:08 -0800284 rtc::PacketTransportInterface* voice_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700285 return rtcp_transport_channel(voice_channel());
286 }
287
johan669d69b2016-11-08 14:14:08 -0800288 rtc::PacketTransportInterface* video_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700289 return rtp_transport_channel(video_channel());
290 }
291
johan669d69b2016-11-08 14:14:08 -0800292 rtc::PacketTransportInterface* video_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700293 return rtcp_transport_channel(video_channel());
294 }
295
deadbeefcbecd352015-09-23 11:50:27 -0700296 private:
johan669d69b2016-11-08 14:14:08 -0800297 rtc::PacketTransportInterface* rtp_transport_channel(
298 cricket::BaseChannel* ch) {
deadbeefcbecd352015-09-23 11:50:27 -0700299 if (!ch) {
300 return nullptr;
301 }
zhihuangb2cdd932017-01-19 16:54:25 -0800302 return ch->rtp_dtls_transport();
deadbeefcbecd352015-09-23 11:50:27 -0700303 }
304
johan669d69b2016-11-08 14:14:08 -0800305 rtc::PacketTransportInterface* rtcp_transport_channel(
306 cricket::BaseChannel* ch) {
deadbeefcbecd352015-09-23 11:50:27 -0700307 if (!ch) {
308 return nullptr;
309 }
zhihuangb2cdd932017-01-19 16:54:25 -0800310 return ch->rtcp_dtls_transport();
deadbeefcbecd352015-09-23 11:50:27 -0700311 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000312};
313
wu@webrtc.org91053e72013-08-10 07:18:04 +0000314class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000315 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000316 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000317 enum State {
318 kInit,
319 kFailed,
320 kSucceeded,
321 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000322 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000323
324 // CreateSessionDescriptionObserver implementation.
325 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000326 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000327 state_ = kSucceeded;
328 }
329 virtual void OnFailure(const std::string& error) {
330 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000331 }
332
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000333 SessionDescriptionInterface* description() { return description_.get(); }
334
335 SessionDescriptionInterface* ReleaseDescription() {
336 return description_.release();
337 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000338
wu@webrtc.org91053e72013-08-10 07:18:04 +0000339 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000340
wu@webrtc.org91053e72013-08-10 07:18:04 +0000341 protected:
342 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000343
344 private:
kwibergd1fe2812016-04-27 06:47:29 -0700345 std::unique_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000346 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000347};
348
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800349class FakeAudioSource : public cricket::AudioSource {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000350 public:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800351 FakeAudioSource() : sink_(NULL) {}
352 virtual ~FakeAudioSource() {
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000353 if (sink_)
354 sink_->OnClose();
355 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000356
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000357 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000358
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800359 const cricket::AudioSource::Sink* sink() const { return sink_; }
360
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000361 private:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800362 cricket::AudioSource::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000363};
364
Henrik Boström87713d02015-08-25 09:53:21 +0200365class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700366 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
367 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000368 protected:
369 // TODO Investigate why ChannelManager crashes, if it's created
370 // after stun_server.
371 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700372 : media_engine_(new cricket::FakeMediaEngine()),
373 data_engine_(new cricket::FakeDataEngine()),
skvlad11a9cbf2016-10-07 11:53:05 -0700374 channel_manager_(new cricket::ChannelManager(media_engine_,
375 data_engine_,
376 rtc::Thread::Current())),
377 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,
423 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000424 ASSERT_TRUE(session_.get() == NULL);
deadbeef953c2ce2017-01-09 14:53:41 -0800425 fake_sctp_transport_factory_ = new FakeSctpTransportFactory();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000426 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700427 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
zhihuang29ff8442016-07-27 11:07:25 -0700428 rtc::Thread::Current(), allocator_.get(), &observer_,
429 std::unique_ptr<cricket::TransportController>(
430 new cricket::TransportController(rtc::Thread::Current(),
431 rtc::Thread::Current(),
deadbeef953c2ce2017-01-09 14:53:41 -0800432 allocator_.get())),
433 std::unique_ptr<FakeSctpTransportFactory>(
434 fake_sctp_transport_factory_)));
deadbeefab9b2d12015-10-14 11:33:11 -0700435 session_->SignalDataChannelOpenMessage.connect(
436 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000437
zhihuang4dfb8ce2016-11-23 10:30:12 -0800438 configuration_.rtcp_mux_policy = rtcp_mux_policy;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000439 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
440 observer_.ice_connection_state_);
441 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
442 observer_.ice_gathering_state_);
443
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200444 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator),
htaa2a49d92016-03-04 02:51:39 -0800445 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700446 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000447 }
448
deadbeefab9b2d12015-10-14 11:33:11 -0700449 void OnDataChannelOpenMessage(const std::string& label,
450 const InternalDataChannelInit& config) {
451 last_data_channel_label_ = label;
452 last_data_channel_config_ = config;
453 }
454
zhihuang4dfb8ce2016-11-23 10:30:12 -0800455 void Init() {
456 Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
457 }
458
459 void Init(PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
460 Init(nullptr, rtcp_mux_policy);
461 }
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;
zhihuang4dfb8ce2016-11-23 10:30:12 -0800472 Init(rtcp_mux_policy);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000473 }
474
Henrik Boström87713d02015-08-25 09:53:21 +0200475 // Successfully init with DTLS; with a certificate generated and supplied or
476 // with a store that generates it for us.
477 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200478 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator;
Henrik Boström87713d02015-08-25 09:53:21 +0200479 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800480 configuration_.certificates.push_back(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200481 FakeRTCCertificateGenerator::GenerateCertificate());
Henrik Boström87713d02015-08-25 09:53:21 +0200482 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200483 cert_generator.reset(new FakeRTCCertificateGenerator());
484 cert_generator->set_should_fail(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200485 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700486 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200487 }
zhihuang4dfb8ce2016-11-23 10:30:12 -0800488 Init(std::move(cert_generator),
489 PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
Henrik Boström87713d02015-08-25 09:53:21 +0200490 }
491
492 // Init with DTLS with a store that will fail to generate a certificate.
493 void InitWithDtlsIdentityGenFail() {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200494 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
495 new FakeRTCCertificateGenerator());
496 cert_generator->set_should_fail(true);
zhihuang4dfb8ce2016-11-23 10:30:12 -0800497 Init(std::move(cert_generator),
498 PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000499 }
500
jbauchcb560652016-08-04 05:20:32 -0700501 void InitWithGcm() {
502 rtc::CryptoOptions crypto_options;
503 crypto_options.enable_gcm_crypto_suites = true;
504 channel_manager_->SetCryptoOptions(crypto_options);
505 with_gcm_ = true;
506 Init();
507 }
508
deadbeefab9b2d12015-10-14 11:33:11 -0700509 void SendAudioVideoStream1() {
510 send_stream_1_ = true;
511 send_stream_2_ = false;
512 send_audio_ = true;
513 send_video_ = true;
514 }
515
516 void SendAudioVideoStream2() {
517 send_stream_1_ = false;
518 send_stream_2_ = true;
519 send_audio_ = true;
520 send_video_ = true;
521 }
522
523 void SendAudioVideoStream1And2() {
524 send_stream_1_ = true;
525 send_stream_2_ = true;
526 send_audio_ = true;
527 send_video_ = true;
528 }
529
530 void SendNothing() {
531 send_stream_1_ = false;
532 send_stream_2_ = false;
533 send_audio_ = false;
534 send_video_ = false;
535 }
536
537 void SendAudioOnlyStream2() {
538 send_stream_1_ = false;
539 send_stream_2_ = true;
540 send_audio_ = true;
541 send_video_ = false;
542 }
543
544 void SendVideoOnlyStream2() {
545 send_stream_1_ = false;
546 send_stream_2_ = true;
547 send_audio_ = false;
548 send_video_ = true;
549 }
550
551 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
552 if (send_stream_1_ && send_audio_) {
553 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
554 kStream1);
555 }
556 if (send_stream_1_ && send_video_) {
557 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
558 kStream1);
559 }
560 if (send_stream_2_ && send_audio_) {
561 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
562 kStream2);
563 }
564 if (send_stream_2_ && send_video_) {
565 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
566 kStream2);
567 }
568 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
569 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
570 data_channel_->label(),
571 data_channel_->label());
572 }
573 }
574
575 void GetOptionsForOffer(
576 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
577 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800578 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700579
deadbeefc80741f2015-10-22 13:14:45 -0700580 AddStreamsToOptions(session_options);
581 if (rtc_options.offer_to_receive_audio ==
582 RTCOfferAnswerOptions::kUndefined) {
583 session_options->recv_audio =
584 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
585 }
586 if (rtc_options.offer_to_receive_video ==
587 RTCOfferAnswerOptions::kUndefined) {
588 session_options->recv_video =
589 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
590 }
591 session_options->bundle_enabled =
592 session_options->bundle_enabled &&
593 (session_options->has_audio() || session_options->has_video() ||
594 session_options->has_data());
595
deadbeefab9b2d12015-10-14 11:33:11 -0700596 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
597 session_options->data_channel_type = cricket::DCT_SCTP;
zhihuang9763d562016-08-05 11:14:50 -0700598 } else if (session_->data_channel_type() == cricket::DCT_QUIC) {
599 session_options->data_channel_type = cricket::DCT_QUIC;
deadbeefab9b2d12015-10-14 11:33:11 -0700600 }
jbauchcb560652016-08-04 05:20:32 -0700601
602 if (with_gcm_) {
603 session_options->crypto_options.enable_gcm_crypto_suites = true;
604 }
deadbeefab9b2d12015-10-14 11:33:11 -0700605 }
606
htaa2a49d92016-03-04 02:51:39 -0800607 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
608 // ParseConstraintsForAnswer is used to set some defaults.
609 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700610
deadbeefc80741f2015-10-22 13:14:45 -0700611 AddStreamsToOptions(session_options);
612 session_options->bundle_enabled =
613 session_options->bundle_enabled &&
614 (session_options->has_audio() || session_options->has_video() ||
615 session_options->has_data());
616
zhihuang9763d562016-08-05 11:14:50 -0700617 if (session_->data_channel_type() != cricket::DCT_RTP) {
618 session_options->data_channel_type = session_->data_channel_type();
deadbeef907abe42016-08-04 12:22:18 -0700619 }
jbauchcb560652016-08-04 05:20:32 -0700620
621 if (with_gcm_) {
622 session_options->crypto_options.enable_gcm_crypto_suites = true;
623 }
deadbeefab9b2d12015-10-14 11:33:11 -0700624 }
625
626 // Creates a local offer and applies it. Starts ICE.
627 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000628 // to decide which streams to create.
629 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000630 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000631 SetLocalDescriptionWithoutError(offer);
632 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
633 observer_.ice_gathering_state_,
634 kIceCandidatesTimeout);
635 }
636
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000637 SessionDescriptionInterface* CreateOffer() {
638 PeerConnectionInterface::RTCOfferAnswerOptions options;
639 options.offer_to_receive_audio =
640 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
641
642 return CreateOffer(options);
643 }
644
wu@webrtc.org91053e72013-08-10 07:18:04 +0000645 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800646 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000647 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000648 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700649 cricket::MediaSessionOptions session_options;
650 GetOptionsForOffer(options, &session_options);
651 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000652 EXPECT_TRUE_WAIT(
653 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000654 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000655 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000656 }
657
658 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800659 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000660 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000661 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800662 cricket::MediaSessionOptions session_options = options;
663 GetOptionsForAnswer(&session_options);
664 // Overwrite recv_audio and recv_video with passed-in values.
665 session_options.recv_video = options.recv_video;
666 session_options.recv_audio = options.recv_audio;
667 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000668 EXPECT_TRUE_WAIT(
669 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000670 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000671 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000672 }
673
htaa2a49d92016-03-04 02:51:39 -0800674 SessionDescriptionInterface* CreateAnswer() {
675 cricket::MediaSessionOptions options;
676 options.recv_video = true;
677 options.recv_audio = true;
678 return CreateAnswer(options);
679 }
680
wu@webrtc.org364f2042013-11-20 21:49:41 +0000681 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000682 return (session_->voice_channel() != NULL &&
683 session_->video_channel() != NULL);
684 }
685
jbauchcb560652016-08-04 05:20:32 -0700686 void VerifyCryptoParams(const cricket::SessionDescription* sdp,
687 bool gcm_enabled = false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000688 ASSERT_TRUE(session_.get() != NULL);
689 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
690 ASSERT_TRUE(content != NULL);
691 const cricket::AudioContentDescription* audio_content =
692 static_cast<const cricket::AudioContentDescription*>(
693 content->description);
694 ASSERT_TRUE(audio_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700695 if (!gcm_enabled) {
696 ASSERT_EQ(1U, audio_content->cryptos().size());
697 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
698 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
699 audio_content->cryptos()[0].cipher_suite);
700 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
701 audio_content->protocol());
702 } else {
703 // The offer contains 3 possible crypto suites, the answer 1.
704 EXPECT_LE(1U, audio_content->cryptos().size());
705 EXPECT_NE(2U, audio_content->cryptos().size());
706 EXPECT_GE(3U, audio_content->cryptos().size());
707 ASSERT_EQ(67U, audio_content->cryptos()[0].key_params.size());
708 ASSERT_EQ("AEAD_AES_256_GCM",
709 audio_content->cryptos()[0].cipher_suite);
710 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
711 audio_content->protocol());
712 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713
714 content = cricket::GetFirstVideoContent(sdp);
715 ASSERT_TRUE(content != NULL);
716 const cricket::VideoContentDescription* video_content =
717 static_cast<const cricket::VideoContentDescription*>(
718 content->description);
719 ASSERT_TRUE(video_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700720 if (!gcm_enabled) {
721 ASSERT_EQ(1U, video_content->cryptos().size());
722 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
723 video_content->cryptos()[0].cipher_suite);
724 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
725 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
726 video_content->protocol());
727 } else {
728 // The offer contains 3 possible crypto suites, the answer 1.
729 EXPECT_LE(1U, video_content->cryptos().size());
730 EXPECT_NE(2U, video_content->cryptos().size());
731 EXPECT_GE(3U, video_content->cryptos().size());
732 ASSERT_EQ("AEAD_AES_256_GCM",
733 video_content->cryptos()[0].cipher_suite);
734 ASSERT_EQ(67U, video_content->cryptos()[0].key_params.size());
735 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
736 video_content->protocol());
737 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000738 }
739
740 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
741 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
742 ASSERT_TRUE(content != NULL);
743 const cricket::AudioContentDescription* audio_content =
744 static_cast<const cricket::AudioContentDescription*>(
745 content->description);
746 ASSERT_TRUE(audio_content != NULL);
747 ASSERT_EQ(0U, audio_content->cryptos().size());
748
749 content = cricket::GetFirstVideoContent(sdp);
750 ASSERT_TRUE(content != NULL);
751 const cricket::VideoContentDescription* video_content =
752 static_cast<const cricket::VideoContentDescription*>(
753 content->description);
754 ASSERT_TRUE(video_content != NULL);
755 ASSERT_EQ(0U, video_content->cryptos().size());
756
757 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700758 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700760 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000761 video_content->protocol());
762 } else {
763 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
764 audio_content->protocol());
765 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
766 video_content->protocol());
767 }
768 }
769
770 // Set the internal fake description factories to do DTLS-SRTP.
771 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000772 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000773 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000774 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200775 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800776 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700777 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800778 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000779 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
780 }
781
782 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
783 bool expected) {
784 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
785 ASSERT_TRUE(audio != NULL);
786 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787 const TransportInfo* video = sdp->GetTransportInfoByName("video");
788 ASSERT_TRUE(video != NULL);
789 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790 }
791
792 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000793 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000795 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000796 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000798 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000800 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
801 offer);
htaa2a49d92016-03-04 02:51:39 -0800802 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803 // Answer should be NULL as no crypto params in offer.
804 ASSERT_TRUE(answer == NULL);
805 }
806
807 void VerifyAnswerFromCryptoOffer() {
808 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000809 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000810 options.bundle_enabled = true;
kwibergd1fe2812016-04-27 06:47:29 -0700811 std::unique_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000812 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
813 ASSERT_TRUE(offer.get() != NULL);
814 VerifyCryptoParams(offer->description());
815 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -0700816 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000817 ASSERT_TRUE(answer.get() != NULL);
818 VerifyCryptoParams(answer->description());
819 }
820
deadbeef0ed85b22016-02-23 17:24:52 -0800821 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
822 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800824 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825 }
826
827 const cricket::ContentInfos& contents = desc1->contents();
828 cricket::ContentInfos::const_iterator it = contents.begin();
829
830 for (; it != contents.end(); ++it) {
831 const cricket::TransportDescription* transport_desc1 =
832 desc1->GetTransportDescriptionByName(it->name);
833 const cricket::TransportDescription* transport_desc2 =
834 desc2->GetTransportDescriptionByName(it->name);
835 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800836 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837 }
838 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
839 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800840 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000841 }
842 }
deadbeef0ed85b22016-02-23 17:24:52 -0800843 return true;
844 }
845
846 // Compares ufrag/password only for the specified |media_type|.
847 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
848 const cricket::SessionDescription* desc2,
849 cricket::MediaType media_type) {
850 if (desc1->contents().size() != desc2->contents().size()) {
851 return false;
852 }
853
854 const cricket::ContentInfo* cinfo =
855 cricket::GetFirstMediaContent(desc1->contents(), media_type);
856 const cricket::TransportDescription* transport_desc1 =
857 desc1->GetTransportDescriptionByName(cinfo->name);
858 const cricket::TransportDescription* transport_desc2 =
859 desc2->GetTransportDescriptionByName(cinfo->name);
860 if (!transport_desc1 || !transport_desc2) {
861 return false;
862 }
863 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
864 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
865 return false;
866 }
867 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000868 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000869
870 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
871 std::string *sdp) {
872 const cricket::SessionDescription* desc = current_desc->description();
873 EXPECT_TRUE(current_desc->ToString(sdp));
874
875 const cricket::ContentInfos& contents = desc->contents();
876 cricket::ContentInfos::const_iterator it = contents.begin();
877 // Replace ufrag and pwd lines with empty strings.
878 for (; it != contents.end(); ++it) {
879 const cricket::TransportDescription* transport_desc =
880 desc->GetTransportDescriptionByName(it->name);
881 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
882 + "\r\n";
883 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
884 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000885 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000886 "", 0,
887 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000888 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000889 "", 0,
890 sdp);
891 }
892 }
893
deadbeef0ed85b22016-02-23 17:24:52 -0800894 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
895 const std::string& ufrag,
896 const std::string& pwd) {
897 cricket::SessionDescription* desc = current_desc->description();
898 for (TransportInfo& transport_info : desc->transport_infos()) {
899 cricket::TransportDescription& transport_desc =
900 transport_info.description;
901 transport_desc.ice_ufrag = ufrag;
902 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000903 }
904 }
905
deadbeef0ed85b22016-02-23 17:24:52 -0800906 // Sets ufrag/pwd for specified |media_type|.
907 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
908 cricket::MediaType media_type,
909 const std::string& ufrag,
910 const std::string& pwd) {
911 cricket::SessionDescription* desc = current_desc->description();
912 const cricket::ContentInfo* cinfo =
913 cricket::GetFirstMediaContent(desc->contents(), media_type);
914 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
915 cricket::TransportDescription* transport_desc =
916 &transport_info->description;
917 transport_desc->ice_ufrag = ufrag;
918 transport_desc->ice_pwd = pwd;
919 }
920
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921 // Creates a remote offer and and applies it as a remote description,
922 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700923 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000924 // to decide which local and remote streams to create.
925 void CreateAndSetRemoteOfferAndLocalAnswer() {
926 SessionDescriptionInterface* offer = CreateRemoteOffer();
927 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800928 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929 SetLocalDescriptionWithoutError(answer);
930 }
931 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
932 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700933 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000934 }
935 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700936 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000937 SetLocalDescriptionWithoutError(desc);
938 EXPECT_EQ(expected_state, session_->state());
939 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000940 void SetLocalDescriptionExpectError(const std::string& action,
941 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000942 SessionDescriptionInterface* desc) {
943 std::string error;
944 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000945 std::string sdp_type = "local ";
946 sdp_type.append(action);
947 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 EXPECT_NE(std::string::npos, error.find(expected_error));
949 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000950 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
951 SessionDescriptionInterface* desc) {
952 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
953 expected_error, desc);
954 }
955 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
956 SessionDescriptionInterface* desc) {
957 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
958 expected_error, desc);
959 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000960 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
961 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
962 }
963 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700964 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000965 SetRemoteDescriptionWithoutError(desc);
966 EXPECT_EQ(expected_state, session_->state());
967 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000968 void SetRemoteDescriptionExpectError(const std::string& action,
969 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970 SessionDescriptionInterface* desc) {
971 std::string error;
972 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000973 std::string sdp_type = "remote ";
974 sdp_type.append(action);
975 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000976 EXPECT_NE(std::string::npos, error.find(expected_error));
977 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000978 void SetRemoteDescriptionOfferExpectError(
979 const std::string& expected_error, SessionDescriptionInterface* desc) {
980 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
981 expected_error, desc);
982 }
983 void SetRemoteDescriptionPranswerExpectError(
984 const std::string& expected_error, SessionDescriptionInterface* desc) {
985 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
986 expected_error, desc);
987 }
988 void SetRemoteDescriptionAnswerExpectError(
989 const std::string& expected_error, SessionDescriptionInterface* desc) {
990 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
991 expected_error, desc);
992 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000993
994 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
995 SessionDescriptionInterface** nocrypto_answer) {
996 // Create a SDP without Crypto.
997 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000998 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000999 options.bundle_enabled = true;
1000 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
1001 ASSERT_TRUE(*offer != NULL);
1002 VerifyCryptoParams((*offer)->description());
1003
1004 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
1005 cricket::SEC_DISABLED);
1006 EXPECT_TRUE(*nocrypto_answer != NULL);
1007 }
1008
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001009 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
1010 SessionDescriptionInterface** nodtls_answer) {
1011 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001012 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001013 options.bundle_enabled = true;
1014
kwibergd1fe2812016-04-27 06:47:29 -07001015 std::unique_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001016 CreateRemoteOffer(options, cricket::SEC_ENABLED));
1017
1018 *nodtls_answer =
1019 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
1020 EXPECT_TRUE(*nodtls_answer != NULL);
1021 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
1022 VerifyCryptoParams((*nodtls_answer)->description());
1023
1024 SetFactoryDtlsSrtp();
1025 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
1026 ASSERT_TRUE(*offer != NULL);
1027 VerifyFingerprintStatus((*offer)->description(), true);
1028 VerifyCryptoParams((*offer)->description());
1029 }
1030
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001031 JsepSessionDescription* CreateRemoteOfferWithVersion(
1032 cricket::MediaSessionOptions options,
1033 cricket::SecurePolicy secure_policy,
1034 const std::string& session_version,
1035 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001036 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001037 const cricket::SessionDescription* cricket_desc = NULL;
1038 if (current_desc) {
1039 cricket_desc = current_desc->description();
1040 session_id = current_desc->session_id();
1041 }
1042
1043 desc_factory_->set_secure(secure_policy);
1044 JsepSessionDescription* offer(
1045 new JsepSessionDescription(JsepSessionDescription::kOffer));
1046 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
1047 session_id, session_version)) {
1048 delete offer;
1049 offer = NULL;
1050 }
1051 return offer;
1052 }
1053 JsepSessionDescription* CreateRemoteOffer(
1054 cricket::MediaSessionOptions options) {
1055 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1056 kSessionVersion, NULL);
1057 }
1058 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001059 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
1060 return CreateRemoteOfferWithVersion(
1061 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001062 }
1063 JsepSessionDescription* CreateRemoteOffer(
1064 cricket::MediaSessionOptions options,
1065 const SessionDescriptionInterface* current_desc) {
1066 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1067 kSessionVersion, current_desc);
1068 }
1069
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001070 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
1071 const char* sctp_stream_name, int new_port,
1072 cricket::MediaSessionOptions options) {
1073 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001074 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
1075 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001076 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
1077 }
1078
1079 // Takes ownership of offer_basis (and deletes it).
1080 JsepSessionDescription* ChangeSDPSctpPort(
1081 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1082 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1083 // SessionDescription from the mutated string.
1084 const char* default_port_str = "5000";
1085 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001086 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001087 std::string offer_str;
1088 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001089 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001090 new_port_str, strlen(new_port_str),
1091 &offer_str);
1092 JsepSessionDescription* offer = new JsepSessionDescription(
1093 offer_basis->type());
1094 delete offer_basis;
1095 offer->Initialize(offer_str, NULL);
1096 return offer;
1097 }
1098
deadbeefab9b2d12015-10-14 11:33:11 -07001099 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001100 // before this function to decide which streams to create.
1101 JsepSessionDescription* CreateRemoteOffer() {
1102 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001103 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001104 return CreateRemoteOffer(options, session_->remote_description());
1105 }
1106
1107 JsepSessionDescription* CreateRemoteAnswer(
1108 const SessionDescriptionInterface* offer,
1109 cricket::MediaSessionOptions options,
1110 cricket::SecurePolicy policy) {
1111 desc_factory_->set_secure(policy);
1112 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001113 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001114 JsepSessionDescription* answer(
1115 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1116 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1117 options, NULL),
1118 session_id, kSessionVersion)) {
1119 delete answer;
1120 answer = NULL;
1121 }
1122 return answer;
1123 }
1124
1125 JsepSessionDescription* CreateRemoteAnswer(
1126 const SessionDescriptionInterface* offer,
1127 cricket::MediaSessionOptions options) {
1128 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1129 }
1130
deadbeefab9b2d12015-10-14 11:33:11 -07001131 // Creates an answer session description.
1132 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001133 // to decide which streams to create.
1134 JsepSessionDescription* CreateRemoteAnswer(
1135 const SessionDescriptionInterface* offer) {
1136 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001137 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001138 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1139 }
1140
1141 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001142 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001143 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001144 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001145
1146 PeerConnectionInterface::RTCOfferAnswerOptions options;
1147 options.use_rtp_mux = bundle;
1148
1149 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001150 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1151 // and answer.
1152 SetLocalDescriptionWithoutError(offer);
1153
kwibergd1fe2812016-04-27 06:47:29 -07001154 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001155 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001156 std::string sdp;
1157 EXPECT_TRUE(answer->ToString(&sdp));
1158
1159 size_t expected_candidate_num = 2;
1160 if (!rtcp_mux) {
1161 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1162 // for rtp and rtcp.
1163 expected_candidate_num = 4;
1164 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001165 const std::string kRtcpMux = "a=rtcp-mux";
1166 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001167 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001168 kXRtcpMux.c_str(), kXRtcpMux.length(),
1169 &sdp);
1170 }
1171
1172 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1173 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001174
1175 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001176 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001177 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1178 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001179 if (bundle) {
1180 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1181 } else {
1182 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001183 }
1184 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001185
zhihuang3a334652016-05-05 18:37:49 -07001186 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1187 const std::string& codec_name) {
1188 for (const auto& content : desc->description()->contents()) {
1189 if (static_cast<cricket::MediaContentDescription*>(content.description)
1190 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1191 const auto* mdesc =
1192 static_cast<cricket::VideoContentDescription*>(content.description);
1193 for (const auto& codec : mdesc->codecs()) {
1194 if (codec.name == codec_name) {
1195 return true;
1196 }
1197 }
1198 }
1199 }
1200 return false;
1201 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001202 // Helper class to configure loopback network and verify Best
1203 // Connection using right IP protocol for TestLoopbackCall
1204 // method. LoopbackNetworkManager applies firewall rules to block
1205 // all ping traffic once ICE completed, and remove them to observe
1206 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1207 // verifies the best connection is using the right IP protocol after
1208 // initial ICE convergences.
1209
1210 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001211 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001212 LoopbackNetworkConfiguration()
1213 : test_ipv6_network_(false),
1214 test_extra_ipv4_network_(false),
1215 best_connection_after_initial_ice_converged_(1, 0) {}
1216
1217 // Used to track the expected best connection count in each IP protocol.
1218 struct ExpectedBestConnection {
1219 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1220 : ipv4_count_(ipv4_count),
1221 ipv6_count_(ipv6_count) {}
1222
1223 int ipv4_count_;
1224 int ipv6_count_;
1225 };
1226
1227 bool test_ipv6_network_;
1228 bool test_extra_ipv4_network_;
1229 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1230
1231 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001232 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001233 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1234 }
1235
1236 private:
jbauchac8869e2015-07-03 01:36:14 -07001237 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001238 const ExpectedBestConnection& expected) const {
1239 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001240 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1241 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001242 expected.ipv4_count_);
1243 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001244 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1245 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001246 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001247 // This is used in the loopback call so there is only single host to host
1248 // candidate pair.
1249 EXPECT_EQ(metrics_observer->GetEnumCounter(
1250 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1251 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001252 0);
1253 EXPECT_EQ(metrics_observer->GetEnumCounter(
1254 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1255 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001256 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001257 }
1258 };
1259
1260 class LoopbackNetworkManager {
1261 public:
1262 LoopbackNetworkManager(WebRtcSessionTest* session,
1263 const LoopbackNetworkConfiguration& config)
1264 : config_(config) {
1265 session->AddInterface(
1266 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1267 if (config_.test_extra_ipv4_network_) {
1268 session->AddInterface(
1269 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1270 }
1271 if (config_.test_ipv6_network_) {
1272 session->AddInterface(
1273 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1274 }
1275 }
1276
1277 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1278 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1279 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1280 if (config_.test_extra_ipv4_network_) {
1281 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1282 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1283 }
1284 if (config_.test_ipv6_network_) {
1285 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1286 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1287 }
1288 }
1289
1290 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1291
1292 private:
1293 LoopbackNetworkConfiguration config_;
1294 };
1295
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001296 // The method sets up a call from the session to itself, in a loopback
1297 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001298 // disconnection, and then a permanent disconnection.
1299 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001300 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1301 // While running the call, this method also checks if the session goes through
1302 // the correct sequence of ICE states when a connection is established,
1303 // broken, and re-established.
1304 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001305 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1306 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001307 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001308
stefanc1aeaf02015-10-15 07:26:07 -07001309 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001310 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001311 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001312 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001313
1314 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1315 observer_.ice_gathering_state_);
1316 SetLocalDescriptionWithoutError(offer);
1317 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1318 observer_.ice_connection_state_);
1319 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001320 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001321 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1322 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001323 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324
1325 std::string sdp;
1326 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001327 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1328 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001329 ASSERT_TRUE(desc != NULL);
1330 SetRemoteDescriptionWithoutError(desc);
1331
1332 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001333 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001334
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001335 // The ice connection state is "Connected" too briefly to catch in a test.
1336 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001337 observer_.ice_connection_state_, kIceCandidatesTimeout);
1338 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001339
stefanc1aeaf02015-10-15 07:26:07 -07001340 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1341 LoopbackNetworkManager loopback_network_manager(this, config);
1342 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001343 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001344 // Adding firewall rule to block ping requests, which should cause
1345 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001346
1347 loopback_network_manager.ApplyFirewallRules(fss_.get());
1348
1349 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001350 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1351 observer_.ice_connection_state_,
1352 kIceCandidatesTimeout);
1353
jbauchac8869e2015-07-03 01:36:14 -07001354 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001355
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001356 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001357 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001358
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001359 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001360 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001361 observer_.ice_connection_state_,
1362 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001363
1364 // Now we block ping requests and wait until the ICE connection transitions
1365 // to the Failed state. This will take at least 30 seconds because it must
1366 // wait for the Port to timeout.
1367 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001368
1369 loopback_network_manager.ApplyFirewallRules(fss_.get());
1370 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001371 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001372 observer_.ice_connection_state_,
1373 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001374 }
1375
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001376 void TestLoopbackCall() {
1377 LoopbackNetworkConfiguration config;
1378 TestLoopbackCall(config);
1379 }
1380
stefanc1aeaf02015-10-15 07:26:07 -07001381 void TestPacketOptions() {
1382 media_controller_.reset(
1383 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1384 LoopbackNetworkConfiguration config;
1385 LoopbackNetworkManager loopback_network_manager(this, config);
1386
1387 SetupLoopbackCall();
1388
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001389 // Wait for channel to be ready for sending.
1390 EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
stefanc1aeaf02015-10-15 07:26:07 -07001391 uint8_t test_packet[15] = {0};
1392 rtc::PacketOptions options;
1393 options.packet_id = 10;
1394 media_engine_->GetVideoChannel(0)
1395 ->SendRtp(test_packet, sizeof(test_packet), options);
1396
1397 const int kPacketTimeout = 2000;
deadbeef14461d42016-06-15 11:06:57 -07001398 EXPECT_EQ_WAIT(10, fake_call_.last_sent_nonnegative_packet_id(),
1399 kPacketTimeout);
stefanc1aeaf02015-10-15 07:26:07 -07001400 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1401 }
1402
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001403 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1404 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001405 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1406 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001407
1408 // Add kCNCodec for dtmf test.
ossudedfd282016-06-14 07:12:39 -07001409 std::vector<cricket::AudioCodec> codecs =
1410 media_engine_->audio_send_codecs();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001411 codecs.push_back(kCNCodec1);
1412 codecs.push_back(kCNCodec2);
1413 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -07001414 desc_factory_->set_audio_codecs(codecs, codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001415 }
1416
1417 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1418 const cricket::ContentDescription* description = content->description;
nissec8ee8822017-01-18 07:20:55 -08001419 RTC_CHECK(description != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001420 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001421 static_cast<const cricket::AudioContentDescription*>(description);
nissec8ee8822017-01-18 07:20:55 -08001422 RTC_CHECK(audio_content_desc != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001423 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1424 if (audio_content_desc->codecs()[i].name == "CN")
1425 return false;
1426 }
1427 return true;
1428 }
1429
deadbeefab9b2d12015-10-14 11:33:11 -07001430 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001431 webrtc::InternalDataChannelInit dci;
nissec8ee8822017-01-18 07:20:55 -08001432 RTC_CHECK(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001433 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1434 data_channel_ = DataChannel::Create(
1435 session_.get(), session_->data_channel_type(), "datachannel", dci);
1436 }
1437
1438 void SetLocalDescriptionWithDataChannel() {
1439 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001440 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001441 SetLocalDescriptionWithoutError(offer);
1442 }
1443
wu@webrtc.org91053e72013-08-10 07:18:04 +00001444 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001445 RTCCertificateGenerationMethod cert_gen_method,
1446 CreateSessionDescriptionRequest::Type type) {
1447 InitWithDtls(cert_gen_method);
1448 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1449 }
1450
1451 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1452 CreateSessionDescriptionRequest::Type type) {
1453 InitWithDtlsIdentityGenFail();
1454 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1455 }
1456
1457 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001458 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001459 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001460 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001461 if (type == CreateSessionDescriptionRequest::kAnswer) {
1462 cricket::MediaSessionOptions options;
kwibergd1fe2812016-04-27 06:47:29 -07001463 std::unique_ptr<JsepSessionDescription> offer(
1464 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001465 ASSERT_TRUE(offer.get() != NULL);
1466 SetRemoteDescriptionWithoutError(offer.release());
1467 }
1468
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001469 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001470 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001471 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001472 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001473 observers[kNumber];
1474 for (int i = 0; i < kNumber; ++i) {
1475 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1476 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001477 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001478 } else {
htaa2a49d92016-03-04 02:51:39 -08001479 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001480 }
1481 }
1482
1483 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1484 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1485 WebRtcSessionCreateSDPObserverForTest::kFailed;
1486
1487 for (int i = 0; i < kNumber; ++i) {
1488 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1489 if (success) {
1490 EXPECT_TRUE(observers[i]->description() != NULL);
1491 } else {
1492 EXPECT_TRUE(observers[i]->description() == NULL);
1493 }
1494 }
1495 }
1496
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001497 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001498 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001499 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001500 turn_server.credentials = credentials;
1501 turn_server.ports.push_back(
hnsl277b2502016-12-13 05:17:23 -08001502 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP));
deadbeef653b8e02015-11-11 12:55:10 -08001503 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001504 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001505 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001506 }
1507
skvlad11a9cbf2016-10-07 11:53:05 -07001508 webrtc::RtcEventLogNullImpl event_log_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001509 cricket::FakeMediaEngine* media_engine_;
1510 cricket::FakeDataEngine* data_engine_;
deadbeef953c2ce2017-01-09 14:53:41 -08001511 // Actually owned by session_.
1512 FakeSctpTransportFactory* fake_sctp_transport_factory_ = nullptr;
kwibergd1fe2812016-04-27 06:47:29 -07001513 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001514 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001515 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_;
1516 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1517 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1518 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1519 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1520 std::unique_ptr<rtc::FirewallSocketServer> fss_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001521 rtc::SocketServerScope ss_scope_;
1522 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001523 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001524 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001525 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001526 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001527 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001528 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001529 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001530 MockIceObserver observer_;
1531 cricket::FakeVideoMediaChannel* video_channel_;
1532 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001533 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001534 // The following flags affect options created for CreateOffer/CreateAnswer.
1535 bool send_stream_1_ = false;
1536 bool send_stream_2_ = false;
1537 bool send_audio_ = false;
1538 bool send_video_ = false;
1539 rtc::scoped_refptr<DataChannel> data_channel_;
1540 // Last values received from data channel creation signal.
1541 std::string last_data_channel_label_;
1542 InternalDataChannelInit last_data_channel_config_;
jbauchcb560652016-08-04 05:20:32 -07001543 bool with_gcm_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001544};
1545
Henrik Boström87713d02015-08-25 09:53:21 +02001546TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1547 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001548 // SDES is disabled when DTLS is on.
1549 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001550}
1551
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001552TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001553 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001554 // SDES is required if DTLS is off.
1555 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001556}
1557
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001558TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1559 TestSessionCandidatesWithBundleRtcpMux(false, false);
1560}
1561
1562// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1563// with rtcp-mux and/or bundle.
1564TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1565 TestSessionCandidatesWithBundleRtcpMux(false, true);
1566}
1567
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001568TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1569 TestSessionCandidatesWithBundleRtcpMux(true, true);
1570}
1571
1572TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001573 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1574 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001575 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001576 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001577 InitiateCall();
1578 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1579 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1580 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1581}
1582
deadbeeff5f03e82016-06-06 11:16:06 -07001583TEST_F(WebRtcSessionTest, TestStunError) {
1584 rtc::ScopedFakeClock clock;
1585
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001586 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1587 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001588 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001589 rtc::FP_UDP,
1590 rtc::FD_ANY,
1591 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001592 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001593 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001594 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001595 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
deadbeeff5f03e82016-06-06 11:16:06 -07001596 EXPECT_TRUE_SIMULATED_WAIT(observer_.oncandidatesready_, kStunTimeout, clock);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001597 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1598 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
deadbeeff5f03e82016-06-06 11:16:06 -07001599 // Destroy session before scoped fake clock goes out of scope to avoid TSan
1600 // warning.
1601 session_->Close();
1602 session_.reset(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603}
1604
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001605TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001606 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001607 SessionDescriptionInterface* offer = NULL;
1608 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1609 std::string unknown_action;
1610 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1611 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1612}
1613
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001614// Test creating offers and receive answers and make sure the
1615// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001616TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001617 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001618 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001619 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001620 const std::string session_id_orig = offer->session_id();
1621 const std::string session_version_orig = offer->session_version();
1622 SetLocalDescriptionWithoutError(offer);
1623
deadbeefab9b2d12015-10-14 11:33:11 -07001624 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001625 SessionDescriptionInterface* answer =
1626 CreateRemoteAnswer(session_->local_description());
1627 SetRemoteDescriptionWithoutError(answer);
1628
1629 video_channel_ = media_engine_->GetVideoChannel(0);
1630 voice_channel_ = media_engine_->GetVoiceChannel(0);
1631
1632 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1633 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1634
1635 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1636 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1637
1638 ASSERT_EQ(1u, video_channel_->send_streams().size());
1639 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1640 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1641 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1642
1643 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001644 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001645 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001646
1647 // Verify the session id is the same and the session version is
1648 // increased.
1649 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001650 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1651 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001652
1653 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001654 EXPECT_EQ(0u, video_channel_->send_streams().size());
1655 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001656
deadbeefab9b2d12015-10-14 11:33:11 -07001657 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001658 answer = CreateRemoteAnswer(session_->local_description());
1659 SetRemoteDescriptionWithoutError(answer);
1660
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001661 // Make sure the receive streams have not changed.
1662 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1663 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1664 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1665 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1666}
1667
1668// Test receiving offers and creating answers and make sure the
1669// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001670TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001671 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001672 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001673 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001674 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001675 SetRemoteDescriptionWithoutError(offer);
1676
deadbeefab9b2d12015-10-14 11:33:11 -07001677 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001678 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001679 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001680 SetLocalDescriptionWithoutError(answer);
1681
1682 const std::string session_id_orig = answer->session_id();
1683 const std::string session_version_orig = answer->session_version();
1684
1685 video_channel_ = media_engine_->GetVideoChannel(0);
1686 voice_channel_ = media_engine_->GetVoiceChannel(0);
1687
htaa2a49d92016-03-04 02:51:39 -08001688 ASSERT_TRUE(video_channel_);
1689 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001690 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1691 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1692
1693 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1694 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1695
1696 ASSERT_EQ(1u, video_channel_->send_streams().size());
1697 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1698 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1699 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1700
deadbeefab9b2d12015-10-14 11:33:11 -07001701 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001702 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001703 SetRemoteDescriptionWithoutError(offer);
1704
1705 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001706 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001707 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708
1709 // Verify the session id is the same and the session version is
1710 // increased.
1711 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001712 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1713 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001714 SetLocalDescriptionWithoutError(answer);
1715
1716 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1717 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1718 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1719 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1720 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1721 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1722
1723 // Make sure we have no send streams.
1724 EXPECT_EQ(0u, video_channel_->send_streams().size());
1725 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1726}
1727
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001728TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001729 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001730 media_engine_->set_fail_create_channel(true);
1731
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001732 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001733 ASSERT_TRUE(offer != NULL);
1734 // SetRemoteDescription and SetLocalDescription will take the ownership of
1735 // the offer.
1736 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001737 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001738 ASSERT_TRUE(offer != NULL);
1739 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1740}
1741
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001742//
1743// Tests for creating/setting SDP under different SDES/DTLS polices:
1744//
1745// --DTLS off and SDES on
1746// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1747// set local/remote offer/answer with crypto --> success
1748// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1749// failure
1750// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1751// failure
1752// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1753// failure
1754//
1755// --DTLS on and SDES off
1756// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1757// set local/remote offer/answer with DTLS fingerprint --> success
1758// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1759// fingerprint --> failure
1760// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1761// --> failure
1762// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1763// --> failure
1764//
1765// --Encryption disabled: DTLS off and SDES off
1766// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1767// answer without SDES or DTLS --> success
1768// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1769// answer without SDES or DTLS --> success
1770//
1771
1772// Test that we return a failure when applying a remote/local offer that doesn't
1773// have cryptos enabled when DTLS is off.
1774TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001775 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001777 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778 JsepSessionDescription* offer = CreateRemoteOffer(
1779 options, cricket::SEC_DISABLED);
1780 ASSERT_TRUE(offer != NULL);
1781 VerifyNoCryptoParams(offer->description(), false);
1782 // SetRemoteDescription and SetLocalDescription will take the ownership of
1783 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001784 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1786 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001787 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788}
1789
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001790// Test that we return a failure when applying a local answer that doesn't have
1791// cryptos enabled when DTLS is off.
1792TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001793 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001794 SessionDescriptionInterface* offer = NULL;
1795 SessionDescriptionInterface* answer = NULL;
1796 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1797 // SetRemoteDescription and SetLocalDescription will take the ownership of
1798 // the offer.
1799 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001800 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001801}
1802
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001803// Test we will return fail when apply an remote answer that doesn't have
1804// crypto enabled when DTLS is off.
1805TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001806 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001807 SessionDescriptionInterface* offer = NULL;
1808 SessionDescriptionInterface* answer = NULL;
1809 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1810 // SetRemoteDescription and SetLocalDescription will take the ownership of
1811 // the offer.
1812 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001813 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001814}
1815
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001816// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1817// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001818TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001819 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001820 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001821 SetFactoryDtlsSrtp();
1822 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001823 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001824 JsepSessionDescription* offer =
1825 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001826 ASSERT_TRUE(offer != NULL);
1827 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001828 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001829
1830 // SetRemoteDescription will take the ownership of the offer.
1831 SetRemoteDescriptionWithoutError(offer);
1832
1833 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001834 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001835 ASSERT_TRUE(answer != NULL);
1836 VerifyFingerprintStatus(answer->description(), true);
1837 // Check that we don't have an a=crypto line in the answer.
1838 VerifyNoCryptoParams(answer->description(), true);
1839
1840 // Now set the local description, which should work, even without a=crypto.
1841 SetLocalDescriptionWithoutError(answer);
1842}
1843
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001844// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1845// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001846TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001847 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001848 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001849 SetFactoryDtlsSrtp();
1850
1851 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001852 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001853 ASSERT_TRUE(offer != NULL);
1854 VerifyFingerprintStatus(offer->description(), true);
1855 // Check that we don't have an a=crypto line in the offer.
1856 VerifyNoCryptoParams(offer->description(), true);
1857
1858 // Now set the local description, which should work, even without a=crypto.
1859 SetLocalDescriptionWithoutError(offer);
1860
1861 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001862 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001863 JsepSessionDescription* answer =
1864 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1865 ASSERT_TRUE(answer != NULL);
1866 VerifyFingerprintStatus(answer->description(), true);
1867 VerifyNoCryptoParams(answer->description(), true);
1868
1869 // SetRemoteDescription will take the ownership of the answer.
1870 SetRemoteDescriptionWithoutError(answer);
1871}
1872
1873// Test that if we support DTLS and the other side didn't offer a fingerprint,
1874// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001875TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02001876 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001877 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001878 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001879 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001880 JsepSessionDescription* offer = CreateRemoteOffer(
1881 options, cricket::SEC_REQUIRED);
1882 ASSERT_TRUE(offer != NULL);
1883 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001884 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001885
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001886 // SetRemoteDescription will take the ownership of the offer.
1887 SetRemoteDescriptionOfferExpectError(
1888 kSdpWithoutDtlsFingerprint, offer);
1889
1890 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1891 // SetLocalDescription will take the ownership of the offer.
1892 SetLocalDescriptionOfferExpectError(
1893 kSdpWithoutDtlsFingerprint, offer);
1894}
1895
1896// Test that we return a failure when applying a local answer that doesn't have
1897// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001898TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02001899 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001900 SessionDescriptionInterface* offer = NULL;
1901 SessionDescriptionInterface* answer = NULL;
1902 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1903
1904 // SetRemoteDescription and SetLocalDescription will take the ownership of
1905 // the offer and answer.
1906 SetRemoteDescriptionWithoutError(offer);
1907 SetLocalDescriptionAnswerExpectError(
1908 kSdpWithoutDtlsFingerprint, answer);
1909}
1910
1911// Test that we return a failure when applying a remote answer that doesn't have
1912// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001913TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02001914 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001915 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001916 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001917 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07001918 std::unique_ptr<SessionDescriptionInterface> temp_offer(
deadbeefcbecd352015-09-23 11:50:27 -07001919 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001920 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001921 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001922
1923 // SetRemoteDescription and SetLocalDescription will take the ownership of
1924 // the offer and answer.
1925 SetLocalDescriptionWithoutError(offer);
1926 SetRemoteDescriptionAnswerExpectError(
1927 kSdpWithoutDtlsFingerprint, answer);
1928}
1929
1930// Test that we create a local offer without SDES or DTLS and accept a remote
1931// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001932TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001933 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001934 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001935 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001936
1937 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001938 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001939 ASSERT_TRUE(offer != NULL);
1940 VerifyFingerprintStatus(offer->description(), false);
1941 // Check that we don't have an a=crypto line in the offer.
1942 VerifyNoCryptoParams(offer->description(), false);
1943
1944 // Now set the local description, which should work, even without a=crypto.
1945 SetLocalDescriptionWithoutError(offer);
1946
1947 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001948 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001949 JsepSessionDescription* answer =
1950 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1951 ASSERT_TRUE(answer != NULL);
1952 VerifyFingerprintStatus(answer->description(), false);
1953 VerifyNoCryptoParams(answer->description(), false);
1954
1955 // SetRemoteDescription will take the ownership of the answer.
1956 SetRemoteDescriptionWithoutError(answer);
1957}
1958
1959// Test that we create a local answer without SDES or DTLS and accept a remote
1960// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001961TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001962 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001963 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001964
1965 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001966 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001967 JsepSessionDescription* offer =
1968 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1969 ASSERT_TRUE(offer != NULL);
1970 VerifyFingerprintStatus(offer->description(), false);
1971 VerifyNoCryptoParams(offer->description(), false);
1972
1973 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001974 SetRemoteDescriptionWithoutError(offer);
1975
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001976 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001977 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001978 ASSERT_TRUE(answer != NULL);
1979 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001980 // Check that we don't have an a=crypto line in the answer.
1981 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001982
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001983 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001984 SetLocalDescriptionWithoutError(answer);
1985}
1986
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001987// Test that we can create and set an answer correctly when different
1988// SSL roles have been negotiated for different transports.
1989// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1990TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1991 SendAudioVideoStream1();
1992 InitWithDtls(GetParam());
1993 SetFactoryDtlsSrtp();
1994
1995 SessionDescriptionInterface* offer = CreateOffer();
1996 SetLocalDescriptionWithoutError(offer);
1997
1998 cricket::MediaSessionOptions options;
1999 options.recv_video = true;
2000
2001 // First, negotiate different SSL roles.
2002 SessionDescriptionInterface* answer =
2003 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
2004 TransportInfo* audio_transport_info =
2005 answer->description()->GetTransportInfoByName("audio");
2006 audio_transport_info->description.connection_role =
2007 cricket::CONNECTIONROLE_ACTIVE;
2008 TransportInfo* video_transport_info =
2009 answer->description()->GetTransportInfoByName("video");
2010 video_transport_info->description.connection_role =
2011 cricket::CONNECTIONROLE_PASSIVE;
2012 SetRemoteDescriptionWithoutError(answer);
2013
2014 // Now create an offer in the reverse direction, and ensure the initial
2015 // offerer responds with an answer with correct SSL roles.
2016 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2017 kSessionVersion,
2018 session_->remote_description());
2019 SetRemoteDescriptionWithoutError(offer);
2020
htaa2a49d92016-03-04 02:51:39 -08002021 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002022 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2023 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2024 audio_transport_info->description.connection_role);
2025 video_transport_info = answer->description()->GetTransportInfoByName("video");
2026 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
2027 video_transport_info->description.connection_role);
2028 SetLocalDescriptionWithoutError(answer);
2029
2030 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
2031 // audio is transferred over to video in the answer that completes the BUNDLE
2032 // negotiation.
2033 options.bundle_enabled = true;
2034 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2035 kSessionVersion,
2036 session_->remote_description());
2037 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08002038 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002039 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2040 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2041 audio_transport_info->description.connection_role);
2042 video_transport_info = answer->description()->GetTransportInfoByName("video");
2043 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2044 video_transport_info->description.connection_role);
2045 SetLocalDescriptionWithoutError(answer);
2046}
2047
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002049 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002050 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002051 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002052 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053 SetLocalDescriptionWithoutError(offer);
2054
2055 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002056 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002057 SetLocalDescriptionWithoutError(offer2);
2058}
2059
2060TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002061 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002062 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002063 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002064 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002065 SetRemoteDescriptionWithoutError(offer);
2066
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002067 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002068 SetRemoteDescriptionWithoutError(offer2);
2069}
2070
2071TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002072 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002073 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002074 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002075 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002076 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002077 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2078 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079}
2080
2081TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002082 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002083 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002084 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002085 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002086 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002087 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002088 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002089}
2090
2091TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002092 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002093 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002094 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002095 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002096
htaa2a49d92016-03-04 02:51:39 -08002097 JsepSessionDescription* pranswer =
2098 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002099 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002100 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002101
deadbeefab9b2d12015-10-14 11:33:11 -07002102 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002103 JsepSessionDescription* pranswer2 =
2104 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002105 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2106
deadbeefd59daf82015-10-14 15:02:44 -07002107 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108
deadbeefab9b2d12015-10-14 11:33:11 -07002109 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002110 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002111 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002112}
2113
2114TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002115 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002116 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002117 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002118 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002119
2120 JsepSessionDescription* pranswer =
2121 CreateRemoteAnswer(session_->local_description());
2122 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2123
2124 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002125 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002126
deadbeefab9b2d12015-10-14 11:33:11 -07002127 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002128 JsepSessionDescription* pranswer2 =
2129 CreateRemoteAnswer(session_->local_description());
2130 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2131
2132 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002133 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002134
deadbeefab9b2d12015-10-14 11:33:11 -07002135 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002136 SessionDescriptionInterface* answer =
2137 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002138 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002139}
2140
2141TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002142 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002143 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002144 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002145
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002146 SessionDescriptionInterface* answer =
2147 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002148 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2149 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002150}
2151
2152TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002153 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002154 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002155 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002156
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002157 SessionDescriptionInterface* answer =
2158 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002159 SetRemoteDescriptionAnswerExpectError(
2160 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002161}
2162
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002163// Tests that the remote candidates are added and removed successfully.
2164TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002165 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002166 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002167
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002168 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
2169 "", "", "host", 0, "");
2170 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002171 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2172
deadbeefd59daf82015-10-14 15:02:44 -07002173 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002174 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2175
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002176 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002177 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002178
2179 // Fail since we have not set a remote description.
2180 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002181
2182 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2183 session_->local_description());
2184 SetRemoteDescriptionWithoutError(answer);
2185
deadbeefd59daf82015-10-14 15:02:44 -07002186 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2187 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002188 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002189 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2190 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2191
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002192 // Verifying the candidates are copied properly from internal vector.
2193 const SessionDescriptionInterface* remote_desc =
2194 session_->remote_description();
2195 ASSERT_TRUE(remote_desc != NULL);
2196 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2197 const IceCandidateCollection* candidates =
2198 remote_desc->candidates(kMediaContentIndex0);
2199 ASSERT_EQ(2u, candidates->count());
2200 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2201 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2202 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2203 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2204
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002205 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2206 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002207 candidate.set_component(2);
2208 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2209 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002210 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002211
2212 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2213 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002214
2215 // Remove candidate1 and candidate2
2216 std::vector<cricket::Candidate> remote_candidates;
2217 remote_candidates.push_back(ice_candidate1.candidate());
2218 remote_candidates.push_back(ice_candidate2.candidate());
2219 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2220 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002221}
2222
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002223// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002224// that it is retained if the remote session description is changed.
2225TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002226 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002227 cricket::Candidate candidate1;
2228 candidate1.set_component(1);
2229 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2230 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002231 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002232 CreateAndSetRemoteOfferAndLocalAnswer();
2233
2234 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2235 const SessionDescriptionInterface* remote_desc =
2236 session_->remote_description();
2237 ASSERT_TRUE(remote_desc != NULL);
2238 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2239 const IceCandidateCollection* candidates =
2240 remote_desc->candidates(kMediaContentIndex0);
2241 ASSERT_EQ(1u, candidates->count());
2242 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2243
2244 // Update the RemoteSessionDescription with a new session description and
2245 // a candidate and check that the new remote session description contains both
2246 // candidates.
2247 SessionDescriptionInterface* offer = CreateRemoteOffer();
2248 cricket::Candidate candidate2;
2249 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2250 candidate2);
2251 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2252 SetRemoteDescriptionWithoutError(offer);
2253
2254 remote_desc = session_->remote_description();
2255 ASSERT_TRUE(remote_desc != NULL);
2256 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2257 candidates = remote_desc->candidates(kMediaContentIndex0);
2258 ASSERT_EQ(2u, candidates->count());
2259 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2260 // Username and password have be updated with the TransportInfo of the
2261 // SessionDescription, won't be equal to the original one.
2262 candidate2.set_username(candidates->at(0)->candidate().username());
2263 candidate2.set_password(candidates->at(0)->candidate().password());
2264 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2265 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2266 // No need to verify the username and password.
2267 candidate1.set_username(candidates->at(1)->candidate().username());
2268 candidate1.set_password(candidates->at(1)->candidate().password());
2269 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2270
2271 // Test that the candidate is ignored if we can add the same candidate again.
2272 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2273}
2274
2275// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002276// that they are retained if the local session description is changed. And if
2277// continual gathering is enabled, they are removed from the local session
2278// description when the network is down.
2279TEST_F(WebRtcSessionTest,
2280 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002281 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002282 Init();
deadbeefb60a8192016-08-24 15:15:00 -07002283 // Enable Continual Gathering.
2284 cricket::IceConfig config;
2285 config.continual_gathering_policy = cricket::GATHER_CONTINUALLY;
2286 session_->SetIceConfig(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002287 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002288 CreateAndSetRemoteOfferAndLocalAnswer();
2289
2290 const SessionDescriptionInterface* local_desc = session_->local_description();
2291 const IceCandidateCollection* candidates =
2292 local_desc->candidates(kMediaContentIndex0);
2293 ASSERT_TRUE(candidates != NULL);
2294 EXPECT_EQ(0u, candidates->count());
2295
deadbeefb60a8192016-08-24 15:15:00 -07002296 // Since we're using continual gathering, we won't get "gathering done".
2297 EXPECT_EQ_WAIT(2u, candidates->count(), kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002298
2299 local_desc = session_->local_description();
2300 candidates = local_desc->candidates(kMediaContentIndex0);
2301 ASSERT_TRUE(candidates != NULL);
2302 EXPECT_LT(0u, candidates->count());
2303 candidates = local_desc->candidates(1);
2304 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002305 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002306
2307 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002308 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002309 CreateAndSetRemoteOfferAndLocalAnswer();
2310
2311 local_desc = session_->local_description();
2312 candidates = local_desc->candidates(kMediaContentIndex0);
2313 ASSERT_TRUE(candidates != NULL);
2314 EXPECT_LT(0u, candidates->count());
2315 candidates = local_desc->candidates(1);
2316 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002317 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002318
2319 candidates = local_desc->candidates(kMediaContentIndex0);
2320 size_t num_local_candidates = candidates->count();
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002321 // Bring down the network interface to trigger candidate removals.
2322 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2323 // Verify that all local candidates are removed.
2324 EXPECT_EQ(0, observer_.num_candidates_removed_);
2325 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2326 kIceCandidatesTimeout);
2327 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2328}
2329
2330// Tests that if continual gathering is disabled, local candidates won't be
2331// removed when the interface is turned down.
2332TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2333 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2334 Init();
2335 SendAudioVideoStream1();
2336 CreateAndSetRemoteOfferAndLocalAnswer();
2337
2338 const SessionDescriptionInterface* local_desc = session_->local_description();
2339 const IceCandidateCollection* candidates =
2340 local_desc->candidates(kMediaContentIndex0);
2341 ASSERT_TRUE(candidates != NULL);
2342 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2343
2344 size_t num_local_candidates = candidates->count();
2345 EXPECT_LT(0u, num_local_candidates);
2346 // By default, Continual Gathering is disabled.
2347 // Bring down the network interface.
2348 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2349 // Verify that the local candidates are not removed.
2350 rtc::Thread::Current()->ProcessMessages(1000);
2351 EXPECT_EQ(0, observer_.num_candidates_removed_);
2352 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002353}
2354
2355// Test that we can set a remote session description with remote candidates.
2356TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002357 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002358
2359 cricket::Candidate candidate1;
2360 candidate1.set_component(1);
2361 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2362 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002363 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002364 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002365
2366 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2367 SetRemoteDescriptionWithoutError(offer);
2368
2369 const SessionDescriptionInterface* remote_desc =
2370 session_->remote_description();
2371 ASSERT_TRUE(remote_desc != NULL);
2372 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2373 const IceCandidateCollection* candidates =
2374 remote_desc->candidates(kMediaContentIndex0);
2375 ASSERT_EQ(1u, candidates->count());
2376 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2377
htaa2a49d92016-03-04 02:51:39 -08002378 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002379 SetLocalDescriptionWithoutError(answer);
2380}
2381
2382// Test that offers and answers contains ice candidates when Ice candidates have
2383// been gathered.
2384TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002385 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002386 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002387 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002388 // Ice is started but candidates are not provided until SetLocalDescription
2389 // is called.
2390 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2391 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2392 CreateAndSetRemoteOfferAndLocalAnswer();
2393 // Wait until at least one local candidate has been collected.
2394 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2395 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002396
kwibergd1fe2812016-04-27 06:47:29 -07002397 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002398
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002399 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2400 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002401
2402 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2403 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002404 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002405 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2406 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002407 SetLocalDescriptionWithoutError(answer);
2408}
2409
2410// Verifies TransportProxy and media channels are created with content names
2411// present in the SessionDescription.
2412TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002413 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002414 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002415 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002416
2417 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002418 // "video". Goal is to modify these content names and verify transport
2419 // channels
2420 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002421 // present in SDP.
2422 std::string sdp;
2423 EXPECT_TRUE(offer->ToString(&sdp));
2424 const std::string kAudioMid = "a=mid:audio";
2425 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2426 const std::string kVideoMid = "a=mid:video";
2427 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2428
2429 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002430 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002431 kAudioMidReplaceStr.c_str(),
2432 kAudioMidReplaceStr.length(),
2433 &sdp);
2434 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002435 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002436 kVideoMidReplaceStr.c_str(),
2437 kVideoMidReplaceStr.length(),
2438 &sdp);
2439
2440 SessionDescriptionInterface* modified_offer =
2441 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2442
2443 SetRemoteDescriptionWithoutError(modified_offer);
2444
htaa2a49d92016-03-04 02:51:39 -08002445 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002446 SetLocalDescriptionWithoutError(answer);
2447
johan669d69b2016-11-08 14:14:08 -08002448 rtc::PacketTransportInterface* voice_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002449 session_->voice_rtp_transport_channel();
2450 EXPECT_TRUE(voice_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002451 EXPECT_EQ(voice_transport_channel->debug_name(),
2452 "audio_content_name " +
2453 std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
2454 rtc::PacketTransportInterface* video_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002455 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002456 ASSERT_TRUE(video_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002457 EXPECT_EQ(video_transport_channel->debug_name(),
2458 "video_content_name " +
2459 std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002460 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2461 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2462}
2463
2464// Test that an offer contains the correct media content descriptions based on
2465// the send streams when no constraints have been set.
2466TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002467 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002468 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002469
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002470 ASSERT_TRUE(offer != NULL);
2471 const cricket::ContentInfo* content =
2472 cricket::GetFirstAudioContent(offer->description());
2473 EXPECT_TRUE(content != NULL);
2474 content = cricket::GetFirstVideoContent(offer->description());
2475 EXPECT_TRUE(content == NULL);
2476}
2477
2478// Test that an offer contains the correct media content descriptions based on
2479// the send streams when no constraints have been set.
2480TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002481 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002482 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002483 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002484 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002485
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002486 const cricket::ContentInfo* content =
2487 cricket::GetFirstAudioContent(offer->description());
2488 EXPECT_TRUE(content != NULL);
2489 content = cricket::GetFirstVideoContent(offer->description());
2490 EXPECT_TRUE(content == NULL);
2491
2492 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002493 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002494 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002495 content = cricket::GetFirstAudioContent(offer->description());
2496 EXPECT_TRUE(content != NULL);
2497 content = cricket::GetFirstVideoContent(offer->description());
2498 EXPECT_TRUE(content != NULL);
2499}
2500
2501// Test that an offer contains no media content descriptions if
2502// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2503TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002504 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002505 PeerConnectionInterface::RTCOfferAnswerOptions options;
2506 options.offer_to_receive_audio = 0;
2507 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002508
kwibergd1fe2812016-04-27 06:47:29 -07002509 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002510
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002511 ASSERT_TRUE(offer != NULL);
2512 const cricket::ContentInfo* content =
2513 cricket::GetFirstAudioContent(offer->description());
2514 EXPECT_TRUE(content == NULL);
2515 content = cricket::GetFirstVideoContent(offer->description());
2516 EXPECT_TRUE(content == NULL);
2517}
2518
2519// Test that an offer contains only audio media content descriptions if
2520// kOfferToReceiveAudio constraints are set to true.
2521TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002522 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002523 PeerConnectionInterface::RTCOfferAnswerOptions options;
2524 options.offer_to_receive_audio =
2525 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2526
kwibergd1fe2812016-04-27 06:47:29 -07002527 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002528
2529 const cricket::ContentInfo* content =
2530 cricket::GetFirstAudioContent(offer->description());
2531 EXPECT_TRUE(content != NULL);
2532 content = cricket::GetFirstVideoContent(offer->description());
2533 EXPECT_TRUE(content == NULL);
2534}
2535
2536// Test that an offer contains audio and video media content descriptions if
2537// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2538TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002539 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002540 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002541 PeerConnectionInterface::RTCOfferAnswerOptions options;
2542 options.offer_to_receive_audio =
2543 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2544 options.offer_to_receive_video =
2545 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2546
kwibergd1fe2812016-04-27 06:47:29 -07002547 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002548
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002549 const cricket::ContentInfo* content =
2550 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002551 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002552
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002553 content = cricket::GetFirstVideoContent(offer->description());
2554 EXPECT_TRUE(content != NULL);
2555
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002556 // Sets constraints to false and verifies that audio/video contents are
2557 // removed.
2558 options.offer_to_receive_audio = 0;
2559 options.offer_to_receive_video = 0;
2560 offer.reset(CreateOffer(options));
2561
2562 content = cricket::GetFirstAudioContent(offer->description());
2563 EXPECT_TRUE(content == NULL);
2564 content = cricket::GetFirstVideoContent(offer->description());
2565 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002566}
2567
2568// Test that an answer can not be created if the last remote description is not
2569// an offer.
2570TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002571 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002572 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002573 SetLocalDescriptionWithoutError(offer);
2574 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2575 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002576 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002577}
2578
2579// Test that an answer contains the correct media content descriptions when no
2580// constraints have been set.
2581TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002582 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002583 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002584 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002585 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002586 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002587 const cricket::ContentInfo* content =
2588 cricket::GetFirstAudioContent(answer->description());
2589 ASSERT_TRUE(content != NULL);
2590 EXPECT_FALSE(content->rejected);
2591
2592 content = cricket::GetFirstVideoContent(answer->description());
2593 ASSERT_TRUE(content != NULL);
2594 EXPECT_FALSE(content->rejected);
2595}
2596
2597// Test that an answer contains the correct media content descriptions when no
2598// constraints have been set and the offer only contain audio.
2599TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002600 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002601 // Create a remote offer with audio only.
2602 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002603
kwibergd1fe2812016-04-27 06:47:29 -07002604 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002605 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2606 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2607
2608 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002609 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002610 const cricket::ContentInfo* content =
2611 cricket::GetFirstAudioContent(answer->description());
2612 ASSERT_TRUE(content != NULL);
2613 EXPECT_FALSE(content->rejected);
2614
2615 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2616}
2617
2618// Test that an answer contains the correct media content descriptions when no
2619// constraints have been set.
2620TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002621 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002622 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002623 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002624 SetRemoteDescriptionWithoutError(offer.release());
2625 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002626 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002627 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002628 const cricket::ContentInfo* content =
2629 cricket::GetFirstAudioContent(answer->description());
2630 ASSERT_TRUE(content != NULL);
2631 EXPECT_FALSE(content->rejected);
2632
2633 content = cricket::GetFirstVideoContent(answer->description());
2634 ASSERT_TRUE(content != NULL);
2635 EXPECT_FALSE(content->rejected);
2636}
2637
2638// Test that an answer contains the correct media content descriptions when
2639// constraints have been set but no stream is sent.
2640TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002641 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002642 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002643 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002644 SetRemoteDescriptionWithoutError(offer.release());
2645
htaa2a49d92016-03-04 02:51:39 -08002646 cricket::MediaSessionOptions session_options;
2647 session_options.recv_audio = false;
2648 session_options.recv_video = false;
kwibergd1fe2812016-04-27 06:47:29 -07002649 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002650 CreateAnswer(session_options));
2651
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002652 const cricket::ContentInfo* content =
2653 cricket::GetFirstAudioContent(answer->description());
2654 ASSERT_TRUE(content != NULL);
2655 EXPECT_TRUE(content->rejected);
2656
2657 content = cricket::GetFirstVideoContent(answer->description());
2658 ASSERT_TRUE(content != NULL);
2659 EXPECT_TRUE(content->rejected);
2660}
2661
2662// Test that an answer contains the correct media content descriptions when
2663// constraints have been set and streams are sent.
2664TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002665 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002666 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002667 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002668 SetRemoteDescriptionWithoutError(offer.release());
2669
htaa2a49d92016-03-04 02:51:39 -08002670 cricket::MediaSessionOptions options;
2671 options.recv_audio = false;
2672 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002673
2674 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002675 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002676 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002677
2678 // TODO(perkj): Should the direction be set to SEND_ONLY?
2679 const cricket::ContentInfo* content =
2680 cricket::GetFirstAudioContent(answer->description());
2681 ASSERT_TRUE(content != NULL);
2682 EXPECT_FALSE(content->rejected);
2683
2684 // TODO(perkj): Should the direction be set to SEND_ONLY?
2685 content = cricket::GetFirstVideoContent(answer->description());
2686 ASSERT_TRUE(content != NULL);
2687 EXPECT_FALSE(content->rejected);
2688}
2689
2690TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2691 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002692 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002693 PeerConnectionInterface::RTCOfferAnswerOptions options;
2694 options.offer_to_receive_audio =
2695 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2696 options.voice_activity_detection = false;
2697
kwibergd1fe2812016-04-27 06:47:29 -07002698 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002699
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002700 const cricket::ContentInfo* content =
2701 cricket::GetFirstAudioContent(offer->description());
2702 EXPECT_TRUE(content != NULL);
2703 EXPECT_TRUE(VerifyNoCNCodecs(content));
2704}
2705
2706TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2707 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002708 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002709 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002710 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002711 SetRemoteDescriptionWithoutError(offer.release());
2712
htaa2a49d92016-03-04 02:51:39 -08002713 cricket::MediaSessionOptions options;
2714 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002715 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002716 const cricket::ContentInfo* content =
2717 cricket::GetFirstAudioContent(answer->description());
2718 ASSERT_TRUE(content != NULL);
2719 EXPECT_TRUE(VerifyNoCNCodecs(content));
2720}
2721
2722// This test verifies the call setup when remote answer with audio only and
2723// later updates with video.
2724TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002725 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002726 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2727 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2728
deadbeefab9b2d12015-10-14 11:33:11 -07002729 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002730 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002731
2732 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002733 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2734
2735 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2736 // and answer;
2737 SetLocalDescriptionWithoutError(offer);
2738 SetRemoteDescriptionWithoutError(answer);
2739
2740 video_channel_ = media_engine_->GetVideoChannel(0);
2741 voice_channel_ = media_engine_->GetVoiceChannel(0);
2742
2743 ASSERT_TRUE(video_channel_ == NULL);
2744
2745 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2746 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2747 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2748
2749 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002750 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002751 CreateAndSetRemoteOfferAndLocalAnswer();
2752
2753 video_channel_ = media_engine_->GetVideoChannel(0);
2754 voice_channel_ = media_engine_->GetVoiceChannel(0);
2755
2756 ASSERT_TRUE(video_channel_ != NULL);
2757 ASSERT_TRUE(voice_channel_ != NULL);
2758
2759 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2760 ASSERT_EQ(1u, video_channel_->send_streams().size());
2761 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2762 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2763 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2764 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2765 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2766 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2767
2768 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002769 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002770 CreateAndSetRemoteOfferAndLocalAnswer();
2771
2772 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2773 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2774 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2775 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2776 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2777}
2778
2779// This test verifies the call setup when remote answer with video only and
2780// later updates with audio.
2781TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002782 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002783 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2784 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002785 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002786 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002787
2788 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002789 options.recv_audio = false;
2790 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002791 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2792 offer, options, cricket::SEC_ENABLED);
2793
2794 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2795 // and answer.
2796 SetLocalDescriptionWithoutError(offer);
2797 SetRemoteDescriptionWithoutError(answer);
2798
2799 video_channel_ = media_engine_->GetVideoChannel(0);
2800 voice_channel_ = media_engine_->GetVoiceChannel(0);
2801
2802 ASSERT_TRUE(voice_channel_ == NULL);
2803 ASSERT_TRUE(video_channel_ != NULL);
2804
2805 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2806 ASSERT_EQ(1u, video_channel_->send_streams().size());
2807 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2808
2809 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002810 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002811 CreateAndSetRemoteOfferAndLocalAnswer();
2812
2813 voice_channel_ = media_engine_->GetVoiceChannel(0);
2814 ASSERT_TRUE(voice_channel_ != NULL);
2815
2816 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2817 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2818 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2819 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2820
2821 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002822 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002823 CreateAndSetRemoteOfferAndLocalAnswer();
2824
2825 video_channel_ = media_engine_->GetVideoChannel(0);
2826 voice_channel_ = media_engine_->GetVoiceChannel(0);
2827
2828 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2829 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2830 ASSERT_EQ(1u, video_channel_->send_streams().size());
2831 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2832}
2833
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002834TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002835 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002836 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002837 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002838 VerifyCryptoParams(offer->description());
2839 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002840 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002841 VerifyCryptoParams(answer->description());
2842}
2843
jbauchcb560652016-08-04 05:20:32 -07002844TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDPGcm) {
2845 InitWithGcm();
2846 SendAudioVideoStream1();
2847 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
2848 VerifyCryptoParams(offer->description(), true);
2849 SetRemoteDescriptionWithoutError(offer.release());
2850 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
2851 VerifyCryptoParams(answer->description(), true);
2852}
2853
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002854TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002855 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002856 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002857 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002858 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002859 VerifyNoCryptoParams(offer->description(), false);
2860}
2861
2862TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002863 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002864 VerifyAnswerFromNonCryptoOffer();
2865}
2866
2867TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002868 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002869 VerifyAnswerFromCryptoOffer();
2870}
2871
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002872// This test verifies that setLocalDescription fails if
2873// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2874TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002875 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002876 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002877 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002878
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002879 std::string sdp;
2880 RemoveIceUfragPwdLines(offer.get(), &sdp);
2881 SessionDescriptionInterface* modified_offer =
2882 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002883 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002884}
2885
2886// This test verifies that setRemoteDescription fails if
2887// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2888TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002889 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002890 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002891 std::string sdp;
2892 RemoveIceUfragPwdLines(offer.get(), &sdp);
2893 SessionDescriptionInterface* modified_offer =
2894 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002895 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002896}
2897
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002898// This test verifies that setLocalDescription fails if local offer has
2899// too short ice ufrag and pwd strings.
2900TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002901 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002902 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002903 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002904 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2905 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002906 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002907 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002908 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002909
2910 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002911 offer.reset(CreateOffer());
2912 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2913 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002914}
2915
2916// This test verifies that setRemoteDescription fails if remote offer has
2917// too short ice ufrag and pwd strings.
2918TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002919 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002920 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002921 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2922 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002923 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002924 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002925 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002926
deadbeef0ed85b22016-02-23 17:24:52 -08002927 offer.reset(CreateRemoteOffer());
2928 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2929 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002930}
2931
Honghai Zhang04e91462015-12-11 14:26:22 -08002932// Test that if the remote offer indicates the peer requested ICE restart (via
2933// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2934TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002935 Init();
honghaiz503726c2015-07-31 12:37:38 -07002936
2937 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07002938 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08002939 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002940 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2941 0, "", "", "relay", 0, "");
2942 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2943 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002944 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2945 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002946 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2947
2948 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002949 offer.reset(CreateRemoteOffer());
2950 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002951 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2952 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2953 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002954 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2955 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002956 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2957
2958 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002959 offer.reset(CreateRemoteOffer());
2960 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002961 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2962 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2963 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002964 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2965 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002966 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2967
2968 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002969 offer.reset(CreateRemoteOffer());
2970 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2971 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002972 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2973}
2974
Honghai Zhang04e91462015-12-11 14:26:22 -08002975// Test that if the remote answer indicates the peer requested ICE restart (via
2976// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2977TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2978 Init();
2979 SessionDescriptionInterface* offer = CreateOffer();
2980 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002981
2982 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07002983 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08002984 answer->set_type(JsepSessionDescription::kPrAnswer);
2985 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002986 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2987 0, "", "", "relay", 0, "");
2988 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2989 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002990 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2991 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002992 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2993
2994 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002995 answer.reset(CreateRemoteAnswer(offer));
2996 answer->set_type(JsepSessionDescription::kPrAnswer);
2997 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002998 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2999 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3000 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003001 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
3002 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003003 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
3004
3005 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08003006 answer.reset(CreateRemoteAnswer(offer));
3007 answer->set_type(JsepSessionDescription::kPrAnswer);
3008 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08003009 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
3010 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
3011 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003012 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
3013 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003014 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
3015
3016 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08003017 answer.reset(CreateRemoteAnswer(offer));
3018 answer->set_type(JsepSessionDescription::kPrAnswer);
3019 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
3020 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003021 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
3022}
3023
Donald Curtisd4f769d2015-05-28 09:48:21 -07003024// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07003025// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07003026TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
3027 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
3028
3029 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003030 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003031
3032 PeerConnectionInterface::RTCOfferAnswerOptions options;
3033 options.use_rtp_mux = true;
3034
3035 SessionDescriptionInterface* offer = CreateRemoteOffer();
3036 SetRemoteDescriptionWithoutError(offer);
3037
htaa2a49d92016-03-04 02:51:39 -08003038 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003039 SetLocalDescriptionWithoutError(answer);
3040
deadbeefcbecd352015-09-23 11:50:27 -07003041 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3042 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07003043
deadbeefcbecd352015-09-23 11:50:27 -07003044 cricket::BaseChannel* voice_channel = session_->voice_channel();
nissec8ee8822017-01-18 07:20:55 -08003045 ASSERT_TRUE(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003046
3047 // Checks if one of the transport channels contains a connection using a given
3048 // port.
deadbeefcbecd352015-09-23 11:50:27 -07003049 auto connection_with_remote_port = [this, voice_channel](int port) {
hbosdf6075a2016-12-19 04:58:02 -08003050 std::unique_ptr<webrtc::SessionStats> stats = session_->GetStats_s();
3051 for (auto& kv : stats->transport_stats) {
deadbeefcbecd352015-09-23 11:50:27 -07003052 for (auto& chan_stat : kv.second.channel_stats) {
3053 for (auto& conn_info : chan_stat.connection_infos) {
3054 if (conn_info.remote_candidate.address().port() == port) {
3055 return true;
3056 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07003057 }
3058 }
3059 }
3060 return false;
3061 };
3062
3063 EXPECT_FALSE(connection_with_remote_port(5000));
3064 EXPECT_FALSE(connection_with_remote_port(5001));
3065 EXPECT_FALSE(connection_with_remote_port(6000));
3066
3067 // The way the *_WAIT checks work is they only wait if the condition fails,
3068 // which does not help in the case where state is not changing. This is
3069 // problematic in this test since we want to verify that adding a video
3070 // candidate does _not_ change state. So we interleave candidates and assume
3071 // that messages are executed in the order they were posted.
3072
3073 // First audio candidate.
3074 cricket::Candidate candidate0;
3075 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3076 candidate0.set_component(1);
3077 candidate0.set_protocol("udp");
3078 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3079 candidate0);
3080 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3081
3082 // Video candidate.
3083 cricket::Candidate candidate1;
3084 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3085 candidate1.set_component(1);
3086 candidate1.set_protocol("udp");
3087 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3088 candidate1);
3089 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3090
3091 // Second audio candidate.
3092 cricket::Candidate candidate2;
3093 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3094 candidate2.set_component(1);
3095 candidate2.set_protocol("udp");
3096 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3097 candidate2);
3098 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3099
3100 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3101 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3102
3103 // No need here for a _WAIT check since we are checking that state hasn't
3104 // changed: if this is false we would be doing waits for nothing and if this
3105 // is true then there will be no messages processed anyways.
3106 EXPECT_FALSE(connection_with_remote_port(6000));
3107}
3108
deadbeefcbecd352015-09-23 11:50:27 -07003109// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003110TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3111 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003112 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003113
3114 PeerConnectionInterface::RTCOfferAnswerOptions options;
3115 options.use_rtp_mux = true;
3116
3117 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003118 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003119
deadbeefcbecd352015-09-23 11:50:27 -07003120 EXPECT_NE(session_->voice_rtp_transport_channel(),
3121 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003122
deadbeefab9b2d12015-10-14 11:33:11 -07003123 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003124 SessionDescriptionInterface* answer =
3125 CreateRemoteAnswer(session_->local_description());
3126 SetRemoteDescriptionWithoutError(answer);
3127
deadbeefcbecd352015-09-23 11:50:27 -07003128 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3129 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003130}
3131
deadbeefcbecd352015-09-23 11:50:27 -07003132// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003133TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3134 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003135 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003136
Donald Curtis0e209b02015-03-24 09:29:54 -07003137 PeerConnectionInterface::RTCOfferAnswerOptions options;
3138 options.use_rtp_mux = true;
3139
3140 SessionDescriptionInterface* offer = CreateOffer(options);
3141 SetLocalDescriptionWithoutError(offer);
3142
deadbeefcbecd352015-09-23 11:50:27 -07003143 EXPECT_NE(session_->voice_rtp_transport_channel(),
3144 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003145
deadbeefab9b2d12015-10-14 11:33:11 -07003146 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003147
3148 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003149 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003150 CreateRemoteAnswer(session_->local_description()));
3151 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3152 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3153 JsepSessionDescription* modified_answer =
3154 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3155 modified_answer->Initialize(answer_copy, "1", "1");
3156 SetRemoteDescriptionWithoutError(modified_answer); //
3157
deadbeefcbecd352015-09-23 11:50:27 -07003158 EXPECT_NE(session_->voice_rtp_transport_channel(),
3159 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003160}
3161
3162// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3163TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3164 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003165 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003166
3167 PeerConnectionInterface::RTCOfferAnswerOptions options;
3168 options.use_rtp_mux = true;
3169
3170 SessionDescriptionInterface* offer = CreateOffer(options);
3171 SetLocalDescriptionWithoutError(offer);
3172
deadbeefcbecd352015-09-23 11:50:27 -07003173 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3174 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003175
deadbeefab9b2d12015-10-14 11:33:11 -07003176 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003177 SessionDescriptionInterface* answer =
3178 CreateRemoteAnswer(session_->local_description());
3179 SetRemoteDescriptionWithoutError(answer);
3180
deadbeefcbecd352015-09-23 11:50:27 -07003181 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3182 session_->video_rtp_transport_channel());
3183}
3184
3185// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3186// audio content in the answer.
3187TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3188 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003189 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003190
3191 PeerConnectionInterface::RTCOfferAnswerOptions options;
3192 options.use_rtp_mux = true;
3193
3194 SessionDescriptionInterface* offer = CreateOffer(options);
3195 SetLocalDescriptionWithoutError(offer);
3196
3197 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3198 session_->video_rtp_transport_channel());
3199
deadbeefab9b2d12015-10-14 11:33:11 -07003200 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003201 cricket::MediaSessionOptions recv_options;
3202 recv_options.recv_audio = false;
3203 recv_options.recv_video = true;
3204 SessionDescriptionInterface* answer =
3205 CreateRemoteAnswer(session_->local_description(), recv_options);
3206 SetRemoteDescriptionWithoutError(answer);
3207
deadbeefd59daf82015-10-14 15:02:44 -07003208 EXPECT_TRUE(nullptr == session_->voice_channel());
3209 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003210
deadbeefd59daf82015-10-14 15:02:44 -07003211 session_->Close();
3212 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3213 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3214 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3215 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003216}
3217
3218// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3219TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3220 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003221 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003222
Donald Curtis0e209b02015-03-24 09:29:54 -07003223 PeerConnectionInterface::RTCOfferAnswerOptions options;
3224 options.use_rtp_mux = true;
3225
3226 SessionDescriptionInterface* offer = CreateOffer(options);
3227 SetLocalDescriptionWithoutError(offer);
3228
deadbeefcbecd352015-09-23 11:50:27 -07003229 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3230 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003231
deadbeefab9b2d12015-10-14 11:33:11 -07003232 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003233
3234 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003235 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003236 CreateRemoteAnswer(session_->local_description()));
3237 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3238 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3239 JsepSessionDescription* modified_answer =
3240 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3241 modified_answer->Initialize(answer_copy, "1", "1");
3242 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003243
deadbeefcbecd352015-09-23 11:50:27 -07003244 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3245 session_->video_rtp_transport_channel());
3246}
3247
3248// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3249TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3250 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003251 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003252
3253 SessionDescriptionInterface* offer = CreateRemoteOffer();
3254 SetRemoteDescriptionWithoutError(offer);
3255
3256 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3257 session_->video_rtp_transport_channel());
3258
deadbeefab9b2d12015-10-14 11:33:11 -07003259 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003260 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003261 SetLocalDescriptionWithoutError(answer);
3262
3263 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3264 session_->video_rtp_transport_channel());
3265}
3266
3267// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3268TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3269 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003270 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003271
3272 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003273 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003274 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3275 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3276 JsepSessionDescription* modified_offer =
3277 new JsepSessionDescription(JsepSessionDescription::kOffer);
3278 modified_offer->Initialize(offer_copy, "1", "1");
3279
3280 // Expect an error when applying the remote description
3281 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3282 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003283}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003284
Peter Thatcher4eddf182015-04-30 10:55:59 -07003285// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003286TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3287 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003288 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003289
Donald Curtis0e209b02015-03-24 09:29:54 -07003290 PeerConnectionInterface::RTCOfferAnswerOptions options;
3291 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003292
Donald Curtis0e209b02015-03-24 09:29:54 -07003293 SessionDescriptionInterface* offer = CreateOffer(options);
3294 SetLocalDescriptionWithoutError(offer);
3295
deadbeefcbecd352015-09-23 11:50:27 -07003296 EXPECT_NE(session_->voice_rtp_transport_channel(),
3297 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003298
deadbeefab9b2d12015-10-14 11:33:11 -07003299 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003300 SessionDescriptionInterface* answer =
3301 CreateRemoteAnswer(session_->local_description());
3302 SetRemoteDescriptionWithoutError(answer);
3303
3304 // This should lead to an audio-only call but isn't implemented
3305 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003306 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3307 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003308}
3309
deadbeefcbecd352015-09-23 11:50:27 -07003310// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003311TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3312 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003313 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003314 PeerConnectionInterface::RTCOfferAnswerOptions options;
3315 options.use_rtp_mux = true;
3316
3317 SessionDescriptionInterface* offer = CreateOffer(options);
3318 SetLocalDescriptionWithoutError(offer);
3319
deadbeefcbecd352015-09-23 11:50:27 -07003320 EXPECT_NE(session_->voice_rtp_transport_channel(),
3321 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003322
deadbeefab9b2d12015-10-14 11:33:11 -07003323 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003324
3325 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003326 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003327 CreateRemoteAnswer(session_->local_description()));
3328 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3329 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3330 JsepSessionDescription* modified_answer =
3331 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3332 modified_answer->Initialize(answer_copy, "1", "1");
3333 SetRemoteDescriptionWithoutError(modified_answer); //
3334
deadbeefcbecd352015-09-23 11:50:27 -07003335 EXPECT_NE(session_->voice_rtp_transport_channel(),
3336 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003337}
3338
Peter Thatcher4eddf182015-04-30 10:55:59 -07003339// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3340TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3341 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003342 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003343
3344 PeerConnectionInterface::RTCOfferAnswerOptions options;
3345 options.use_rtp_mux = true;
3346
3347 SessionDescriptionInterface* offer = CreateOffer(options);
3348 SetRemoteDescriptionWithoutError(offer);
3349
deadbeefcbecd352015-09-23 11:50:27 -07003350 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3351 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003352}
3353
skvlad6c87a672016-05-17 17:49:52 -07003354// Adding a new channel to a BUNDLE which is already connected should directly
3355// assign the bundle transport to the channel, without first setting a
3356// disconnected non-bundle transport and then replacing it. The application
3357// should not receive any changes in the ICE state.
3358TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) {
3359 LoopbackNetworkConfiguration config;
3360 LoopbackNetworkManager loopback_network_manager(this, config);
3361 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain
3362 // connected. Disabling either of these two means that we need to wait for the
3363 // answer to find out if more transports are needed.
3364 configuration_.bundle_policy =
3365 PeerConnectionInterface::kBundlePolicyMaxBundle;
skvlad6c87a672016-05-17 17:49:52 -07003366 options_.disable_encryption = true;
zhihuang4dfb8ce2016-11-23 10:30:12 -08003367 Init(PeerConnectionInterface::kRtcpMuxPolicyRequire);
skvlad6c87a672016-05-17 17:49:52 -07003368
3369 // Negotiate an audio channel with MAX_BUNDLE enabled.
3370 SendAudioOnlyStream2();
3371 SessionDescriptionInterface* offer = CreateOffer();
3372 SetLocalDescriptionWithoutError(offer);
3373 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
3374 observer_.ice_gathering_state_, kIceCandidatesTimeout);
3375 std::string sdp;
3376 offer->ToString(&sdp);
3377 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription(
3378 JsepSessionDescription::kAnswer, sdp, nullptr);
3379 ASSERT_TRUE(answer != NULL);
3380 SetRemoteDescriptionWithoutError(answer);
3381
3382 // Wait for the ICE state to stabilize.
3383 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3384 observer_.ice_connection_state_, kIceCandidatesTimeout);
3385 observer_.ice_connection_state_history_.clear();
3386
3387 // Now add a video channel which should be using the same bundle transport.
3388 SendAudioVideoStream2();
3389 offer = CreateOffer();
3390 offer->ToString(&sdp);
3391 SetLocalDescriptionWithoutError(offer);
3392 answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer,
3393 sdp, nullptr);
3394 ASSERT_TRUE(answer != NULL);
3395 SetRemoteDescriptionWithoutError(answer);
3396
3397 // Wait for ICE state to stabilize
3398 rtc::Thread::Current()->ProcessMessages(0);
3399 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3400 observer_.ice_connection_state_, kIceCandidatesTimeout);
3401
3402 // No ICE state changes are expected to happen.
3403 EXPECT_EQ(0, observer_.ice_connection_state_history_.size());
3404}
3405
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003406TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3407 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003408 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003409
3410 PeerConnectionInterface::RTCOfferAnswerOptions options;
3411 SessionDescriptionInterface* offer = CreateOffer(options);
3412 SetLocalDescriptionWithoutError(offer);
3413
deadbeefcbecd352015-09-23 11:50:27 -07003414 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3415 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003416
deadbeefab9b2d12015-10-14 11:33:11 -07003417 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003418 SessionDescriptionInterface* answer =
3419 CreateRemoteAnswer(session_->local_description());
3420 SetRemoteDescriptionWithoutError(answer);
3421
deadbeefcbecd352015-09-23 11:50:27 -07003422 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3423 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003424}
3425
3426TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3427 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003428 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003429
3430 PeerConnectionInterface::RTCOfferAnswerOptions options;
3431 SessionDescriptionInterface* offer = CreateOffer(options);
3432 SetLocalDescriptionWithoutError(offer);
3433
deadbeefcbecd352015-09-23 11:50:27 -07003434 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3435 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003436
deadbeefab9b2d12015-10-14 11:33:11 -07003437 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003438 SessionDescriptionInterface* answer =
3439 CreateRemoteAnswer(session_->local_description());
3440 SetRemoteDescriptionWithoutError(answer);
3441
deadbeefcbecd352015-09-23 11:50:27 -07003442 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3443 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003444}
3445
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003446// This test verifies that SetLocalDescription and SetRemoteDescription fails
3447// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3448TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003449 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003450 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003451
3452 PeerConnectionInterface::RTCOfferAnswerOptions options;
3453 options.use_rtp_mux = true;
3454
3455 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003456 std::string offer_str;
3457 offer->ToString(&offer_str);
3458 // Disable rtcp-mux
3459 const std::string rtcp_mux = "rtcp-mux";
3460 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003461 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003462 xrtcp_mux.c_str(), xrtcp_mux.length(),
3463 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003464 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003465 new JsepSessionDescription(JsepSessionDescription::kOffer);
3466 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003467 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003468 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003469 new JsepSessionDescription(JsepSessionDescription::kOffer);
3470 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003471 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003472 // Trying unmodified SDP.
3473 SetLocalDescriptionWithoutError(offer);
3474}
3475
jbauchcb560652016-08-04 05:20:32 -07003476TEST_F(WebRtcSessionTest, SetSetupGcm) {
3477 InitWithGcm();
3478 SendAudioVideoStream1();
3479 CreateAndSetRemoteOfferAndLocalAnswer();
3480}
3481
deadbeefd59daf82015-10-14 15:02:44 -07003482// This test verifies the |initial_offerer| flag when session initiates the
3483// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003484TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003485 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003486 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003487 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003488 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3489 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003490 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003491 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003492 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003493}
3494
deadbeefd59daf82015-10-14 15:02:44 -07003495// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003496TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003497 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003498 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003499 SessionDescriptionInterface* offer = CreateRemoteOffer();
3500 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003501 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003502
deadbeefd59daf82015-10-14 15:02:44 -07003503 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003504 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003505 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003506}
3507
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003508// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3509TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003510 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003511 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003512 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003513 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003514 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003515 CreateRemoteAnswer(session_->local_description()));
3516
3517 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3518 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003519 JsepSessionDescription* modified_answer =
3520 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003521
3522 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3523 answer->session_id(),
3524 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003525 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003526
wu@webrtc.org4e393072014-04-07 17:04:35 +00003527 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003528 std::string sdp;
3529 EXPECT_TRUE(answer->ToString(&sdp));
3530 const std::string kAudioMid = "a=mid:audio";
3531 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003532 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003533 kAudioMidReplaceStr.c_str(),
3534 kAudioMidReplaceStr.length(),
3535 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003536 SessionDescriptionInterface* modified_answer1 =
3537 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003538 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003539
wu@webrtc.org4e393072014-04-07 17:04:35 +00003540 // Different media types.
3541 EXPECT_TRUE(answer->ToString(&sdp));
3542 const std::string kAudioMline = "m=audio";
3543 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003544 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003545 kAudioMlineReplaceStr.c_str(),
3546 kAudioMlineReplaceStr.length(),
3547 &sdp);
3548 SessionDescriptionInterface* modified_answer2 =
3549 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3550 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3551
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003552 SetRemoteDescriptionWithoutError(answer.release());
3553}
3554
3555// Verifying remote offer and local answer have matching m-lines as per
3556// RFC 3264.
3557TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003558 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003559 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003560 SessionDescriptionInterface* offer = CreateRemoteOffer();
3561 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003562 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003563
3564 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3565 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003566 JsepSessionDescription* modified_answer =
3567 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003568
3569 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3570 answer->session_id(),
3571 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003572 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003573 SetLocalDescriptionWithoutError(answer);
3574}
3575
3576// This test verifies that WebRtcSession does not start candidate allocation
3577// before SetLocalDescription is called.
3578TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003579 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003580 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003581 SessionDescriptionInterface* offer = CreateRemoteOffer();
3582 cricket::Candidate candidate;
3583 candidate.set_component(1);
3584 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3585 candidate);
3586 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3587 cricket::Candidate candidate1;
3588 candidate1.set_component(1);
3589 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3590 candidate1);
3591 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3592 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003593 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3594 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003595
3596 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003597 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003598 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3599 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3600
htaa2a49d92016-03-04 02:51:39 -08003601 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003602 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003603 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3604}
3605
3606// This test verifies that crypto parameter is updated in local session
3607// description as per security policy set in MediaSessionDescriptionFactory.
3608TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003609 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003610 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003611 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003612
3613 // Making sure SetLocalDescription correctly sets crypto value in
3614 // SessionDescription object after de-serialization of sdp string. The value
3615 // will be set as per MediaSessionDescriptionFactory.
3616 std::string offer_str;
3617 offer->ToString(&offer_str);
3618 SessionDescriptionInterface* jsep_offer_str =
3619 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3620 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003621 EXPECT_TRUE(session_->voice_channel()->srtp_required_for_testing());
3622 EXPECT_TRUE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003623}
3624
3625// This test verifies the crypto parameter when security is disabled.
3626TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003627 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003628 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003629 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003630 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003631
3632 // Making sure SetLocalDescription correctly sets crypto value in
3633 // SessionDescription object after de-serialization of sdp string. The value
3634 // will be set as per MediaSessionDescriptionFactory.
3635 std::string offer_str;
3636 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003637 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003638 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3639 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003640 EXPECT_FALSE(session_->voice_channel()->srtp_required_for_testing());
3641 EXPECT_FALSE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003642}
3643
3644// This test verifies that an answer contains new ufrag and password if an offer
3645// with new ufrag and password is received.
3646TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003647 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003648 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003649 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003650 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003651 SetRemoteDescriptionWithoutError(offer.release());
3652
deadbeefab9b2d12015-10-14 11:33:11 -07003653 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003654 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003655 SetLocalDescriptionWithoutError(answer.release());
3656
3657 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003658 for (const cricket::ContentInfo& content :
3659 session_->local_description()->description()->contents()) {
3660 options.transport_options[content.name].ice_restart = true;
3661 }
kwibergd1fe2812016-04-27 06:47:29 -07003662 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003663 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003664 SetRemoteDescriptionWithoutError(updated_offer1.release());
3665
kwibergd1fe2812016-04-27 06:47:29 -07003666 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003667
deadbeef0ed85b22016-02-23 17:24:52 -08003668 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3669 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003670
deadbeef0ed85b22016-02-23 17:24:52 -08003671 // Even a second answer (created before the description is set) should have
3672 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003673 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003674
3675 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3676 session_->local_description()->description()));
3677
3678 SetLocalDescriptionWithoutError(updated_answer2.release());
3679}
3680
3681// This test verifies that an answer contains new ufrag and password if an offer
3682// that changes either the ufrag or password (but not both) is received.
3683// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3684// a=ice-pwd attributes compared to the previous SDP from the peer, it
3685// indicates that ICE is restarting for this media stream."
3686TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3687 Init();
3688 cricket::MediaSessionOptions options;
3689 options.recv_audio = true;
3690 options.recv_video = true;
3691 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003692 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003693 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3694 SetRemoteDescriptionWithoutError(offer.release());
3695
3696 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003697 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003698 SetLocalDescriptionWithoutError(answer.release());
3699
3700 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003701 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003702 CreateRemoteOffer(options, session_->remote_description()));
3703 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3704 "original_password12345");
3705 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3706
kwibergd1fe2812016-04-27 06:47:29 -07003707 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003708 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3709 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003710 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003711
3712 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003713 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003714 CreateRemoteOffer(options, session_->remote_description()));
3715 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3716 "modified_password12345");
3717 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3718
kwibergd1fe2812016-04-27 06:47:29 -07003719 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003720 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3721 session_->local_description()->description()));
3722 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003723}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003724
wu@webrtc.org91053e72013-08-10 07:18:04 +00003725// This test verifies that an answer contains old ufrag and password if an offer
3726// with old ufrag and password is received.
3727TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003728 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003729 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003730 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003731 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003732 SetRemoteDescriptionWithoutError(offer.release());
3733
deadbeefab9b2d12015-10-14 11:33:11 -07003734 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003735 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003736 SetLocalDescriptionWithoutError(answer.release());
3737
3738 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003739 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003740 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003741 SetRemoteDescriptionWithoutError(updated_offer2.release());
3742
kwibergd1fe2812016-04-27 06:47:29 -07003743 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003744
deadbeef0ed85b22016-02-23 17:24:52 -08003745 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3746 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003747
3748 SetLocalDescriptionWithoutError(updated_answer2.release());
3749}
3750
deadbeef0ed85b22016-02-23 17:24:52 -08003751// This test verifies that if an offer does an ICE restart on some, but not all
3752// media sections, the answer will change the ufrag/password in the correct
3753// media sections.
3754TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3755 Init();
3756 cricket::MediaSessionOptions options;
3757 options.recv_video = true;
3758 options.recv_audio = true;
3759 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003760 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003761
3762 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3763 "aaaaaaaaaaaaaaaaaaaaaa");
3764 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3765 "bbbbbbbbbbbbbbbbbbbbbb");
3766 SetRemoteDescriptionWithoutError(offer.release());
3767
3768 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003769 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003770 SetLocalDescriptionWithoutError(answer.release());
3771
3772 // Receive an offer with new ufrag and password, but only for the video media
3773 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003774 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003775 CreateRemoteOffer(options, session_->remote_description()));
3776 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3777 "cccccccccccccccccccccc");
3778 SetRemoteDescriptionWithoutError(updated_offer.release());
3779
kwibergd1fe2812016-04-27 06:47:29 -07003780 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003781
3782 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3783 session_->local_description()->description(),
3784 cricket::MEDIA_TYPE_AUDIO));
3785
3786 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3787 session_->local_description()->description(),
3788 cricket::MEDIA_TYPE_VIDEO));
3789
3790 SetLocalDescriptionWithoutError(updated_answer.release());
3791}
3792
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003793TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003794 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003795 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003796 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003797 const std::string session_id_orig = offer->session_id();
3798 const std::string session_version_orig = offer->session_version();
3799 SetLocalDescriptionWithoutError(offer);
3800
3801 video_channel_ = media_engine_->GetVideoChannel(0);
3802 video_channel_->set_fail_set_send_codecs(true);
3803
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003804 SessionDescriptionInterface* answer =
3805 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003806 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003807
3808 // Test that after a content error, setting any description will
3809 // result in an error.
3810 video_channel_->set_fail_set_send_codecs(false);
3811 answer = CreateRemoteAnswer(session_->local_description());
3812 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3813 offer = CreateRemoteOffer();
3814 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003815}
3816
3817// Runs the loopback call test with BUNDLE and STUN disabled.
3818TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3819 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003820 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003821 cricket::PORTALLOCATOR_DISABLE_STUN |
3822 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003823 TestLoopbackCall();
3824}
3825
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003826TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
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_ENABLE_IPV6 |
3830 cricket::PORTALLOCATOR_DISABLE_RELAY);
3831
3832 // best connection is IPv6 since it has higher network preference.
3833 LoopbackNetworkConfiguration config;
3834 config.test_ipv6_network_ = true;
3835 config.best_connection_after_initial_ice_converged_ =
3836 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3837
3838 TestLoopbackCall(config);
3839}
3840
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003841// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003842TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003843 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3844 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003845 TestLoopbackCall();
3846}
3847
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003848TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003849 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003850 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003851 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003852 ASSERT_TRUE(data_engine_);
deadbeef953c2ce2017-01-09 14:53:41 -08003853 EXPECT_NE(nullptr, data_engine_->GetChannel(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003854}
3855
Henrik Boström87713d02015-08-25 09:53:21 +02003856TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
htaa2a49d92016-03-04 02:51:39 -08003857 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003858 options_.disable_sctp_data_channels = false;
3859
Henrik Boström87713d02015-08-25 09:53:21 +02003860 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003861
3862 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003863 EXPECT_NE(nullptr, data_engine_->GetChannel(0));
3864}
3865
3866// Test that sctp_content_name/sctp_transport_name (used for stats) are correct
3867// before and after BUNDLE is negotiated.
3868TEST_P(WebRtcSessionTest, SctpContentAndTransportName) {
deadbeef953c2ce2017-01-09 14:53:41 -08003869 SetFactoryDtlsSrtp();
3870 InitWithDtls(GetParam());
3871
3872 // Initially these fields should be empty.
3873 EXPECT_FALSE(session_->sctp_content_name());
3874 EXPECT_FALSE(session_->sctp_transport_name());
3875
3876 // Create offer with audio/video/data.
3877 // Default bundle policy is "balanced", so data should be using its own
3878 // transport.
3879 SendAudioVideoStream1();
3880 CreateDataChannel();
3881 InitiateCall();
3882 ASSERT_TRUE(session_->sctp_content_name());
3883 ASSERT_TRUE(session_->sctp_transport_name());
3884 EXPECT_EQ("data", *session_->sctp_content_name());
3885 EXPECT_EQ("data", *session_->sctp_transport_name());
3886
3887 // Create answer that finishes BUNDLE negotiation, which means everything
3888 // should be bundled on the first transport (audio).
3889 cricket::MediaSessionOptions answer_options;
3890 answer_options.recv_video = true;
3891 answer_options.bundle_enabled = true;
3892 answer_options.data_channel_type = cricket::DCT_SCTP;
3893 SetRemoteDescriptionWithoutError(CreateRemoteAnswer(
3894 session_->local_description(), answer_options, cricket::SEC_DISABLED));
3895 ASSERT_TRUE(session_->sctp_content_name());
3896 ASSERT_TRUE(session_->sctp_transport_name());
3897 EXPECT_EQ("data", *session_->sctp_content_name());
3898 EXPECT_EQ("audio", *session_->sctp_transport_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003899}
3900
Henrik Boström87713d02015-08-25 09:53:21 +02003901TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
Henrik Boström87713d02015-08-25 09:53:21 +02003902 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003903
kwibergd1fe2812016-04-27 06:47:29 -07003904 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003905 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003906 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3907}
3908
Henrik Boström87713d02015-08-25 09:53:21 +02003909TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003910 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003911 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003912
3913 // Create remote offer with SCTP.
3914 cricket::MediaSessionOptions options;
3915 options.data_channel_type = cricket::DCT_SCTP;
3916 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003917 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003918 SetRemoteDescriptionWithoutError(offer);
3919
3920 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07003921 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003922 EXPECT_TRUE(answer != NULL);
3923 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3924 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003925}
3926
deadbeef953c2ce2017-01-09 14:53:41 -08003927// Test that if DTLS is disabled, we don't end up with an SctpTransport
3928// created (or an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02003929TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003930 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003931 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003932
3933 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003934 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
3935 EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003936}
3937
deadbeef953c2ce2017-01-09 14:53:41 -08003938// Test that if DTLS is enabled, we end up with an SctpTransport created
3939// (and not an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02003940TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
Henrik Boström87713d02015-08-25 09:53:21 +02003941 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003942
3943 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003944 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
3945 EXPECT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003946}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003947
deadbeef953c2ce2017-01-09 14:53:41 -08003948// Test that if SCTP is disabled, we don't end up with an SctpTransport
3949// created (or an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02003950TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003951 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003952 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003953
3954 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003955 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
3956 EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003957}
3958
Henrik Boström87713d02015-08-25 09:53:21 +02003959TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003960 const int new_send_port = 9998;
3961 const int new_recv_port = 7775;
3962
Henrik Boström87713d02015-08-25 09:53:21 +02003963 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003964 SetFactoryDtlsSrtp();
3965
3966 // By default, don't actually add the codecs to desc_factory_; they don't
3967 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3968 // let the session description get parsed. That'll get the proper codecs
3969 // into the stream.
3970 cricket::MediaSessionOptions options;
3971 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3972 "stream1", new_send_port, options);
3973
3974 // SetRemoteDescription will take the ownership of the offer.
3975 SetRemoteDescriptionWithoutError(offer);
3976
htaa2a49d92016-03-04 02:51:39 -08003977 SessionDescriptionInterface* answer =
3978 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003979 ASSERT_TRUE(answer != NULL);
3980
3981 // Now set the local description, which'll take ownership of the answer.
3982 SetLocalDescriptionWithoutError(answer);
3983
3984 // TEST PLAN: Set the port number to something new, set it in the SDP,
3985 // and pass it all the way down.
deadbeef953c2ce2017-01-09 14:53:41 -08003986 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
deadbeefab9b2d12015-10-14 11:33:11 -07003987 CreateDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003988 ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
3989 EXPECT_EQ(
3990 new_recv_port,
3991 fake_sctp_transport_factory_->last_fake_sctp_transport()->local_port());
3992 EXPECT_EQ(
3993 new_send_port,
3994 fake_sctp_transport_factory_->last_fake_sctp_transport()->remote_port());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003995}
3996
deadbeef953c2ce2017-01-09 14:53:41 -08003997// Verifies that when a session's SctpTransport receives an OPEN message,
3998// WebRtcSession signals the SctpTransport creation request with the expected
deadbeefab9b2d12015-10-14 11:33:11 -07003999// config.
4000TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
deadbeefab9b2d12015-10-14 11:33:11 -07004001 InitWithDtls(GetParam());
4002
4003 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004004 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4005 ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
deadbeefab9b2d12015-10-14 11:33:11 -07004006
deadbeef953c2ce2017-01-09 14:53:41 -08004007 // Make the fake SCTP transport pretend it received an OPEN message.
deadbeefab9b2d12015-10-14 11:33:11 -07004008 webrtc::DataChannelInit config;
4009 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07004010 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07004011 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4012 cricket::ReceiveDataParams params;
4013 params.ssrc = config.id;
4014 params.type = cricket::DMT_CONTROL;
deadbeef953c2ce2017-01-09 14:53:41 -08004015 fake_sctp_transport_factory_->last_fake_sctp_transport()->SignalDataReceived(
4016 params, payload);
deadbeefab9b2d12015-10-14 11:33:11 -07004017
deadbeef953c2ce2017-01-09 14:53:41 -08004018 EXPECT_EQ_WAIT("a", last_data_channel_label_, kDefaultTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07004019 EXPECT_EQ(config.id, last_data_channel_config_.id);
4020 EXPECT_FALSE(last_data_channel_config_.negotiated);
4021 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4022 last_data_channel_config_.open_handshake_role);
4023}
4024
4025TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004026 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
Henrik Boströmd79599d2016-06-01 13:58:50 +02004027 FakeRTCCertificateGenerator::GenerateCertificate();
Henrik Boströmd8281982015-08-27 10:12:24 +02004028
htaa2a49d92016-03-04 02:51:39 -08004029 configuration_.certificates.push_back(certificate);
4030 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004031 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4032
4033 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4034}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004035
Henrik Boström87713d02015-08-25 09:53:21 +02004036// Verifies that CreateOffer succeeds when CreateOffer is called before async
4037// identity generation is finished (even if a certificate is provided this is
4038// an async op).
4039TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004040 InitWithDtls(GetParam());
4041
Henrik Boströmd8281982015-08-27 10:12:24 +02004042 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004043 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07004044 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004045
wu@webrtc.org91053e72013-08-10 07:18:04 +00004046 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004047 VerifyNoCryptoParams(offer->description(), true);
4048 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004049}
4050
4051// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004052// identity generation is finished (even if a certificate is provided this is
4053// an async op).
4054TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004055 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004056 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004057
4058 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004059 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07004060 std::unique_ptr<JsepSessionDescription> offer(
4061 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004062 ASSERT_TRUE(offer.get() != NULL);
4063 SetRemoteDescriptionWithoutError(offer.release());
4064
kwibergd1fe2812016-04-27 06:47:29 -07004065 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004066 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004067 VerifyNoCryptoParams(answer->description(), true);
4068 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004069}
4070
4071// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004072// identity generation is finished (even if a certificate is provided this is
4073// an async op).
4074TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004075 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004076
Henrik Boströmd8281982015-08-27 10:12:24 +02004077 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004078
kwibergd1fe2812016-04-27 06:47:29 -07004079 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004080 EXPECT_TRUE(offer != NULL);
4081}
4082
4083// Verifies that CreateOffer fails when CreateOffer is called after async
4084// identity generation fails.
4085TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004086 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004087
Henrik Boströmd8281982015-08-27 10:12:24 +02004088 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004089
kwibergd1fe2812016-04-27 06:47:29 -07004090 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004091 EXPECT_TRUE(offer == NULL);
4092}
4093
4094// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4095// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004096TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004097 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
deadbeefcbecd352015-09-23 11:50:27 -07004098 VerifyMultipleAsyncCreateDescription(GetParam(),
4099 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004100}
4101
4102// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4103// before async identity generation fails.
4104TEST_F(WebRtcSessionTest,
4105 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004106 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4107 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004108}
4109
4110// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4111// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004112TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004113 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00004114 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004115 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004116}
4117
4118// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4119// before async identity generation fails.
4120TEST_F(WebRtcSessionTest,
4121 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004122 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4123 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004124}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004125
4126// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4127// offer has no SDES crypto but only DTLS fingerprint.
4128TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4129 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004130 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004131 // Create a remote offer with secured transport disabled.
4132 cricket::MediaSessionOptions options;
4133 JsepSessionDescription* offer(CreateRemoteOffer(
4134 options, cricket::SEC_DISABLED));
4135 // Adds a DTLS fingerprint to the remote offer.
4136 cricket::SessionDescription* sdp = offer->description();
4137 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4138 ASSERT_TRUE(audio != NULL);
4139 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4140 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004141 rtc::SSLFingerprint::CreateFromRfc4572(
4142 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004143 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004144 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004145}
4146
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004147TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004148 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004149 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004150 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004151 SessionDescriptionInterface* offer = CreateOffer();
4152
4153 SetLocalDescriptionWithoutError(offer);
4154
4155 voice_channel_ = media_engine_->GetVoiceChannel(0);
4156
4157 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004158 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004159 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004160}
4161
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004162// Tests that we can renegotiate new media content with ICE candidates in the
4163// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004164TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
Henrik Boström87713d02015-08-25 09:53:21 +02004165 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004166 SetFactoryDtlsSrtp();
4167
deadbeefab9b2d12015-10-14 11:33:11 -07004168 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004169 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004170 SetLocalDescriptionWithoutError(offer);
4171
4172 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4173 SetRemoteDescriptionWithoutError(answer);
4174
4175 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004176 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004177 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4178
4179 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004180 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004181 candidate1.set_component(1);
4182 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4183 candidate1);
4184 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4185 SetRemoteDescriptionWithoutError(offer);
4186
htaa2a49d92016-03-04 02:51:39 -08004187 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004188 SetLocalDescriptionWithoutError(answer);
4189}
4190
4191// Tests that we can renegotiate new media content with ICE candidates separated
4192// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004193TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
Henrik Boström87713d02015-08-25 09:53:21 +02004194 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004195 SetFactoryDtlsSrtp();
4196
deadbeefab9b2d12015-10-14 11:33:11 -07004197 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004198 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004199 SetLocalDescriptionWithoutError(offer);
4200
4201 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4202 SetRemoteDescriptionWithoutError(answer);
4203
4204 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004205 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004206 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4207 SetRemoteDescriptionWithoutError(offer);
4208
4209 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004210 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004211 candidate1.set_component(1);
4212 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4213 candidate1);
4214 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4215
htaa2a49d92016-03-04 02:51:39 -08004216 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004217 SetLocalDescriptionWithoutError(answer);
4218}
honghaiz7f777492016-02-02 21:54:01 -08004219
zhihuang9763d562016-08-05 11:14:50 -07004220#ifdef HAVE_QUIC
4221TEST_P(WebRtcSessionTest, TestNegotiateQuic) {
4222 configuration_.enable_quic = true;
4223 InitWithDtls(GetParam());
4224 EXPECT_TRUE(session_->data_channel_type() == cricket::DCT_QUIC);
4225 SessionDescriptionInterface* offer = CreateOffer();
4226 ASSERT_TRUE(offer);
4227 ASSERT_TRUE(offer->description());
4228 SetLocalDescriptionWithoutError(offer);
4229 cricket::MediaSessionOptions options;
4230 options.recv_audio = true;
4231 options.recv_video = true;
4232 SessionDescriptionInterface* answer =
4233 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
4234 ASSERT_TRUE(answer);
4235 ASSERT_TRUE(answer->description());
4236 SetRemoteDescriptionWithoutError(answer);
4237}
4238#endif // HAVE_QUIC
4239
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004240// Tests that RTX codec is removed from the answer when it isn't supported
4241// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004242TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004243 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004244 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004245 std::string offer_sdp(kSdpWithRtx);
4246
4247 SessionDescriptionInterface* offer =
4248 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4249 EXPECT_TRUE(offer->ToString(&offer_sdp));
4250
4251 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004252 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004253 SetRemoteDescriptionWithoutError(offer);
4254
htaa2a49d92016-03-04 02:51:39 -08004255 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004256 // Answer SDP does not contain the RTX codec.
4257 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004258 SetLocalDescriptionWithoutError(answer);
4259}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004260
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004261// This verifies that the voice channel after bundle has both options from video
4262// and voice channels.
4263TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4264 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004265 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004266
4267 PeerConnectionInterface::RTCOfferAnswerOptions options;
4268 options.use_rtp_mux = true;
4269
4270 SessionDescriptionInterface* offer = CreateOffer(options);
4271 SetLocalDescriptionWithoutError(offer);
4272
4273 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4274 rtc::Socket::Option::OPT_SNDBUF, 4000);
4275
4276 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4277 rtc::Socket::Option::OPT_RCVBUF, 8000);
4278
4279 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004280 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004281 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4282 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004283 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004284 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4285
deadbeefcbecd352015-09-23 11:50:27 -07004286 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004287 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4288 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004289 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004290 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4291
deadbeefcbecd352015-09-23 11:50:27 -07004292 EXPECT_NE(session_->voice_rtp_transport_channel(),
4293 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004294
deadbeefab9b2d12015-10-14 11:33:11 -07004295 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004296 SessionDescriptionInterface* answer =
4297 CreateRemoteAnswer(session_->local_description());
4298 SetRemoteDescriptionWithoutError(answer);
4299
deadbeefcbecd352015-09-23 11:50:27 -07004300 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004301 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4302 EXPECT_EQ(4000, option_val);
4303
deadbeefcbecd352015-09-23 11:50:27 -07004304 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004305 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4306 EXPECT_EQ(8000, option_val);
4307}
4308
tommi0f620f42015-07-09 03:25:02 -07004309// Test creating a session, request multiple offers, destroy the session
4310// and make sure we got success/failure callbacks for all of the requests.
4311// Background: crbug.com/507307
4312TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4313 Init();
4314
4315 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4316 PeerConnectionInterface::RTCOfferAnswerOptions options;
4317 options.offer_to_receive_audio =
4318 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004319 cricket::MediaSessionOptions session_options;
4320 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004321
4322 for (auto& o : observers) {
4323 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004324 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004325 }
4326
4327 session_.reset();
4328
tommi0f620f42015-07-09 03:25:02 -07004329 for (auto& o : observers) {
4330 // We expect to have received a notification now even if the session was
4331 // terminated. The offer creation may or may not have succeeded, but we
4332 // must have received a notification which, so the only invalid state
4333 // is kInit.
4334 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4335 }
4336}
4337
stefanc1aeaf02015-10-15 07:26:07 -07004338TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4339 TestPacketOptions();
4340}
4341
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004342// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4343// currently fails because upon disconnection and reconnection OnIceComplete is
4344// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004345
deadbeefcbecd352015-09-23 11:50:27 -07004346INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4347 WebRtcSessionTest,
4348 testing::Values(ALREADY_GENERATED,
4349 DTLS_IDENTITY_STORE));