blob: 7c26d1db57b3a8c44cd54d5fd30379af9d92ff87 [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"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000026#include "webrtc/base/fakenetwork.h"
27#include "webrtc/base/firewallsocketserver.h"
28#include "webrtc/base/gunit.h"
29#include "webrtc/base/logging.h"
30#include "webrtc/base/network.h"
31#include "webrtc/base/physicalsocketserver.h"
32#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020033#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000034#include "webrtc/base/sslstreamadapter.h"
35#include "webrtc/base/stringutils.h"
36#include "webrtc/base/thread.h"
37#include "webrtc/base/virtualsocketserver.h"
skvlad11a9cbf2016-10-07 11:53:05 -070038#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
kjellandera96e2d72016-02-04 23:52:28 -080039#include "webrtc/media/base/fakemediaengine.h"
40#include "webrtc/media/base/fakevideorenderer.h"
41#include "webrtc/media/base/mediachannel.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010042#include "webrtc/media/engine/fakewebrtccall.h"
deadbeef953c2ce2017-01-09 14:53:41 -080043#include "webrtc/media/sctp/sctptransportinternal.h"
johan669d69b2016-11-08 14:14:08 -080044#include "webrtc/p2p/base/packettransportinterface.h"
kjellandera96e2d72016-02-04 23:52:28 -080045#include "webrtc/p2p/base/stunserver.h"
46#include "webrtc/p2p/base/teststunserver.h"
47#include "webrtc/p2p/base/testturnserver.h"
48#include "webrtc/p2p/base/transportchannel.h"
49#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
53#define MAYBE_SKIP_TEST(feature) \
54 if (!(feature())) { \
55 LOG(LS_INFO) << "Feature disabled... skipping"; \
56 return; \
57 }
58
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000061using rtc::SocketAddress;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000062using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000064using webrtc::CreateSessionDescriptionObserver;
65using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070066using webrtc::DataChannel;
jbauchac8869e2015-07-03 01:36:14 -070067using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070069using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070using webrtc::JsepIceCandidate;
71using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000072using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073using webrtc::PeerConnectionInterface;
74using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070075using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000077using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000078using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000079using webrtc::kCreateChannelFailed;
80using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000082using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000083using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000084using webrtc::kSdpWithoutDtlsFingerprint;
85using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000087using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000088using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +000090typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
91
wu@webrtc.org364f2042013-11-20 21:49:41 +000092static const int kClientAddrPort = 0;
93static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +000094static const char kClientIPv6AddrHost1[] =
95 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +000096static const char kClientAddrHost2[] = "22.22.22.22";
97static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +000098static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
99static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000100static const char kTurnUsername[] = "test";
101static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102
103static const char kSessionVersion[] = "1";
104
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105// Media index of candidates belonging to the first media content.
106static const int kMediaContentIndex0 = 0;
107static const char kMediaContentName0[] = "audio";
108
109// Media index of candidates belonging to the second media content.
110static const int kMediaContentIndex1 = 1;
111static const char kMediaContentName1[] = "video";
112
deadbeef953c2ce2017-01-09 14:53:41 -0800113static const int kDefaultTimeout = 10000; // 10 seconds.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000114static const int kIceCandidatesTimeout = 10000;
deadbeeff5f03e82016-06-06 11:16:06 -0700115// STUN timeout with all retransmissions is a total of 9500ms.
116static const int kStunTimeout = 9500;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000117
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000118static const char kFakeDtlsFingerprint[] =
119 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
120 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
121
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000122static const char kTooLongIceUfragPwd[] =
123 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
124 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
125 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
126 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
127
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000128static const char kSdpWithRtx[] =
129 "v=0\r\n"
130 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
131 "s=-\r\n"
132 "t=0 0\r\n"
133 "a=msid-semantic: WMS stream1\r\n"
134 "m=video 9 RTP/SAVPF 0 96\r\n"
135 "c=IN IP4 0.0.0.0\r\n"
136 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
137 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
138 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
139 "a=mid:video\r\n"
140 "a=sendrecv\r\n"
141 "a=rtcp-mux\r\n"
142 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
143 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
144 "a=rtpmap:0 fake_video_codec/90000\r\n"
145 "a=rtpmap:96 rtx/90000\r\n"
146 "a=fmtp:96 apt=0\r\n";
147
deadbeefab9b2d12015-10-14 11:33:11 -0700148static const char kStream1[] = "stream1";
149static const char kVideoTrack1[] = "video1";
150static const char kAudioTrack1[] = "audio1";
151
152static const char kStream2[] = "stream2";
153static const char kVideoTrack2[] = "video2";
154static const char kAudioTrack2[] = "audio2";
155
Henrik Boström87713d02015-08-25 09:53:21 +0200156enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
157
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000158class MockIceObserver : public webrtc::IceObserver {
159 public:
160 MockIceObserver()
161 : oncandidatesready_(false),
162 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
163 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
164 }
165
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200166 virtual ~MockIceObserver() = default;
167
perkjdfb769d2016-02-09 03:09:43 -0800168 void OnIceConnectionChange(
169 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000170 ice_connection_state_ = new_state;
skvlad6c87a672016-05-17 17:49:52 -0700171 ice_connection_state_history_.push_back(new_state);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000172 }
perkjdfb769d2016-02-09 03:09:43 -0800173 void OnIceGatheringChange(
174 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000175 // We can never transition back to "new".
176 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
177 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800178 oncandidatesready_ =
179 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000180 }
181
182 // Found a new candidate.
perkjdfb769d2016-02-09 03:09:43 -0800183 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000184 switch (candidate->sdp_mline_index()) {
185 case kMediaContentIndex0:
186 mline_0_candidates_.push_back(candidate->candidate());
187 break;
188 case kMediaContentIndex1:
189 mline_1_candidates_.push_back(candidate->candidate());
190 break;
191 default:
192 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000193 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000194
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000195 // The ICE gathering state should always be Gathering when a candidate is
196 // received (or possibly Completed in the case of the final candidate).
197 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
198 }
199
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700200 // Some local candidates are removed.
201 void OnIceCandidatesRemoved(
nisseef8b61e2016-04-29 06:09:15 -0700202 const std::vector<cricket::Candidate>& candidates) override {
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700203 num_candidates_removed_ += candidates.size();
204 }
205
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000206 bool oncandidatesready_;
207 std::vector<cricket::Candidate> mline_0_candidates_;
208 std::vector<cricket::Candidate> mline_1_candidates_;
209 PeerConnectionInterface::IceConnectionState ice_connection_state_;
210 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
skvlad6c87a672016-05-17 17:49:52 -0700211 std::vector<PeerConnectionInterface::IceConnectionState>
212 ice_connection_state_history_;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700213 size_t num_candidates_removed_ = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000214};
215
deadbeef953c2ce2017-01-09 14:53:41 -0800216// Used for tests in this file to verify that WebRtcSession responds to signals
217// from the SctpTransport correctly, and calls Start with the correct
218// local/remote ports.
219class FakeSctpTransport : public cricket::SctpTransportInternal {
220 public:
221 void SetTransportChannel(cricket::TransportChannel* channel) override {}
222 bool Start(int local_port, int remote_port) override {
223 local_port_ = local_port;
224 remote_port_ = remote_port;
225 return true;
226 }
227 bool OpenStream(int sid) override { return true; }
228 bool ResetStream(int sid) override { return true; }
229 bool SendData(const cricket::SendDataParams& params,
230 const rtc::CopyOnWriteBuffer& payload,
231 cricket::SendDataResult* result = nullptr) override {
232 return true;
233 }
234 bool ReadyToSendData() override { return true; }
235 void set_debug_name_for_testing(const char* debug_name) override {}
236
237 int local_port() const { return local_port_; }
238 int remote_port() const { return remote_port_; }
239
240 private:
241 int local_port_ = -1;
242 int remote_port_ = -1;
243};
244
245class FakeSctpTransportFactory : public cricket::SctpTransportInternalFactory {
246 public:
247 std::unique_ptr<cricket::SctpTransportInternal> CreateSctpTransport(
248 cricket::TransportChannel*) override {
249 last_fake_sctp_transport_ = new FakeSctpTransport();
250 return std::unique_ptr<cricket::SctpTransportInternal>(
251 last_fake_sctp_transport_);
252 }
253
254 FakeSctpTransport* last_fake_sctp_transport() {
255 return last_fake_sctp_transport_;
256 }
257
258 private:
259 FakeSctpTransport* last_fake_sctp_transport_ = nullptr;
260};
261
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000262class WebRtcSessionForTest : public webrtc::WebRtcSession {
263 public:
zhihuang29ff8442016-07-27 11:07:25 -0700264 WebRtcSessionForTest(
265 webrtc::MediaControllerInterface* media_controller,
266 rtc::Thread* network_thread,
267 rtc::Thread* worker_thread,
268 rtc::Thread* signaling_thread,
269 cricket::PortAllocator* port_allocator,
270 webrtc::IceObserver* ice_observer,
deadbeef953c2ce2017-01-09 14:53:41 -0800271 std::unique_ptr<cricket::TransportController> transport_controller,
272 std::unique_ptr<FakeSctpTransportFactory> sctp_factory)
stefanc1aeaf02015-10-15 07:26:07 -0700273 : WebRtcSession(media_controller,
danilchape9021a32016-05-17 01:52:02 -0700274 network_thread,
stefanc1aeaf02015-10-15 07:26:07 -0700275 worker_thread,
danilchape9021a32016-05-17 01:52:02 -0700276 signaling_thread,
zhihuang29ff8442016-07-27 11:07:25 -0700277 port_allocator,
deadbeef953c2ce2017-01-09 14:53:41 -0800278 std::move(transport_controller),
279 std::move(sctp_factory)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000280 RegisterIceObserver(ice_observer);
281 }
282 virtual ~WebRtcSessionForTest() {}
283
deadbeefcbecd352015-09-23 11:50:27 -0700284 // Note that these methods are only safe to use if the signaling thread
285 // is the same as the worker thread
johan669d69b2016-11-08 14:14:08 -0800286 rtc::PacketTransportInterface* voice_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700287 return rtp_transport_channel(voice_channel());
288 }
289
johan669d69b2016-11-08 14:14:08 -0800290 rtc::PacketTransportInterface* voice_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700291 return rtcp_transport_channel(voice_channel());
292 }
293
johan669d69b2016-11-08 14:14:08 -0800294 rtc::PacketTransportInterface* video_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700295 return rtp_transport_channel(video_channel());
296 }
297
johan669d69b2016-11-08 14:14:08 -0800298 rtc::PacketTransportInterface* video_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700299 return rtcp_transport_channel(video_channel());
300 }
301
deadbeefcbecd352015-09-23 11:50:27 -0700302 private:
johan669d69b2016-11-08 14:14:08 -0800303 rtc::PacketTransportInterface* rtp_transport_channel(
304 cricket::BaseChannel* ch) {
deadbeefcbecd352015-09-23 11:50:27 -0700305 if (!ch) {
306 return nullptr;
307 }
308 return ch->transport_channel();
309 }
310
johan669d69b2016-11-08 14:14:08 -0800311 rtc::PacketTransportInterface* rtcp_transport_channel(
312 cricket::BaseChannel* ch) {
deadbeefcbecd352015-09-23 11:50:27 -0700313 if (!ch) {
314 return nullptr;
315 }
316 return ch->rtcp_transport_channel();
317 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000318};
319
wu@webrtc.org91053e72013-08-10 07:18:04 +0000320class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000321 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000323 enum State {
324 kInit,
325 kFailed,
326 kSucceeded,
327 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000328 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000329
330 // CreateSessionDescriptionObserver implementation.
331 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000332 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000333 state_ = kSucceeded;
334 }
335 virtual void OnFailure(const std::string& error) {
336 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000337 }
338
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000339 SessionDescriptionInterface* description() { return description_.get(); }
340
341 SessionDescriptionInterface* ReleaseDescription() {
342 return description_.release();
343 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000344
wu@webrtc.org91053e72013-08-10 07:18:04 +0000345 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000346
wu@webrtc.org91053e72013-08-10 07:18:04 +0000347 protected:
348 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349
350 private:
kwibergd1fe2812016-04-27 06:47:29 -0700351 std::unique_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000352 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353};
354
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800355class FakeAudioSource : public cricket::AudioSource {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000356 public:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800357 FakeAudioSource() : sink_(NULL) {}
358 virtual ~FakeAudioSource() {
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000359 if (sink_)
360 sink_->OnClose();
361 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000362
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000363 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000364
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800365 const cricket::AudioSource::Sink* sink() const { return sink_; }
366
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000367 private:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800368 cricket::AudioSource::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000369};
370
Henrik Boström87713d02015-08-25 09:53:21 +0200371class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700372 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
373 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000374 protected:
375 // TODO Investigate why ChannelManager crashes, if it's created
376 // after stun_server.
377 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700378 : media_engine_(new cricket::FakeMediaEngine()),
379 data_engine_(new cricket::FakeDataEngine()),
skvlad11a9cbf2016-10-07 11:53:05 -0700380 channel_manager_(new cricket::ChannelManager(media_engine_,
381 data_engine_,
382 rtc::Thread::Current())),
383 fake_call_(webrtc::Call::Config(&event_log_)),
stefanc1aeaf02015-10-15 07:26:07 -0700384 media_controller_(
nisse51542be2016-02-12 02:27:06 -0800385 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
386 rtc::Thread::Current(),
skvlad11a9cbf2016-10-07 11:53:05 -0700387 channel_manager_.get(),
388 &event_log_)),
stefanc1aeaf02015-10-15 07:26:07 -0700389 tdesc_factory_(new cricket::TransportDescriptionFactory()),
390 desc_factory_(
391 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
392 tdesc_factory_.get())),
393 pss_(new rtc::PhysicalSocketServer),
394 vss_(new rtc::VirtualSocketServer(pss_.get())),
395 fss_(new rtc::FirewallSocketServer(vss_.get())),
396 ss_scope_(fss_.get()),
397 stun_socket_addr_(
398 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
399 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
400 stun_socket_addr_)),
401 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
402 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000403 cricket::ServerAddresses stun_servers;
404 stun_servers.insert(stun_socket_addr_);
405 allocator_.reset(new cricket::BasicPortAllocator(
406 &network_manager_,
407 stun_servers,
408 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000409 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700410 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000411 EXPECT_TRUE(channel_manager_->Init());
412 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000413 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000414 }
415
416 void AddInterface(const SocketAddress& addr) {
417 network_manager_.AddInterface(addr);
418 }
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700419 void RemoveInterface(const SocketAddress& addr) {
420 network_manager_.RemoveInterface(addr);
421 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000422
Henrik Boströmd79599d2016-06-01 13:58:50 +0200423 // If |cert_generator| != null or |rtc_configuration| contains |certificates|
424 // then DTLS will be enabled unless explicitly disabled by |rtc_configuration|
425 // options. When DTLS is enabled a certificate will be used if provided,
426 // otherwise one will be generated using the |cert_generator|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000427 void Init(
zhihuang4dfb8ce2016-11-23 10:30:12 -0800428 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
429 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000430 ASSERT_TRUE(session_.get() == NULL);
deadbeef953c2ce2017-01-09 14:53:41 -0800431 fake_sctp_transport_factory_ = new FakeSctpTransportFactory();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000432 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700433 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
zhihuang29ff8442016-07-27 11:07:25 -0700434 rtc::Thread::Current(), allocator_.get(), &observer_,
435 std::unique_ptr<cricket::TransportController>(
436 new cricket::TransportController(rtc::Thread::Current(),
437 rtc::Thread::Current(),
deadbeef953c2ce2017-01-09 14:53:41 -0800438 allocator_.get())),
439 std::unique_ptr<FakeSctpTransportFactory>(
440 fake_sctp_transport_factory_)));
deadbeefab9b2d12015-10-14 11:33:11 -0700441 session_->SignalDataChannelOpenMessage.connect(
442 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
deadbeef057ecf02016-01-20 14:30:43 -0800443 session_->GetOnDestroyedSignal()->connect(
444 this, &WebRtcSessionTest::OnSessionDestroyed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000445
zhihuang4dfb8ce2016-11-23 10:30:12 -0800446 configuration_.rtcp_mux_policy = rtcp_mux_policy;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000447 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
448 observer_.ice_connection_state_);
449 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
450 observer_.ice_gathering_state_);
451
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200452 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator),
htaa2a49d92016-03-04 02:51:39 -0800453 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700454 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000455 }
456
deadbeefab9b2d12015-10-14 11:33:11 -0700457 void OnDataChannelOpenMessage(const std::string& label,
458 const InternalDataChannelInit& config) {
459 last_data_channel_label_ = label;
460 last_data_channel_config_ = config;
461 }
462
deadbeef057ecf02016-01-20 14:30:43 -0800463 void OnSessionDestroyed() { session_destroyed_ = true; }
464
zhihuang4dfb8ce2016-11-23 10:30:12 -0800465 void Init() {
466 Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
467 }
468
469 void Init(PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
470 Init(nullptr, rtcp_mux_policy);
471 }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000472
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000473 void InitWithBundlePolicy(
474 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800475 configuration_.bundle_policy = bundle_policy;
476 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700477 }
478
479 void InitWithRtcpMuxPolicy(
480 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
481 PeerConnectionInterface::RTCConfiguration configuration;
zhihuang4dfb8ce2016-11-23 10:30:12 -0800482 Init(rtcp_mux_policy);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000483 }
484
Henrik Boström87713d02015-08-25 09:53:21 +0200485 // Successfully init with DTLS; with a certificate generated and supplied or
486 // with a store that generates it for us.
487 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200488 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator;
Henrik Boström87713d02015-08-25 09:53:21 +0200489 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800490 configuration_.certificates.push_back(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200491 FakeRTCCertificateGenerator::GenerateCertificate());
Henrik Boström87713d02015-08-25 09:53:21 +0200492 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200493 cert_generator.reset(new FakeRTCCertificateGenerator());
494 cert_generator->set_should_fail(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200495 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700496 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200497 }
zhihuang4dfb8ce2016-11-23 10:30:12 -0800498 Init(std::move(cert_generator),
499 PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
Henrik Boström87713d02015-08-25 09:53:21 +0200500 }
501
502 // Init with DTLS with a store that will fail to generate a certificate.
503 void InitWithDtlsIdentityGenFail() {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200504 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
505 new FakeRTCCertificateGenerator());
506 cert_generator->set_should_fail(true);
zhihuang4dfb8ce2016-11-23 10:30:12 -0800507 Init(std::move(cert_generator),
508 PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000509 }
510
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000511 void InitWithDtmfCodec() {
512 // Add kTelephoneEventCodec for dtmf test.
deadbeef67cf2c12016-04-13 10:07:16 -0700513 const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000,
514 0, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000515 std::vector<cricket::AudioCodec> codecs;
516 codecs.push_back(kTelephoneEventCodec);
517 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -0700518 desc_factory_->set_audio_codecs(codecs, codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000519 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000520 }
521
jbauchcb560652016-08-04 05:20:32 -0700522 void InitWithGcm() {
523 rtc::CryptoOptions crypto_options;
524 crypto_options.enable_gcm_crypto_suites = true;
525 channel_manager_->SetCryptoOptions(crypto_options);
526 with_gcm_ = true;
527 Init();
528 }
529
deadbeefab9b2d12015-10-14 11:33:11 -0700530 void SendAudioVideoStream1() {
531 send_stream_1_ = true;
532 send_stream_2_ = false;
533 send_audio_ = true;
534 send_video_ = true;
535 }
536
537 void SendAudioVideoStream2() {
538 send_stream_1_ = false;
539 send_stream_2_ = true;
540 send_audio_ = true;
541 send_video_ = true;
542 }
543
544 void SendAudioVideoStream1And2() {
545 send_stream_1_ = true;
546 send_stream_2_ = true;
547 send_audio_ = true;
548 send_video_ = true;
549 }
550
551 void SendNothing() {
552 send_stream_1_ = false;
553 send_stream_2_ = false;
554 send_audio_ = false;
555 send_video_ = false;
556 }
557
558 void SendAudioOnlyStream2() {
559 send_stream_1_ = false;
560 send_stream_2_ = true;
561 send_audio_ = true;
562 send_video_ = false;
563 }
564
565 void SendVideoOnlyStream2() {
566 send_stream_1_ = false;
567 send_stream_2_ = true;
568 send_audio_ = false;
569 send_video_ = true;
570 }
571
572 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
573 if (send_stream_1_ && send_audio_) {
574 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
575 kStream1);
576 }
577 if (send_stream_1_ && send_video_) {
578 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
579 kStream1);
580 }
581 if (send_stream_2_ && send_audio_) {
582 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
583 kStream2);
584 }
585 if (send_stream_2_ && send_video_) {
586 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
587 kStream2);
588 }
589 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
590 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
591 data_channel_->label(),
592 data_channel_->label());
593 }
594 }
595
596 void GetOptionsForOffer(
597 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
598 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800599 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700600
deadbeefc80741f2015-10-22 13:14:45 -0700601 AddStreamsToOptions(session_options);
602 if (rtc_options.offer_to_receive_audio ==
603 RTCOfferAnswerOptions::kUndefined) {
604 session_options->recv_audio =
605 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
606 }
607 if (rtc_options.offer_to_receive_video ==
608 RTCOfferAnswerOptions::kUndefined) {
609 session_options->recv_video =
610 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
611 }
612 session_options->bundle_enabled =
613 session_options->bundle_enabled &&
614 (session_options->has_audio() || session_options->has_video() ||
615 session_options->has_data());
616
deadbeefab9b2d12015-10-14 11:33:11 -0700617 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
618 session_options->data_channel_type = cricket::DCT_SCTP;
zhihuang9763d562016-08-05 11:14:50 -0700619 } else if (session_->data_channel_type() == cricket::DCT_QUIC) {
620 session_options->data_channel_type = cricket::DCT_QUIC;
deadbeefab9b2d12015-10-14 11:33:11 -0700621 }
jbauchcb560652016-08-04 05:20:32 -0700622
623 if (with_gcm_) {
624 session_options->crypto_options.enable_gcm_crypto_suites = true;
625 }
deadbeefab9b2d12015-10-14 11:33:11 -0700626 }
627
htaa2a49d92016-03-04 02:51:39 -0800628 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
629 // ParseConstraintsForAnswer is used to set some defaults.
630 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700631
deadbeefc80741f2015-10-22 13:14:45 -0700632 AddStreamsToOptions(session_options);
633 session_options->bundle_enabled =
634 session_options->bundle_enabled &&
635 (session_options->has_audio() || session_options->has_video() ||
636 session_options->has_data());
637
zhihuang9763d562016-08-05 11:14:50 -0700638 if (session_->data_channel_type() != cricket::DCT_RTP) {
639 session_options->data_channel_type = session_->data_channel_type();
deadbeef907abe42016-08-04 12:22:18 -0700640 }
jbauchcb560652016-08-04 05:20:32 -0700641
642 if (with_gcm_) {
643 session_options->crypto_options.enable_gcm_crypto_suites = true;
644 }
deadbeefab9b2d12015-10-14 11:33:11 -0700645 }
646
647 // Creates a local offer and applies it. Starts ICE.
648 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000649 // to decide which streams to create.
650 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000651 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000652 SetLocalDescriptionWithoutError(offer);
653 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
654 observer_.ice_gathering_state_,
655 kIceCandidatesTimeout);
656 }
657
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000658 SessionDescriptionInterface* CreateOffer() {
659 PeerConnectionInterface::RTCOfferAnswerOptions options;
660 options.offer_to_receive_audio =
661 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
662
663 return CreateOffer(options);
664 }
665
wu@webrtc.org91053e72013-08-10 07:18:04 +0000666 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800667 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000668 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000669 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700670 cricket::MediaSessionOptions session_options;
671 GetOptionsForOffer(options, &session_options);
672 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000673 EXPECT_TRUE_WAIT(
674 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000675 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000676 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000677 }
678
679 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800680 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000681 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000682 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800683 cricket::MediaSessionOptions session_options = options;
684 GetOptionsForAnswer(&session_options);
685 // Overwrite recv_audio and recv_video with passed-in values.
686 session_options.recv_video = options.recv_video;
687 session_options.recv_audio = options.recv_audio;
688 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000689 EXPECT_TRUE_WAIT(
690 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000691 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000692 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000693 }
694
htaa2a49d92016-03-04 02:51:39 -0800695 SessionDescriptionInterface* CreateAnswer() {
696 cricket::MediaSessionOptions options;
697 options.recv_video = true;
698 options.recv_audio = true;
699 return CreateAnswer(options);
700 }
701
wu@webrtc.org364f2042013-11-20 21:49:41 +0000702 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000703 return (session_->voice_channel() != NULL &&
704 session_->video_channel() != NULL);
705 }
706
jbauchcb560652016-08-04 05:20:32 -0700707 void VerifyCryptoParams(const cricket::SessionDescription* sdp,
708 bool gcm_enabled = false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000709 ASSERT_TRUE(session_.get() != NULL);
710 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
711 ASSERT_TRUE(content != NULL);
712 const cricket::AudioContentDescription* audio_content =
713 static_cast<const cricket::AudioContentDescription*>(
714 content->description);
715 ASSERT_TRUE(audio_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700716 if (!gcm_enabled) {
717 ASSERT_EQ(1U, audio_content->cryptos().size());
718 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
719 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
720 audio_content->cryptos()[0].cipher_suite);
721 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
722 audio_content->protocol());
723 } else {
724 // The offer contains 3 possible crypto suites, the answer 1.
725 EXPECT_LE(1U, audio_content->cryptos().size());
726 EXPECT_NE(2U, audio_content->cryptos().size());
727 EXPECT_GE(3U, audio_content->cryptos().size());
728 ASSERT_EQ(67U, audio_content->cryptos()[0].key_params.size());
729 ASSERT_EQ("AEAD_AES_256_GCM",
730 audio_content->cryptos()[0].cipher_suite);
731 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
732 audio_content->protocol());
733 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000734
735 content = cricket::GetFirstVideoContent(sdp);
736 ASSERT_TRUE(content != NULL);
737 const cricket::VideoContentDescription* video_content =
738 static_cast<const cricket::VideoContentDescription*>(
739 content->description);
740 ASSERT_TRUE(video_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700741 if (!gcm_enabled) {
742 ASSERT_EQ(1U, video_content->cryptos().size());
743 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
744 video_content->cryptos()[0].cipher_suite);
745 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
746 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
747 video_content->protocol());
748 } else {
749 // The offer contains 3 possible crypto suites, the answer 1.
750 EXPECT_LE(1U, video_content->cryptos().size());
751 EXPECT_NE(2U, video_content->cryptos().size());
752 EXPECT_GE(3U, video_content->cryptos().size());
753 ASSERT_EQ("AEAD_AES_256_GCM",
754 video_content->cryptos()[0].cipher_suite);
755 ASSERT_EQ(67U, video_content->cryptos()[0].key_params.size());
756 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
757 video_content->protocol());
758 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000759 }
760
761 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
762 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
763 ASSERT_TRUE(content != NULL);
764 const cricket::AudioContentDescription* audio_content =
765 static_cast<const cricket::AudioContentDescription*>(
766 content->description);
767 ASSERT_TRUE(audio_content != NULL);
768 ASSERT_EQ(0U, audio_content->cryptos().size());
769
770 content = cricket::GetFirstVideoContent(sdp);
771 ASSERT_TRUE(content != NULL);
772 const cricket::VideoContentDescription* video_content =
773 static_cast<const cricket::VideoContentDescription*>(
774 content->description);
775 ASSERT_TRUE(video_content != NULL);
776 ASSERT_EQ(0U, video_content->cryptos().size());
777
778 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700779 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000780 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700781 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000782 video_content->protocol());
783 } else {
784 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
785 audio_content->protocol());
786 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
787 video_content->protocol());
788 }
789 }
790
791 // Set the internal fake description factories to do DTLS-SRTP.
792 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000793 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000794 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000795 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200796 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800797 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700798 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800799 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000800 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
801 }
802
803 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
804 bool expected) {
805 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
806 ASSERT_TRUE(audio != NULL);
807 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808 const TransportInfo* video = sdp->GetTransportInfoByName("video");
809 ASSERT_TRUE(video != NULL);
810 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000811 }
812
813 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000814 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000816 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000817 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000818 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000819 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000820 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000821 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
822 offer);
htaa2a49d92016-03-04 02:51:39 -0800823 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824 // Answer should be NULL as no crypto params in offer.
825 ASSERT_TRUE(answer == NULL);
826 }
827
828 void VerifyAnswerFromCryptoOffer() {
829 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000830 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000831 options.bundle_enabled = true;
kwibergd1fe2812016-04-27 06:47:29 -0700832 std::unique_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000833 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
834 ASSERT_TRUE(offer.get() != NULL);
835 VerifyCryptoParams(offer->description());
836 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -0700837 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000838 ASSERT_TRUE(answer.get() != NULL);
839 VerifyCryptoParams(answer->description());
840 }
841
deadbeef0ed85b22016-02-23 17:24:52 -0800842 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
843 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800845 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846 }
847
848 const cricket::ContentInfos& contents = desc1->contents();
849 cricket::ContentInfos::const_iterator it = contents.begin();
850
851 for (; it != contents.end(); ++it) {
852 const cricket::TransportDescription* transport_desc1 =
853 desc1->GetTransportDescriptionByName(it->name);
854 const cricket::TransportDescription* transport_desc2 =
855 desc2->GetTransportDescriptionByName(it->name);
856 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800857 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858 }
859 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
860 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800861 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000862 }
863 }
deadbeef0ed85b22016-02-23 17:24:52 -0800864 return true;
865 }
866
867 // Compares ufrag/password only for the specified |media_type|.
868 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
869 const cricket::SessionDescription* desc2,
870 cricket::MediaType media_type) {
871 if (desc1->contents().size() != desc2->contents().size()) {
872 return false;
873 }
874
875 const cricket::ContentInfo* cinfo =
876 cricket::GetFirstMediaContent(desc1->contents(), media_type);
877 const cricket::TransportDescription* transport_desc1 =
878 desc1->GetTransportDescriptionByName(cinfo->name);
879 const cricket::TransportDescription* transport_desc2 =
880 desc2->GetTransportDescriptionByName(cinfo->name);
881 if (!transport_desc1 || !transport_desc2) {
882 return false;
883 }
884 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
885 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
886 return false;
887 }
888 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000890
891 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
892 std::string *sdp) {
893 const cricket::SessionDescription* desc = current_desc->description();
894 EXPECT_TRUE(current_desc->ToString(sdp));
895
896 const cricket::ContentInfos& contents = desc->contents();
897 cricket::ContentInfos::const_iterator it = contents.begin();
898 // Replace ufrag and pwd lines with empty strings.
899 for (; it != contents.end(); ++it) {
900 const cricket::TransportDescription* transport_desc =
901 desc->GetTransportDescriptionByName(it->name);
902 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
903 + "\r\n";
904 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
905 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000906 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000907 "", 0,
908 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000909 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000910 "", 0,
911 sdp);
912 }
913 }
914
deadbeef0ed85b22016-02-23 17:24:52 -0800915 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
916 const std::string& ufrag,
917 const std::string& pwd) {
918 cricket::SessionDescription* desc = current_desc->description();
919 for (TransportInfo& transport_info : desc->transport_infos()) {
920 cricket::TransportDescription& transport_desc =
921 transport_info.description;
922 transport_desc.ice_ufrag = ufrag;
923 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000924 }
925 }
926
deadbeef0ed85b22016-02-23 17:24:52 -0800927 // Sets ufrag/pwd for specified |media_type|.
928 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
929 cricket::MediaType media_type,
930 const std::string& ufrag,
931 const std::string& pwd) {
932 cricket::SessionDescription* desc = current_desc->description();
933 const cricket::ContentInfo* cinfo =
934 cricket::GetFirstMediaContent(desc->contents(), media_type);
935 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
936 cricket::TransportDescription* transport_desc =
937 &transport_info->description;
938 transport_desc->ice_ufrag = ufrag;
939 transport_desc->ice_pwd = pwd;
940 }
941
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000942 // Creates a remote offer and and applies it as a remote description,
943 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700944 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 // to decide which local and remote streams to create.
946 void CreateAndSetRemoteOfferAndLocalAnswer() {
947 SessionDescriptionInterface* offer = CreateRemoteOffer();
948 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800949 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000950 SetLocalDescriptionWithoutError(answer);
951 }
952 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
953 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700954 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955 }
956 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700957 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000958 SetLocalDescriptionWithoutError(desc);
959 EXPECT_EQ(expected_state, session_->state());
960 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000961 void SetLocalDescriptionExpectError(const std::string& action,
962 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000963 SessionDescriptionInterface* desc) {
964 std::string error;
965 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000966 std::string sdp_type = "local ";
967 sdp_type.append(action);
968 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 EXPECT_NE(std::string::npos, error.find(expected_error));
970 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000971 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
972 SessionDescriptionInterface* desc) {
973 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
974 expected_error, desc);
975 }
976 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
977 SessionDescriptionInterface* desc) {
978 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
979 expected_error, desc);
980 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000981 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
982 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
983 }
984 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700985 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000986 SetRemoteDescriptionWithoutError(desc);
987 EXPECT_EQ(expected_state, session_->state());
988 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000989 void SetRemoteDescriptionExpectError(const std::string& action,
990 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991 SessionDescriptionInterface* desc) {
992 std::string error;
993 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000994 std::string sdp_type = "remote ";
995 sdp_type.append(action);
996 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000997 EXPECT_NE(std::string::npos, error.find(expected_error));
998 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000999 void SetRemoteDescriptionOfferExpectError(
1000 const std::string& expected_error, SessionDescriptionInterface* desc) {
1001 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
1002 expected_error, desc);
1003 }
1004 void SetRemoteDescriptionPranswerExpectError(
1005 const std::string& expected_error, SessionDescriptionInterface* desc) {
1006 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
1007 expected_error, desc);
1008 }
1009 void SetRemoteDescriptionAnswerExpectError(
1010 const std::string& expected_error, SessionDescriptionInterface* desc) {
1011 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
1012 expected_error, desc);
1013 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001014
1015 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
1016 SessionDescriptionInterface** nocrypto_answer) {
1017 // Create a SDP without Crypto.
1018 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001019 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001020 options.bundle_enabled = true;
1021 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
1022 ASSERT_TRUE(*offer != NULL);
1023 VerifyCryptoParams((*offer)->description());
1024
1025 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
1026 cricket::SEC_DISABLED);
1027 EXPECT_TRUE(*nocrypto_answer != NULL);
1028 }
1029
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001030 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
1031 SessionDescriptionInterface** nodtls_answer) {
1032 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001033 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001034 options.bundle_enabled = true;
1035
kwibergd1fe2812016-04-27 06:47:29 -07001036 std::unique_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001037 CreateRemoteOffer(options, cricket::SEC_ENABLED));
1038
1039 *nodtls_answer =
1040 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
1041 EXPECT_TRUE(*nodtls_answer != NULL);
1042 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
1043 VerifyCryptoParams((*nodtls_answer)->description());
1044
1045 SetFactoryDtlsSrtp();
1046 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
1047 ASSERT_TRUE(*offer != NULL);
1048 VerifyFingerprintStatus((*offer)->description(), true);
1049 VerifyCryptoParams((*offer)->description());
1050 }
1051
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001052 JsepSessionDescription* CreateRemoteOfferWithVersion(
1053 cricket::MediaSessionOptions options,
1054 cricket::SecurePolicy secure_policy,
1055 const std::string& session_version,
1056 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001057 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001058 const cricket::SessionDescription* cricket_desc = NULL;
1059 if (current_desc) {
1060 cricket_desc = current_desc->description();
1061 session_id = current_desc->session_id();
1062 }
1063
1064 desc_factory_->set_secure(secure_policy);
1065 JsepSessionDescription* offer(
1066 new JsepSessionDescription(JsepSessionDescription::kOffer));
1067 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
1068 session_id, session_version)) {
1069 delete offer;
1070 offer = NULL;
1071 }
1072 return offer;
1073 }
1074 JsepSessionDescription* CreateRemoteOffer(
1075 cricket::MediaSessionOptions options) {
1076 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1077 kSessionVersion, NULL);
1078 }
1079 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001080 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
1081 return CreateRemoteOfferWithVersion(
1082 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001083 }
1084 JsepSessionDescription* CreateRemoteOffer(
1085 cricket::MediaSessionOptions options,
1086 const SessionDescriptionInterface* current_desc) {
1087 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1088 kSessionVersion, current_desc);
1089 }
1090
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001091 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
1092 const char* sctp_stream_name, int new_port,
1093 cricket::MediaSessionOptions options) {
1094 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001095 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
1096 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001097 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
1098 }
1099
1100 // Takes ownership of offer_basis (and deletes it).
1101 JsepSessionDescription* ChangeSDPSctpPort(
1102 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1103 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1104 // SessionDescription from the mutated string.
1105 const char* default_port_str = "5000";
1106 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001107 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001108 std::string offer_str;
1109 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001110 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001111 new_port_str, strlen(new_port_str),
1112 &offer_str);
1113 JsepSessionDescription* offer = new JsepSessionDescription(
1114 offer_basis->type());
1115 delete offer_basis;
1116 offer->Initialize(offer_str, NULL);
1117 return offer;
1118 }
1119
deadbeefab9b2d12015-10-14 11:33:11 -07001120 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001121 // before this function to decide which streams to create.
1122 JsepSessionDescription* CreateRemoteOffer() {
1123 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001124 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001125 return CreateRemoteOffer(options, session_->remote_description());
1126 }
1127
1128 JsepSessionDescription* CreateRemoteAnswer(
1129 const SessionDescriptionInterface* offer,
1130 cricket::MediaSessionOptions options,
1131 cricket::SecurePolicy policy) {
1132 desc_factory_->set_secure(policy);
1133 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001134 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001135 JsepSessionDescription* answer(
1136 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1137 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1138 options, NULL),
1139 session_id, kSessionVersion)) {
1140 delete answer;
1141 answer = NULL;
1142 }
1143 return answer;
1144 }
1145
1146 JsepSessionDescription* CreateRemoteAnswer(
1147 const SessionDescriptionInterface* offer,
1148 cricket::MediaSessionOptions options) {
1149 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1150 }
1151
deadbeefab9b2d12015-10-14 11:33:11 -07001152 // Creates an answer session description.
1153 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001154 // to decide which streams to create.
1155 JsepSessionDescription* CreateRemoteAnswer(
1156 const SessionDescriptionInterface* offer) {
1157 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001158 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001159 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1160 }
1161
1162 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001163 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001164 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001165 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001166
1167 PeerConnectionInterface::RTCOfferAnswerOptions options;
1168 options.use_rtp_mux = bundle;
1169
1170 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001171 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1172 // and answer.
1173 SetLocalDescriptionWithoutError(offer);
1174
kwibergd1fe2812016-04-27 06:47:29 -07001175 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001176 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001177 std::string sdp;
1178 EXPECT_TRUE(answer->ToString(&sdp));
1179
1180 size_t expected_candidate_num = 2;
1181 if (!rtcp_mux) {
1182 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1183 // for rtp and rtcp.
1184 expected_candidate_num = 4;
1185 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001186 const std::string kRtcpMux = "a=rtcp-mux";
1187 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001188 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001189 kXRtcpMux.c_str(), kXRtcpMux.length(),
1190 &sdp);
1191 }
1192
1193 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1194 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001195
1196 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001197 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001198 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1199 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001200 if (bundle) {
1201 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1202 } else {
1203 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001204 }
1205 }
1206 // Tests that we can only send DTMF when the dtmf codec is supported.
1207 void TestCanInsertDtmf(bool can) {
1208 if (can) {
1209 InitWithDtmfCodec();
1210 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001211 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001212 }
deadbeefab9b2d12015-10-14 11:33:11 -07001213 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001214 CreateAndSetRemoteOfferAndLocalAnswer();
1215 EXPECT_FALSE(session_->CanInsertDtmf(""));
1216 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1217 }
1218
zhihuang3a334652016-05-05 18:37:49 -07001219 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1220 const std::string& codec_name) {
1221 for (const auto& content : desc->description()->contents()) {
1222 if (static_cast<cricket::MediaContentDescription*>(content.description)
1223 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1224 const auto* mdesc =
1225 static_cast<cricket::VideoContentDescription*>(content.description);
1226 for (const auto& codec : mdesc->codecs()) {
1227 if (codec.name == codec_name) {
1228 return true;
1229 }
1230 }
1231 }
1232 }
1233 return false;
1234 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001235 // Helper class to configure loopback network and verify Best
1236 // Connection using right IP protocol for TestLoopbackCall
1237 // method. LoopbackNetworkManager applies firewall rules to block
1238 // all ping traffic once ICE completed, and remove them to observe
1239 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1240 // verifies the best connection is using the right IP protocol after
1241 // initial ICE convergences.
1242
1243 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001244 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001245 LoopbackNetworkConfiguration()
1246 : test_ipv6_network_(false),
1247 test_extra_ipv4_network_(false),
1248 best_connection_after_initial_ice_converged_(1, 0) {}
1249
1250 // Used to track the expected best connection count in each IP protocol.
1251 struct ExpectedBestConnection {
1252 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1253 : ipv4_count_(ipv4_count),
1254 ipv6_count_(ipv6_count) {}
1255
1256 int ipv4_count_;
1257 int ipv6_count_;
1258 };
1259
1260 bool test_ipv6_network_;
1261 bool test_extra_ipv4_network_;
1262 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1263
1264 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001265 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001266 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1267 }
1268
1269 private:
jbauchac8869e2015-07-03 01:36:14 -07001270 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001271 const ExpectedBestConnection& expected) const {
1272 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001273 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1274 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001275 expected.ipv4_count_);
1276 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001277 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1278 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001279 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001280 // This is used in the loopback call so there is only single host to host
1281 // candidate pair.
1282 EXPECT_EQ(metrics_observer->GetEnumCounter(
1283 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1284 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001285 0);
1286 EXPECT_EQ(metrics_observer->GetEnumCounter(
1287 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1288 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001289 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001290 }
1291 };
1292
1293 class LoopbackNetworkManager {
1294 public:
1295 LoopbackNetworkManager(WebRtcSessionTest* session,
1296 const LoopbackNetworkConfiguration& config)
1297 : config_(config) {
1298 session->AddInterface(
1299 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1300 if (config_.test_extra_ipv4_network_) {
1301 session->AddInterface(
1302 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1303 }
1304 if (config_.test_ipv6_network_) {
1305 session->AddInterface(
1306 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1307 }
1308 }
1309
1310 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1311 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1312 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1313 if (config_.test_extra_ipv4_network_) {
1314 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1315 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1316 }
1317 if (config_.test_ipv6_network_) {
1318 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1319 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1320 }
1321 }
1322
1323 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1324
1325 private:
1326 LoopbackNetworkConfiguration config_;
1327 };
1328
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001329 // The method sets up a call from the session to itself, in a loopback
1330 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001331 // disconnection, and then a permanent disconnection.
1332 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001333 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1334 // While running the call, this method also checks if the session goes through
1335 // the correct sequence of ICE states when a connection is established,
1336 // broken, and re-established.
1337 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001338 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1339 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001340 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001341
stefanc1aeaf02015-10-15 07:26:07 -07001342 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001343 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001344 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001345 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001346
1347 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1348 observer_.ice_gathering_state_);
1349 SetLocalDescriptionWithoutError(offer);
1350 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1351 observer_.ice_connection_state_);
1352 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001353 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001354 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1355 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001356 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001357
1358 std::string sdp;
1359 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001360 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1361 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001362 ASSERT_TRUE(desc != NULL);
1363 SetRemoteDescriptionWithoutError(desc);
1364
1365 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001366 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001367
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001368 // The ice connection state is "Connected" too briefly to catch in a test.
1369 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001370 observer_.ice_connection_state_, kIceCandidatesTimeout);
1371 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001372
stefanc1aeaf02015-10-15 07:26:07 -07001373 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1374 LoopbackNetworkManager loopback_network_manager(this, config);
1375 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001376 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001377 // Adding firewall rule to block ping requests, which should cause
1378 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001379
1380 loopback_network_manager.ApplyFirewallRules(fss_.get());
1381
1382 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001383 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1384 observer_.ice_connection_state_,
1385 kIceCandidatesTimeout);
1386
jbauchac8869e2015-07-03 01:36:14 -07001387 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001388
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001389 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001390 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001391
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001392 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001393 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001394 observer_.ice_connection_state_,
1395 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001396
1397 // Now we block ping requests and wait until the ICE connection transitions
1398 // to the Failed state. This will take at least 30 seconds because it must
1399 // wait for the Port to timeout.
1400 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001401
1402 loopback_network_manager.ApplyFirewallRules(fss_.get());
1403 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001404 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001405 observer_.ice_connection_state_,
1406 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001407 }
1408
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001409 void TestLoopbackCall() {
1410 LoopbackNetworkConfiguration config;
1411 TestLoopbackCall(config);
1412 }
1413
stefanc1aeaf02015-10-15 07:26:07 -07001414 void TestPacketOptions() {
1415 media_controller_.reset(
1416 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1417 LoopbackNetworkConfiguration config;
1418 LoopbackNetworkManager loopback_network_manager(this, config);
1419
1420 SetupLoopbackCall();
1421
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001422 // Wait for channel to be ready for sending.
1423 EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
stefanc1aeaf02015-10-15 07:26:07 -07001424 uint8_t test_packet[15] = {0};
1425 rtc::PacketOptions options;
1426 options.packet_id = 10;
1427 media_engine_->GetVideoChannel(0)
1428 ->SendRtp(test_packet, sizeof(test_packet), options);
1429
1430 const int kPacketTimeout = 2000;
deadbeef14461d42016-06-15 11:06:57 -07001431 EXPECT_EQ_WAIT(10, fake_call_.last_sent_nonnegative_packet_id(),
1432 kPacketTimeout);
stefanc1aeaf02015-10-15 07:26:07 -07001433 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1434 }
1435
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001436 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1437 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001438 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1439 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001440
1441 // Add kCNCodec for dtmf test.
ossudedfd282016-06-14 07:12:39 -07001442 std::vector<cricket::AudioCodec> codecs =
1443 media_engine_->audio_send_codecs();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001444 codecs.push_back(kCNCodec1);
1445 codecs.push_back(kCNCodec2);
1446 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -07001447 desc_factory_->set_audio_codecs(codecs, codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001448 }
1449
1450 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1451 const cricket::ContentDescription* description = content->description;
1452 ASSERT(description != NULL);
1453 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001454 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001455 ASSERT(audio_content_desc != NULL);
1456 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1457 if (audio_content_desc->codecs()[i].name == "CN")
1458 return false;
1459 }
1460 return true;
1461 }
1462
deadbeefab9b2d12015-10-14 11:33:11 -07001463 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001464 webrtc::InternalDataChannelInit dci;
htaa2a49d92016-03-04 02:51:39 -08001465 ASSERT(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001466 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1467 data_channel_ = DataChannel::Create(
1468 session_.get(), session_->data_channel_type(), "datachannel", dci);
1469 }
1470
1471 void SetLocalDescriptionWithDataChannel() {
1472 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001473 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001474 SetLocalDescriptionWithoutError(offer);
1475 }
1476
wu@webrtc.org91053e72013-08-10 07:18:04 +00001477 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001478 RTCCertificateGenerationMethod cert_gen_method,
1479 CreateSessionDescriptionRequest::Type type) {
1480 InitWithDtls(cert_gen_method);
1481 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1482 }
1483
1484 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1485 CreateSessionDescriptionRequest::Type type) {
1486 InitWithDtlsIdentityGenFail();
1487 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1488 }
1489
1490 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001491 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001492 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001493 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001494 if (type == CreateSessionDescriptionRequest::kAnswer) {
1495 cricket::MediaSessionOptions options;
kwibergd1fe2812016-04-27 06:47:29 -07001496 std::unique_ptr<JsepSessionDescription> offer(
1497 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001498 ASSERT_TRUE(offer.get() != NULL);
1499 SetRemoteDescriptionWithoutError(offer.release());
1500 }
1501
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001502 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001503 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001504 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001505 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001506 observers[kNumber];
1507 for (int i = 0; i < kNumber; ++i) {
1508 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1509 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001510 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001511 } else {
htaa2a49d92016-03-04 02:51:39 -08001512 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001513 }
1514 }
1515
1516 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1517 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1518 WebRtcSessionCreateSDPObserverForTest::kFailed;
1519
1520 for (int i = 0; i < kNumber; ++i) {
1521 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1522 if (success) {
1523 EXPECT_TRUE(observers[i]->description() != NULL);
1524 } else {
1525 EXPECT_TRUE(observers[i]->description() == NULL);
1526 }
1527 }
1528 }
1529
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001530 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001531 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001532 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001533 turn_server.credentials = credentials;
1534 turn_server.ports.push_back(
hnsl277b2502016-12-13 05:17:23 -08001535 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP));
deadbeef653b8e02015-11-11 12:55:10 -08001536 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001537 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001538 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001539 }
1540
skvlad11a9cbf2016-10-07 11:53:05 -07001541 webrtc::RtcEventLogNullImpl event_log_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001542 cricket::FakeMediaEngine* media_engine_;
1543 cricket::FakeDataEngine* data_engine_;
deadbeef953c2ce2017-01-09 14:53:41 -08001544 // Actually owned by session_.
1545 FakeSctpTransportFactory* fake_sctp_transport_factory_ = nullptr;
kwibergd1fe2812016-04-27 06:47:29 -07001546 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001547 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001548 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_;
1549 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1550 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1551 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1552 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1553 std::unique_ptr<rtc::FirewallSocketServer> fss_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001554 rtc::SocketServerScope ss_scope_;
1555 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001556 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001557 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001558 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001559 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001560 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001561 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001562 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001563 MockIceObserver observer_;
1564 cricket::FakeVideoMediaChannel* video_channel_;
1565 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001566 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001567 // The following flags affect options created for CreateOffer/CreateAnswer.
1568 bool send_stream_1_ = false;
1569 bool send_stream_2_ = false;
1570 bool send_audio_ = false;
1571 bool send_video_ = false;
1572 rtc::scoped_refptr<DataChannel> data_channel_;
1573 // Last values received from data channel creation signal.
1574 std::string last_data_channel_label_;
1575 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001576 bool session_destroyed_ = false;
jbauchcb560652016-08-04 05:20:32 -07001577 bool with_gcm_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001578};
1579
Henrik Boström87713d02015-08-25 09:53:21 +02001580TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1581 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001582 // SDES is disabled when DTLS is on.
1583 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584}
1585
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001586TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001587 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001588 // SDES is required if DTLS is off.
1589 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001590}
1591
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001592TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1593 TestSessionCandidatesWithBundleRtcpMux(false, false);
1594}
1595
1596// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1597// with rtcp-mux and/or bundle.
1598TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1599 TestSessionCandidatesWithBundleRtcpMux(false, true);
1600}
1601
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001602TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1603 TestSessionCandidatesWithBundleRtcpMux(true, true);
1604}
1605
1606TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001607 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1608 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001609 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001610 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001611 InitiateCall();
1612 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1613 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1614 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1615}
1616
deadbeeff5f03e82016-06-06 11:16:06 -07001617TEST_F(WebRtcSessionTest, TestStunError) {
1618 rtc::ScopedFakeClock clock;
1619
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001620 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1621 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001622 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001623 rtc::FP_UDP,
1624 rtc::FD_ANY,
1625 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001626 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001627 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001628 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001629 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
deadbeeff5f03e82016-06-06 11:16:06 -07001630 EXPECT_TRUE_SIMULATED_WAIT(observer_.oncandidatesready_, kStunTimeout, clock);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001631 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1632 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
deadbeeff5f03e82016-06-06 11:16:06 -07001633 // Destroy session before scoped fake clock goes out of scope to avoid TSan
1634 // warning.
1635 session_->Close();
1636 session_.reset(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001637}
1638
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001639TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001640 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001641 SessionDescriptionInterface* offer = NULL;
1642 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1643 std::string unknown_action;
1644 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1645 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1646}
1647
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001648// Test creating offers and receive answers and make sure the
1649// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001650TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001651 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001652 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001653 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654 const std::string session_id_orig = offer->session_id();
1655 const std::string session_version_orig = offer->session_version();
1656 SetLocalDescriptionWithoutError(offer);
1657
deadbeefab9b2d12015-10-14 11:33:11 -07001658 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001659 SessionDescriptionInterface* answer =
1660 CreateRemoteAnswer(session_->local_description());
1661 SetRemoteDescriptionWithoutError(answer);
1662
1663 video_channel_ = media_engine_->GetVideoChannel(0);
1664 voice_channel_ = media_engine_->GetVoiceChannel(0);
1665
1666 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1667 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1668
1669 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1670 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1671
1672 ASSERT_EQ(1u, video_channel_->send_streams().size());
1673 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1674 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1675 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1676
1677 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001678 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001679 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001680
1681 // Verify the session id is the same and the session version is
1682 // increased.
1683 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001684 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1685 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686
1687 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001688 EXPECT_EQ(0u, video_channel_->send_streams().size());
1689 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001690
deadbeefab9b2d12015-10-14 11:33:11 -07001691 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001692 answer = CreateRemoteAnswer(session_->local_description());
1693 SetRemoteDescriptionWithoutError(answer);
1694
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001695 // Make sure the receive streams have not changed.
1696 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1697 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1698 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1699 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1700}
1701
1702// Test receiving offers and creating answers and make sure the
1703// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001704TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001705 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001706 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001707 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001708 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001709 SetRemoteDescriptionWithoutError(offer);
1710
deadbeefab9b2d12015-10-14 11:33:11 -07001711 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001712 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001713 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001714 SetLocalDescriptionWithoutError(answer);
1715
1716 const std::string session_id_orig = answer->session_id();
1717 const std::string session_version_orig = answer->session_version();
1718
1719 video_channel_ = media_engine_->GetVideoChannel(0);
1720 voice_channel_ = media_engine_->GetVoiceChannel(0);
1721
htaa2a49d92016-03-04 02:51:39 -08001722 ASSERT_TRUE(video_channel_);
1723 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001724 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1725 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1726
1727 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1728 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1729
1730 ASSERT_EQ(1u, video_channel_->send_streams().size());
1731 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1732 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1733 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1734
deadbeefab9b2d12015-10-14 11:33:11 -07001735 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001736 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001737 SetRemoteDescriptionWithoutError(offer);
1738
1739 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001740 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001741 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001742
1743 // Verify the session id is the same and the session version is
1744 // increased.
1745 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001746 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1747 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748 SetLocalDescriptionWithoutError(answer);
1749
1750 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1751 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1752 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1753 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1754 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1755 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1756
1757 // Make sure we have no send streams.
1758 EXPECT_EQ(0u, video_channel_->send_streams().size());
1759 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1760}
1761
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001762TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001763 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001764 media_engine_->set_fail_create_channel(true);
1765
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001766 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001767 ASSERT_TRUE(offer != NULL);
1768 // SetRemoteDescription and SetLocalDescription will take the ownership of
1769 // the offer.
1770 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001771 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001772 ASSERT_TRUE(offer != NULL);
1773 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1774}
1775
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001776//
1777// Tests for creating/setting SDP under different SDES/DTLS polices:
1778//
1779// --DTLS off and SDES on
1780// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1781// set local/remote offer/answer with crypto --> success
1782// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1783// failure
1784// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1785// failure
1786// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1787// failure
1788//
1789// --DTLS on and SDES off
1790// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1791// set local/remote offer/answer with DTLS fingerprint --> success
1792// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1793// fingerprint --> failure
1794// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1795// --> failure
1796// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1797// --> failure
1798//
1799// --Encryption disabled: DTLS off and SDES off
1800// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1801// answer without SDES or DTLS --> success
1802// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1803// answer without SDES or DTLS --> success
1804//
1805
1806// Test that we return a failure when applying a remote/local offer that doesn't
1807// have cryptos enabled when DTLS is off.
1808TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001809 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001811 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001812 JsepSessionDescription* offer = CreateRemoteOffer(
1813 options, cricket::SEC_DISABLED);
1814 ASSERT_TRUE(offer != NULL);
1815 VerifyNoCryptoParams(offer->description(), false);
1816 // SetRemoteDescription and SetLocalDescription will take the ownership of
1817 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001818 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001819 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1820 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001821 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001822}
1823
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001824// Test that we return a failure when applying a local answer that doesn't have
1825// cryptos enabled when DTLS is off.
1826TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001827 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001828 SessionDescriptionInterface* offer = NULL;
1829 SessionDescriptionInterface* answer = NULL;
1830 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1831 // SetRemoteDescription and SetLocalDescription will take the ownership of
1832 // the offer.
1833 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001834 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001835}
1836
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001837// Test we will return fail when apply an remote answer that doesn't have
1838// crypto enabled when DTLS is off.
1839TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001840 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001841 SessionDescriptionInterface* offer = NULL;
1842 SessionDescriptionInterface* answer = NULL;
1843 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1844 // SetRemoteDescription and SetLocalDescription will take the ownership of
1845 // the offer.
1846 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001847 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001848}
1849
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001850// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1851// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001852TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001853 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001854 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001855 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001856 SetFactoryDtlsSrtp();
1857 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001858 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001859 JsepSessionDescription* offer =
1860 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001861 ASSERT_TRUE(offer != NULL);
1862 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001863 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001864
1865 // SetRemoteDescription will take the ownership of the offer.
1866 SetRemoteDescriptionWithoutError(offer);
1867
1868 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001869 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001870 ASSERT_TRUE(answer != NULL);
1871 VerifyFingerprintStatus(answer->description(), true);
1872 // Check that we don't have an a=crypto line in the answer.
1873 VerifyNoCryptoParams(answer->description(), true);
1874
1875 // Now set the local description, which should work, even without a=crypto.
1876 SetLocalDescriptionWithoutError(answer);
1877}
1878
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001879// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1880// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001881TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001882 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001883 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001884 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001885 SetFactoryDtlsSrtp();
1886
1887 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001888 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001889 ASSERT_TRUE(offer != NULL);
1890 VerifyFingerprintStatus(offer->description(), true);
1891 // Check that we don't have an a=crypto line in the offer.
1892 VerifyNoCryptoParams(offer->description(), true);
1893
1894 // Now set the local description, which should work, even without a=crypto.
1895 SetLocalDescriptionWithoutError(offer);
1896
1897 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001898 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001899 JsepSessionDescription* answer =
1900 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1901 ASSERT_TRUE(answer != NULL);
1902 VerifyFingerprintStatus(answer->description(), true);
1903 VerifyNoCryptoParams(answer->description(), true);
1904
1905 // SetRemoteDescription will take the ownership of the answer.
1906 SetRemoteDescriptionWithoutError(answer);
1907}
1908
1909// Test that if we support DTLS and the other side didn't offer a fingerprint,
1910// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001911TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001912 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001913 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001914 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001915 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001916 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001917 JsepSessionDescription* offer = CreateRemoteOffer(
1918 options, cricket::SEC_REQUIRED);
1919 ASSERT_TRUE(offer != NULL);
1920 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001921 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001922
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001923 // SetRemoteDescription will take the ownership of the offer.
1924 SetRemoteDescriptionOfferExpectError(
1925 kSdpWithoutDtlsFingerprint, offer);
1926
1927 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1928 // SetLocalDescription will take the ownership of the offer.
1929 SetLocalDescriptionOfferExpectError(
1930 kSdpWithoutDtlsFingerprint, offer);
1931}
1932
1933// Test that we return a failure when applying a local answer that doesn't have
1934// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001935TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001936 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001937 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001938 SessionDescriptionInterface* offer = NULL;
1939 SessionDescriptionInterface* answer = NULL;
1940 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1941
1942 // SetRemoteDescription and SetLocalDescription will take the ownership of
1943 // the offer and answer.
1944 SetRemoteDescriptionWithoutError(offer);
1945 SetLocalDescriptionAnswerExpectError(
1946 kSdpWithoutDtlsFingerprint, answer);
1947}
1948
1949// Test that we return a failure when applying a remote answer that doesn't have
1950// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001951TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001952 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001953 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001954 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001955 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001956 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07001957 std::unique_ptr<SessionDescriptionInterface> temp_offer(
deadbeefcbecd352015-09-23 11:50:27 -07001958 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001959 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001960 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001961
1962 // SetRemoteDescription and SetLocalDescription will take the ownership of
1963 // the offer and answer.
1964 SetLocalDescriptionWithoutError(offer);
1965 SetRemoteDescriptionAnswerExpectError(
1966 kSdpWithoutDtlsFingerprint, answer);
1967}
1968
1969// Test that we create a local offer without SDES or DTLS and accept a remote
1970// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001971TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001972 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001973 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001974 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001975
1976 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001977 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001978 ASSERT_TRUE(offer != NULL);
1979 VerifyFingerprintStatus(offer->description(), false);
1980 // Check that we don't have an a=crypto line in the offer.
1981 VerifyNoCryptoParams(offer->description(), false);
1982
1983 // Now set the local description, which should work, even without a=crypto.
1984 SetLocalDescriptionWithoutError(offer);
1985
1986 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001987 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001988 JsepSessionDescription* answer =
1989 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1990 ASSERT_TRUE(answer != NULL);
1991 VerifyFingerprintStatus(answer->description(), false);
1992 VerifyNoCryptoParams(answer->description(), false);
1993
1994 // SetRemoteDescription will take the ownership of the answer.
1995 SetRemoteDescriptionWithoutError(answer);
1996}
1997
1998// Test that we create a local answer without SDES or DTLS and accept a remote
1999// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02002000TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002001 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02002002 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002003
2004 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002005 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002006 JsepSessionDescription* offer =
2007 CreateRemoteOffer(options, cricket::SEC_DISABLED);
2008 ASSERT_TRUE(offer != NULL);
2009 VerifyFingerprintStatus(offer->description(), false);
2010 VerifyNoCryptoParams(offer->description(), false);
2011
2012 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002013 SetRemoteDescriptionWithoutError(offer);
2014
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002015 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08002016 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002017 ASSERT_TRUE(answer != NULL);
2018 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002019 // Check that we don't have an a=crypto line in the answer.
2020 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002021
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002022 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002023 SetLocalDescriptionWithoutError(answer);
2024}
2025
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002026// Test that we can create and set an answer correctly when different
2027// SSL roles have been negotiated for different transports.
2028// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
2029TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
2030 SendAudioVideoStream1();
2031 InitWithDtls(GetParam());
2032 SetFactoryDtlsSrtp();
2033
2034 SessionDescriptionInterface* offer = CreateOffer();
2035 SetLocalDescriptionWithoutError(offer);
2036
2037 cricket::MediaSessionOptions options;
2038 options.recv_video = true;
2039
2040 // First, negotiate different SSL roles.
2041 SessionDescriptionInterface* answer =
2042 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
2043 TransportInfo* audio_transport_info =
2044 answer->description()->GetTransportInfoByName("audio");
2045 audio_transport_info->description.connection_role =
2046 cricket::CONNECTIONROLE_ACTIVE;
2047 TransportInfo* video_transport_info =
2048 answer->description()->GetTransportInfoByName("video");
2049 video_transport_info->description.connection_role =
2050 cricket::CONNECTIONROLE_PASSIVE;
2051 SetRemoteDescriptionWithoutError(answer);
2052
2053 // Now create an offer in the reverse direction, and ensure the initial
2054 // offerer responds with an answer with correct SSL roles.
2055 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2056 kSessionVersion,
2057 session_->remote_description());
2058 SetRemoteDescriptionWithoutError(offer);
2059
htaa2a49d92016-03-04 02:51:39 -08002060 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002061 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2062 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2063 audio_transport_info->description.connection_role);
2064 video_transport_info = answer->description()->GetTransportInfoByName("video");
2065 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
2066 video_transport_info->description.connection_role);
2067 SetLocalDescriptionWithoutError(answer);
2068
2069 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
2070 // audio is transferred over to video in the answer that completes the BUNDLE
2071 // negotiation.
2072 options.bundle_enabled = true;
2073 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2074 kSessionVersion,
2075 session_->remote_description());
2076 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08002077 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002078 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2079 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2080 audio_transport_info->description.connection_role);
2081 video_transport_info = answer->description()->GetTransportInfoByName("video");
2082 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2083 video_transport_info->description.connection_role);
2084 SetLocalDescriptionWithoutError(answer);
2085}
2086
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002087TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002088 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002089 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002090 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002091 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092 SetLocalDescriptionWithoutError(offer);
2093
2094 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002095 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002096 SetLocalDescriptionWithoutError(offer2);
2097}
2098
2099TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002100 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002101 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002102 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002103 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002104 SetRemoteDescriptionWithoutError(offer);
2105
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002106 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107 SetRemoteDescriptionWithoutError(offer2);
2108}
2109
2110TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002111 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002112 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002113 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002114 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002115 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002116 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2117 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118}
2119
2120TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002121 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002122 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002123 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002125 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002126 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002127 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002128}
2129
2130TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002131 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002132 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002134 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002135
htaa2a49d92016-03-04 02:51:39 -08002136 JsepSessionDescription* pranswer =
2137 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002139 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140
deadbeefab9b2d12015-10-14 11:33:11 -07002141 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002142 JsepSessionDescription* pranswer2 =
2143 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002144 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2145
deadbeefd59daf82015-10-14 15:02:44 -07002146 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002147
deadbeefab9b2d12015-10-14 11:33:11 -07002148 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002149 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002150 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002151}
2152
2153TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002154 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002155 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002156 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002157 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002158
2159 JsepSessionDescription* pranswer =
2160 CreateRemoteAnswer(session_->local_description());
2161 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2162
2163 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002164 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002165
deadbeefab9b2d12015-10-14 11:33:11 -07002166 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002167 JsepSessionDescription* pranswer2 =
2168 CreateRemoteAnswer(session_->local_description());
2169 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2170
2171 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002172 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002173
deadbeefab9b2d12015-10-14 11:33:11 -07002174 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002175 SessionDescriptionInterface* answer =
2176 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002177 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002178}
2179
2180TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
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 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2188 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002189}
2190
2191TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002192 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002193 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002194 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002195
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002196 SessionDescriptionInterface* answer =
2197 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002198 SetRemoteDescriptionAnswerExpectError(
2199 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002200}
2201
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002202// Tests that the remote candidates are added and removed successfully.
2203TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002204 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002205 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002206
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002207 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
2208 "", "", "host", 0, "");
2209 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002210 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2211
deadbeefd59daf82015-10-14 15:02:44 -07002212 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002213 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2214
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002215 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002216 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002217
2218 // Fail since we have not set a remote description.
2219 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002220
2221 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2222 session_->local_description());
2223 SetRemoteDescriptionWithoutError(answer);
2224
deadbeefd59daf82015-10-14 15:02:44 -07002225 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2226 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002227 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002228 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2229 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2230
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002231 // Verifying the candidates are copied properly from internal vector.
2232 const SessionDescriptionInterface* remote_desc =
2233 session_->remote_description();
2234 ASSERT_TRUE(remote_desc != NULL);
2235 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2236 const IceCandidateCollection* candidates =
2237 remote_desc->candidates(kMediaContentIndex0);
2238 ASSERT_EQ(2u, candidates->count());
2239 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2240 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2241 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2242 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2243
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002244 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2245 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002246 candidate.set_component(2);
2247 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2248 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002249 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002250
2251 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2252 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002253
2254 // Remove candidate1 and candidate2
2255 std::vector<cricket::Candidate> remote_candidates;
2256 remote_candidates.push_back(ice_candidate1.candidate());
2257 remote_candidates.push_back(ice_candidate2.candidate());
2258 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2259 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002260}
2261
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002262// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002263// that it is retained if the remote session description is changed.
2264TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002265 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002266 cricket::Candidate candidate1;
2267 candidate1.set_component(1);
2268 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2269 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002270 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002271 CreateAndSetRemoteOfferAndLocalAnswer();
2272
2273 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2274 const SessionDescriptionInterface* remote_desc =
2275 session_->remote_description();
2276 ASSERT_TRUE(remote_desc != NULL);
2277 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2278 const IceCandidateCollection* candidates =
2279 remote_desc->candidates(kMediaContentIndex0);
2280 ASSERT_EQ(1u, candidates->count());
2281 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2282
2283 // Update the RemoteSessionDescription with a new session description and
2284 // a candidate and check that the new remote session description contains both
2285 // candidates.
2286 SessionDescriptionInterface* offer = CreateRemoteOffer();
2287 cricket::Candidate candidate2;
2288 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2289 candidate2);
2290 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2291 SetRemoteDescriptionWithoutError(offer);
2292
2293 remote_desc = session_->remote_description();
2294 ASSERT_TRUE(remote_desc != NULL);
2295 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2296 candidates = remote_desc->candidates(kMediaContentIndex0);
2297 ASSERT_EQ(2u, candidates->count());
2298 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2299 // Username and password have be updated with the TransportInfo of the
2300 // SessionDescription, won't be equal to the original one.
2301 candidate2.set_username(candidates->at(0)->candidate().username());
2302 candidate2.set_password(candidates->at(0)->candidate().password());
2303 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2304 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2305 // No need to verify the username and password.
2306 candidate1.set_username(candidates->at(1)->candidate().username());
2307 candidate1.set_password(candidates->at(1)->candidate().password());
2308 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2309
2310 // Test that the candidate is ignored if we can add the same candidate again.
2311 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2312}
2313
2314// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002315// that they are retained if the local session description is changed. And if
2316// continual gathering is enabled, they are removed from the local session
2317// description when the network is down.
2318TEST_F(WebRtcSessionTest,
2319 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002320 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002321 Init();
deadbeefb60a8192016-08-24 15:15:00 -07002322 // Enable Continual Gathering.
2323 cricket::IceConfig config;
2324 config.continual_gathering_policy = cricket::GATHER_CONTINUALLY;
2325 session_->SetIceConfig(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002326 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002327 CreateAndSetRemoteOfferAndLocalAnswer();
2328
2329 const SessionDescriptionInterface* local_desc = session_->local_description();
2330 const IceCandidateCollection* candidates =
2331 local_desc->candidates(kMediaContentIndex0);
2332 ASSERT_TRUE(candidates != NULL);
2333 EXPECT_EQ(0u, candidates->count());
2334
deadbeefb60a8192016-08-24 15:15:00 -07002335 // Since we're using continual gathering, we won't get "gathering done".
2336 EXPECT_EQ_WAIT(2u, candidates->count(), kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002337
2338 local_desc = session_->local_description();
2339 candidates = local_desc->candidates(kMediaContentIndex0);
2340 ASSERT_TRUE(candidates != NULL);
2341 EXPECT_LT(0u, candidates->count());
2342 candidates = local_desc->candidates(1);
2343 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002344 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002345
2346 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002347 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002348 CreateAndSetRemoteOfferAndLocalAnswer();
2349
2350 local_desc = session_->local_description();
2351 candidates = local_desc->candidates(kMediaContentIndex0);
2352 ASSERT_TRUE(candidates != NULL);
2353 EXPECT_LT(0u, candidates->count());
2354 candidates = local_desc->candidates(1);
2355 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002356 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002357
2358 candidates = local_desc->candidates(kMediaContentIndex0);
2359 size_t num_local_candidates = candidates->count();
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002360 // Bring down the network interface to trigger candidate removals.
2361 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2362 // Verify that all local candidates are removed.
2363 EXPECT_EQ(0, observer_.num_candidates_removed_);
2364 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2365 kIceCandidatesTimeout);
2366 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2367}
2368
2369// Tests that if continual gathering is disabled, local candidates won't be
2370// removed when the interface is turned down.
2371TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2372 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2373 Init();
2374 SendAudioVideoStream1();
2375 CreateAndSetRemoteOfferAndLocalAnswer();
2376
2377 const SessionDescriptionInterface* local_desc = session_->local_description();
2378 const IceCandidateCollection* candidates =
2379 local_desc->candidates(kMediaContentIndex0);
2380 ASSERT_TRUE(candidates != NULL);
2381 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2382
2383 size_t num_local_candidates = candidates->count();
2384 EXPECT_LT(0u, num_local_candidates);
2385 // By default, Continual Gathering is disabled.
2386 // Bring down the network interface.
2387 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2388 // Verify that the local candidates are not removed.
2389 rtc::Thread::Current()->ProcessMessages(1000);
2390 EXPECT_EQ(0, observer_.num_candidates_removed_);
2391 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002392}
2393
2394// Test that we can set a remote session description with remote candidates.
2395TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002396 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002397
2398 cricket::Candidate candidate1;
2399 candidate1.set_component(1);
2400 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2401 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002402 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002403 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002404
2405 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2406 SetRemoteDescriptionWithoutError(offer);
2407
2408 const SessionDescriptionInterface* remote_desc =
2409 session_->remote_description();
2410 ASSERT_TRUE(remote_desc != NULL);
2411 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2412 const IceCandidateCollection* candidates =
2413 remote_desc->candidates(kMediaContentIndex0);
2414 ASSERT_EQ(1u, candidates->count());
2415 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2416
htaa2a49d92016-03-04 02:51:39 -08002417 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002418 SetLocalDescriptionWithoutError(answer);
2419}
2420
2421// Test that offers and answers contains ice candidates when Ice candidates have
2422// been gathered.
2423TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002424 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002425 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002426 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002427 // Ice is started but candidates are not provided until SetLocalDescription
2428 // is called.
2429 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2430 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2431 CreateAndSetRemoteOfferAndLocalAnswer();
2432 // Wait until at least one local candidate has been collected.
2433 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2434 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002435
kwibergd1fe2812016-04-27 06:47:29 -07002436 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002437
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002438 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2439 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002440
2441 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2442 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002443 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002444 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2445 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002446 SetLocalDescriptionWithoutError(answer);
2447}
2448
2449// Verifies TransportProxy and media channels are created with content names
2450// present in the SessionDescription.
2451TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002452 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002453 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002454 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002455
2456 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002457 // "video". Goal is to modify these content names and verify transport
2458 // channels
2459 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002460 // present in SDP.
2461 std::string sdp;
2462 EXPECT_TRUE(offer->ToString(&sdp));
2463 const std::string kAudioMid = "a=mid:audio";
2464 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2465 const std::string kVideoMid = "a=mid:video";
2466 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2467
2468 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002469 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002470 kAudioMidReplaceStr.c_str(),
2471 kAudioMidReplaceStr.length(),
2472 &sdp);
2473 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002474 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002475 kVideoMidReplaceStr.c_str(),
2476 kVideoMidReplaceStr.length(),
2477 &sdp);
2478
2479 SessionDescriptionInterface* modified_offer =
2480 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2481
2482 SetRemoteDescriptionWithoutError(modified_offer);
2483
htaa2a49d92016-03-04 02:51:39 -08002484 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002485 SetLocalDescriptionWithoutError(answer);
2486
johan669d69b2016-11-08 14:14:08 -08002487 rtc::PacketTransportInterface* voice_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002488 session_->voice_rtp_transport_channel();
2489 EXPECT_TRUE(voice_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002490 EXPECT_EQ(voice_transport_channel->debug_name(),
2491 "audio_content_name " +
2492 std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
2493 rtc::PacketTransportInterface* video_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002494 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002495 ASSERT_TRUE(video_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002496 EXPECT_EQ(video_transport_channel->debug_name(),
2497 "video_content_name " +
2498 std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002499 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2500 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2501}
2502
2503// Test that an offer contains the correct media content descriptions based on
2504// the send streams when no constraints have been set.
2505TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002506 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002507 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002508
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002509 ASSERT_TRUE(offer != NULL);
2510 const cricket::ContentInfo* content =
2511 cricket::GetFirstAudioContent(offer->description());
2512 EXPECT_TRUE(content != NULL);
2513 content = cricket::GetFirstVideoContent(offer->description());
2514 EXPECT_TRUE(content == NULL);
2515}
2516
2517// Test that an offer contains the correct media content descriptions based on
2518// the send streams when no constraints have been set.
2519TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002520 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002521 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002522 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002523 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002524
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002525 const cricket::ContentInfo* content =
2526 cricket::GetFirstAudioContent(offer->description());
2527 EXPECT_TRUE(content != NULL);
2528 content = cricket::GetFirstVideoContent(offer->description());
2529 EXPECT_TRUE(content == NULL);
2530
2531 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002532 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002533 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002534 content = cricket::GetFirstAudioContent(offer->description());
2535 EXPECT_TRUE(content != NULL);
2536 content = cricket::GetFirstVideoContent(offer->description());
2537 EXPECT_TRUE(content != NULL);
2538}
2539
2540// Test that an offer contains no media content descriptions if
2541// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2542TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002543 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002544 PeerConnectionInterface::RTCOfferAnswerOptions options;
2545 options.offer_to_receive_audio = 0;
2546 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002547
kwibergd1fe2812016-04-27 06:47:29 -07002548 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002549
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002550 ASSERT_TRUE(offer != NULL);
2551 const cricket::ContentInfo* content =
2552 cricket::GetFirstAudioContent(offer->description());
2553 EXPECT_TRUE(content == NULL);
2554 content = cricket::GetFirstVideoContent(offer->description());
2555 EXPECT_TRUE(content == NULL);
2556}
2557
2558// Test that an offer contains only audio media content descriptions if
2559// kOfferToReceiveAudio constraints are set to true.
2560TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002561 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002562 PeerConnectionInterface::RTCOfferAnswerOptions options;
2563 options.offer_to_receive_audio =
2564 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2565
kwibergd1fe2812016-04-27 06:47:29 -07002566 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002567
2568 const cricket::ContentInfo* content =
2569 cricket::GetFirstAudioContent(offer->description());
2570 EXPECT_TRUE(content != NULL);
2571 content = cricket::GetFirstVideoContent(offer->description());
2572 EXPECT_TRUE(content == NULL);
2573}
2574
2575// Test that an offer contains audio and video media content descriptions if
2576// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2577TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002578 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002579 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002580 PeerConnectionInterface::RTCOfferAnswerOptions options;
2581 options.offer_to_receive_audio =
2582 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2583 options.offer_to_receive_video =
2584 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2585
kwibergd1fe2812016-04-27 06:47:29 -07002586 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002587
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002588 const cricket::ContentInfo* content =
2589 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002590 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002591
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002592 content = cricket::GetFirstVideoContent(offer->description());
2593 EXPECT_TRUE(content != NULL);
2594
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002595 // Sets constraints to false and verifies that audio/video contents are
2596 // removed.
2597 options.offer_to_receive_audio = 0;
2598 options.offer_to_receive_video = 0;
2599 offer.reset(CreateOffer(options));
2600
2601 content = cricket::GetFirstAudioContent(offer->description());
2602 EXPECT_TRUE(content == NULL);
2603 content = cricket::GetFirstVideoContent(offer->description());
2604 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002605}
2606
2607// Test that an answer can not be created if the last remote description is not
2608// an offer.
2609TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002610 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002611 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002612 SetLocalDescriptionWithoutError(offer);
2613 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2614 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002615 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002616}
2617
2618// Test that an answer contains the correct media content descriptions when no
2619// constraints have been set.
2620TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002621 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002622 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002623 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002624 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002625 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002626 const cricket::ContentInfo* content =
2627 cricket::GetFirstAudioContent(answer->description());
2628 ASSERT_TRUE(content != NULL);
2629 EXPECT_FALSE(content->rejected);
2630
2631 content = cricket::GetFirstVideoContent(answer->description());
2632 ASSERT_TRUE(content != NULL);
2633 EXPECT_FALSE(content->rejected);
2634}
2635
2636// Test that an answer contains the correct media content descriptions when no
2637// constraints have been set and the offer only contain audio.
2638TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002639 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002640 // Create a remote offer with audio only.
2641 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002642
kwibergd1fe2812016-04-27 06:47:29 -07002643 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002644 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2645 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2646
2647 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002648 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002649 const cricket::ContentInfo* content =
2650 cricket::GetFirstAudioContent(answer->description());
2651 ASSERT_TRUE(content != NULL);
2652 EXPECT_FALSE(content->rejected);
2653
2654 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2655}
2656
2657// Test that an answer contains the correct media content descriptions when no
2658// constraints have been set.
2659TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002660 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002661 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002662 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002663 SetRemoteDescriptionWithoutError(offer.release());
2664 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002665 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002666 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002667 const cricket::ContentInfo* content =
2668 cricket::GetFirstAudioContent(answer->description());
2669 ASSERT_TRUE(content != NULL);
2670 EXPECT_FALSE(content->rejected);
2671
2672 content = cricket::GetFirstVideoContent(answer->description());
2673 ASSERT_TRUE(content != NULL);
2674 EXPECT_FALSE(content->rejected);
2675}
2676
2677// Test that an answer contains the correct media content descriptions when
2678// constraints have been set but no stream is sent.
2679TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002680 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002681 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002682 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002683 SetRemoteDescriptionWithoutError(offer.release());
2684
htaa2a49d92016-03-04 02:51:39 -08002685 cricket::MediaSessionOptions session_options;
2686 session_options.recv_audio = false;
2687 session_options.recv_video = false;
kwibergd1fe2812016-04-27 06:47:29 -07002688 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002689 CreateAnswer(session_options));
2690
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002691 const cricket::ContentInfo* content =
2692 cricket::GetFirstAudioContent(answer->description());
2693 ASSERT_TRUE(content != NULL);
2694 EXPECT_TRUE(content->rejected);
2695
2696 content = cricket::GetFirstVideoContent(answer->description());
2697 ASSERT_TRUE(content != NULL);
2698 EXPECT_TRUE(content->rejected);
2699}
2700
2701// Test that an answer contains the correct media content descriptions when
2702// constraints have been set and streams are sent.
2703TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002704 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002705 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002706 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002707 SetRemoteDescriptionWithoutError(offer.release());
2708
htaa2a49d92016-03-04 02:51:39 -08002709 cricket::MediaSessionOptions options;
2710 options.recv_audio = false;
2711 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002712
2713 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002714 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002715 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002716
2717 // TODO(perkj): Should the direction be set to SEND_ONLY?
2718 const cricket::ContentInfo* content =
2719 cricket::GetFirstAudioContent(answer->description());
2720 ASSERT_TRUE(content != NULL);
2721 EXPECT_FALSE(content->rejected);
2722
2723 // TODO(perkj): Should the direction be set to SEND_ONLY?
2724 content = cricket::GetFirstVideoContent(answer->description());
2725 ASSERT_TRUE(content != NULL);
2726 EXPECT_FALSE(content->rejected);
2727}
2728
2729TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2730 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002731 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002732 PeerConnectionInterface::RTCOfferAnswerOptions options;
2733 options.offer_to_receive_audio =
2734 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2735 options.voice_activity_detection = false;
2736
kwibergd1fe2812016-04-27 06:47:29 -07002737 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002738
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002739 const cricket::ContentInfo* content =
2740 cricket::GetFirstAudioContent(offer->description());
2741 EXPECT_TRUE(content != NULL);
2742 EXPECT_TRUE(VerifyNoCNCodecs(content));
2743}
2744
2745TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2746 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002747 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002748 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002749 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002750 SetRemoteDescriptionWithoutError(offer.release());
2751
htaa2a49d92016-03-04 02:51:39 -08002752 cricket::MediaSessionOptions options;
2753 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002754 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002755 const cricket::ContentInfo* content =
2756 cricket::GetFirstAudioContent(answer->description());
2757 ASSERT_TRUE(content != NULL);
2758 EXPECT_TRUE(VerifyNoCNCodecs(content));
2759}
2760
2761// This test verifies the call setup when remote answer with audio only and
2762// later updates with video.
2763TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002764 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002765 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2766 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2767
deadbeefab9b2d12015-10-14 11:33:11 -07002768 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002769 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002770
2771 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002772 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2773
2774 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2775 // and answer;
2776 SetLocalDescriptionWithoutError(offer);
2777 SetRemoteDescriptionWithoutError(answer);
2778
2779 video_channel_ = media_engine_->GetVideoChannel(0);
2780 voice_channel_ = media_engine_->GetVoiceChannel(0);
2781
2782 ASSERT_TRUE(video_channel_ == NULL);
2783
2784 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2785 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2786 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2787
2788 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002789 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002790 CreateAndSetRemoteOfferAndLocalAnswer();
2791
2792 video_channel_ = media_engine_->GetVideoChannel(0);
2793 voice_channel_ = media_engine_->GetVoiceChannel(0);
2794
2795 ASSERT_TRUE(video_channel_ != NULL);
2796 ASSERT_TRUE(voice_channel_ != NULL);
2797
2798 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2799 ASSERT_EQ(1u, video_channel_->send_streams().size());
2800 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2801 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2802 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2803 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2804 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2805 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2806
2807 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002808 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002809 CreateAndSetRemoteOfferAndLocalAnswer();
2810
2811 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2812 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2813 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2814 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2815 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2816}
2817
2818// This test verifies the call setup when remote answer with video only and
2819// later updates with audio.
2820TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002821 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002822 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2823 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002824 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002825 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002826
2827 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002828 options.recv_audio = false;
2829 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002830 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2831 offer, options, cricket::SEC_ENABLED);
2832
2833 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2834 // and answer.
2835 SetLocalDescriptionWithoutError(offer);
2836 SetRemoteDescriptionWithoutError(answer);
2837
2838 video_channel_ = media_engine_->GetVideoChannel(0);
2839 voice_channel_ = media_engine_->GetVoiceChannel(0);
2840
2841 ASSERT_TRUE(voice_channel_ == NULL);
2842 ASSERT_TRUE(video_channel_ != NULL);
2843
2844 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2845 ASSERT_EQ(1u, video_channel_->send_streams().size());
2846 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2847
2848 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002849 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002850 CreateAndSetRemoteOfferAndLocalAnswer();
2851
2852 voice_channel_ = media_engine_->GetVoiceChannel(0);
2853 ASSERT_TRUE(voice_channel_ != NULL);
2854
2855 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2856 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2857 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2858 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2859
2860 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002861 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002862 CreateAndSetRemoteOfferAndLocalAnswer();
2863
2864 video_channel_ = media_engine_->GetVideoChannel(0);
2865 voice_channel_ = media_engine_->GetVoiceChannel(0);
2866
2867 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2868 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2869 ASSERT_EQ(1u, video_channel_->send_streams().size());
2870 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2871}
2872
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002873TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002874 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002875 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002876 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002877 VerifyCryptoParams(offer->description());
2878 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002879 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002880 VerifyCryptoParams(answer->description());
2881}
2882
jbauchcb560652016-08-04 05:20:32 -07002883TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDPGcm) {
2884 InitWithGcm();
2885 SendAudioVideoStream1();
2886 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
2887 VerifyCryptoParams(offer->description(), true);
2888 SetRemoteDescriptionWithoutError(offer.release());
2889 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
2890 VerifyCryptoParams(answer->description(), true);
2891}
2892
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002893TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002894 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002895 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002896 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002897 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002898 VerifyNoCryptoParams(offer->description(), false);
2899}
2900
2901TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002902 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002903 VerifyAnswerFromNonCryptoOffer();
2904}
2905
2906TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002907 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002908 VerifyAnswerFromCryptoOffer();
2909}
2910
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002911// This test verifies that setLocalDescription fails if
2912// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2913TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002914 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002915 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002916 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002917
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002918 std::string sdp;
2919 RemoveIceUfragPwdLines(offer.get(), &sdp);
2920 SessionDescriptionInterface* modified_offer =
2921 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002922 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002923}
2924
2925// This test verifies that setRemoteDescription fails if
2926// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2927TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002928 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002929 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002930 std::string sdp;
2931 RemoveIceUfragPwdLines(offer.get(), &sdp);
2932 SessionDescriptionInterface* modified_offer =
2933 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002934 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002935}
2936
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002937// This test verifies that setLocalDescription fails if local offer has
2938// too short ice ufrag and pwd strings.
2939TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002940 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002941 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002942 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002943 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2944 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002945 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002946 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002947 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002948
2949 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002950 offer.reset(CreateOffer());
2951 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2952 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002953}
2954
2955// This test verifies that setRemoteDescription fails if remote offer has
2956// too short ice ufrag and pwd strings.
2957TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002958 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002959 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002960 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2961 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002962 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002963 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002964 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002965
deadbeef0ed85b22016-02-23 17:24:52 -08002966 offer.reset(CreateRemoteOffer());
2967 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2968 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002969}
2970
Honghai Zhang04e91462015-12-11 14:26:22 -08002971// Test that if the remote offer indicates the peer requested ICE restart (via
2972// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2973TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002974 Init();
honghaiz503726c2015-07-31 12:37:38 -07002975
2976 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07002977 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08002978 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002979 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2980 0, "", "", "relay", 0, "");
2981 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2982 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002983 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2984 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002985 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2986
2987 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002988 offer.reset(CreateRemoteOffer());
2989 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002990 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2991 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2992 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002993 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2994 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002995 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2996
2997 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002998 offer.reset(CreateRemoteOffer());
2999 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07003000 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
3001 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
3002 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003003 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
3004 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07003005 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
3006
3007 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08003008 offer.reset(CreateRemoteOffer());
3009 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
3010 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07003011 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
3012}
3013
Honghai Zhang04e91462015-12-11 14:26:22 -08003014// Test that if the remote answer indicates the peer requested ICE restart (via
3015// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
3016TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
3017 Init();
3018 SessionDescriptionInterface* offer = CreateOffer();
3019 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08003020
3021 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07003022 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08003023 answer->set_type(JsepSessionDescription::kPrAnswer);
3024 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08003025 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
3026 0, "", "", "relay", 0, "");
3027 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
3028 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003029 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
3030 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003031 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
3032
3033 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08003034 answer.reset(CreateRemoteAnswer(offer));
3035 answer->set_type(JsepSessionDescription::kPrAnswer);
3036 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08003037 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3038 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3039 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003040 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
3041 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003042 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
3043
3044 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08003045 answer.reset(CreateRemoteAnswer(offer));
3046 answer->set_type(JsepSessionDescription::kPrAnswer);
3047 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08003048 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
3049 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
3050 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003051 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
3052 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003053 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
3054
3055 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08003056 answer.reset(CreateRemoteAnswer(offer));
3057 answer->set_type(JsepSessionDescription::kPrAnswer);
3058 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
3059 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003060 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
3061}
3062
Donald Curtisd4f769d2015-05-28 09:48:21 -07003063// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07003064// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07003065TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
3066 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
3067
3068 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003069 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003070
3071 PeerConnectionInterface::RTCOfferAnswerOptions options;
3072 options.use_rtp_mux = true;
3073
3074 SessionDescriptionInterface* offer = CreateRemoteOffer();
3075 SetRemoteDescriptionWithoutError(offer);
3076
htaa2a49d92016-03-04 02:51:39 -08003077 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003078 SetLocalDescriptionWithoutError(answer);
3079
deadbeefcbecd352015-09-23 11:50:27 -07003080 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3081 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07003082
deadbeefcbecd352015-09-23 11:50:27 -07003083 cricket::BaseChannel* voice_channel = session_->voice_channel();
3084 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003085
3086 // Checks if one of the transport channels contains a connection using a given
3087 // port.
deadbeefcbecd352015-09-23 11:50:27 -07003088 auto connection_with_remote_port = [this, voice_channel](int port) {
hbosdf6075a2016-12-19 04:58:02 -08003089 std::unique_ptr<webrtc::SessionStats> stats = session_->GetStats_s();
3090 for (auto& kv : stats->transport_stats) {
deadbeefcbecd352015-09-23 11:50:27 -07003091 for (auto& chan_stat : kv.second.channel_stats) {
3092 for (auto& conn_info : chan_stat.connection_infos) {
3093 if (conn_info.remote_candidate.address().port() == port) {
3094 return true;
3095 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07003096 }
3097 }
3098 }
3099 return false;
3100 };
3101
3102 EXPECT_FALSE(connection_with_remote_port(5000));
3103 EXPECT_FALSE(connection_with_remote_port(5001));
3104 EXPECT_FALSE(connection_with_remote_port(6000));
3105
3106 // The way the *_WAIT checks work is they only wait if the condition fails,
3107 // which does not help in the case where state is not changing. This is
3108 // problematic in this test since we want to verify that adding a video
3109 // candidate does _not_ change state. So we interleave candidates and assume
3110 // that messages are executed in the order they were posted.
3111
3112 // First audio candidate.
3113 cricket::Candidate candidate0;
3114 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3115 candidate0.set_component(1);
3116 candidate0.set_protocol("udp");
3117 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3118 candidate0);
3119 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3120
3121 // Video candidate.
3122 cricket::Candidate candidate1;
3123 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3124 candidate1.set_component(1);
3125 candidate1.set_protocol("udp");
3126 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3127 candidate1);
3128 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3129
3130 // Second audio candidate.
3131 cricket::Candidate candidate2;
3132 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3133 candidate2.set_component(1);
3134 candidate2.set_protocol("udp");
3135 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3136 candidate2);
3137 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3138
3139 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3140 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3141
3142 // No need here for a _WAIT check since we are checking that state hasn't
3143 // changed: if this is false we would be doing waits for nothing and if this
3144 // is true then there will be no messages processed anyways.
3145 EXPECT_FALSE(connection_with_remote_port(6000));
3146}
3147
deadbeefcbecd352015-09-23 11:50:27 -07003148// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003149TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3150 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003151 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003152
3153 PeerConnectionInterface::RTCOfferAnswerOptions options;
3154 options.use_rtp_mux = true;
3155
3156 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003157 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003158
deadbeefcbecd352015-09-23 11:50:27 -07003159 EXPECT_NE(session_->voice_rtp_transport_channel(),
3160 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003161
deadbeefab9b2d12015-10-14 11:33:11 -07003162 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003163 SessionDescriptionInterface* answer =
3164 CreateRemoteAnswer(session_->local_description());
3165 SetRemoteDescriptionWithoutError(answer);
3166
deadbeefcbecd352015-09-23 11:50:27 -07003167 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3168 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003169}
3170
deadbeefcbecd352015-09-23 11:50:27 -07003171// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003172TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3173 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003174 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003175
Donald Curtis0e209b02015-03-24 09:29:54 -07003176 PeerConnectionInterface::RTCOfferAnswerOptions options;
3177 options.use_rtp_mux = true;
3178
3179 SessionDescriptionInterface* offer = CreateOffer(options);
3180 SetLocalDescriptionWithoutError(offer);
3181
deadbeefcbecd352015-09-23 11:50:27 -07003182 EXPECT_NE(session_->voice_rtp_transport_channel(),
3183 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003184
deadbeefab9b2d12015-10-14 11:33:11 -07003185 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003186
3187 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003188 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003189 CreateRemoteAnswer(session_->local_description()));
3190 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3191 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3192 JsepSessionDescription* modified_answer =
3193 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3194 modified_answer->Initialize(answer_copy, "1", "1");
3195 SetRemoteDescriptionWithoutError(modified_answer); //
3196
deadbeefcbecd352015-09-23 11:50:27 -07003197 EXPECT_NE(session_->voice_rtp_transport_channel(),
3198 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003199}
3200
3201// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3202TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3203 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003204 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003205
3206 PeerConnectionInterface::RTCOfferAnswerOptions options;
3207 options.use_rtp_mux = true;
3208
3209 SessionDescriptionInterface* offer = CreateOffer(options);
3210 SetLocalDescriptionWithoutError(offer);
3211
deadbeefcbecd352015-09-23 11:50:27 -07003212 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3213 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003214
deadbeefab9b2d12015-10-14 11:33:11 -07003215 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003216 SessionDescriptionInterface* answer =
3217 CreateRemoteAnswer(session_->local_description());
3218 SetRemoteDescriptionWithoutError(answer);
3219
deadbeefcbecd352015-09-23 11:50:27 -07003220 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3221 session_->video_rtp_transport_channel());
3222}
3223
3224// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3225// audio content in the answer.
3226TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3227 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003228 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003229
3230 PeerConnectionInterface::RTCOfferAnswerOptions options;
3231 options.use_rtp_mux = true;
3232
3233 SessionDescriptionInterface* offer = CreateOffer(options);
3234 SetLocalDescriptionWithoutError(offer);
3235
3236 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3237 session_->video_rtp_transport_channel());
3238
deadbeefab9b2d12015-10-14 11:33:11 -07003239 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003240 cricket::MediaSessionOptions recv_options;
3241 recv_options.recv_audio = false;
3242 recv_options.recv_video = true;
3243 SessionDescriptionInterface* answer =
3244 CreateRemoteAnswer(session_->local_description(), recv_options);
3245 SetRemoteDescriptionWithoutError(answer);
3246
deadbeefd59daf82015-10-14 15:02:44 -07003247 EXPECT_TRUE(nullptr == session_->voice_channel());
3248 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003249
deadbeefd59daf82015-10-14 15:02:44 -07003250 session_->Close();
3251 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3252 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3253 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3254 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003255}
3256
3257// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3258TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3259 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003260 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003261
Donald Curtis0e209b02015-03-24 09:29:54 -07003262 PeerConnectionInterface::RTCOfferAnswerOptions options;
3263 options.use_rtp_mux = true;
3264
3265 SessionDescriptionInterface* offer = CreateOffer(options);
3266 SetLocalDescriptionWithoutError(offer);
3267
deadbeefcbecd352015-09-23 11:50:27 -07003268 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3269 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003270
deadbeefab9b2d12015-10-14 11:33:11 -07003271 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003272
3273 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003274 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003275 CreateRemoteAnswer(session_->local_description()));
3276 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3277 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3278 JsepSessionDescription* modified_answer =
3279 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3280 modified_answer->Initialize(answer_copy, "1", "1");
3281 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003282
deadbeefcbecd352015-09-23 11:50:27 -07003283 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3284 session_->video_rtp_transport_channel());
3285}
3286
3287// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3288TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3289 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003290 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003291
3292 SessionDescriptionInterface* offer = CreateRemoteOffer();
3293 SetRemoteDescriptionWithoutError(offer);
3294
3295 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3296 session_->video_rtp_transport_channel());
3297
deadbeefab9b2d12015-10-14 11:33:11 -07003298 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003299 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003300 SetLocalDescriptionWithoutError(answer);
3301
3302 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3303 session_->video_rtp_transport_channel());
3304}
3305
3306// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3307TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3308 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003309 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003310
3311 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003312 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003313 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3314 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3315 JsepSessionDescription* modified_offer =
3316 new JsepSessionDescription(JsepSessionDescription::kOffer);
3317 modified_offer->Initialize(offer_copy, "1", "1");
3318
3319 // Expect an error when applying the remote description
3320 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3321 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003322}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003323
Peter Thatcher4eddf182015-04-30 10:55:59 -07003324// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003325TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3326 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003327 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003328
Donald Curtis0e209b02015-03-24 09:29:54 -07003329 PeerConnectionInterface::RTCOfferAnswerOptions options;
3330 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003331
Donald Curtis0e209b02015-03-24 09:29:54 -07003332 SessionDescriptionInterface* offer = CreateOffer(options);
3333 SetLocalDescriptionWithoutError(offer);
3334
deadbeefcbecd352015-09-23 11:50:27 -07003335 EXPECT_NE(session_->voice_rtp_transport_channel(),
3336 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003337
deadbeefab9b2d12015-10-14 11:33:11 -07003338 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003339 SessionDescriptionInterface* answer =
3340 CreateRemoteAnswer(session_->local_description());
3341 SetRemoteDescriptionWithoutError(answer);
3342
3343 // This should lead to an audio-only call but isn't implemented
3344 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003345 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3346 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003347}
3348
deadbeefcbecd352015-09-23 11:50:27 -07003349// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003350TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3351 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003352 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003353 PeerConnectionInterface::RTCOfferAnswerOptions options;
3354 options.use_rtp_mux = true;
3355
3356 SessionDescriptionInterface* offer = CreateOffer(options);
3357 SetLocalDescriptionWithoutError(offer);
3358
deadbeefcbecd352015-09-23 11:50:27 -07003359 EXPECT_NE(session_->voice_rtp_transport_channel(),
3360 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003361
deadbeefab9b2d12015-10-14 11:33:11 -07003362 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003363
3364 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003365 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003366 CreateRemoteAnswer(session_->local_description()));
3367 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3368 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3369 JsepSessionDescription* modified_answer =
3370 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3371 modified_answer->Initialize(answer_copy, "1", "1");
3372 SetRemoteDescriptionWithoutError(modified_answer); //
3373
deadbeefcbecd352015-09-23 11:50:27 -07003374 EXPECT_NE(session_->voice_rtp_transport_channel(),
3375 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003376}
3377
Peter Thatcher4eddf182015-04-30 10:55:59 -07003378// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3379TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3380 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003381 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003382
3383 PeerConnectionInterface::RTCOfferAnswerOptions options;
3384 options.use_rtp_mux = true;
3385
3386 SessionDescriptionInterface* offer = CreateOffer(options);
3387 SetRemoteDescriptionWithoutError(offer);
3388
deadbeefcbecd352015-09-23 11:50:27 -07003389 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3390 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003391}
3392
skvlad6c87a672016-05-17 17:49:52 -07003393// Adding a new channel to a BUNDLE which is already connected should directly
3394// assign the bundle transport to the channel, without first setting a
3395// disconnected non-bundle transport and then replacing it. The application
3396// should not receive any changes in the ICE state.
3397TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) {
3398 LoopbackNetworkConfiguration config;
3399 LoopbackNetworkManager loopback_network_manager(this, config);
3400 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain
3401 // connected. Disabling either of these two means that we need to wait for the
3402 // answer to find out if more transports are needed.
3403 configuration_.bundle_policy =
3404 PeerConnectionInterface::kBundlePolicyMaxBundle;
skvlad6c87a672016-05-17 17:49:52 -07003405 options_.disable_encryption = true;
zhihuang4dfb8ce2016-11-23 10:30:12 -08003406 Init(PeerConnectionInterface::kRtcpMuxPolicyRequire);
skvlad6c87a672016-05-17 17:49:52 -07003407
3408 // Negotiate an audio channel with MAX_BUNDLE enabled.
3409 SendAudioOnlyStream2();
3410 SessionDescriptionInterface* offer = CreateOffer();
3411 SetLocalDescriptionWithoutError(offer);
3412 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
3413 observer_.ice_gathering_state_, kIceCandidatesTimeout);
3414 std::string sdp;
3415 offer->ToString(&sdp);
3416 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription(
3417 JsepSessionDescription::kAnswer, sdp, nullptr);
3418 ASSERT_TRUE(answer != NULL);
3419 SetRemoteDescriptionWithoutError(answer);
3420
3421 // Wait for the ICE state to stabilize.
3422 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3423 observer_.ice_connection_state_, kIceCandidatesTimeout);
3424 observer_.ice_connection_state_history_.clear();
3425
3426 // Now add a video channel which should be using the same bundle transport.
3427 SendAudioVideoStream2();
3428 offer = CreateOffer();
3429 offer->ToString(&sdp);
3430 SetLocalDescriptionWithoutError(offer);
3431 answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer,
3432 sdp, nullptr);
3433 ASSERT_TRUE(answer != NULL);
3434 SetRemoteDescriptionWithoutError(answer);
3435
3436 // Wait for ICE state to stabilize
3437 rtc::Thread::Current()->ProcessMessages(0);
3438 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3439 observer_.ice_connection_state_, kIceCandidatesTimeout);
3440
3441 // No ICE state changes are expected to happen.
3442 EXPECT_EQ(0, observer_.ice_connection_state_history_.size());
3443}
3444
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003445TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3446 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003447 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003448
3449 PeerConnectionInterface::RTCOfferAnswerOptions options;
3450 SessionDescriptionInterface* offer = CreateOffer(options);
3451 SetLocalDescriptionWithoutError(offer);
3452
deadbeefcbecd352015-09-23 11:50:27 -07003453 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3454 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003455
deadbeefab9b2d12015-10-14 11:33:11 -07003456 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003457 SessionDescriptionInterface* answer =
3458 CreateRemoteAnswer(session_->local_description());
3459 SetRemoteDescriptionWithoutError(answer);
3460
deadbeefcbecd352015-09-23 11:50:27 -07003461 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3462 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003463}
3464
3465TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3466 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003467 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003468
3469 PeerConnectionInterface::RTCOfferAnswerOptions options;
3470 SessionDescriptionInterface* offer = CreateOffer(options);
3471 SetLocalDescriptionWithoutError(offer);
3472
deadbeefcbecd352015-09-23 11:50:27 -07003473 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3474 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003475
deadbeefab9b2d12015-10-14 11:33:11 -07003476 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003477 SessionDescriptionInterface* answer =
3478 CreateRemoteAnswer(session_->local_description());
3479 SetRemoteDescriptionWithoutError(answer);
3480
deadbeefcbecd352015-09-23 11:50:27 -07003481 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3482 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003483}
3484
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003485// This test verifies that SetLocalDescription and SetRemoteDescription fails
3486// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3487TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003488 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003489 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003490
3491 PeerConnectionInterface::RTCOfferAnswerOptions options;
3492 options.use_rtp_mux = true;
3493
3494 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003495 std::string offer_str;
3496 offer->ToString(&offer_str);
3497 // Disable rtcp-mux
3498 const std::string rtcp_mux = "rtcp-mux";
3499 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003500 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003501 xrtcp_mux.c_str(), xrtcp_mux.length(),
3502 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003503 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003504 new JsepSessionDescription(JsepSessionDescription::kOffer);
3505 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003506 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003507 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003508 new JsepSessionDescription(JsepSessionDescription::kOffer);
3509 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003510 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003511 // Trying unmodified SDP.
3512 SetLocalDescriptionWithoutError(offer);
3513}
3514
jbauchcb560652016-08-04 05:20:32 -07003515TEST_F(WebRtcSessionTest, SetSetupGcm) {
3516 InitWithGcm();
3517 SendAudioVideoStream1();
3518 CreateAndSetRemoteOfferAndLocalAnswer();
3519}
3520
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003521TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3522 TestCanInsertDtmf(false);
3523}
3524
3525TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3526 TestCanInsertDtmf(true);
3527}
3528
3529TEST_F(WebRtcSessionTest, InsertDtmf) {
3530 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003531 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003532 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003533 CreateAndSetRemoteOfferAndLocalAnswer();
3534 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3535 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3536
3537 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003538 const int expected_duration = 90;
3539 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3540 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3541 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3542
3543 // Verify
3544 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003545 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003546 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003547 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003548 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003549 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003550 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003551 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003552}
3553
deadbeefd59daf82015-10-14 15:02:44 -07003554// This test verifies the |initial_offerer| flag when session initiates the
3555// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003556TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003557 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003558 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003559 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003560 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3561 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003562 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003563 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003564 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003565}
3566
deadbeefd59daf82015-10-14 15:02:44 -07003567// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003568TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003569 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003570 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003571 SessionDescriptionInterface* offer = CreateRemoteOffer();
3572 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003573 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003574
deadbeefd59daf82015-10-14 15:02:44 -07003575 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003576 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003577 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003578}
3579
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003580// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3581TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003582 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003583 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003584 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003585 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003586 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003587 CreateRemoteAnswer(session_->local_description()));
3588
3589 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3590 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003591 JsepSessionDescription* modified_answer =
3592 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003593
3594 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3595 answer->session_id(),
3596 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003597 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003598
wu@webrtc.org4e393072014-04-07 17:04:35 +00003599 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003600 std::string sdp;
3601 EXPECT_TRUE(answer->ToString(&sdp));
3602 const std::string kAudioMid = "a=mid:audio";
3603 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003604 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003605 kAudioMidReplaceStr.c_str(),
3606 kAudioMidReplaceStr.length(),
3607 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003608 SessionDescriptionInterface* modified_answer1 =
3609 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003610 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003611
wu@webrtc.org4e393072014-04-07 17:04:35 +00003612 // Different media types.
3613 EXPECT_TRUE(answer->ToString(&sdp));
3614 const std::string kAudioMline = "m=audio";
3615 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003616 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003617 kAudioMlineReplaceStr.c_str(),
3618 kAudioMlineReplaceStr.length(),
3619 &sdp);
3620 SessionDescriptionInterface* modified_answer2 =
3621 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3622 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3623
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003624 SetRemoteDescriptionWithoutError(answer.release());
3625}
3626
3627// Verifying remote offer and local answer have matching m-lines as per
3628// RFC 3264.
3629TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003630 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003631 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003632 SessionDescriptionInterface* offer = CreateRemoteOffer();
3633 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003634 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003635
3636 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3637 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003638 JsepSessionDescription* modified_answer =
3639 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003640
3641 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3642 answer->session_id(),
3643 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003644 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003645 SetLocalDescriptionWithoutError(answer);
3646}
3647
3648// This test verifies that WebRtcSession does not start candidate allocation
3649// before SetLocalDescription is called.
3650TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003651 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003652 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003653 SessionDescriptionInterface* offer = CreateRemoteOffer();
3654 cricket::Candidate candidate;
3655 candidate.set_component(1);
3656 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3657 candidate);
3658 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3659 cricket::Candidate candidate1;
3660 candidate1.set_component(1);
3661 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3662 candidate1);
3663 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3664 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003665 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3666 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003667
3668 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003669 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003670 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3671 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3672
htaa2a49d92016-03-04 02:51:39 -08003673 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003674 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003675 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3676}
3677
3678// This test verifies that crypto parameter is updated in local session
3679// description as per security policy set in MediaSessionDescriptionFactory.
3680TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003681 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003682 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003683 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003684
3685 // Making sure SetLocalDescription correctly sets crypto value in
3686 // SessionDescription object after de-serialization of sdp string. The value
3687 // will be set as per MediaSessionDescriptionFactory.
3688 std::string offer_str;
3689 offer->ToString(&offer_str);
3690 SessionDescriptionInterface* jsep_offer_str =
3691 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3692 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003693 EXPECT_TRUE(session_->voice_channel()->srtp_required_for_testing());
3694 EXPECT_TRUE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003695}
3696
3697// This test verifies the crypto parameter when security is disabled.
3698TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003699 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003700 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003701 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003702 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003703
3704 // Making sure SetLocalDescription correctly sets crypto value in
3705 // SessionDescription object after de-serialization of sdp string. The value
3706 // will be set as per MediaSessionDescriptionFactory.
3707 std::string offer_str;
3708 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003709 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003710 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3711 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003712 EXPECT_FALSE(session_->voice_channel()->srtp_required_for_testing());
3713 EXPECT_FALSE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003714}
3715
3716// This test verifies that an answer contains new ufrag and password if an offer
3717// with new ufrag and password is received.
3718TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003719 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003720 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003721 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003722 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003723 SetRemoteDescriptionWithoutError(offer.release());
3724
deadbeefab9b2d12015-10-14 11:33:11 -07003725 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003726 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003727 SetLocalDescriptionWithoutError(answer.release());
3728
3729 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003730 for (const cricket::ContentInfo& content :
3731 session_->local_description()->description()->contents()) {
3732 options.transport_options[content.name].ice_restart = true;
3733 }
kwibergd1fe2812016-04-27 06:47:29 -07003734 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003735 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003736 SetRemoteDescriptionWithoutError(updated_offer1.release());
3737
kwibergd1fe2812016-04-27 06:47:29 -07003738 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003739
deadbeef0ed85b22016-02-23 17:24:52 -08003740 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3741 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003742
deadbeef0ed85b22016-02-23 17:24:52 -08003743 // Even a second answer (created before the description is set) should have
3744 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003745 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003746
3747 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3748 session_->local_description()->description()));
3749
3750 SetLocalDescriptionWithoutError(updated_answer2.release());
3751}
3752
3753// This test verifies that an answer contains new ufrag and password if an offer
3754// that changes either the ufrag or password (but not both) is received.
3755// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3756// a=ice-pwd attributes compared to the previous SDP from the peer, it
3757// indicates that ICE is restarting for this media stream."
3758TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3759 Init();
3760 cricket::MediaSessionOptions options;
3761 options.recv_audio = true;
3762 options.recv_video = true;
3763 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003764 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003765 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3766 SetRemoteDescriptionWithoutError(offer.release());
3767
3768 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003769 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003770 SetLocalDescriptionWithoutError(answer.release());
3771
3772 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003773 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003774 CreateRemoteOffer(options, session_->remote_description()));
3775 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3776 "original_password12345");
3777 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3778
kwibergd1fe2812016-04-27 06:47:29 -07003779 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003780 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3781 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003782 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003783
3784 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003785 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003786 CreateRemoteOffer(options, session_->remote_description()));
3787 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3788 "modified_password12345");
3789 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3790
kwibergd1fe2812016-04-27 06:47:29 -07003791 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003792 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3793 session_->local_description()->description()));
3794 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003795}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003796
wu@webrtc.org91053e72013-08-10 07:18:04 +00003797// This test verifies that an answer contains old ufrag and password if an offer
3798// with old ufrag and password is received.
3799TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003800 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003801 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003802 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003803 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003804 SetRemoteDescriptionWithoutError(offer.release());
3805
deadbeefab9b2d12015-10-14 11:33:11 -07003806 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003807 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003808 SetLocalDescriptionWithoutError(answer.release());
3809
3810 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003811 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003812 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003813 SetRemoteDescriptionWithoutError(updated_offer2.release());
3814
kwibergd1fe2812016-04-27 06:47:29 -07003815 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003816
deadbeef0ed85b22016-02-23 17:24:52 -08003817 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3818 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003819
3820 SetLocalDescriptionWithoutError(updated_answer2.release());
3821}
3822
deadbeef0ed85b22016-02-23 17:24:52 -08003823// This test verifies that if an offer does an ICE restart on some, but not all
3824// media sections, the answer will change the ufrag/password in the correct
3825// media sections.
3826TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3827 Init();
3828 cricket::MediaSessionOptions options;
3829 options.recv_video = true;
3830 options.recv_audio = true;
3831 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003832 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003833
3834 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3835 "aaaaaaaaaaaaaaaaaaaaaa");
3836 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3837 "bbbbbbbbbbbbbbbbbbbbbb");
3838 SetRemoteDescriptionWithoutError(offer.release());
3839
3840 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003841 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003842 SetLocalDescriptionWithoutError(answer.release());
3843
3844 // Receive an offer with new ufrag and password, but only for the video media
3845 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003846 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003847 CreateRemoteOffer(options, session_->remote_description()));
3848 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3849 "cccccccccccccccccccccc");
3850 SetRemoteDescriptionWithoutError(updated_offer.release());
3851
kwibergd1fe2812016-04-27 06:47:29 -07003852 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003853
3854 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3855 session_->local_description()->description(),
3856 cricket::MEDIA_TYPE_AUDIO));
3857
3858 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3859 session_->local_description()->description(),
3860 cricket::MEDIA_TYPE_VIDEO));
3861
3862 SetLocalDescriptionWithoutError(updated_answer.release());
3863}
3864
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003865TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003866 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003867 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003868 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003869 const std::string session_id_orig = offer->session_id();
3870 const std::string session_version_orig = offer->session_version();
3871 SetLocalDescriptionWithoutError(offer);
3872
3873 video_channel_ = media_engine_->GetVideoChannel(0);
3874 video_channel_->set_fail_set_send_codecs(true);
3875
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003876 SessionDescriptionInterface* answer =
3877 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003878 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003879
3880 // Test that after a content error, setting any description will
3881 // result in an error.
3882 video_channel_->set_fail_set_send_codecs(false);
3883 answer = CreateRemoteAnswer(session_->local_description());
3884 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3885 offer = CreateRemoteOffer();
3886 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003887}
3888
3889// Runs the loopback call test with BUNDLE and STUN disabled.
3890TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3891 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003892 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003893 cricket::PORTALLOCATOR_DISABLE_STUN |
3894 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003895 TestLoopbackCall();
3896}
3897
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003898TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003899 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003900 cricket::PORTALLOCATOR_DISABLE_STUN |
3901 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3902 cricket::PORTALLOCATOR_DISABLE_RELAY);
3903
3904 // best connection is IPv6 since it has higher network preference.
3905 LoopbackNetworkConfiguration config;
3906 config.test_ipv6_network_ = true;
3907 config.best_connection_after_initial_ice_converged_ =
3908 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3909
3910 TestLoopbackCall(config);
3911}
3912
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003913// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003914TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003915 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3916 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003917 TestLoopbackCall();
3918}
3919
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003920TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003921 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003922 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003923 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003924 ASSERT_TRUE(data_engine_);
deadbeef953c2ce2017-01-09 14:53:41 -08003925 EXPECT_NE(nullptr, data_engine_->GetChannel(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003926}
3927
Henrik Boström87713d02015-08-25 09:53:21 +02003928TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003929 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003930
htaa2a49d92016-03-04 02:51:39 -08003931 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003932 options_.disable_sctp_data_channels = false;
3933
Henrik Boström87713d02015-08-25 09:53:21 +02003934 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003935
3936 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08003937 EXPECT_NE(nullptr, data_engine_->GetChannel(0));
3938}
3939
3940// Test that sctp_content_name/sctp_transport_name (used for stats) are correct
3941// before and after BUNDLE is negotiated.
3942TEST_P(WebRtcSessionTest, SctpContentAndTransportName) {
3943 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3944 SetFactoryDtlsSrtp();
3945 InitWithDtls(GetParam());
3946
3947 // Initially these fields should be empty.
3948 EXPECT_FALSE(session_->sctp_content_name());
3949 EXPECT_FALSE(session_->sctp_transport_name());
3950
3951 // Create offer with audio/video/data.
3952 // Default bundle policy is "balanced", so data should be using its own
3953 // transport.
3954 SendAudioVideoStream1();
3955 CreateDataChannel();
3956 InitiateCall();
3957 ASSERT_TRUE(session_->sctp_content_name());
3958 ASSERT_TRUE(session_->sctp_transport_name());
3959 EXPECT_EQ("data", *session_->sctp_content_name());
3960 EXPECT_EQ("data", *session_->sctp_transport_name());
3961
3962 // Create answer that finishes BUNDLE negotiation, which means everything
3963 // should be bundled on the first transport (audio).
3964 cricket::MediaSessionOptions answer_options;
3965 answer_options.recv_video = true;
3966 answer_options.bundle_enabled = true;
3967 answer_options.data_channel_type = cricket::DCT_SCTP;
3968 SetRemoteDescriptionWithoutError(CreateRemoteAnswer(
3969 session_->local_description(), answer_options, cricket::SEC_DISABLED));
3970 ASSERT_TRUE(session_->sctp_content_name());
3971 ASSERT_TRUE(session_->sctp_transport_name());
3972 EXPECT_EQ("data", *session_->sctp_content_name());
3973 EXPECT_EQ("audio", *session_->sctp_transport_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003974}
3975
Henrik Boström87713d02015-08-25 09:53:21 +02003976TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003977 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003978
Henrik Boström87713d02015-08-25 09:53:21 +02003979 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003980
kwibergd1fe2812016-04-27 06:47:29 -07003981 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003982 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003983 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3984}
3985
Henrik Boström87713d02015-08-25 09:53:21 +02003986TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003987 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003988 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003989 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003990
3991 // Create remote offer with SCTP.
3992 cricket::MediaSessionOptions options;
3993 options.data_channel_type = cricket::DCT_SCTP;
3994 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003995 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003996 SetRemoteDescriptionWithoutError(offer);
3997
3998 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07003999 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00004000 EXPECT_TRUE(answer != NULL);
4001 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
4002 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00004003}
4004
deadbeef953c2ce2017-01-09 14:53:41 -08004005// Test that if DTLS is disabled, we don't end up with an SctpTransport
4006// created (or an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02004007TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08004008 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02004009 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004010
4011 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004012 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4013 EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004014}
4015
deadbeef953c2ce2017-01-09 14:53:41 -08004016// Test that if DTLS is enabled, we end up with an SctpTransport created
4017// (and not an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02004018TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004019 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004020
Henrik Boström87713d02015-08-25 09:53:21 +02004021 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004022
4023 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004024 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4025 EXPECT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004026}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004027
deadbeef953c2ce2017-01-09 14:53:41 -08004028// Test that if SCTP is disabled, we don't end up with an SctpTransport
4029// created (or an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02004030TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004031 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00004032 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02004033 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00004034
4035 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004036 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4037 EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
wu@webrtc.org97077a32013-10-25 21:18:33 +00004038}
4039
Henrik Boström87713d02015-08-25 09:53:21 +02004040TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004041 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004042 const int new_send_port = 9998;
4043 const int new_recv_port = 7775;
4044
Henrik Boström87713d02015-08-25 09:53:21 +02004045 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004046 SetFactoryDtlsSrtp();
4047
4048 // By default, don't actually add the codecs to desc_factory_; they don't
4049 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
4050 // let the session description get parsed. That'll get the proper codecs
4051 // into the stream.
4052 cricket::MediaSessionOptions options;
4053 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
4054 "stream1", new_send_port, options);
4055
4056 // SetRemoteDescription will take the ownership of the offer.
4057 SetRemoteDescriptionWithoutError(offer);
4058
htaa2a49d92016-03-04 02:51:39 -08004059 SessionDescriptionInterface* answer =
4060 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004061 ASSERT_TRUE(answer != NULL);
4062
4063 // Now set the local description, which'll take ownership of the answer.
4064 SetLocalDescriptionWithoutError(answer);
4065
4066 // TEST PLAN: Set the port number to something new, set it in the SDP,
4067 // and pass it all the way down.
deadbeef953c2ce2017-01-09 14:53:41 -08004068 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
deadbeefab9b2d12015-10-14 11:33:11 -07004069 CreateDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004070 ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
4071 EXPECT_EQ(
4072 new_recv_port,
4073 fake_sctp_transport_factory_->last_fake_sctp_transport()->local_port());
4074 EXPECT_EQ(
4075 new_send_port,
4076 fake_sctp_transport_factory_->last_fake_sctp_transport()->remote_port());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00004077}
4078
deadbeef953c2ce2017-01-09 14:53:41 -08004079// Verifies that when a session's SctpTransport receives an OPEN message,
4080// WebRtcSession signals the SctpTransport creation request with the expected
deadbeefab9b2d12015-10-14 11:33:11 -07004081// config.
4082TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
4083 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4084
4085 InitWithDtls(GetParam());
4086
4087 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08004088 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
4089 ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
deadbeefab9b2d12015-10-14 11:33:11 -07004090
deadbeef953c2ce2017-01-09 14:53:41 -08004091 // Make the fake SCTP transport pretend it received an OPEN message.
deadbeefab9b2d12015-10-14 11:33:11 -07004092 webrtc::DataChannelInit config;
4093 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07004094 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07004095 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4096 cricket::ReceiveDataParams params;
4097 params.ssrc = config.id;
4098 params.type = cricket::DMT_CONTROL;
deadbeef953c2ce2017-01-09 14:53:41 -08004099 fake_sctp_transport_factory_->last_fake_sctp_transport()->SignalDataReceived(
4100 params, payload);
deadbeefab9b2d12015-10-14 11:33:11 -07004101
deadbeef953c2ce2017-01-09 14:53:41 -08004102 EXPECT_EQ_WAIT("a", last_data_channel_label_, kDefaultTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07004103 EXPECT_EQ(config.id, last_data_channel_config_.id);
4104 EXPECT_FALSE(last_data_channel_config_.negotiated);
4105 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4106 last_data_channel_config_.open_handshake_role);
4107}
4108
4109TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004110 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
Henrik Boströmd79599d2016-06-01 13:58:50 +02004111 FakeRTCCertificateGenerator::GenerateCertificate();
Henrik Boströmd8281982015-08-27 10:12:24 +02004112
htaa2a49d92016-03-04 02:51:39 -08004113 configuration_.certificates.push_back(certificate);
4114 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004115 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4116
4117 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4118}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004119
Henrik Boström87713d02015-08-25 09:53:21 +02004120// Verifies that CreateOffer succeeds when CreateOffer is called before async
4121// identity generation is finished (even if a certificate is provided this is
4122// an async op).
4123TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
4124 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4125 InitWithDtls(GetParam());
4126
Henrik Boströmd8281982015-08-27 10:12:24 +02004127 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004128 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07004129 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004130
wu@webrtc.org91053e72013-08-10 07:18:04 +00004131 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004132 VerifyNoCryptoParams(offer->description(), true);
4133 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004134}
4135
4136// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004137// identity generation is finished (even if a certificate is provided this is
4138// an async op).
4139TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004140 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004141 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004142 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004143
4144 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004145 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07004146 std::unique_ptr<JsepSessionDescription> offer(
4147 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004148 ASSERT_TRUE(offer.get() != NULL);
4149 SetRemoteDescriptionWithoutError(offer.release());
4150
kwibergd1fe2812016-04-27 06:47:29 -07004151 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004152 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004153 VerifyNoCryptoParams(answer->description(), true);
4154 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004155}
4156
4157// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004158// identity generation is finished (even if a certificate is provided this is
4159// an async op).
4160TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004161 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004162 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004163
Henrik Boströmd8281982015-08-27 10:12:24 +02004164 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004165
kwibergd1fe2812016-04-27 06:47:29 -07004166 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004167 EXPECT_TRUE(offer != NULL);
4168}
4169
4170// Verifies that CreateOffer fails when CreateOffer is called after async
4171// identity generation fails.
4172TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004173 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004174 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004175
Henrik Boströmd8281982015-08-27 10:12:24 +02004176 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004177
kwibergd1fe2812016-04-27 06:47:29 -07004178 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004179 EXPECT_TRUE(offer == NULL);
4180}
4181
4182// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4183// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004184TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004185 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004186 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004187 VerifyMultipleAsyncCreateDescription(GetParam(),
4188 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004189}
4190
4191// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4192// before async identity generation fails.
4193TEST_F(WebRtcSessionTest,
4194 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004195 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004196 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4197 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004198}
4199
4200// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4201// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004202TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004203 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004204 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004205 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004206 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004207}
4208
4209// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4210// before async identity generation fails.
4211TEST_F(WebRtcSessionTest,
4212 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004213 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004214 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4215 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004216}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004217
4218// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4219// offer has no SDES crypto but only DTLS fingerprint.
4220TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4221 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004222 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004223 // Create a remote offer with secured transport disabled.
4224 cricket::MediaSessionOptions options;
4225 JsepSessionDescription* offer(CreateRemoteOffer(
4226 options, cricket::SEC_DISABLED));
4227 // Adds a DTLS fingerprint to the remote offer.
4228 cricket::SessionDescription* sdp = offer->description();
4229 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4230 ASSERT_TRUE(audio != NULL);
4231 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4232 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004233 rtc::SSLFingerprint::CreateFromRfc4572(
4234 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004235 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004236 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004237}
4238
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004239TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004240 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004241 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004242 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004243 SessionDescriptionInterface* offer = CreateOffer();
4244
4245 SetLocalDescriptionWithoutError(offer);
4246
4247 voice_channel_ = media_engine_->GetVoiceChannel(0);
4248
4249 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004250 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004251 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004252}
4253
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004254// Tests that we can renegotiate new media content with ICE candidates in the
4255// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004256TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004257 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004258 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004259 SetFactoryDtlsSrtp();
4260
deadbeefab9b2d12015-10-14 11:33:11 -07004261 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004262 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004263 SetLocalDescriptionWithoutError(offer);
4264
4265 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4266 SetRemoteDescriptionWithoutError(answer);
4267
4268 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004269 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004270 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4271
4272 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004273 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004274 candidate1.set_component(1);
4275 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4276 candidate1);
4277 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4278 SetRemoteDescriptionWithoutError(offer);
4279
htaa2a49d92016-03-04 02:51:39 -08004280 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004281 SetLocalDescriptionWithoutError(answer);
4282}
4283
4284// Tests that we can renegotiate new media content with ICE candidates separated
4285// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004286TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004287 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004288 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004289 SetFactoryDtlsSrtp();
4290
deadbeefab9b2d12015-10-14 11:33:11 -07004291 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004292 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004293 SetLocalDescriptionWithoutError(offer);
4294
4295 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4296 SetRemoteDescriptionWithoutError(answer);
4297
4298 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004299 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004300 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4301 SetRemoteDescriptionWithoutError(offer);
4302
4303 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004304 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004305 candidate1.set_component(1);
4306 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4307 candidate1);
4308 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4309
htaa2a49d92016-03-04 02:51:39 -08004310 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004311 SetLocalDescriptionWithoutError(answer);
4312}
honghaiz7f777492016-02-02 21:54:01 -08004313
zhihuang9763d562016-08-05 11:14:50 -07004314#ifdef HAVE_QUIC
4315TEST_P(WebRtcSessionTest, TestNegotiateQuic) {
4316 configuration_.enable_quic = true;
4317 InitWithDtls(GetParam());
4318 EXPECT_TRUE(session_->data_channel_type() == cricket::DCT_QUIC);
4319 SessionDescriptionInterface* offer = CreateOffer();
4320 ASSERT_TRUE(offer);
4321 ASSERT_TRUE(offer->description());
4322 SetLocalDescriptionWithoutError(offer);
4323 cricket::MediaSessionOptions options;
4324 options.recv_audio = true;
4325 options.recv_video = true;
4326 SessionDescriptionInterface* answer =
4327 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
4328 ASSERT_TRUE(answer);
4329 ASSERT_TRUE(answer->description());
4330 SetRemoteDescriptionWithoutError(answer);
4331}
4332#endif // HAVE_QUIC
4333
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004334// Tests that RTX codec is removed from the answer when it isn't supported
4335// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004336TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004337 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004338 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004339 std::string offer_sdp(kSdpWithRtx);
4340
4341 SessionDescriptionInterface* offer =
4342 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4343 EXPECT_TRUE(offer->ToString(&offer_sdp));
4344
4345 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004346 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004347 SetRemoteDescriptionWithoutError(offer);
4348
htaa2a49d92016-03-04 02:51:39 -08004349 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004350 // Answer SDP does not contain the RTX codec.
4351 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004352 SetLocalDescriptionWithoutError(answer);
4353}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004354
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004355// This verifies that the voice channel after bundle has both options from video
4356// and voice channels.
4357TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4358 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004359 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004360
4361 PeerConnectionInterface::RTCOfferAnswerOptions options;
4362 options.use_rtp_mux = true;
4363
4364 SessionDescriptionInterface* offer = CreateOffer(options);
4365 SetLocalDescriptionWithoutError(offer);
4366
4367 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4368 rtc::Socket::Option::OPT_SNDBUF, 4000);
4369
4370 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4371 rtc::Socket::Option::OPT_RCVBUF, 8000);
4372
4373 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004374 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004375 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4376 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004377 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004378 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4379
deadbeefcbecd352015-09-23 11:50:27 -07004380 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004381 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4382 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004383 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004384 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4385
deadbeefcbecd352015-09-23 11:50:27 -07004386 EXPECT_NE(session_->voice_rtp_transport_channel(),
4387 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004388
deadbeefab9b2d12015-10-14 11:33:11 -07004389 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004390 SessionDescriptionInterface* answer =
4391 CreateRemoteAnswer(session_->local_description());
4392 SetRemoteDescriptionWithoutError(answer);
4393
deadbeefcbecd352015-09-23 11:50:27 -07004394 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004395 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4396 EXPECT_EQ(4000, option_val);
4397
deadbeefcbecd352015-09-23 11:50:27 -07004398 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004399 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4400 EXPECT_EQ(8000, option_val);
4401}
4402
tommi0f620f42015-07-09 03:25:02 -07004403// Test creating a session, request multiple offers, destroy the session
4404// and make sure we got success/failure callbacks for all of the requests.
4405// Background: crbug.com/507307
4406TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4407 Init();
4408
4409 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4410 PeerConnectionInterface::RTCOfferAnswerOptions options;
4411 options.offer_to_receive_audio =
4412 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004413 cricket::MediaSessionOptions session_options;
4414 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004415
4416 for (auto& o : observers) {
4417 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004418 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004419 }
4420
4421 session_.reset();
4422
tommi0f620f42015-07-09 03:25:02 -07004423 for (auto& o : observers) {
4424 // We expect to have received a notification now even if the session was
4425 // terminated. The offer creation may or may not have succeeded, but we
4426 // must have received a notification which, so the only invalid state
4427 // is kInit.
4428 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4429 }
4430}
4431
stefanc1aeaf02015-10-15 07:26:07 -07004432TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4433 TestPacketOptions();
4434}
4435
deadbeef057ecf02016-01-20 14:30:43 -08004436// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4437// is destroyed.
4438TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4439 Init();
4440 session_.reset();
4441 EXPECT_TRUE(session_destroyed_);
4442}
4443
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004444// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4445// currently fails because upon disconnection and reconnection OnIceComplete is
4446// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004447
deadbeefcbecd352015-09-23 11:50:27 -07004448INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4449 WebRtcSessionTest,
4450 testing::Values(ALREADY_GENERATED,
4451 DTLS_IDENTITY_STORE));