blob: c8ae058bac8c4a2724a02f277390ee132af12258 [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/audiotrack.h"
16#include "webrtc/api/fakemediacontroller.h"
17#include "webrtc/api/fakemetricsobserver.h"
18#include "webrtc/api/jsepicecandidate.h"
19#include "webrtc/api/jsepsessiondescription.h"
20#include "webrtc/api/peerconnection.h"
21#include "webrtc/api/sctputils.h"
Henrik Boströmd79599d2016-06-01 13:58:50 +020022#include "webrtc/api/test/fakertccertificategenerator.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010023#include "webrtc/api/videotrack.h"
24#include "webrtc/api/webrtcsession.h"
25#include "webrtc/api/webrtcsessiondescriptionfactory.h"
nissec80e7412017-01-11 05:56:46 -080026#include "webrtc/base/checks.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000027#include "webrtc/base/fakenetwork.h"
28#include "webrtc/base/firewallsocketserver.h"
29#include "webrtc/base/gunit.h"
30#include "webrtc/base/logging.h"
31#include "webrtc/base/network.h"
32#include "webrtc/base/physicalsocketserver.h"
33#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020034#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000035#include "webrtc/base/sslstreamadapter.h"
36#include "webrtc/base/stringutils.h"
37#include "webrtc/base/thread.h"
38#include "webrtc/base/virtualsocketserver.h"
skvlad11a9cbf2016-10-07 11:53:05 -070039#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
kjellandera96e2d72016-02-04 23:52:28 -080040#include "webrtc/media/base/fakemediaengine.h"
41#include "webrtc/media/base/fakevideorenderer.h"
42#include "webrtc/media/base/mediachannel.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010043#include "webrtc/media/engine/fakewebrtccall.h"
deadbeef953c2ce2017-01-09 14:53:41 -080044#include "webrtc/media/sctp/sctptransportinternal.h"
johan669d69b2016-11-08 14:14:08 -080045#include "webrtc/p2p/base/packettransportinterface.h"
kjellandera96e2d72016-02-04 23:52:28 -080046#include "webrtc/p2p/base/stunserver.h"
47#include "webrtc/p2p/base/teststunserver.h"
48#include "webrtc/p2p/base/testturnserver.h"
kjellandera96e2d72016-02-04 23:52:28 -080049#include "webrtc/p2p/client/basicportallocator.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010050#include "webrtc/pc/channelmanager.h"
51#include "webrtc/pc/mediasession.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);
deadbeef057ecf02016-01-20 14:30:43 -0800437 session_->GetOnDestroyedSignal()->connect(
438 this, &WebRtcSessionTest::OnSessionDestroyed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000439
zhihuang4dfb8ce2016-11-23 10:30:12 -0800440 configuration_.rtcp_mux_policy = rtcp_mux_policy;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000441 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
442 observer_.ice_connection_state_);
443 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
444 observer_.ice_gathering_state_);
445
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200446 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator),
htaa2a49d92016-03-04 02:51:39 -0800447 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700448 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000449 }
450
deadbeefab9b2d12015-10-14 11:33:11 -0700451 void OnDataChannelOpenMessage(const std::string& label,
452 const InternalDataChannelInit& config) {
453 last_data_channel_label_ = label;
454 last_data_channel_config_ = config;
455 }
456
deadbeef057ecf02016-01-20 14:30:43 -0800457 void OnSessionDestroyed() { session_destroyed_ = true; }
458
zhihuang4dfb8ce2016-11-23 10:30:12 -0800459 void Init() {
460 Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
461 }
462
463 void Init(PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
464 Init(nullptr, rtcp_mux_policy);
465 }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000466
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000467 void InitWithBundlePolicy(
468 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800469 configuration_.bundle_policy = bundle_policy;
470 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700471 }
472
473 void InitWithRtcpMuxPolicy(
474 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
475 PeerConnectionInterface::RTCConfiguration configuration;
zhihuang4dfb8ce2016-11-23 10:30:12 -0800476 Init(rtcp_mux_policy);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000477 }
478
Henrik Boström87713d02015-08-25 09:53:21 +0200479 // Successfully init with DTLS; with a certificate generated and supplied or
480 // with a store that generates it for us.
481 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200482 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator;
Henrik Boström87713d02015-08-25 09:53:21 +0200483 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800484 configuration_.certificates.push_back(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200485 FakeRTCCertificateGenerator::GenerateCertificate());
Henrik Boström87713d02015-08-25 09:53:21 +0200486 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200487 cert_generator.reset(new FakeRTCCertificateGenerator());
488 cert_generator->set_should_fail(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200489 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700490 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200491 }
zhihuang4dfb8ce2016-11-23 10:30:12 -0800492 Init(std::move(cert_generator),
493 PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
Henrik Boström87713d02015-08-25 09:53:21 +0200494 }
495
496 // Init with DTLS with a store that will fail to generate a certificate.
497 void InitWithDtlsIdentityGenFail() {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200498 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
499 new FakeRTCCertificateGenerator());
500 cert_generator->set_should_fail(true);
zhihuang4dfb8ce2016-11-23 10:30:12 -0800501 Init(std::move(cert_generator),
502 PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000503 }
504
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000505 void InitWithDtmfCodec() {
506 // Add kTelephoneEventCodec for dtmf test.
deadbeef67cf2c12016-04-13 10:07:16 -0700507 const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000,
508 0, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000509 std::vector<cricket::AudioCodec> codecs;
510 codecs.push_back(kTelephoneEventCodec);
511 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -0700512 desc_factory_->set_audio_codecs(codecs, codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000513 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000514 }
515
jbauchcb560652016-08-04 05:20:32 -0700516 void InitWithGcm() {
517 rtc::CryptoOptions crypto_options;
518 crypto_options.enable_gcm_crypto_suites = true;
519 channel_manager_->SetCryptoOptions(crypto_options);
520 with_gcm_ = true;
521 Init();
522 }
523
deadbeefab9b2d12015-10-14 11:33:11 -0700524 void SendAudioVideoStream1() {
525 send_stream_1_ = true;
526 send_stream_2_ = false;
527 send_audio_ = true;
528 send_video_ = true;
529 }
530
531 void SendAudioVideoStream2() {
532 send_stream_1_ = false;
533 send_stream_2_ = true;
534 send_audio_ = true;
535 send_video_ = true;
536 }
537
538 void SendAudioVideoStream1And2() {
539 send_stream_1_ = true;
540 send_stream_2_ = true;
541 send_audio_ = true;
542 send_video_ = true;
543 }
544
545 void SendNothing() {
546 send_stream_1_ = false;
547 send_stream_2_ = false;
548 send_audio_ = false;
549 send_video_ = false;
550 }
551
552 void SendAudioOnlyStream2() {
553 send_stream_1_ = false;
554 send_stream_2_ = true;
555 send_audio_ = true;
556 send_video_ = false;
557 }
558
559 void SendVideoOnlyStream2() {
560 send_stream_1_ = false;
561 send_stream_2_ = true;
562 send_audio_ = false;
563 send_video_ = true;
564 }
565
566 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
567 if (send_stream_1_ && send_audio_) {
568 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
569 kStream1);
570 }
571 if (send_stream_1_ && send_video_) {
572 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
573 kStream1);
574 }
575 if (send_stream_2_ && send_audio_) {
576 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
577 kStream2);
578 }
579 if (send_stream_2_ && send_video_) {
580 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
581 kStream2);
582 }
583 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
584 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
585 data_channel_->label(),
586 data_channel_->label());
587 }
588 }
589
590 void GetOptionsForOffer(
591 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
592 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800593 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700594
deadbeefc80741f2015-10-22 13:14:45 -0700595 AddStreamsToOptions(session_options);
596 if (rtc_options.offer_to_receive_audio ==
597 RTCOfferAnswerOptions::kUndefined) {
598 session_options->recv_audio =
599 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
600 }
601 if (rtc_options.offer_to_receive_video ==
602 RTCOfferAnswerOptions::kUndefined) {
603 session_options->recv_video =
604 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
605 }
606 session_options->bundle_enabled =
607 session_options->bundle_enabled &&
608 (session_options->has_audio() || session_options->has_video() ||
609 session_options->has_data());
610
deadbeefab9b2d12015-10-14 11:33:11 -0700611 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
612 session_options->data_channel_type = cricket::DCT_SCTP;
zhihuang9763d562016-08-05 11:14:50 -0700613 } else if (session_->data_channel_type() == cricket::DCT_QUIC) {
614 session_options->data_channel_type = cricket::DCT_QUIC;
deadbeefab9b2d12015-10-14 11:33:11 -0700615 }
jbauchcb560652016-08-04 05:20:32 -0700616
617 if (with_gcm_) {
618 session_options->crypto_options.enable_gcm_crypto_suites = true;
619 }
deadbeefab9b2d12015-10-14 11:33:11 -0700620 }
621
htaa2a49d92016-03-04 02:51:39 -0800622 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
623 // ParseConstraintsForAnswer is used to set some defaults.
624 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700625
deadbeefc80741f2015-10-22 13:14:45 -0700626 AddStreamsToOptions(session_options);
627 session_options->bundle_enabled =
628 session_options->bundle_enabled &&
629 (session_options->has_audio() || session_options->has_video() ||
630 session_options->has_data());
631
zhihuang9763d562016-08-05 11:14:50 -0700632 if (session_->data_channel_type() != cricket::DCT_RTP) {
633 session_options->data_channel_type = session_->data_channel_type();
deadbeef907abe42016-08-04 12:22:18 -0700634 }
jbauchcb560652016-08-04 05:20:32 -0700635
636 if (with_gcm_) {
637 session_options->crypto_options.enable_gcm_crypto_suites = true;
638 }
deadbeefab9b2d12015-10-14 11:33:11 -0700639 }
640
641 // Creates a local offer and applies it. Starts ICE.
642 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000643 // to decide which streams to create.
644 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000645 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000646 SetLocalDescriptionWithoutError(offer);
647 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
648 observer_.ice_gathering_state_,
649 kIceCandidatesTimeout);
650 }
651
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000652 SessionDescriptionInterface* CreateOffer() {
653 PeerConnectionInterface::RTCOfferAnswerOptions options;
654 options.offer_to_receive_audio =
655 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
656
657 return CreateOffer(options);
658 }
659
wu@webrtc.org91053e72013-08-10 07:18:04 +0000660 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800661 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000662 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000663 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700664 cricket::MediaSessionOptions session_options;
665 GetOptionsForOffer(options, &session_options);
666 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000667 EXPECT_TRUE_WAIT(
668 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000669 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000670 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000671 }
672
673 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800674 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000675 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000676 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800677 cricket::MediaSessionOptions session_options = options;
678 GetOptionsForAnswer(&session_options);
679 // Overwrite recv_audio and recv_video with passed-in values.
680 session_options.recv_video = options.recv_video;
681 session_options.recv_audio = options.recv_audio;
682 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000683 EXPECT_TRUE_WAIT(
684 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000685 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000686 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000687 }
688
htaa2a49d92016-03-04 02:51:39 -0800689 SessionDescriptionInterface* CreateAnswer() {
690 cricket::MediaSessionOptions options;
691 options.recv_video = true;
692 options.recv_audio = true;
693 return CreateAnswer(options);
694 }
695
wu@webrtc.org364f2042013-11-20 21:49:41 +0000696 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000697 return (session_->voice_channel() != NULL &&
698 session_->video_channel() != NULL);
699 }
700
jbauchcb560652016-08-04 05:20:32 -0700701 void VerifyCryptoParams(const cricket::SessionDescription* sdp,
702 bool gcm_enabled = false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000703 ASSERT_TRUE(session_.get() != NULL);
704 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
705 ASSERT_TRUE(content != NULL);
706 const cricket::AudioContentDescription* audio_content =
707 static_cast<const cricket::AudioContentDescription*>(
708 content->description);
709 ASSERT_TRUE(audio_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700710 if (!gcm_enabled) {
711 ASSERT_EQ(1U, audio_content->cryptos().size());
712 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
713 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
714 audio_content->cryptos()[0].cipher_suite);
715 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
716 audio_content->protocol());
717 } else {
718 // The offer contains 3 possible crypto suites, the answer 1.
719 EXPECT_LE(1U, audio_content->cryptos().size());
720 EXPECT_NE(2U, audio_content->cryptos().size());
721 EXPECT_GE(3U, audio_content->cryptos().size());
722 ASSERT_EQ(67U, audio_content->cryptos()[0].key_params.size());
723 ASSERT_EQ("AEAD_AES_256_GCM",
724 audio_content->cryptos()[0].cipher_suite);
725 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
726 audio_content->protocol());
727 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000728
729 content = cricket::GetFirstVideoContent(sdp);
730 ASSERT_TRUE(content != NULL);
731 const cricket::VideoContentDescription* video_content =
732 static_cast<const cricket::VideoContentDescription*>(
733 content->description);
734 ASSERT_TRUE(video_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700735 if (!gcm_enabled) {
736 ASSERT_EQ(1U, video_content->cryptos().size());
737 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
738 video_content->cryptos()[0].cipher_suite);
739 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
740 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
741 video_content->protocol());
742 } else {
743 // The offer contains 3 possible crypto suites, the answer 1.
744 EXPECT_LE(1U, video_content->cryptos().size());
745 EXPECT_NE(2U, video_content->cryptos().size());
746 EXPECT_GE(3U, video_content->cryptos().size());
747 ASSERT_EQ("AEAD_AES_256_GCM",
748 video_content->cryptos()[0].cipher_suite);
749 ASSERT_EQ(67U, video_content->cryptos()[0].key_params.size());
750 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
751 video_content->protocol());
752 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000753 }
754
755 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
756 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
757 ASSERT_TRUE(content != NULL);
758 const cricket::AudioContentDescription* audio_content =
759 static_cast<const cricket::AudioContentDescription*>(
760 content->description);
761 ASSERT_TRUE(audio_content != NULL);
762 ASSERT_EQ(0U, audio_content->cryptos().size());
763
764 content = cricket::GetFirstVideoContent(sdp);
765 ASSERT_TRUE(content != NULL);
766 const cricket::VideoContentDescription* video_content =
767 static_cast<const cricket::VideoContentDescription*>(
768 content->description);
769 ASSERT_TRUE(video_content != NULL);
770 ASSERT_EQ(0U, video_content->cryptos().size());
771
772 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700773 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000774 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700775 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000776 video_content->protocol());
777 } else {
778 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
779 audio_content->protocol());
780 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
781 video_content->protocol());
782 }
783 }
784
785 // Set the internal fake description factories to do DTLS-SRTP.
786 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000787 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000789 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200790 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800791 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700792 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800793 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
795 }
796
797 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
798 bool expected) {
799 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
800 ASSERT_TRUE(audio != NULL);
801 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802 const TransportInfo* video = sdp->GetTransportInfoByName("video");
803 ASSERT_TRUE(video != NULL);
804 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000805 }
806
807 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000808 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000809 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000810 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000811 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000812 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000813 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000814 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000815 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
816 offer);
htaa2a49d92016-03-04 02:51:39 -0800817 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818 // Answer should be NULL as no crypto params in offer.
819 ASSERT_TRUE(answer == NULL);
820 }
821
822 void VerifyAnswerFromCryptoOffer() {
823 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000824 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825 options.bundle_enabled = true;
kwibergd1fe2812016-04-27 06:47:29 -0700826 std::unique_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000827 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
828 ASSERT_TRUE(offer.get() != NULL);
829 VerifyCryptoParams(offer->description());
830 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -0700831 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 ASSERT_TRUE(answer.get() != NULL);
833 VerifyCryptoParams(answer->description());
834 }
835
deadbeef0ed85b22016-02-23 17:24:52 -0800836 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
837 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800839 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 }
841
842 const cricket::ContentInfos& contents = desc1->contents();
843 cricket::ContentInfos::const_iterator it = contents.begin();
844
845 for (; it != contents.end(); ++it) {
846 const cricket::TransportDescription* transport_desc1 =
847 desc1->GetTransportDescriptionByName(it->name);
848 const cricket::TransportDescription* transport_desc2 =
849 desc2->GetTransportDescriptionByName(it->name);
850 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800851 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000852 }
853 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
854 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800855 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000856 }
857 }
deadbeef0ed85b22016-02-23 17:24:52 -0800858 return true;
859 }
860
861 // Compares ufrag/password only for the specified |media_type|.
862 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
863 const cricket::SessionDescription* desc2,
864 cricket::MediaType media_type) {
865 if (desc1->contents().size() != desc2->contents().size()) {
866 return false;
867 }
868
869 const cricket::ContentInfo* cinfo =
870 cricket::GetFirstMediaContent(desc1->contents(), media_type);
871 const cricket::TransportDescription* transport_desc1 =
872 desc1->GetTransportDescriptionByName(cinfo->name);
873 const cricket::TransportDescription* transport_desc2 =
874 desc2->GetTransportDescriptionByName(cinfo->name);
875 if (!transport_desc1 || !transport_desc2) {
876 return false;
877 }
878 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
879 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
880 return false;
881 }
882 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000884
885 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
886 std::string *sdp) {
887 const cricket::SessionDescription* desc = current_desc->description();
888 EXPECT_TRUE(current_desc->ToString(sdp));
889
890 const cricket::ContentInfos& contents = desc->contents();
891 cricket::ContentInfos::const_iterator it = contents.begin();
892 // Replace ufrag and pwd lines with empty strings.
893 for (; it != contents.end(); ++it) {
894 const cricket::TransportDescription* transport_desc =
895 desc->GetTransportDescriptionByName(it->name);
896 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
897 + "\r\n";
898 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
899 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000900 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000901 "", 0,
902 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000903 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000904 "", 0,
905 sdp);
906 }
907 }
908
deadbeef0ed85b22016-02-23 17:24:52 -0800909 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
910 const std::string& ufrag,
911 const std::string& pwd) {
912 cricket::SessionDescription* desc = current_desc->description();
913 for (TransportInfo& transport_info : desc->transport_infos()) {
914 cricket::TransportDescription& transport_desc =
915 transport_info.description;
916 transport_desc.ice_ufrag = ufrag;
917 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000918 }
919 }
920
deadbeef0ed85b22016-02-23 17:24:52 -0800921 // Sets ufrag/pwd for specified |media_type|.
922 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
923 cricket::MediaType media_type,
924 const std::string& ufrag,
925 const std::string& pwd) {
926 cricket::SessionDescription* desc = current_desc->description();
927 const cricket::ContentInfo* cinfo =
928 cricket::GetFirstMediaContent(desc->contents(), media_type);
929 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
930 cricket::TransportDescription* transport_desc =
931 &transport_info->description;
932 transport_desc->ice_ufrag = ufrag;
933 transport_desc->ice_pwd = pwd;
934 }
935
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000936 // Creates a remote offer and and applies it as a remote description,
937 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700938 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000939 // to decide which local and remote streams to create.
940 void CreateAndSetRemoteOfferAndLocalAnswer() {
941 SessionDescriptionInterface* offer = CreateRemoteOffer();
942 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800943 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944 SetLocalDescriptionWithoutError(answer);
945 }
946 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
947 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700948 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000949 }
950 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700951 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000952 SetLocalDescriptionWithoutError(desc);
953 EXPECT_EQ(expected_state, session_->state());
954 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000955 void SetLocalDescriptionExpectError(const std::string& action,
956 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000957 SessionDescriptionInterface* desc) {
958 std::string error;
959 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000960 std::string sdp_type = "local ";
961 sdp_type.append(action);
962 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000963 EXPECT_NE(std::string::npos, error.find(expected_error));
964 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000965 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
966 SessionDescriptionInterface* desc) {
967 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
968 expected_error, desc);
969 }
970 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
971 SessionDescriptionInterface* desc) {
972 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
973 expected_error, desc);
974 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
976 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
977 }
978 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700979 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000980 SetRemoteDescriptionWithoutError(desc);
981 EXPECT_EQ(expected_state, session_->state());
982 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000983 void SetRemoteDescriptionExpectError(const std::string& action,
984 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000985 SessionDescriptionInterface* desc) {
986 std::string error;
987 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000988 std::string sdp_type = "remote ";
989 sdp_type.append(action);
990 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991 EXPECT_NE(std::string::npos, error.find(expected_error));
992 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000993 void SetRemoteDescriptionOfferExpectError(
994 const std::string& expected_error, SessionDescriptionInterface* desc) {
995 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
996 expected_error, desc);
997 }
998 void SetRemoteDescriptionPranswerExpectError(
999 const std::string& expected_error, SessionDescriptionInterface* desc) {
1000 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
1001 expected_error, desc);
1002 }
1003 void SetRemoteDescriptionAnswerExpectError(
1004 const std::string& expected_error, SessionDescriptionInterface* desc) {
1005 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
1006 expected_error, desc);
1007 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001008
1009 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
1010 SessionDescriptionInterface** nocrypto_answer) {
1011 // Create a SDP without Crypto.
1012 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001013 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001014 options.bundle_enabled = true;
1015 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
1016 ASSERT_TRUE(*offer != NULL);
1017 VerifyCryptoParams((*offer)->description());
1018
1019 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
1020 cricket::SEC_DISABLED);
1021 EXPECT_TRUE(*nocrypto_answer != NULL);
1022 }
1023
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001024 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
1025 SessionDescriptionInterface** nodtls_answer) {
1026 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001027 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001028 options.bundle_enabled = true;
1029
kwibergd1fe2812016-04-27 06:47:29 -07001030 std::unique_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001031 CreateRemoteOffer(options, cricket::SEC_ENABLED));
1032
1033 *nodtls_answer =
1034 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
1035 EXPECT_TRUE(*nodtls_answer != NULL);
1036 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
1037 VerifyCryptoParams((*nodtls_answer)->description());
1038
1039 SetFactoryDtlsSrtp();
1040 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
1041 ASSERT_TRUE(*offer != NULL);
1042 VerifyFingerprintStatus((*offer)->description(), true);
1043 VerifyCryptoParams((*offer)->description());
1044 }
1045
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001046 JsepSessionDescription* CreateRemoteOfferWithVersion(
1047 cricket::MediaSessionOptions options,
1048 cricket::SecurePolicy secure_policy,
1049 const std::string& session_version,
1050 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001051 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001052 const cricket::SessionDescription* cricket_desc = NULL;
1053 if (current_desc) {
1054 cricket_desc = current_desc->description();
1055 session_id = current_desc->session_id();
1056 }
1057
1058 desc_factory_->set_secure(secure_policy);
1059 JsepSessionDescription* offer(
1060 new JsepSessionDescription(JsepSessionDescription::kOffer));
1061 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
1062 session_id, session_version)) {
1063 delete offer;
1064 offer = NULL;
1065 }
1066 return offer;
1067 }
1068 JsepSessionDescription* CreateRemoteOffer(
1069 cricket::MediaSessionOptions options) {
1070 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1071 kSessionVersion, NULL);
1072 }
1073 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001074 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
1075 return CreateRemoteOfferWithVersion(
1076 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001077 }
1078 JsepSessionDescription* CreateRemoteOffer(
1079 cricket::MediaSessionOptions options,
1080 const SessionDescriptionInterface* current_desc) {
1081 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1082 kSessionVersion, current_desc);
1083 }
1084
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001085 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
1086 const char* sctp_stream_name, int new_port,
1087 cricket::MediaSessionOptions options) {
1088 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001089 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
1090 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001091 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
1092 }
1093
1094 // Takes ownership of offer_basis (and deletes it).
1095 JsepSessionDescription* ChangeSDPSctpPort(
1096 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1097 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1098 // SessionDescription from the mutated string.
1099 const char* default_port_str = "5000";
1100 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001101 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001102 std::string offer_str;
1103 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001104 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001105 new_port_str, strlen(new_port_str),
1106 &offer_str);
1107 JsepSessionDescription* offer = new JsepSessionDescription(
1108 offer_basis->type());
1109 delete offer_basis;
1110 offer->Initialize(offer_str, NULL);
1111 return offer;
1112 }
1113
deadbeefab9b2d12015-10-14 11:33:11 -07001114 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001115 // before this function to decide which streams to create.
1116 JsepSessionDescription* CreateRemoteOffer() {
1117 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001118 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001119 return CreateRemoteOffer(options, session_->remote_description());
1120 }
1121
1122 JsepSessionDescription* CreateRemoteAnswer(
1123 const SessionDescriptionInterface* offer,
1124 cricket::MediaSessionOptions options,
1125 cricket::SecurePolicy policy) {
1126 desc_factory_->set_secure(policy);
1127 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001128 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001129 JsepSessionDescription* answer(
1130 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1131 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1132 options, NULL),
1133 session_id, kSessionVersion)) {
1134 delete answer;
1135 answer = NULL;
1136 }
1137 return answer;
1138 }
1139
1140 JsepSessionDescription* CreateRemoteAnswer(
1141 const SessionDescriptionInterface* offer,
1142 cricket::MediaSessionOptions options) {
1143 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1144 }
1145
deadbeefab9b2d12015-10-14 11:33:11 -07001146 // Creates an answer session description.
1147 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001148 // to decide which streams to create.
1149 JsepSessionDescription* CreateRemoteAnswer(
1150 const SessionDescriptionInterface* offer) {
1151 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001152 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001153 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1154 }
1155
1156 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001157 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001158 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001159 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001160
1161 PeerConnectionInterface::RTCOfferAnswerOptions options;
1162 options.use_rtp_mux = bundle;
1163
1164 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001165 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1166 // and answer.
1167 SetLocalDescriptionWithoutError(offer);
1168
kwibergd1fe2812016-04-27 06:47:29 -07001169 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001170 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001171 std::string sdp;
1172 EXPECT_TRUE(answer->ToString(&sdp));
1173
1174 size_t expected_candidate_num = 2;
1175 if (!rtcp_mux) {
1176 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1177 // for rtp and rtcp.
1178 expected_candidate_num = 4;
1179 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001180 const std::string kRtcpMux = "a=rtcp-mux";
1181 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001182 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001183 kXRtcpMux.c_str(), kXRtcpMux.length(),
1184 &sdp);
1185 }
1186
1187 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1188 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001189
1190 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001191 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001192 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1193 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001194 if (bundle) {
1195 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1196 } else {
1197 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001198 }
1199 }
1200 // Tests that we can only send DTMF when the dtmf codec is supported.
1201 void TestCanInsertDtmf(bool can) {
1202 if (can) {
1203 InitWithDtmfCodec();
1204 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001205 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001206 }
deadbeefab9b2d12015-10-14 11:33:11 -07001207 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001208 CreateAndSetRemoteOfferAndLocalAnswer();
1209 EXPECT_FALSE(session_->CanInsertDtmf(""));
1210 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1211 }
1212
zhihuang3a334652016-05-05 18:37:49 -07001213 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1214 const std::string& codec_name) {
1215 for (const auto& content : desc->description()->contents()) {
1216 if (static_cast<cricket::MediaContentDescription*>(content.description)
1217 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1218 const auto* mdesc =
1219 static_cast<cricket::VideoContentDescription*>(content.description);
1220 for (const auto& codec : mdesc->codecs()) {
1221 if (codec.name == codec_name) {
1222 return true;
1223 }
1224 }
1225 }
1226 }
1227 return false;
1228 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001229 // Helper class to configure loopback network and verify Best
1230 // Connection using right IP protocol for TestLoopbackCall
1231 // method. LoopbackNetworkManager applies firewall rules to block
1232 // all ping traffic once ICE completed, and remove them to observe
1233 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1234 // verifies the best connection is using the right IP protocol after
1235 // initial ICE convergences.
1236
1237 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001238 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001239 LoopbackNetworkConfiguration()
1240 : test_ipv6_network_(false),
1241 test_extra_ipv4_network_(false),
1242 best_connection_after_initial_ice_converged_(1, 0) {}
1243
1244 // Used to track the expected best connection count in each IP protocol.
1245 struct ExpectedBestConnection {
1246 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1247 : ipv4_count_(ipv4_count),
1248 ipv6_count_(ipv6_count) {}
1249
1250 int ipv4_count_;
1251 int ipv6_count_;
1252 };
1253
1254 bool test_ipv6_network_;
1255 bool test_extra_ipv4_network_;
1256 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1257
1258 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001259 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001260 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1261 }
1262
1263 private:
jbauchac8869e2015-07-03 01:36:14 -07001264 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001265 const ExpectedBestConnection& expected) const {
1266 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001267 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1268 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001269 expected.ipv4_count_);
1270 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001271 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1272 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001273 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001274 // This is used in the loopback call so there is only single host to host
1275 // candidate pair.
1276 EXPECT_EQ(metrics_observer->GetEnumCounter(
1277 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1278 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001279 0);
1280 EXPECT_EQ(metrics_observer->GetEnumCounter(
1281 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1282 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001283 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001284 }
1285 };
1286
1287 class LoopbackNetworkManager {
1288 public:
1289 LoopbackNetworkManager(WebRtcSessionTest* session,
1290 const LoopbackNetworkConfiguration& config)
1291 : config_(config) {
1292 session->AddInterface(
1293 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1294 if (config_.test_extra_ipv4_network_) {
1295 session->AddInterface(
1296 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1297 }
1298 if (config_.test_ipv6_network_) {
1299 session->AddInterface(
1300 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1301 }
1302 }
1303
1304 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1305 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1306 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1307 if (config_.test_extra_ipv4_network_) {
1308 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1309 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1310 }
1311 if (config_.test_ipv6_network_) {
1312 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1313 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1314 }
1315 }
1316
1317 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1318
1319 private:
1320 LoopbackNetworkConfiguration config_;
1321 };
1322
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001323 // The method sets up a call from the session to itself, in a loopback
1324 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001325 // disconnection, and then a permanent disconnection.
1326 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001327 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1328 // While running the call, this method also checks if the session goes through
1329 // the correct sequence of ICE states when a connection is established,
1330 // broken, and re-established.
1331 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001332 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1333 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001334 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001335
stefanc1aeaf02015-10-15 07:26:07 -07001336 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001337 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001338 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001339 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001340
1341 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1342 observer_.ice_gathering_state_);
1343 SetLocalDescriptionWithoutError(offer);
1344 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1345 observer_.ice_connection_state_);
1346 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001347 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001348 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1349 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001350 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001351
1352 std::string sdp;
1353 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001354 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1355 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001356 ASSERT_TRUE(desc != NULL);
1357 SetRemoteDescriptionWithoutError(desc);
1358
1359 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001360 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001361
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001362 // The ice connection state is "Connected" too briefly to catch in a test.
1363 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001364 observer_.ice_connection_state_, kIceCandidatesTimeout);
1365 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001366
stefanc1aeaf02015-10-15 07:26:07 -07001367 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1368 LoopbackNetworkManager loopback_network_manager(this, config);
1369 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001370 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001371 // Adding firewall rule to block ping requests, which should cause
1372 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001373
1374 loopback_network_manager.ApplyFirewallRules(fss_.get());
1375
1376 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001377 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1378 observer_.ice_connection_state_,
1379 kIceCandidatesTimeout);
1380
jbauchac8869e2015-07-03 01:36:14 -07001381 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001382
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001383 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001384 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001385
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001386 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001387 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001388 observer_.ice_connection_state_,
1389 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001390
1391 // Now we block ping requests and wait until the ICE connection transitions
1392 // to the Failed state. This will take at least 30 seconds because it must
1393 // wait for the Port to timeout.
1394 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001395
1396 loopback_network_manager.ApplyFirewallRules(fss_.get());
1397 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001398 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001399 observer_.ice_connection_state_,
1400 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001401 }
1402
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001403 void TestLoopbackCall() {
1404 LoopbackNetworkConfiguration config;
1405 TestLoopbackCall(config);
1406 }
1407
stefanc1aeaf02015-10-15 07:26:07 -07001408 void TestPacketOptions() {
1409 media_controller_.reset(
1410 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1411 LoopbackNetworkConfiguration config;
1412 LoopbackNetworkManager loopback_network_manager(this, config);
1413
1414 SetupLoopbackCall();
1415
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001416 // Wait for channel to be ready for sending.
1417 EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
stefanc1aeaf02015-10-15 07:26:07 -07001418 uint8_t test_packet[15] = {0};
1419 rtc::PacketOptions options;
1420 options.packet_id = 10;
1421 media_engine_->GetVideoChannel(0)
1422 ->SendRtp(test_packet, sizeof(test_packet), options);
1423
1424 const int kPacketTimeout = 2000;
deadbeef14461d42016-06-15 11:06:57 -07001425 EXPECT_EQ_WAIT(10, fake_call_.last_sent_nonnegative_packet_id(),
1426 kPacketTimeout);
stefanc1aeaf02015-10-15 07:26:07 -07001427 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1428 }
1429
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001430 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1431 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001432 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1433 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001434
1435 // Add kCNCodec for dtmf test.
ossudedfd282016-06-14 07:12:39 -07001436 std::vector<cricket::AudioCodec> codecs =
1437 media_engine_->audio_send_codecs();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001438 codecs.push_back(kCNCodec1);
1439 codecs.push_back(kCNCodec2);
1440 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -07001441 desc_factory_->set_audio_codecs(codecs, codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001442 }
1443
1444 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1445 const cricket::ContentDescription* description = content->description;
nissec8ee8822017-01-18 07:20:55 -08001446 RTC_CHECK(description != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001447 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001448 static_cast<const cricket::AudioContentDescription*>(description);
nissec8ee8822017-01-18 07:20:55 -08001449 RTC_CHECK(audio_content_desc != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001450 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1451 if (audio_content_desc->codecs()[i].name == "CN")
1452 return false;
1453 }
1454 return true;
1455 }
1456
deadbeefab9b2d12015-10-14 11:33:11 -07001457 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001458 webrtc::InternalDataChannelInit dci;
nissec8ee8822017-01-18 07:20:55 -08001459 RTC_CHECK(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001460 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1461 data_channel_ = DataChannel::Create(
1462 session_.get(), session_->data_channel_type(), "datachannel", dci);
1463 }
1464
1465 void SetLocalDescriptionWithDataChannel() {
1466 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001467 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001468 SetLocalDescriptionWithoutError(offer);
1469 }
1470
wu@webrtc.org91053e72013-08-10 07:18:04 +00001471 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001472 RTCCertificateGenerationMethod cert_gen_method,
1473 CreateSessionDescriptionRequest::Type type) {
1474 InitWithDtls(cert_gen_method);
1475 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1476 }
1477
1478 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1479 CreateSessionDescriptionRequest::Type type) {
1480 InitWithDtlsIdentityGenFail();
1481 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1482 }
1483
1484 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001485 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001486 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001487 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001488 if (type == CreateSessionDescriptionRequest::kAnswer) {
1489 cricket::MediaSessionOptions options;
kwibergd1fe2812016-04-27 06:47:29 -07001490 std::unique_ptr<JsepSessionDescription> offer(
1491 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001492 ASSERT_TRUE(offer.get() != NULL);
1493 SetRemoteDescriptionWithoutError(offer.release());
1494 }
1495
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001496 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001497 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001498 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001499 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001500 observers[kNumber];
1501 for (int i = 0; i < kNumber; ++i) {
1502 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1503 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001504 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001505 } else {
htaa2a49d92016-03-04 02:51:39 -08001506 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001507 }
1508 }
1509
1510 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1511 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1512 WebRtcSessionCreateSDPObserverForTest::kFailed;
1513
1514 for (int i = 0; i < kNumber; ++i) {
1515 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1516 if (success) {
1517 EXPECT_TRUE(observers[i]->description() != NULL);
1518 } else {
1519 EXPECT_TRUE(observers[i]->description() == NULL);
1520 }
1521 }
1522 }
1523
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001524 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001525 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001526 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001527 turn_server.credentials = credentials;
1528 turn_server.ports.push_back(
hnsl277b2502016-12-13 05:17:23 -08001529 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP));
deadbeef653b8e02015-11-11 12:55:10 -08001530 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001531 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001532 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001533 }
1534
skvlad11a9cbf2016-10-07 11:53:05 -07001535 webrtc::RtcEventLogNullImpl event_log_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001536 cricket::FakeMediaEngine* media_engine_;
1537 cricket::FakeDataEngine* data_engine_;
deadbeef953c2ce2017-01-09 14:53:41 -08001538 // Actually owned by session_.
1539 FakeSctpTransportFactory* fake_sctp_transport_factory_ = nullptr;
kwibergd1fe2812016-04-27 06:47:29 -07001540 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001541 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001542 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_;
1543 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1544 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1545 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1546 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1547 std::unique_ptr<rtc::FirewallSocketServer> fss_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001548 rtc::SocketServerScope ss_scope_;
1549 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001550 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001551 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001552 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001553 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001554 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001555 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001556 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001557 MockIceObserver observer_;
1558 cricket::FakeVideoMediaChannel* video_channel_;
1559 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001560 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001561 // The following flags affect options created for CreateOffer/CreateAnswer.
1562 bool send_stream_1_ = false;
1563 bool send_stream_2_ = false;
1564 bool send_audio_ = false;
1565 bool send_video_ = false;
1566 rtc::scoped_refptr<DataChannel> data_channel_;
1567 // Last values received from data channel creation signal.
1568 std::string last_data_channel_label_;
1569 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001570 bool session_destroyed_ = false;
jbauchcb560652016-08-04 05:20:32 -07001571 bool with_gcm_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001572};
1573
Henrik Boström87713d02015-08-25 09:53:21 +02001574TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1575 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001576 // SDES is disabled when DTLS is on.
1577 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001578}
1579
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001580TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001581 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001582 // SDES is required if DTLS is off.
1583 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001584}
1585
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001586TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1587 TestSessionCandidatesWithBundleRtcpMux(false, false);
1588}
1589
1590// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1591// with rtcp-mux and/or bundle.
1592TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1593 TestSessionCandidatesWithBundleRtcpMux(false, true);
1594}
1595
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001596TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1597 TestSessionCandidatesWithBundleRtcpMux(true, true);
1598}
1599
1600TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001601 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1602 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001603 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001604 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001605 InitiateCall();
1606 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1607 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1608 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1609}
1610
deadbeeff5f03e82016-06-06 11:16:06 -07001611TEST_F(WebRtcSessionTest, TestStunError) {
1612 rtc::ScopedFakeClock clock;
1613
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001614 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1615 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001616 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001617 rtc::FP_UDP,
1618 rtc::FD_ANY,
1619 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001620 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001621 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001622 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001623 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
deadbeeff5f03e82016-06-06 11:16:06 -07001624 EXPECT_TRUE_SIMULATED_WAIT(observer_.oncandidatesready_, kStunTimeout, clock);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001625 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1626 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
deadbeeff5f03e82016-06-06 11:16:06 -07001627 // Destroy session before scoped fake clock goes out of scope to avoid TSan
1628 // warning.
1629 session_->Close();
1630 session_.reset(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001631}
1632
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001633TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001634 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001635 SessionDescriptionInterface* offer = NULL;
1636 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1637 std::string unknown_action;
1638 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1639 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1640}
1641
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001642// Test creating offers and receive answers and make sure the
1643// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001644TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001645 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001646 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001647 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001648 const std::string session_id_orig = offer->session_id();
1649 const std::string session_version_orig = offer->session_version();
1650 SetLocalDescriptionWithoutError(offer);
1651
deadbeefab9b2d12015-10-14 11:33:11 -07001652 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001653 SessionDescriptionInterface* answer =
1654 CreateRemoteAnswer(session_->local_description());
1655 SetRemoteDescriptionWithoutError(answer);
1656
1657 video_channel_ = media_engine_->GetVideoChannel(0);
1658 voice_channel_ = media_engine_->GetVoiceChannel(0);
1659
1660 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1661 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1662
1663 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1664 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1665
1666 ASSERT_EQ(1u, video_channel_->send_streams().size());
1667 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1668 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1669 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1670
1671 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001672 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001673 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001674
1675 // Verify the session id is the same and the session version is
1676 // increased.
1677 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001678 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1679 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001680
1681 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001682 EXPECT_EQ(0u, video_channel_->send_streams().size());
1683 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001684
deadbeefab9b2d12015-10-14 11:33:11 -07001685 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686 answer = CreateRemoteAnswer(session_->local_description());
1687 SetRemoteDescriptionWithoutError(answer);
1688
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001689 // Make sure the receive streams have not changed.
1690 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1691 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1692 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1693 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1694}
1695
1696// Test receiving offers and creating answers and make sure the
1697// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001698TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001699 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001700 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001701 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001702 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001703 SetRemoteDescriptionWithoutError(offer);
1704
deadbeefab9b2d12015-10-14 11:33:11 -07001705 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001706 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001707 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708 SetLocalDescriptionWithoutError(answer);
1709
1710 const std::string session_id_orig = answer->session_id();
1711 const std::string session_version_orig = answer->session_version();
1712
1713 video_channel_ = media_engine_->GetVideoChannel(0);
1714 voice_channel_ = media_engine_->GetVoiceChannel(0);
1715
htaa2a49d92016-03-04 02:51:39 -08001716 ASSERT_TRUE(video_channel_);
1717 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001718 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1719 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1720
1721 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1722 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1723
1724 ASSERT_EQ(1u, video_channel_->send_streams().size());
1725 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1726 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1727 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1728
deadbeefab9b2d12015-10-14 11:33:11 -07001729 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001730 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731 SetRemoteDescriptionWithoutError(offer);
1732
1733 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001734 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001735 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001736
1737 // Verify the session id is the same and the session version is
1738 // increased.
1739 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001740 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1741 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001742 SetLocalDescriptionWithoutError(answer);
1743
1744 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1745 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1746 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1747 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1748 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1749 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1750
1751 // Make sure we have no send streams.
1752 EXPECT_EQ(0u, video_channel_->send_streams().size());
1753 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1754}
1755
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001756TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001757 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001758 media_engine_->set_fail_create_channel(true);
1759
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001760 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001761 ASSERT_TRUE(offer != NULL);
1762 // SetRemoteDescription and SetLocalDescription will take the ownership of
1763 // the offer.
1764 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001765 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001766 ASSERT_TRUE(offer != NULL);
1767 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1768}
1769
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001770//
1771// Tests for creating/setting SDP under different SDES/DTLS polices:
1772//
1773// --DTLS off and SDES on
1774// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1775// set local/remote offer/answer with crypto --> success
1776// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1777// failure
1778// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1779// failure
1780// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1781// failure
1782//
1783// --DTLS on and SDES off
1784// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1785// set local/remote offer/answer with DTLS fingerprint --> success
1786// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1787// fingerprint --> failure
1788// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1789// --> failure
1790// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1791// --> failure
1792//
1793// --Encryption disabled: DTLS off and SDES off
1794// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1795// answer without SDES or DTLS --> success
1796// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1797// answer without SDES or DTLS --> success
1798//
1799
1800// Test that we return a failure when applying a remote/local offer that doesn't
1801// have cryptos enabled when DTLS is off.
1802TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001803 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001804 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001805 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001806 JsepSessionDescription* offer = CreateRemoteOffer(
1807 options, cricket::SEC_DISABLED);
1808 ASSERT_TRUE(offer != NULL);
1809 VerifyNoCryptoParams(offer->description(), false);
1810 // SetRemoteDescription and SetLocalDescription will take the ownership of
1811 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001812 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001813 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1814 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001815 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001816}
1817
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001818// Test that we return a failure when applying a local answer that doesn't have
1819// cryptos enabled when DTLS is off.
1820TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001821 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001822 SessionDescriptionInterface* offer = NULL;
1823 SessionDescriptionInterface* answer = NULL;
1824 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1825 // SetRemoteDescription and SetLocalDescription will take the ownership of
1826 // the offer.
1827 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001828 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001829}
1830
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001831// Test we will return fail when apply an remote answer that doesn't have
1832// crypto enabled when DTLS is off.
1833TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001834 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001835 SessionDescriptionInterface* offer = NULL;
1836 SessionDescriptionInterface* answer = NULL;
1837 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1838 // SetRemoteDescription and SetLocalDescription will take the ownership of
1839 // the offer.
1840 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001841 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001842}
1843
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001844// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1845// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001846TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001847 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001848 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001849 SetFactoryDtlsSrtp();
1850 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001851 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001852 JsepSessionDescription* offer =
1853 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001854 ASSERT_TRUE(offer != NULL);
1855 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001856 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857
1858 // SetRemoteDescription will take the ownership of the offer.
1859 SetRemoteDescriptionWithoutError(offer);
1860
1861 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001862 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001863 ASSERT_TRUE(answer != NULL);
1864 VerifyFingerprintStatus(answer->description(), true);
1865 // Check that we don't have an a=crypto line in the answer.
1866 VerifyNoCryptoParams(answer->description(), true);
1867
1868 // Now set the local description, which should work, even without a=crypto.
1869 SetLocalDescriptionWithoutError(answer);
1870}
1871
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001872// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1873// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001874TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001875 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001876 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001877 SetFactoryDtlsSrtp();
1878
1879 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001880 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001881 ASSERT_TRUE(offer != NULL);
1882 VerifyFingerprintStatus(offer->description(), true);
1883 // Check that we don't have an a=crypto line in the offer.
1884 VerifyNoCryptoParams(offer->description(), true);
1885
1886 // Now set the local description, which should work, even without a=crypto.
1887 SetLocalDescriptionWithoutError(offer);
1888
1889 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001890 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001891 JsepSessionDescription* answer =
1892 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1893 ASSERT_TRUE(answer != NULL);
1894 VerifyFingerprintStatus(answer->description(), true);
1895 VerifyNoCryptoParams(answer->description(), true);
1896
1897 // SetRemoteDescription will take the ownership of the answer.
1898 SetRemoteDescriptionWithoutError(answer);
1899}
1900
1901// Test that if we support DTLS and the other side didn't offer a fingerprint,
1902// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001903TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02001904 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001905 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001906 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001907 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001908 JsepSessionDescription* offer = CreateRemoteOffer(
1909 options, cricket::SEC_REQUIRED);
1910 ASSERT_TRUE(offer != NULL);
1911 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001912 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001913
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001914 // SetRemoteDescription will take the ownership of the offer.
1915 SetRemoteDescriptionOfferExpectError(
1916 kSdpWithoutDtlsFingerprint, offer);
1917
1918 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1919 // SetLocalDescription will take the ownership of the offer.
1920 SetLocalDescriptionOfferExpectError(
1921 kSdpWithoutDtlsFingerprint, offer);
1922}
1923
1924// Test that we return a failure when applying a local answer that doesn't have
1925// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001926TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02001927 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001928 SessionDescriptionInterface* offer = NULL;
1929 SessionDescriptionInterface* answer = NULL;
1930 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1931
1932 // SetRemoteDescription and SetLocalDescription will take the ownership of
1933 // the offer and answer.
1934 SetRemoteDescriptionWithoutError(offer);
1935 SetLocalDescriptionAnswerExpectError(
1936 kSdpWithoutDtlsFingerprint, answer);
1937}
1938
1939// Test that we return a failure when applying a remote answer that doesn't have
1940// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001941TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
Henrik Boström87713d02015-08-25 09:53:21 +02001942 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001943 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001944 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001945 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07001946 std::unique_ptr<SessionDescriptionInterface> temp_offer(
deadbeefcbecd352015-09-23 11:50:27 -07001947 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001948 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001949 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001950
1951 // SetRemoteDescription and SetLocalDescription will take the ownership of
1952 // the offer and answer.
1953 SetLocalDescriptionWithoutError(offer);
1954 SetRemoteDescriptionAnswerExpectError(
1955 kSdpWithoutDtlsFingerprint, answer);
1956}
1957
1958// Test that we create a local offer without SDES or DTLS and accept a remote
1959// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001960TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001961 SendAudioVideoStream1();
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 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001966 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001967 ASSERT_TRUE(offer != NULL);
1968 VerifyFingerprintStatus(offer->description(), false);
1969 // Check that we don't have an a=crypto line in the offer.
1970 VerifyNoCryptoParams(offer->description(), false);
1971
1972 // Now set the local description, which should work, even without a=crypto.
1973 SetLocalDescriptionWithoutError(offer);
1974
1975 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001976 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001977 JsepSessionDescription* answer =
1978 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1979 ASSERT_TRUE(answer != NULL);
1980 VerifyFingerprintStatus(answer->description(), false);
1981 VerifyNoCryptoParams(answer->description(), false);
1982
1983 // SetRemoteDescription will take the ownership of the answer.
1984 SetRemoteDescriptionWithoutError(answer);
1985}
1986
1987// Test that we create a local answer without SDES or DTLS and accept a remote
1988// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001989TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001990 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001991 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001992
1993 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001994 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001995 JsepSessionDescription* offer =
1996 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1997 ASSERT_TRUE(offer != NULL);
1998 VerifyFingerprintStatus(offer->description(), false);
1999 VerifyNoCryptoParams(offer->description(), false);
2000
2001 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002002 SetRemoteDescriptionWithoutError(offer);
2003
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002004 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08002005 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002006 ASSERT_TRUE(answer != NULL);
2007 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002008 // Check that we don't have an a=crypto line in the answer.
2009 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002010
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002011 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002012 SetLocalDescriptionWithoutError(answer);
2013}
2014
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002015// Test that we can create and set an answer correctly when different
2016// SSL roles have been negotiated for different transports.
2017// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
2018TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
2019 SendAudioVideoStream1();
2020 InitWithDtls(GetParam());
2021 SetFactoryDtlsSrtp();
2022
2023 SessionDescriptionInterface* offer = CreateOffer();
2024 SetLocalDescriptionWithoutError(offer);
2025
2026 cricket::MediaSessionOptions options;
2027 options.recv_video = true;
2028
2029 // First, negotiate different SSL roles.
2030 SessionDescriptionInterface* answer =
2031 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
2032 TransportInfo* audio_transport_info =
2033 answer->description()->GetTransportInfoByName("audio");
2034 audio_transport_info->description.connection_role =
2035 cricket::CONNECTIONROLE_ACTIVE;
2036 TransportInfo* video_transport_info =
2037 answer->description()->GetTransportInfoByName("video");
2038 video_transport_info->description.connection_role =
2039 cricket::CONNECTIONROLE_PASSIVE;
2040 SetRemoteDescriptionWithoutError(answer);
2041
2042 // Now create an offer in the reverse direction, and ensure the initial
2043 // offerer responds with an answer with correct SSL roles.
2044 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2045 kSessionVersion,
2046 session_->remote_description());
2047 SetRemoteDescriptionWithoutError(offer);
2048
htaa2a49d92016-03-04 02:51:39 -08002049 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002050 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2051 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2052 audio_transport_info->description.connection_role);
2053 video_transport_info = answer->description()->GetTransportInfoByName("video");
2054 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
2055 video_transport_info->description.connection_role);
2056 SetLocalDescriptionWithoutError(answer);
2057
2058 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
2059 // audio is transferred over to video in the answer that completes the BUNDLE
2060 // negotiation.
2061 options.bundle_enabled = true;
2062 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2063 kSessionVersion,
2064 session_->remote_description());
2065 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08002066 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002067 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2068 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2069 audio_transport_info->description.connection_role);
2070 video_transport_info = answer->description()->GetTransportInfoByName("video");
2071 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2072 video_transport_info->description.connection_role);
2073 SetLocalDescriptionWithoutError(answer);
2074}
2075
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002076TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002077 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002078 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002080 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002081 SetLocalDescriptionWithoutError(offer);
2082
2083 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002084 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002085 SetLocalDescriptionWithoutError(offer2);
2086}
2087
2088TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002089 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002090 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002092 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093 SetRemoteDescriptionWithoutError(offer);
2094
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002095 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002096 SetRemoteDescriptionWithoutError(offer2);
2097}
2098
2099TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002100 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002101 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002102 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002104 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002105 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2106 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107}
2108
2109TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002110 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002111 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002112 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002113 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002114 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002115 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002116 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002117}
2118
2119TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002120 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002121 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002122 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002123 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124
htaa2a49d92016-03-04 02:51:39 -08002125 JsepSessionDescription* pranswer =
2126 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002127 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002128 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129
deadbeefab9b2d12015-10-14 11:33:11 -07002130 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002131 JsepSessionDescription* pranswer2 =
2132 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2134
deadbeefd59daf82015-10-14 15:02:44 -07002135 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002136
deadbeefab9b2d12015-10-14 11:33:11 -07002137 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002138 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002139 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140}
2141
2142TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002143 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002144 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002145 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002146 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002147
2148 JsepSessionDescription* pranswer =
2149 CreateRemoteAnswer(session_->local_description());
2150 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2151
2152 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002153 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154
deadbeefab9b2d12015-10-14 11:33:11 -07002155 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002156 JsepSessionDescription* pranswer2 =
2157 CreateRemoteAnswer(session_->local_description());
2158 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2159
2160 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002161 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002162
deadbeefab9b2d12015-10-14 11:33:11 -07002163 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002164 SessionDescriptionInterface* answer =
2165 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002166 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002167}
2168
2169TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002170 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002171 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002172 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002173
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002174 SessionDescriptionInterface* answer =
2175 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002176 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2177 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002178}
2179
2180TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002181 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002182 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002183 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002184
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002185 SessionDescriptionInterface* answer =
2186 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002187 SetRemoteDescriptionAnswerExpectError(
2188 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002189}
2190
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002191// Tests that the remote candidates are added and removed successfully.
2192TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002193 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002194 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002195
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002196 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
2197 "", "", "host", 0, "");
2198 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002199 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2200
deadbeefd59daf82015-10-14 15:02:44 -07002201 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002202 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2203
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002204 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002205 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002206
2207 // Fail since we have not set a remote description.
2208 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002209
2210 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2211 session_->local_description());
2212 SetRemoteDescriptionWithoutError(answer);
2213
deadbeefd59daf82015-10-14 15:02:44 -07002214 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2215 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002216 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002217 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2218 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2219
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002220 // Verifying the candidates are copied properly from internal vector.
2221 const SessionDescriptionInterface* remote_desc =
2222 session_->remote_description();
2223 ASSERT_TRUE(remote_desc != NULL);
2224 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2225 const IceCandidateCollection* candidates =
2226 remote_desc->candidates(kMediaContentIndex0);
2227 ASSERT_EQ(2u, candidates->count());
2228 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2229 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2230 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2231 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2232
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002233 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2234 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002235 candidate.set_component(2);
2236 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2237 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002238 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002239
2240 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2241 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002242
2243 // Remove candidate1 and candidate2
2244 std::vector<cricket::Candidate> remote_candidates;
2245 remote_candidates.push_back(ice_candidate1.candidate());
2246 remote_candidates.push_back(ice_candidate2.candidate());
2247 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2248 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002249}
2250
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002251// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002252// that it is retained if the remote session description is changed.
2253TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002254 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002255 cricket::Candidate candidate1;
2256 candidate1.set_component(1);
2257 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2258 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002259 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002260 CreateAndSetRemoteOfferAndLocalAnswer();
2261
2262 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2263 const SessionDescriptionInterface* remote_desc =
2264 session_->remote_description();
2265 ASSERT_TRUE(remote_desc != NULL);
2266 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2267 const IceCandidateCollection* candidates =
2268 remote_desc->candidates(kMediaContentIndex0);
2269 ASSERT_EQ(1u, candidates->count());
2270 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2271
2272 // Update the RemoteSessionDescription with a new session description and
2273 // a candidate and check that the new remote session description contains both
2274 // candidates.
2275 SessionDescriptionInterface* offer = CreateRemoteOffer();
2276 cricket::Candidate candidate2;
2277 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2278 candidate2);
2279 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2280 SetRemoteDescriptionWithoutError(offer);
2281
2282 remote_desc = session_->remote_description();
2283 ASSERT_TRUE(remote_desc != NULL);
2284 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2285 candidates = remote_desc->candidates(kMediaContentIndex0);
2286 ASSERT_EQ(2u, candidates->count());
2287 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2288 // Username and password have be updated with the TransportInfo of the
2289 // SessionDescription, won't be equal to the original one.
2290 candidate2.set_username(candidates->at(0)->candidate().username());
2291 candidate2.set_password(candidates->at(0)->candidate().password());
2292 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2293 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2294 // No need to verify the username and password.
2295 candidate1.set_username(candidates->at(1)->candidate().username());
2296 candidate1.set_password(candidates->at(1)->candidate().password());
2297 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2298
2299 // Test that the candidate is ignored if we can add the same candidate again.
2300 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2301}
2302
2303// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002304// that they are retained if the local session description is changed. And if
2305// continual gathering is enabled, they are removed from the local session
2306// description when the network is down.
2307TEST_F(WebRtcSessionTest,
2308 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002309 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002310 Init();
deadbeefb60a8192016-08-24 15:15:00 -07002311 // Enable Continual Gathering.
2312 cricket::IceConfig config;
2313 config.continual_gathering_policy = cricket::GATHER_CONTINUALLY;
2314 session_->SetIceConfig(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002315 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002316 CreateAndSetRemoteOfferAndLocalAnswer();
2317
2318 const SessionDescriptionInterface* local_desc = session_->local_description();
2319 const IceCandidateCollection* candidates =
2320 local_desc->candidates(kMediaContentIndex0);
2321 ASSERT_TRUE(candidates != NULL);
2322 EXPECT_EQ(0u, candidates->count());
2323
deadbeefb60a8192016-08-24 15:15:00 -07002324 // Since we're using continual gathering, we won't get "gathering done".
2325 EXPECT_EQ_WAIT(2u, candidates->count(), kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326
2327 local_desc = session_->local_description();
2328 candidates = local_desc->candidates(kMediaContentIndex0);
2329 ASSERT_TRUE(candidates != NULL);
2330 EXPECT_LT(0u, candidates->count());
2331 candidates = local_desc->candidates(1);
2332 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002333 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002334
2335 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002336 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002337 CreateAndSetRemoteOfferAndLocalAnswer();
2338
2339 local_desc = session_->local_description();
2340 candidates = local_desc->candidates(kMediaContentIndex0);
2341 ASSERT_TRUE(candidates != NULL);
2342 EXPECT_LT(0u, candidates->count());
2343 candidates = local_desc->candidates(1);
2344 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002345 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002346
2347 candidates = local_desc->candidates(kMediaContentIndex0);
2348 size_t num_local_candidates = candidates->count();
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002349 // Bring down the network interface to trigger candidate removals.
2350 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2351 // Verify that all local candidates are removed.
2352 EXPECT_EQ(0, observer_.num_candidates_removed_);
2353 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2354 kIceCandidatesTimeout);
2355 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2356}
2357
2358// Tests that if continual gathering is disabled, local candidates won't be
2359// removed when the interface is turned down.
2360TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2361 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2362 Init();
2363 SendAudioVideoStream1();
2364 CreateAndSetRemoteOfferAndLocalAnswer();
2365
2366 const SessionDescriptionInterface* local_desc = session_->local_description();
2367 const IceCandidateCollection* candidates =
2368 local_desc->candidates(kMediaContentIndex0);
2369 ASSERT_TRUE(candidates != NULL);
2370 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2371
2372 size_t num_local_candidates = candidates->count();
2373 EXPECT_LT(0u, num_local_candidates);
2374 // By default, Continual Gathering is disabled.
2375 // Bring down the network interface.
2376 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2377 // Verify that the local candidates are not removed.
2378 rtc::Thread::Current()->ProcessMessages(1000);
2379 EXPECT_EQ(0, observer_.num_candidates_removed_);
2380 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002381}
2382
2383// Test that we can set a remote session description with remote candidates.
2384TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002385 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002386
2387 cricket::Candidate candidate1;
2388 candidate1.set_component(1);
2389 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2390 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002391 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002392 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002393
2394 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2395 SetRemoteDescriptionWithoutError(offer);
2396
2397 const SessionDescriptionInterface* remote_desc =
2398 session_->remote_description();
2399 ASSERT_TRUE(remote_desc != NULL);
2400 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2401 const IceCandidateCollection* candidates =
2402 remote_desc->candidates(kMediaContentIndex0);
2403 ASSERT_EQ(1u, candidates->count());
2404 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2405
htaa2a49d92016-03-04 02:51:39 -08002406 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002407 SetLocalDescriptionWithoutError(answer);
2408}
2409
2410// Test that offers and answers contains ice candidates when Ice candidates have
2411// been gathered.
2412TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002413 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002414 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002415 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002416 // Ice is started but candidates are not provided until SetLocalDescription
2417 // is called.
2418 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2419 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2420 CreateAndSetRemoteOfferAndLocalAnswer();
2421 // Wait until at least one local candidate has been collected.
2422 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2423 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002424
kwibergd1fe2812016-04-27 06:47:29 -07002425 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002426
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002427 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2428 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002429
2430 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2431 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002432 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002433 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2434 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002435 SetLocalDescriptionWithoutError(answer);
2436}
2437
2438// Verifies TransportProxy and media channels are created with content names
2439// present in the SessionDescription.
2440TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002441 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002442 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002443 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002444
2445 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002446 // "video". Goal is to modify these content names and verify transport
2447 // channels
2448 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002449 // present in SDP.
2450 std::string sdp;
2451 EXPECT_TRUE(offer->ToString(&sdp));
2452 const std::string kAudioMid = "a=mid:audio";
2453 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2454 const std::string kVideoMid = "a=mid:video";
2455 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2456
2457 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002458 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002459 kAudioMidReplaceStr.c_str(),
2460 kAudioMidReplaceStr.length(),
2461 &sdp);
2462 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002463 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002464 kVideoMidReplaceStr.c_str(),
2465 kVideoMidReplaceStr.length(),
2466 &sdp);
2467
2468 SessionDescriptionInterface* modified_offer =
2469 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2470
2471 SetRemoteDescriptionWithoutError(modified_offer);
2472
htaa2a49d92016-03-04 02:51:39 -08002473 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002474 SetLocalDescriptionWithoutError(answer);
2475
johan669d69b2016-11-08 14:14:08 -08002476 rtc::PacketTransportInterface* voice_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002477 session_->voice_rtp_transport_channel();
2478 EXPECT_TRUE(voice_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002479 EXPECT_EQ(voice_transport_channel->debug_name(),
2480 "audio_content_name " +
2481 std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
2482 rtc::PacketTransportInterface* video_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002483 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002484 ASSERT_TRUE(video_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002485 EXPECT_EQ(video_transport_channel->debug_name(),
2486 "video_content_name " +
2487 std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002488 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2489 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2490}
2491
2492// Test that an offer contains the correct media content descriptions based on
2493// the send streams when no constraints have been set.
2494TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002495 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002496 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002497
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002498 ASSERT_TRUE(offer != NULL);
2499 const cricket::ContentInfo* content =
2500 cricket::GetFirstAudioContent(offer->description());
2501 EXPECT_TRUE(content != NULL);
2502 content = cricket::GetFirstVideoContent(offer->description());
2503 EXPECT_TRUE(content == NULL);
2504}
2505
2506// Test that an offer contains the correct media content descriptions based on
2507// the send streams when no constraints have been set.
2508TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002509 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002510 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002511 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002512 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002513
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002514 const cricket::ContentInfo* content =
2515 cricket::GetFirstAudioContent(offer->description());
2516 EXPECT_TRUE(content != NULL);
2517 content = cricket::GetFirstVideoContent(offer->description());
2518 EXPECT_TRUE(content == NULL);
2519
2520 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002521 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002522 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002523 content = cricket::GetFirstAudioContent(offer->description());
2524 EXPECT_TRUE(content != NULL);
2525 content = cricket::GetFirstVideoContent(offer->description());
2526 EXPECT_TRUE(content != NULL);
2527}
2528
2529// Test that an offer contains no media content descriptions if
2530// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2531TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002532 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002533 PeerConnectionInterface::RTCOfferAnswerOptions options;
2534 options.offer_to_receive_audio = 0;
2535 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002536
kwibergd1fe2812016-04-27 06:47:29 -07002537 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002538
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002539 ASSERT_TRUE(offer != NULL);
2540 const cricket::ContentInfo* content =
2541 cricket::GetFirstAudioContent(offer->description());
2542 EXPECT_TRUE(content == NULL);
2543 content = cricket::GetFirstVideoContent(offer->description());
2544 EXPECT_TRUE(content == NULL);
2545}
2546
2547// Test that an offer contains only audio media content descriptions if
2548// kOfferToReceiveAudio constraints are set to true.
2549TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002550 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002551 PeerConnectionInterface::RTCOfferAnswerOptions options;
2552 options.offer_to_receive_audio =
2553 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2554
kwibergd1fe2812016-04-27 06:47:29 -07002555 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002556
2557 const cricket::ContentInfo* content =
2558 cricket::GetFirstAudioContent(offer->description());
2559 EXPECT_TRUE(content != NULL);
2560 content = cricket::GetFirstVideoContent(offer->description());
2561 EXPECT_TRUE(content == NULL);
2562}
2563
2564// Test that an offer contains audio and video media content descriptions if
2565// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2566TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002567 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002568 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002569 PeerConnectionInterface::RTCOfferAnswerOptions options;
2570 options.offer_to_receive_audio =
2571 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2572 options.offer_to_receive_video =
2573 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2574
kwibergd1fe2812016-04-27 06:47:29 -07002575 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002576
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002577 const cricket::ContentInfo* content =
2578 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002579 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002580
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002581 content = cricket::GetFirstVideoContent(offer->description());
2582 EXPECT_TRUE(content != NULL);
2583
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002584 // Sets constraints to false and verifies that audio/video contents are
2585 // removed.
2586 options.offer_to_receive_audio = 0;
2587 options.offer_to_receive_video = 0;
2588 offer.reset(CreateOffer(options));
2589
2590 content = cricket::GetFirstAudioContent(offer->description());
2591 EXPECT_TRUE(content == NULL);
2592 content = cricket::GetFirstVideoContent(offer->description());
2593 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002594}
2595
2596// Test that an answer can not be created if the last remote description is not
2597// an offer.
2598TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002599 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002600 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002601 SetLocalDescriptionWithoutError(offer);
2602 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2603 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002604 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002605}
2606
2607// Test that an answer contains the correct media content descriptions when no
2608// constraints have been set.
2609TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002610 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002611 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002612 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002613 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002614 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002615 const cricket::ContentInfo* content =
2616 cricket::GetFirstAudioContent(answer->description());
2617 ASSERT_TRUE(content != NULL);
2618 EXPECT_FALSE(content->rejected);
2619
2620 content = cricket::GetFirstVideoContent(answer->description());
2621 ASSERT_TRUE(content != NULL);
2622 EXPECT_FALSE(content->rejected);
2623}
2624
2625// Test that an answer contains the correct media content descriptions when no
2626// constraints have been set and the offer only contain audio.
2627TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002628 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002629 // Create a remote offer with audio only.
2630 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002631
kwibergd1fe2812016-04-27 06:47:29 -07002632 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002633 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2634 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2635
2636 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002637 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002638 const cricket::ContentInfo* content =
2639 cricket::GetFirstAudioContent(answer->description());
2640 ASSERT_TRUE(content != NULL);
2641 EXPECT_FALSE(content->rejected);
2642
2643 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2644}
2645
2646// Test that an answer contains the correct media content descriptions when no
2647// constraints have been set.
2648TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002649 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002650 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002651 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002652 SetRemoteDescriptionWithoutError(offer.release());
2653 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002654 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002655 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002656 const cricket::ContentInfo* content =
2657 cricket::GetFirstAudioContent(answer->description());
2658 ASSERT_TRUE(content != NULL);
2659 EXPECT_FALSE(content->rejected);
2660
2661 content = cricket::GetFirstVideoContent(answer->description());
2662 ASSERT_TRUE(content != NULL);
2663 EXPECT_FALSE(content->rejected);
2664}
2665
2666// Test that an answer contains the correct media content descriptions when
2667// constraints have been set but no stream is sent.
2668TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002669 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002670 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002671 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002672 SetRemoteDescriptionWithoutError(offer.release());
2673
htaa2a49d92016-03-04 02:51:39 -08002674 cricket::MediaSessionOptions session_options;
2675 session_options.recv_audio = false;
2676 session_options.recv_video = false;
kwibergd1fe2812016-04-27 06:47:29 -07002677 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002678 CreateAnswer(session_options));
2679
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002680 const cricket::ContentInfo* content =
2681 cricket::GetFirstAudioContent(answer->description());
2682 ASSERT_TRUE(content != NULL);
2683 EXPECT_TRUE(content->rejected);
2684
2685 content = cricket::GetFirstVideoContent(answer->description());
2686 ASSERT_TRUE(content != NULL);
2687 EXPECT_TRUE(content->rejected);
2688}
2689
2690// Test that an answer contains the correct media content descriptions when
2691// constraints have been set and streams are sent.
2692TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002693 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002694 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002695 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002696 SetRemoteDescriptionWithoutError(offer.release());
2697
htaa2a49d92016-03-04 02:51:39 -08002698 cricket::MediaSessionOptions options;
2699 options.recv_audio = false;
2700 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002701
2702 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002703 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002704 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002705
2706 // TODO(perkj): Should the direction be set to SEND_ONLY?
2707 const cricket::ContentInfo* content =
2708 cricket::GetFirstAudioContent(answer->description());
2709 ASSERT_TRUE(content != NULL);
2710 EXPECT_FALSE(content->rejected);
2711
2712 // TODO(perkj): Should the direction be set to SEND_ONLY?
2713 content = cricket::GetFirstVideoContent(answer->description());
2714 ASSERT_TRUE(content != NULL);
2715 EXPECT_FALSE(content->rejected);
2716}
2717
2718TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2719 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002720 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002721 PeerConnectionInterface::RTCOfferAnswerOptions options;
2722 options.offer_to_receive_audio =
2723 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2724 options.voice_activity_detection = false;
2725
kwibergd1fe2812016-04-27 06:47:29 -07002726 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002727
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002728 const cricket::ContentInfo* content =
2729 cricket::GetFirstAudioContent(offer->description());
2730 EXPECT_TRUE(content != NULL);
2731 EXPECT_TRUE(VerifyNoCNCodecs(content));
2732}
2733
2734TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2735 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002736 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002737 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002738 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002739 SetRemoteDescriptionWithoutError(offer.release());
2740
htaa2a49d92016-03-04 02:51:39 -08002741 cricket::MediaSessionOptions options;
2742 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002743 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002744 const cricket::ContentInfo* content =
2745 cricket::GetFirstAudioContent(answer->description());
2746 ASSERT_TRUE(content != NULL);
2747 EXPECT_TRUE(VerifyNoCNCodecs(content));
2748}
2749
2750// This test verifies the call setup when remote answer with audio only and
2751// later updates with video.
2752TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002753 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002754 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2755 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2756
deadbeefab9b2d12015-10-14 11:33:11 -07002757 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002758 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002759
2760 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002761 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2762
2763 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2764 // and answer;
2765 SetLocalDescriptionWithoutError(offer);
2766 SetRemoteDescriptionWithoutError(answer);
2767
2768 video_channel_ = media_engine_->GetVideoChannel(0);
2769 voice_channel_ = media_engine_->GetVoiceChannel(0);
2770
2771 ASSERT_TRUE(video_channel_ == NULL);
2772
2773 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2774 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2775 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2776
2777 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002778 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002779 CreateAndSetRemoteOfferAndLocalAnswer();
2780
2781 video_channel_ = media_engine_->GetVideoChannel(0);
2782 voice_channel_ = media_engine_->GetVoiceChannel(0);
2783
2784 ASSERT_TRUE(video_channel_ != NULL);
2785 ASSERT_TRUE(voice_channel_ != NULL);
2786
2787 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2788 ASSERT_EQ(1u, video_channel_->send_streams().size());
2789 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2790 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2791 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2792 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2793 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2794 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2795
2796 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002797 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002798 CreateAndSetRemoteOfferAndLocalAnswer();
2799
2800 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2801 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2802 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2803 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2804 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2805}
2806
2807// This test verifies the call setup when remote answer with video only and
2808// later updates with audio.
2809TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002810 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002811 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2812 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002813 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002814 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002815
2816 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002817 options.recv_audio = false;
2818 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002819 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2820 offer, options, cricket::SEC_ENABLED);
2821
2822 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2823 // and answer.
2824 SetLocalDescriptionWithoutError(offer);
2825 SetRemoteDescriptionWithoutError(answer);
2826
2827 video_channel_ = media_engine_->GetVideoChannel(0);
2828 voice_channel_ = media_engine_->GetVoiceChannel(0);
2829
2830 ASSERT_TRUE(voice_channel_ == NULL);
2831 ASSERT_TRUE(video_channel_ != NULL);
2832
2833 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2834 ASSERT_EQ(1u, video_channel_->send_streams().size());
2835 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2836
2837 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002838 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002839 CreateAndSetRemoteOfferAndLocalAnswer();
2840
2841 voice_channel_ = media_engine_->GetVoiceChannel(0);
2842 ASSERT_TRUE(voice_channel_ != NULL);
2843
2844 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2845 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2846 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2847 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2848
2849 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002850 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002851 CreateAndSetRemoteOfferAndLocalAnswer();
2852
2853 video_channel_ = media_engine_->GetVideoChannel(0);
2854 voice_channel_ = media_engine_->GetVoiceChannel(0);
2855
2856 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2857 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2858 ASSERT_EQ(1u, video_channel_->send_streams().size());
2859 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2860}
2861
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002862TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002863 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002864 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002865 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002866 VerifyCryptoParams(offer->description());
2867 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002868 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002869 VerifyCryptoParams(answer->description());
2870}
2871
jbauchcb560652016-08-04 05:20:32 -07002872TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDPGcm) {
2873 InitWithGcm();
2874 SendAudioVideoStream1();
2875 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
2876 VerifyCryptoParams(offer->description(), true);
2877 SetRemoteDescriptionWithoutError(offer.release());
2878 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
2879 VerifyCryptoParams(answer->description(), true);
2880}
2881
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002882TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002883 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002884 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002885 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002886 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002887 VerifyNoCryptoParams(offer->description(), false);
2888}
2889
2890TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002891 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002892 VerifyAnswerFromNonCryptoOffer();
2893}
2894
2895TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002896 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002897 VerifyAnswerFromCryptoOffer();
2898}
2899
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002900// This test verifies that setLocalDescription fails if
2901// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2902TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002903 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002904 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002905 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002906
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002907 std::string sdp;
2908 RemoveIceUfragPwdLines(offer.get(), &sdp);
2909 SessionDescriptionInterface* modified_offer =
2910 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002911 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002912}
2913
2914// This test verifies that setRemoteDescription fails if
2915// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2916TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002917 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002918 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002919 std::string sdp;
2920 RemoveIceUfragPwdLines(offer.get(), &sdp);
2921 SessionDescriptionInterface* modified_offer =
2922 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002923 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002924}
2925
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002926// This test verifies that setLocalDescription fails if local offer has
2927// too short ice ufrag and pwd strings.
2928TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002929 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002930 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002931 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002932 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2933 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002934 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002935 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002936 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002937
2938 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002939 offer.reset(CreateOffer());
2940 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2941 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002942}
2943
2944// This test verifies that setRemoteDescription fails if remote offer has
2945// too short ice ufrag and pwd strings.
2946TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002947 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002948 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002949 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2950 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002951 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002952 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002953 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002954
deadbeef0ed85b22016-02-23 17:24:52 -08002955 offer.reset(CreateRemoteOffer());
2956 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2957 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002958}
2959
Honghai Zhang04e91462015-12-11 14:26:22 -08002960// Test that if the remote offer indicates the peer requested ICE restart (via
2961// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2962TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002963 Init();
honghaiz503726c2015-07-31 12:37:38 -07002964
2965 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07002966 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08002967 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002968 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2969 0, "", "", "relay", 0, "");
2970 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2971 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002972 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2973 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002974 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2975
2976 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002977 offer.reset(CreateRemoteOffer());
2978 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002979 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2980 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2981 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002982 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2983 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002984 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2985
2986 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002987 offer.reset(CreateRemoteOffer());
2988 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002989 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2990 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2991 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002992 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2993 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002994 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2995
2996 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002997 offer.reset(CreateRemoteOffer());
2998 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2999 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07003000 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
3001}
3002
Honghai Zhang04e91462015-12-11 14:26:22 -08003003// Test that if the remote answer indicates the peer requested ICE restart (via
3004// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
3005TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
3006 Init();
3007 SessionDescriptionInterface* offer = CreateOffer();
3008 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08003009
3010 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07003011 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08003012 answer->set_type(JsepSessionDescription::kPrAnswer);
3013 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08003014 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
3015 0, "", "", "relay", 0, "");
3016 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
3017 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003018 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
3019 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003020 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
3021
3022 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08003023 answer.reset(CreateRemoteAnswer(offer));
3024 answer->set_type(JsepSessionDescription::kPrAnswer);
3025 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08003026 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3027 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3028 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003029 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
3030 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003031 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
3032
3033 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08003034 answer.reset(CreateRemoteAnswer(offer));
3035 answer->set_type(JsepSessionDescription::kPrAnswer);
3036 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08003037 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
3038 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
3039 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003040 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
3041 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003042 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
3043
3044 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08003045 answer.reset(CreateRemoteAnswer(offer));
3046 answer->set_type(JsepSessionDescription::kPrAnswer);
3047 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
3048 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003049 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
3050}
3051
Donald Curtisd4f769d2015-05-28 09:48:21 -07003052// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07003053// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07003054TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
3055 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
3056
3057 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003058 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003059
3060 PeerConnectionInterface::RTCOfferAnswerOptions options;
3061 options.use_rtp_mux = true;
3062
3063 SessionDescriptionInterface* offer = CreateRemoteOffer();
3064 SetRemoteDescriptionWithoutError(offer);
3065
htaa2a49d92016-03-04 02:51:39 -08003066 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003067 SetLocalDescriptionWithoutError(answer);
3068
deadbeefcbecd352015-09-23 11:50:27 -07003069 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3070 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07003071
deadbeefcbecd352015-09-23 11:50:27 -07003072 cricket::BaseChannel* voice_channel = session_->voice_channel();
nissec8ee8822017-01-18 07:20:55 -08003073 ASSERT_TRUE(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003074
3075 // Checks if one of the transport channels contains a connection using a given
3076 // port.
deadbeefcbecd352015-09-23 11:50:27 -07003077 auto connection_with_remote_port = [this, voice_channel](int port) {
hbosdf6075a2016-12-19 04:58:02 -08003078 std::unique_ptr<webrtc::SessionStats> stats = session_->GetStats_s();
3079 for (auto& kv : stats->transport_stats) {
deadbeefcbecd352015-09-23 11:50:27 -07003080 for (auto& chan_stat : kv.second.channel_stats) {
3081 for (auto& conn_info : chan_stat.connection_infos) {
3082 if (conn_info.remote_candidate.address().port() == port) {
3083 return true;
3084 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07003085 }
3086 }
3087 }
3088 return false;
3089 };
3090
3091 EXPECT_FALSE(connection_with_remote_port(5000));
3092 EXPECT_FALSE(connection_with_remote_port(5001));
3093 EXPECT_FALSE(connection_with_remote_port(6000));
3094
3095 // The way the *_WAIT checks work is they only wait if the condition fails,
3096 // which does not help in the case where state is not changing. This is
3097 // problematic in this test since we want to verify that adding a video
3098 // candidate does _not_ change state. So we interleave candidates and assume
3099 // that messages are executed in the order they were posted.
3100
3101 // First audio candidate.
3102 cricket::Candidate candidate0;
3103 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3104 candidate0.set_component(1);
3105 candidate0.set_protocol("udp");
3106 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3107 candidate0);
3108 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3109
3110 // Video candidate.
3111 cricket::Candidate candidate1;
3112 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3113 candidate1.set_component(1);
3114 candidate1.set_protocol("udp");
3115 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3116 candidate1);
3117 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3118
3119 // Second audio candidate.
3120 cricket::Candidate candidate2;
3121 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3122 candidate2.set_component(1);
3123 candidate2.set_protocol("udp");
3124 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3125 candidate2);
3126 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3127
3128 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3129 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3130
3131 // No need here for a _WAIT check since we are checking that state hasn't
3132 // changed: if this is false we would be doing waits for nothing and if this
3133 // is true then there will be no messages processed anyways.
3134 EXPECT_FALSE(connection_with_remote_port(6000));
3135}
3136
deadbeefcbecd352015-09-23 11:50:27 -07003137// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003138TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3139 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003140 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003141
3142 PeerConnectionInterface::RTCOfferAnswerOptions options;
3143 options.use_rtp_mux = true;
3144
3145 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003146 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003147
deadbeefcbecd352015-09-23 11:50:27 -07003148 EXPECT_NE(session_->voice_rtp_transport_channel(),
3149 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003150
deadbeefab9b2d12015-10-14 11:33:11 -07003151 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003152 SessionDescriptionInterface* answer =
3153 CreateRemoteAnswer(session_->local_description());
3154 SetRemoteDescriptionWithoutError(answer);
3155
deadbeefcbecd352015-09-23 11:50:27 -07003156 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3157 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003158}
3159
deadbeefcbecd352015-09-23 11:50:27 -07003160// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003161TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3162 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003163 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003164
Donald Curtis0e209b02015-03-24 09:29:54 -07003165 PeerConnectionInterface::RTCOfferAnswerOptions options;
3166 options.use_rtp_mux = true;
3167
3168 SessionDescriptionInterface* offer = CreateOffer(options);
3169 SetLocalDescriptionWithoutError(offer);
3170
deadbeefcbecd352015-09-23 11:50:27 -07003171 EXPECT_NE(session_->voice_rtp_transport_channel(),
3172 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003173
deadbeefab9b2d12015-10-14 11:33:11 -07003174 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003175
3176 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003177 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003178 CreateRemoteAnswer(session_->local_description()));
3179 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3180 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3181 JsepSessionDescription* modified_answer =
3182 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3183 modified_answer->Initialize(answer_copy, "1", "1");
3184 SetRemoteDescriptionWithoutError(modified_answer); //
3185
deadbeefcbecd352015-09-23 11:50:27 -07003186 EXPECT_NE(session_->voice_rtp_transport_channel(),
3187 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003188}
3189
3190// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3191TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3192 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003193 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003194
3195 PeerConnectionInterface::RTCOfferAnswerOptions options;
3196 options.use_rtp_mux = true;
3197
3198 SessionDescriptionInterface* offer = CreateOffer(options);
3199 SetLocalDescriptionWithoutError(offer);
3200
deadbeefcbecd352015-09-23 11:50:27 -07003201 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3202 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003203
deadbeefab9b2d12015-10-14 11:33:11 -07003204 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003205 SessionDescriptionInterface* answer =
3206 CreateRemoteAnswer(session_->local_description());
3207 SetRemoteDescriptionWithoutError(answer);
3208
deadbeefcbecd352015-09-23 11:50:27 -07003209 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3210 session_->video_rtp_transport_channel());
3211}
3212
3213// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3214// audio content in the answer.
3215TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3216 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003217 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003218
3219 PeerConnectionInterface::RTCOfferAnswerOptions options;
3220 options.use_rtp_mux = true;
3221
3222 SessionDescriptionInterface* offer = CreateOffer(options);
3223 SetLocalDescriptionWithoutError(offer);
3224
3225 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3226 session_->video_rtp_transport_channel());
3227
deadbeefab9b2d12015-10-14 11:33:11 -07003228 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003229 cricket::MediaSessionOptions recv_options;
3230 recv_options.recv_audio = false;
3231 recv_options.recv_video = true;
3232 SessionDescriptionInterface* answer =
3233 CreateRemoteAnswer(session_->local_description(), recv_options);
3234 SetRemoteDescriptionWithoutError(answer);
3235
deadbeefd59daf82015-10-14 15:02:44 -07003236 EXPECT_TRUE(nullptr == session_->voice_channel());
3237 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003238
deadbeefd59daf82015-10-14 15:02:44 -07003239 session_->Close();
3240 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3241 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3242 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3243 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003244}
3245
3246// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3247TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3248 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003249 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003250
Donald Curtis0e209b02015-03-24 09:29:54 -07003251 PeerConnectionInterface::RTCOfferAnswerOptions options;
3252 options.use_rtp_mux = true;
3253
3254 SessionDescriptionInterface* offer = CreateOffer(options);
3255 SetLocalDescriptionWithoutError(offer);
3256
deadbeefcbecd352015-09-23 11:50:27 -07003257 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3258 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003259
deadbeefab9b2d12015-10-14 11:33:11 -07003260 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003261
3262 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003263 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003264 CreateRemoteAnswer(session_->local_description()));
3265 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3266 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3267 JsepSessionDescription* modified_answer =
3268 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3269 modified_answer->Initialize(answer_copy, "1", "1");
3270 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003271
deadbeefcbecd352015-09-23 11:50:27 -07003272 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3273 session_->video_rtp_transport_channel());
3274}
3275
3276// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3277TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3278 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003279 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003280
3281 SessionDescriptionInterface* offer = CreateRemoteOffer();
3282 SetRemoteDescriptionWithoutError(offer);
3283
3284 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3285 session_->video_rtp_transport_channel());
3286
deadbeefab9b2d12015-10-14 11:33:11 -07003287 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003288 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003289 SetLocalDescriptionWithoutError(answer);
3290
3291 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3292 session_->video_rtp_transport_channel());
3293}
3294
3295// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3296TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3297 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003298 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003299
3300 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003301 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003302 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3303 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3304 JsepSessionDescription* modified_offer =
3305 new JsepSessionDescription(JsepSessionDescription::kOffer);
3306 modified_offer->Initialize(offer_copy, "1", "1");
3307
3308 // Expect an error when applying the remote description
3309 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3310 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003311}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003312
Peter Thatcher4eddf182015-04-30 10:55:59 -07003313// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003314TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3315 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003316 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003317
Donald Curtis0e209b02015-03-24 09:29:54 -07003318 PeerConnectionInterface::RTCOfferAnswerOptions options;
3319 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003320
Donald Curtis0e209b02015-03-24 09:29:54 -07003321 SessionDescriptionInterface* offer = CreateOffer(options);
3322 SetLocalDescriptionWithoutError(offer);
3323
deadbeefcbecd352015-09-23 11:50:27 -07003324 EXPECT_NE(session_->voice_rtp_transport_channel(),
3325 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003326
deadbeefab9b2d12015-10-14 11:33:11 -07003327 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003328 SessionDescriptionInterface* answer =
3329 CreateRemoteAnswer(session_->local_description());
3330 SetRemoteDescriptionWithoutError(answer);
3331
3332 // This should lead to an audio-only call but isn't implemented
3333 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003334 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3335 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003336}
3337
deadbeefcbecd352015-09-23 11:50:27 -07003338// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003339TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3340 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003341 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003342 PeerConnectionInterface::RTCOfferAnswerOptions options;
3343 options.use_rtp_mux = true;
3344
3345 SessionDescriptionInterface* offer = CreateOffer(options);
3346 SetLocalDescriptionWithoutError(offer);
3347
deadbeefcbecd352015-09-23 11:50:27 -07003348 EXPECT_NE(session_->voice_rtp_transport_channel(),
3349 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003350
deadbeefab9b2d12015-10-14 11:33:11 -07003351 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003352
3353 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003354 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003355 CreateRemoteAnswer(session_->local_description()));
3356 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3357 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3358 JsepSessionDescription* modified_answer =
3359 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3360 modified_answer->Initialize(answer_copy, "1", "1");
3361 SetRemoteDescriptionWithoutError(modified_answer); //
3362
deadbeefcbecd352015-09-23 11:50:27 -07003363 EXPECT_NE(session_->voice_rtp_transport_channel(),
3364 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003365}
3366
Peter Thatcher4eddf182015-04-30 10:55:59 -07003367// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3368TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3369 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003370 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003371
3372 PeerConnectionInterface::RTCOfferAnswerOptions options;
3373 options.use_rtp_mux = true;
3374
3375 SessionDescriptionInterface* offer = CreateOffer(options);
3376 SetRemoteDescriptionWithoutError(offer);
3377
deadbeefcbecd352015-09-23 11:50:27 -07003378 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3379 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003380}
3381
skvlad6c87a672016-05-17 17:49:52 -07003382// Adding a new channel to a BUNDLE which is already connected should directly
3383// assign the bundle transport to the channel, without first setting a
3384// disconnected non-bundle transport and then replacing it. The application
3385// should not receive any changes in the ICE state.
3386TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) {
3387 LoopbackNetworkConfiguration config;
3388 LoopbackNetworkManager loopback_network_manager(this, config);
3389 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain
3390 // connected. Disabling either of these two means that we need to wait for the
3391 // answer to find out if more transports are needed.
3392 configuration_.bundle_policy =
3393 PeerConnectionInterface::kBundlePolicyMaxBundle;
skvlad6c87a672016-05-17 17:49:52 -07003394 options_.disable_encryption = true;
zhihuang4dfb8ce2016-11-23 10:30:12 -08003395 Init(PeerConnectionInterface::kRtcpMuxPolicyRequire);
skvlad6c87a672016-05-17 17:49:52 -07003396
3397 // Negotiate an audio channel with MAX_BUNDLE enabled.
3398 SendAudioOnlyStream2();
3399 SessionDescriptionInterface* offer = CreateOffer();
3400 SetLocalDescriptionWithoutError(offer);
3401 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
3402 observer_.ice_gathering_state_, kIceCandidatesTimeout);
3403 std::string sdp;
3404 offer->ToString(&sdp);
3405 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription(
3406 JsepSessionDescription::kAnswer, sdp, nullptr);
3407 ASSERT_TRUE(answer != NULL);
3408 SetRemoteDescriptionWithoutError(answer);
3409
3410 // Wait for the ICE state to stabilize.
3411 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3412 observer_.ice_connection_state_, kIceCandidatesTimeout);
3413 observer_.ice_connection_state_history_.clear();
3414
3415 // Now add a video channel which should be using the same bundle transport.
3416 SendAudioVideoStream2();
3417 offer = CreateOffer();
3418 offer->ToString(&sdp);
3419 SetLocalDescriptionWithoutError(offer);
3420 answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer,
3421 sdp, nullptr);
3422 ASSERT_TRUE(answer != NULL);
3423 SetRemoteDescriptionWithoutError(answer);
3424
3425 // Wait for ICE state to stabilize
3426 rtc::Thread::Current()->ProcessMessages(0);
3427 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3428 observer_.ice_connection_state_, kIceCandidatesTimeout);
3429
3430 // No ICE state changes are expected to happen.
3431 EXPECT_EQ(0, observer_.ice_connection_state_history_.size());
3432}
3433
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003434TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3435 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003436 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003437
3438 PeerConnectionInterface::RTCOfferAnswerOptions options;
3439 SessionDescriptionInterface* offer = CreateOffer(options);
3440 SetLocalDescriptionWithoutError(offer);
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
deadbeefab9b2d12015-10-14 11:33:11 -07003445 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003446 SessionDescriptionInterface* answer =
3447 CreateRemoteAnswer(session_->local_description());
3448 SetRemoteDescriptionWithoutError(answer);
3449
deadbeefcbecd352015-09-23 11:50:27 -07003450 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3451 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003452}
3453
3454TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3455 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003456 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003457
3458 PeerConnectionInterface::RTCOfferAnswerOptions options;
3459 SessionDescriptionInterface* offer = CreateOffer(options);
3460 SetLocalDescriptionWithoutError(offer);
3461
deadbeefcbecd352015-09-23 11:50:27 -07003462 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3463 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003464
deadbeefab9b2d12015-10-14 11:33:11 -07003465 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003466 SessionDescriptionInterface* answer =
3467 CreateRemoteAnswer(session_->local_description());
3468 SetRemoteDescriptionWithoutError(answer);
3469
deadbeefcbecd352015-09-23 11:50:27 -07003470 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3471 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003472}
3473
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003474// This test verifies that SetLocalDescription and SetRemoteDescription fails
3475// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3476TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003477 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003478 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003479
3480 PeerConnectionInterface::RTCOfferAnswerOptions options;
3481 options.use_rtp_mux = true;
3482
3483 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003484 std::string offer_str;
3485 offer->ToString(&offer_str);
3486 // Disable rtcp-mux
3487 const std::string rtcp_mux = "rtcp-mux";
3488 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003489 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003490 xrtcp_mux.c_str(), xrtcp_mux.length(),
3491 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003492 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003493 new JsepSessionDescription(JsepSessionDescription::kOffer);
3494 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003495 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003496 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003497 new JsepSessionDescription(JsepSessionDescription::kOffer);
3498 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003499 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003500 // Trying unmodified SDP.
3501 SetLocalDescriptionWithoutError(offer);
3502}
3503
jbauchcb560652016-08-04 05:20:32 -07003504TEST_F(WebRtcSessionTest, SetSetupGcm) {
3505 InitWithGcm();
3506 SendAudioVideoStream1();
3507 CreateAndSetRemoteOfferAndLocalAnswer();
3508}
3509
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003510TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3511 TestCanInsertDtmf(false);
3512}
3513
3514TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3515 TestCanInsertDtmf(true);
3516}
3517
3518TEST_F(WebRtcSessionTest, InsertDtmf) {
3519 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003520 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003521 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003522 CreateAndSetRemoteOfferAndLocalAnswer();
3523 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3524 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3525
3526 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003527 const int expected_duration = 90;
3528 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3529 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3530 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3531
3532 // Verify
3533 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003534 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003535 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003536 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003537 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003538 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003539 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003540 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003541}
3542
deadbeefd59daf82015-10-14 15:02:44 -07003543// This test verifies the |initial_offerer| flag when session initiates the
3544// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003545TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003546 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003547 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003548 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003549 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3550 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003551 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003552 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003553 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003554}
3555
deadbeefd59daf82015-10-14 15:02:44 -07003556// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003557TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003558 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003559 EXPECT_FALSE(session_->initial_offerer());
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
deadbeefd59daf82015-10-14 15:02:44 -07003564 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003565 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003566 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003567}
3568
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003569// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3570TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003571 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003572 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003573 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003574 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003575 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003576 CreateRemoteAnswer(session_->local_description()));
3577
3578 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3579 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003580 JsepSessionDescription* modified_answer =
3581 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003582
3583 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3584 answer->session_id(),
3585 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003586 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003587
wu@webrtc.org4e393072014-04-07 17:04:35 +00003588 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003589 std::string sdp;
3590 EXPECT_TRUE(answer->ToString(&sdp));
3591 const std::string kAudioMid = "a=mid:audio";
3592 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003593 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003594 kAudioMidReplaceStr.c_str(),
3595 kAudioMidReplaceStr.length(),
3596 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003597 SessionDescriptionInterface* modified_answer1 =
3598 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003599 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003600
wu@webrtc.org4e393072014-04-07 17:04:35 +00003601 // Different media types.
3602 EXPECT_TRUE(answer->ToString(&sdp));
3603 const std::string kAudioMline = "m=audio";
3604 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003605 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003606 kAudioMlineReplaceStr.c_str(),
3607 kAudioMlineReplaceStr.length(),
3608 &sdp);
3609 SessionDescriptionInterface* modified_answer2 =
3610 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3611 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3612
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003613 SetRemoteDescriptionWithoutError(answer.release());
3614}
3615
3616// Verifying remote offer and local answer have matching m-lines as per
3617// RFC 3264.
3618TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003619 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003620 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003621 SessionDescriptionInterface* offer = CreateRemoteOffer();
3622 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003623 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003624
3625 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3626 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003627 JsepSessionDescription* modified_answer =
3628 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003629
3630 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3631 answer->session_id(),
3632 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003633 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003634 SetLocalDescriptionWithoutError(answer);
3635}
3636
3637// This test verifies that WebRtcSession does not start candidate allocation
3638// before SetLocalDescription is called.
3639TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003640 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003641 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003642 SessionDescriptionInterface* offer = CreateRemoteOffer();
3643 cricket::Candidate candidate;
3644 candidate.set_component(1);
3645 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3646 candidate);
3647 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3648 cricket::Candidate candidate1;
3649 candidate1.set_component(1);
3650 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3651 candidate1);
3652 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3653 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003654 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3655 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003656
3657 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003658 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003659 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3660 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3661
htaa2a49d92016-03-04 02:51:39 -08003662 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003663 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003664 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3665}
3666
3667// This test verifies that crypto parameter is updated in local session
3668// description as per security policy set in MediaSessionDescriptionFactory.
3669TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003670 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003671 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003672 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003673
3674 // Making sure SetLocalDescription correctly sets crypto value in
3675 // SessionDescription object after de-serialization of sdp string. The value
3676 // will be set as per MediaSessionDescriptionFactory.
3677 std::string offer_str;
3678 offer->ToString(&offer_str);
3679 SessionDescriptionInterface* jsep_offer_str =
3680 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3681 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003682 EXPECT_TRUE(session_->voice_channel()->srtp_required_for_testing());
3683 EXPECT_TRUE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003684}
3685
3686// This test verifies the crypto parameter when security is disabled.
3687TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003688 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003689 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003690 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003691 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003692
3693 // Making sure SetLocalDescription correctly sets crypto value in
3694 // SessionDescription object after de-serialization of sdp string. The value
3695 // will be set as per MediaSessionDescriptionFactory.
3696 std::string offer_str;
3697 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003698 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003699 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3700 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003701 EXPECT_FALSE(session_->voice_channel()->srtp_required_for_testing());
3702 EXPECT_FALSE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003703}
3704
3705// This test verifies that an answer contains new ufrag and password if an offer
3706// with new ufrag and password is received.
3707TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003708 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003709 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003710 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003711 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003712 SetRemoteDescriptionWithoutError(offer.release());
3713
deadbeefab9b2d12015-10-14 11:33:11 -07003714 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003715 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003716 SetLocalDescriptionWithoutError(answer.release());
3717
3718 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003719 for (const cricket::ContentInfo& content :
3720 session_->local_description()->description()->contents()) {
3721 options.transport_options[content.name].ice_restart = true;
3722 }
kwibergd1fe2812016-04-27 06:47:29 -07003723 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003724 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003725 SetRemoteDescriptionWithoutError(updated_offer1.release());
3726
kwibergd1fe2812016-04-27 06:47:29 -07003727 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003728
deadbeef0ed85b22016-02-23 17:24:52 -08003729 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3730 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003731
deadbeef0ed85b22016-02-23 17:24:52 -08003732 // Even a second answer (created before the description is set) should have
3733 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003734 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003735
3736 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3737 session_->local_description()->description()));
3738
3739 SetLocalDescriptionWithoutError(updated_answer2.release());
3740}
3741
3742// This test verifies that an answer contains new ufrag and password if an offer
3743// that changes either the ufrag or password (but not both) is received.
3744// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3745// a=ice-pwd attributes compared to the previous SDP from the peer, it
3746// indicates that ICE is restarting for this media stream."
3747TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3748 Init();
3749 cricket::MediaSessionOptions options;
3750 options.recv_audio = true;
3751 options.recv_video = true;
3752 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003753 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003754 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3755 SetRemoteDescriptionWithoutError(offer.release());
3756
3757 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003758 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003759 SetLocalDescriptionWithoutError(answer.release());
3760
3761 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003762 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003763 CreateRemoteOffer(options, session_->remote_description()));
3764 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3765 "original_password12345");
3766 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3767
kwibergd1fe2812016-04-27 06:47:29 -07003768 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003769 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3770 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003771 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003772
3773 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003774 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003775 CreateRemoteOffer(options, session_->remote_description()));
3776 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3777 "modified_password12345");
3778 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3779
kwibergd1fe2812016-04-27 06:47:29 -07003780 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003781 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3782 session_->local_description()->description()));
3783 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003784}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003785
wu@webrtc.org91053e72013-08-10 07:18:04 +00003786// This test verifies that an answer contains old ufrag and password if an offer
3787// with old ufrag and password is received.
3788TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003789 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003790 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003791 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003792 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003793 SetRemoteDescriptionWithoutError(offer.release());
3794
deadbeefab9b2d12015-10-14 11:33:11 -07003795 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003796 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003797 SetLocalDescriptionWithoutError(answer.release());
3798
3799 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003800 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003801 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003802 SetRemoteDescriptionWithoutError(updated_offer2.release());
3803
kwibergd1fe2812016-04-27 06:47:29 -07003804 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003805
deadbeef0ed85b22016-02-23 17:24:52 -08003806 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3807 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003808
3809 SetLocalDescriptionWithoutError(updated_answer2.release());
3810}
3811
deadbeef0ed85b22016-02-23 17:24:52 -08003812// This test verifies that if an offer does an ICE restart on some, but not all
3813// media sections, the answer will change the ufrag/password in the correct
3814// media sections.
3815TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3816 Init();
3817 cricket::MediaSessionOptions options;
3818 options.recv_video = true;
3819 options.recv_audio = true;
3820 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003821 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003822
3823 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3824 "aaaaaaaaaaaaaaaaaaaaaa");
3825 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3826 "bbbbbbbbbbbbbbbbbbbbbb");
3827 SetRemoteDescriptionWithoutError(offer.release());
3828
3829 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003830 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003831 SetLocalDescriptionWithoutError(answer.release());
3832
3833 // Receive an offer with new ufrag and password, but only for the video media
3834 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003835 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003836 CreateRemoteOffer(options, session_->remote_description()));
3837 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3838 "cccccccccccccccccccccc");
3839 SetRemoteDescriptionWithoutError(updated_offer.release());
3840
kwibergd1fe2812016-04-27 06:47:29 -07003841 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003842
3843 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3844 session_->local_description()->description(),
3845 cricket::MEDIA_TYPE_AUDIO));
3846
3847 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3848 session_->local_description()->description(),
3849 cricket::MEDIA_TYPE_VIDEO));
3850
3851 SetLocalDescriptionWithoutError(updated_answer.release());
3852}
3853
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003854TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003855 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003856 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003857 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003858 const std::string session_id_orig = offer->session_id();
3859 const std::string session_version_orig = offer->session_version();
3860 SetLocalDescriptionWithoutError(offer);
3861
3862 video_channel_ = media_engine_->GetVideoChannel(0);
3863 video_channel_->set_fail_set_send_codecs(true);
3864
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003865 SessionDescriptionInterface* answer =
3866 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003867 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003868
3869 // Test that after a content error, setting any description will
3870 // result in an error.
3871 video_channel_->set_fail_set_send_codecs(false);
3872 answer = CreateRemoteAnswer(session_->local_description());
3873 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3874 offer = CreateRemoteOffer();
3875 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003876}
3877
3878// Runs the loopback call test with BUNDLE and STUN disabled.
3879TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3880 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003881 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003882 cricket::PORTALLOCATOR_DISABLE_STUN |
3883 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003884 TestLoopbackCall();
3885}
3886
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003887TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003888 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003889 cricket::PORTALLOCATOR_DISABLE_STUN |
3890 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3891 cricket::PORTALLOCATOR_DISABLE_RELAY);
3892
3893 // best connection is IPv6 since it has higher network preference.
3894 LoopbackNetworkConfiguration config;
3895 config.test_ipv6_network_ = true;
3896 config.best_connection_after_initial_ice_converged_ =
3897 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3898
3899 TestLoopbackCall(config);
3900}
3901
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003902// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003903TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003904 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3905 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003906 TestLoopbackCall();
3907}
3908
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003909TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003910 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003911 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003912 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003913 ASSERT_TRUE(data_engine_);
deadbeef953c2ce2017-01-09 14:53:41 -08003914 EXPECT_NE(nullptr, data_engine_->GetChannel(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003915}
3916
Henrik Boström87713d02015-08-25 09:53:21 +02003917TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
htaa2a49d92016-03-04 02:51:39 -08003918 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003919 options_.disable_sctp_data_channels = false;
3920
Henrik Boström87713d02015-08-25 09:53:21 +02003921 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003922
3923 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003924 EXPECT_NE(nullptr, data_engine_->GetChannel(0));
3925}
3926
3927// Test that sctp_content_name/sctp_transport_name (used for stats) are correct
3928// before and after BUNDLE is negotiated.
3929TEST_P(WebRtcSessionTest, SctpContentAndTransportName) {
deadbeef953c2ce2017-01-09 14:53:41 -08003930 SetFactoryDtlsSrtp();
3931 InitWithDtls(GetParam());
3932
3933 // Initially these fields should be empty.
3934 EXPECT_FALSE(session_->sctp_content_name());
3935 EXPECT_FALSE(session_->sctp_transport_name());
3936
3937 // Create offer with audio/video/data.
3938 // Default bundle policy is "balanced", so data should be using its own
3939 // transport.
3940 SendAudioVideoStream1();
3941 CreateDataChannel();
3942 InitiateCall();
3943 ASSERT_TRUE(session_->sctp_content_name());
3944 ASSERT_TRUE(session_->sctp_transport_name());
3945 EXPECT_EQ("data", *session_->sctp_content_name());
3946 EXPECT_EQ("data", *session_->sctp_transport_name());
3947
3948 // Create answer that finishes BUNDLE negotiation, which means everything
3949 // should be bundled on the first transport (audio).
3950 cricket::MediaSessionOptions answer_options;
3951 answer_options.recv_video = true;
3952 answer_options.bundle_enabled = true;
3953 answer_options.data_channel_type = cricket::DCT_SCTP;
3954 SetRemoteDescriptionWithoutError(CreateRemoteAnswer(
3955 session_->local_description(), answer_options, cricket::SEC_DISABLED));
3956 ASSERT_TRUE(session_->sctp_content_name());
3957 ASSERT_TRUE(session_->sctp_transport_name());
3958 EXPECT_EQ("data", *session_->sctp_content_name());
3959 EXPECT_EQ("audio", *session_->sctp_transport_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003960}
3961
Henrik Boström87713d02015-08-25 09:53:21 +02003962TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
Henrik Boström87713d02015-08-25 09:53:21 +02003963 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003964
kwibergd1fe2812016-04-27 06:47:29 -07003965 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003966 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003967 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3968}
3969
Henrik Boström87713d02015-08-25 09:53:21 +02003970TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003971 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003972 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003973
3974 // Create remote offer with SCTP.
3975 cricket::MediaSessionOptions options;
3976 options.data_channel_type = cricket::DCT_SCTP;
3977 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003978 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003979 SetRemoteDescriptionWithoutError(offer);
3980
3981 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07003982 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003983 EXPECT_TRUE(answer != NULL);
3984 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3985 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003986}
3987
deadbeef953c2ce2017-01-09 14:53:41 -08003988// Test that if DTLS is disabled, we don't end up with an SctpTransport
3989// created (or an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02003990TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003991 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003992 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003993
3994 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003995 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
3996 EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003997}
3998
deadbeef953c2ce2017-01-09 14:53:41 -08003999// Test that if DTLS is enabled, we end up with an SctpTransport created
4000// (and not an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02004001TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
Henrik Boström87713d02015-08-25 09:53:21 +02004002 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004003
4004 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004005 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4006 EXPECT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004007}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004008
deadbeef953c2ce2017-01-09 14:53:41 -08004009// Test that if SCTP is disabled, we don't end up with an SctpTransport
4010// created (or an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02004011TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00004012 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02004013 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00004014
4015 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004016 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4017 EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
wu@webrtc.org97077a32013-10-25 21:18:33 +00004018}
4019
Henrik Boström87713d02015-08-25 09:53:21 +02004020TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004021 const int new_send_port = 9998;
4022 const int new_recv_port = 7775;
4023
Henrik Boström87713d02015-08-25 09:53:21 +02004024 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004025 SetFactoryDtlsSrtp();
4026
4027 // By default, don't actually add the codecs to desc_factory_; they don't
4028 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
4029 // let the session description get parsed. That'll get the proper codecs
4030 // into the stream.
4031 cricket::MediaSessionOptions options;
4032 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
4033 "stream1", new_send_port, options);
4034
4035 // SetRemoteDescription will take the ownership of the offer.
4036 SetRemoteDescriptionWithoutError(offer);
4037
htaa2a49d92016-03-04 02:51:39 -08004038 SessionDescriptionInterface* answer =
4039 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004040 ASSERT_TRUE(answer != NULL);
4041
4042 // Now set the local description, which'll take ownership of the answer.
4043 SetLocalDescriptionWithoutError(answer);
4044
4045 // TEST PLAN: Set the port number to something new, set it in the SDP,
4046 // and pass it all the way down.
deadbeef953c2ce2017-01-09 14:53:41 -08004047 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
deadbeefab9b2d12015-10-14 11:33:11 -07004048 CreateDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004049 ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
4050 EXPECT_EQ(
4051 new_recv_port,
4052 fake_sctp_transport_factory_->last_fake_sctp_transport()->local_port());
4053 EXPECT_EQ(
4054 new_send_port,
4055 fake_sctp_transport_factory_->last_fake_sctp_transport()->remote_port());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004056}
4057
deadbeef953c2ce2017-01-09 14:53:41 -08004058// Verifies that when a session's SctpTransport receives an OPEN message,
4059// WebRtcSession signals the SctpTransport creation request with the expected
deadbeefab9b2d12015-10-14 11:33:11 -07004060// config.
4061TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
deadbeefab9b2d12015-10-14 11:33:11 -07004062 InitWithDtls(GetParam());
4063
4064 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004065 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4066 ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
deadbeefab9b2d12015-10-14 11:33:11 -07004067
deadbeef953c2ce2017-01-09 14:53:41 -08004068 // Make the fake SCTP transport pretend it received an OPEN message.
deadbeefab9b2d12015-10-14 11:33:11 -07004069 webrtc::DataChannelInit config;
4070 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07004071 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07004072 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4073 cricket::ReceiveDataParams params;
4074 params.ssrc = config.id;
4075 params.type = cricket::DMT_CONTROL;
deadbeef953c2ce2017-01-09 14:53:41 -08004076 fake_sctp_transport_factory_->last_fake_sctp_transport()->SignalDataReceived(
4077 params, payload);
deadbeefab9b2d12015-10-14 11:33:11 -07004078
deadbeef953c2ce2017-01-09 14:53:41 -08004079 EXPECT_EQ_WAIT("a", last_data_channel_label_, kDefaultTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07004080 EXPECT_EQ(config.id, last_data_channel_config_.id);
4081 EXPECT_FALSE(last_data_channel_config_.negotiated);
4082 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4083 last_data_channel_config_.open_handshake_role);
4084}
4085
4086TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004087 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
Henrik Boströmd79599d2016-06-01 13:58:50 +02004088 FakeRTCCertificateGenerator::GenerateCertificate();
Henrik Boströmd8281982015-08-27 10:12:24 +02004089
htaa2a49d92016-03-04 02:51:39 -08004090 configuration_.certificates.push_back(certificate);
4091 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004092 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4093
4094 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4095}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004096
Henrik Boström87713d02015-08-25 09:53:21 +02004097// Verifies that CreateOffer succeeds when CreateOffer is called before async
4098// identity generation is finished (even if a certificate is provided this is
4099// an async op).
4100TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004101 InitWithDtls(GetParam());
4102
Henrik Boströmd8281982015-08-27 10:12:24 +02004103 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004104 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07004105 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004106
wu@webrtc.org91053e72013-08-10 07:18:04 +00004107 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004108 VerifyNoCryptoParams(offer->description(), true);
4109 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004110}
4111
4112// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004113// identity generation is finished (even if a certificate is provided this is
4114// an async op).
4115TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004116 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004117 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004118
4119 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004120 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07004121 std::unique_ptr<JsepSessionDescription> offer(
4122 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004123 ASSERT_TRUE(offer.get() != NULL);
4124 SetRemoteDescriptionWithoutError(offer.release());
4125
kwibergd1fe2812016-04-27 06:47:29 -07004126 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004127 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004128 VerifyNoCryptoParams(answer->description(), true);
4129 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004130}
4131
4132// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004133// identity generation is finished (even if a certificate is provided this is
4134// an async op).
4135TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
Henrik Boström87713d02015-08-25 09:53:21 +02004136 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004137
Henrik Boströmd8281982015-08-27 10:12:24 +02004138 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004139
kwibergd1fe2812016-04-27 06:47:29 -07004140 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004141 EXPECT_TRUE(offer != NULL);
4142}
4143
4144// Verifies that CreateOffer fails when CreateOffer is called after async
4145// identity generation fails.
4146TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004147 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004148
Henrik Boströmd8281982015-08-27 10:12:24 +02004149 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004150
kwibergd1fe2812016-04-27 06:47:29 -07004151 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004152 EXPECT_TRUE(offer == NULL);
4153}
4154
4155// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4156// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004157TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004158 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
deadbeefcbecd352015-09-23 11:50:27 -07004159 VerifyMultipleAsyncCreateDescription(GetParam(),
4160 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004161}
4162
4163// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4164// before async identity generation fails.
4165TEST_F(WebRtcSessionTest,
4166 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004167 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4168 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004169}
4170
4171// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4172// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004173TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004174 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00004175 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004176 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004177}
4178
4179// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4180// before async identity generation fails.
4181TEST_F(WebRtcSessionTest,
4182 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
Henrik Boström87713d02015-08-25 09:53:21 +02004183 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4184 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004185}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004186
4187// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4188// offer has no SDES crypto but only DTLS fingerprint.
4189TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4190 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004191 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004192 // Create a remote offer with secured transport disabled.
4193 cricket::MediaSessionOptions options;
4194 JsepSessionDescription* offer(CreateRemoteOffer(
4195 options, cricket::SEC_DISABLED));
4196 // Adds a DTLS fingerprint to the remote offer.
4197 cricket::SessionDescription* sdp = offer->description();
4198 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4199 ASSERT_TRUE(audio != NULL);
4200 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4201 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004202 rtc::SSLFingerprint::CreateFromRfc4572(
4203 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004204 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004205 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004206}
4207
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004208TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004209 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004210 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004211 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004212 SessionDescriptionInterface* offer = CreateOffer();
4213
4214 SetLocalDescriptionWithoutError(offer);
4215
4216 voice_channel_ = media_engine_->GetVoiceChannel(0);
4217
4218 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004219 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004220 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004221}
4222
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004223// Tests that we can renegotiate new media content with ICE candidates in the
4224// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004225TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
Henrik Boström87713d02015-08-25 09:53:21 +02004226 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004227 SetFactoryDtlsSrtp();
4228
deadbeefab9b2d12015-10-14 11:33:11 -07004229 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004230 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004231 SetLocalDescriptionWithoutError(offer);
4232
4233 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4234 SetRemoteDescriptionWithoutError(answer);
4235
4236 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004237 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004238 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4239
4240 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004241 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004242 candidate1.set_component(1);
4243 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4244 candidate1);
4245 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4246 SetRemoteDescriptionWithoutError(offer);
4247
htaa2a49d92016-03-04 02:51:39 -08004248 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004249 SetLocalDescriptionWithoutError(answer);
4250}
4251
4252// Tests that we can renegotiate new media content with ICE candidates separated
4253// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004254TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
Henrik Boström87713d02015-08-25 09:53:21 +02004255 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004256 SetFactoryDtlsSrtp();
4257
deadbeefab9b2d12015-10-14 11:33:11 -07004258 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004259 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004260 SetLocalDescriptionWithoutError(offer);
4261
4262 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4263 SetRemoteDescriptionWithoutError(answer);
4264
4265 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004266 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004267 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4268 SetRemoteDescriptionWithoutError(offer);
4269
4270 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004271 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004272 candidate1.set_component(1);
4273 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4274 candidate1);
4275 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4276
htaa2a49d92016-03-04 02:51:39 -08004277 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004278 SetLocalDescriptionWithoutError(answer);
4279}
honghaiz7f777492016-02-02 21:54:01 -08004280
zhihuang9763d562016-08-05 11:14:50 -07004281#ifdef HAVE_QUIC
4282TEST_P(WebRtcSessionTest, TestNegotiateQuic) {
4283 configuration_.enable_quic = true;
4284 InitWithDtls(GetParam());
4285 EXPECT_TRUE(session_->data_channel_type() == cricket::DCT_QUIC);
4286 SessionDescriptionInterface* offer = CreateOffer();
4287 ASSERT_TRUE(offer);
4288 ASSERT_TRUE(offer->description());
4289 SetLocalDescriptionWithoutError(offer);
4290 cricket::MediaSessionOptions options;
4291 options.recv_audio = true;
4292 options.recv_video = true;
4293 SessionDescriptionInterface* answer =
4294 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
4295 ASSERT_TRUE(answer);
4296 ASSERT_TRUE(answer->description());
4297 SetRemoteDescriptionWithoutError(answer);
4298}
4299#endif // HAVE_QUIC
4300
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004301// Tests that RTX codec is removed from the answer when it isn't supported
4302// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004303TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004304 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004305 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004306 std::string offer_sdp(kSdpWithRtx);
4307
4308 SessionDescriptionInterface* offer =
4309 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4310 EXPECT_TRUE(offer->ToString(&offer_sdp));
4311
4312 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004313 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004314 SetRemoteDescriptionWithoutError(offer);
4315
htaa2a49d92016-03-04 02:51:39 -08004316 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004317 // Answer SDP does not contain the RTX codec.
4318 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004319 SetLocalDescriptionWithoutError(answer);
4320}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004321
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004322// This verifies that the voice channel after bundle has both options from video
4323// and voice channels.
4324TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4325 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004326 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004327
4328 PeerConnectionInterface::RTCOfferAnswerOptions options;
4329 options.use_rtp_mux = true;
4330
4331 SessionDescriptionInterface* offer = CreateOffer(options);
4332 SetLocalDescriptionWithoutError(offer);
4333
4334 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4335 rtc::Socket::Option::OPT_SNDBUF, 4000);
4336
4337 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4338 rtc::Socket::Option::OPT_RCVBUF, 8000);
4339
4340 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004341 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004342 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4343 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004344 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004345 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4346
deadbeefcbecd352015-09-23 11:50:27 -07004347 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004348 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4349 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004350 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004351 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4352
deadbeefcbecd352015-09-23 11:50:27 -07004353 EXPECT_NE(session_->voice_rtp_transport_channel(),
4354 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004355
deadbeefab9b2d12015-10-14 11:33:11 -07004356 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004357 SessionDescriptionInterface* answer =
4358 CreateRemoteAnswer(session_->local_description());
4359 SetRemoteDescriptionWithoutError(answer);
4360
deadbeefcbecd352015-09-23 11:50:27 -07004361 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004362 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4363 EXPECT_EQ(4000, option_val);
4364
deadbeefcbecd352015-09-23 11:50:27 -07004365 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004366 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4367 EXPECT_EQ(8000, option_val);
4368}
4369
tommi0f620f42015-07-09 03:25:02 -07004370// Test creating a session, request multiple offers, destroy the session
4371// and make sure we got success/failure callbacks for all of the requests.
4372// Background: crbug.com/507307
4373TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4374 Init();
4375
4376 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4377 PeerConnectionInterface::RTCOfferAnswerOptions options;
4378 options.offer_to_receive_audio =
4379 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004380 cricket::MediaSessionOptions session_options;
4381 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004382
4383 for (auto& o : observers) {
4384 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004385 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004386 }
4387
4388 session_.reset();
4389
tommi0f620f42015-07-09 03:25:02 -07004390 for (auto& o : observers) {
4391 // We expect to have received a notification now even if the session was
4392 // terminated. The offer creation may or may not have succeeded, but we
4393 // must have received a notification which, so the only invalid state
4394 // is kInit.
4395 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4396 }
4397}
4398
stefanc1aeaf02015-10-15 07:26:07 -07004399TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4400 TestPacketOptions();
4401}
4402
deadbeef057ecf02016-01-20 14:30:43 -08004403// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4404// is destroyed.
4405TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4406 Init();
4407 session_.reset();
4408 EXPECT_TRUE(session_destroyed_);
4409}
4410
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004411// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4412// currently fails because upon disconnection and reconnection OnIceComplete is
4413// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004414
deadbeefcbecd352015-09-23 11:50:27 -07004415INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4416 WebRtcSessionTest,
4417 testing::Values(ALREADY_GENERATED,
4418 DTLS_IDENTITY_STORE));