blob: 6efb996f769e74d503267a46b6334f2794df8058 [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"
johan669d69b2016-11-08 14:14:08 -080043#include "webrtc/p2p/base/packettransportinterface.h"
kjellandera96e2d72016-02-04 23:52:28 -080044#include "webrtc/p2p/base/stunserver.h"
45#include "webrtc/p2p/base/teststunserver.h"
46#include "webrtc/p2p/base/testturnserver.h"
47#include "webrtc/p2p/base/transportchannel.h"
48#include "webrtc/p2p/client/basicportallocator.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010049#include "webrtc/pc/channelmanager.h"
50#include "webrtc/pc/mediasession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051
52#define MAYBE_SKIP_TEST(feature) \
53 if (!(feature())) { \
54 LOG(LS_INFO) << "Feature disabled... skipping"; \
55 return; \
56 }
57
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000060using rtc::SocketAddress;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000061using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000063using webrtc::CreateSessionDescriptionObserver;
64using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070065using webrtc::DataChannel;
jbauchac8869e2015-07-03 01:36:14 -070066using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070068using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069using webrtc::JsepIceCandidate;
70using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000071using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072using webrtc::PeerConnectionInterface;
73using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070074using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000076using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000077using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000078using webrtc::kCreateChannelFailed;
79using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000081using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000082using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000083using webrtc::kSdpWithoutDtlsFingerprint;
84using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000086using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000087using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +000089typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
90
wu@webrtc.org364f2042013-11-20 21:49:41 +000091static const int kClientAddrPort = 0;
92static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +000093static const char kClientIPv6AddrHost1[] =
94 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +000095static const char kClientAddrHost2[] = "22.22.22.22";
96static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +000097static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
98static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +000099static const char kTurnUsername[] = "test";
100static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101
102static const char kSessionVersion[] = "1";
103
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104// Media index of candidates belonging to the first media content.
105static const int kMediaContentIndex0 = 0;
106static const char kMediaContentName0[] = "audio";
107
108// Media index of candidates belonging to the second media content.
109static const int kMediaContentIndex1 = 1;
110static const char kMediaContentName1[] = "video";
111
112static const int kIceCandidatesTimeout = 10000;
deadbeeff5f03e82016-06-06 11:16:06 -0700113// STUN timeout with all retransmissions is a total of 9500ms.
114static const int kStunTimeout = 9500;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000116static const char kFakeDtlsFingerprint[] =
117 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
118 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
119
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000120static const char kTooLongIceUfragPwd[] =
121 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
122 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
123 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
124 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
125
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000126static const char kSdpWithRtx[] =
127 "v=0\r\n"
128 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
129 "s=-\r\n"
130 "t=0 0\r\n"
131 "a=msid-semantic: WMS stream1\r\n"
132 "m=video 9 RTP/SAVPF 0 96\r\n"
133 "c=IN IP4 0.0.0.0\r\n"
134 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
135 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
136 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
137 "a=mid:video\r\n"
138 "a=sendrecv\r\n"
139 "a=rtcp-mux\r\n"
140 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
141 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
142 "a=rtpmap:0 fake_video_codec/90000\r\n"
143 "a=rtpmap:96 rtx/90000\r\n"
144 "a=fmtp:96 apt=0\r\n";
145
deadbeefab9b2d12015-10-14 11:33:11 -0700146static const char kStream1[] = "stream1";
147static const char kVideoTrack1[] = "video1";
148static const char kAudioTrack1[] = "audio1";
149
150static const char kStream2[] = "stream2";
151static const char kVideoTrack2[] = "video2";
152static const char kAudioTrack2[] = "audio2";
153
Henrik Boström87713d02015-08-25 09:53:21 +0200154enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
155
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000156class MockIceObserver : public webrtc::IceObserver {
157 public:
158 MockIceObserver()
159 : oncandidatesready_(false),
160 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
161 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
162 }
163
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200164 virtual ~MockIceObserver() = default;
165
perkjdfb769d2016-02-09 03:09:43 -0800166 void OnIceConnectionChange(
167 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000168 ice_connection_state_ = new_state;
skvlad6c87a672016-05-17 17:49:52 -0700169 ice_connection_state_history_.push_back(new_state);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000170 }
perkjdfb769d2016-02-09 03:09:43 -0800171 void OnIceGatheringChange(
172 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173 // We can never transition back to "new".
174 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
175 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800176 oncandidatesready_ =
177 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000178 }
179
180 // Found a new candidate.
perkjdfb769d2016-02-09 03:09:43 -0800181 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000182 switch (candidate->sdp_mline_index()) {
183 case kMediaContentIndex0:
184 mline_0_candidates_.push_back(candidate->candidate());
185 break;
186 case kMediaContentIndex1:
187 mline_1_candidates_.push_back(candidate->candidate());
188 break;
189 default:
190 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000191 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000192
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000193 // The ICE gathering state should always be Gathering when a candidate is
194 // received (or possibly Completed in the case of the final candidate).
195 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
196 }
197
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700198 // Some local candidates are removed.
199 void OnIceCandidatesRemoved(
nisseef8b61e2016-04-29 06:09:15 -0700200 const std::vector<cricket::Candidate>& candidates) override {
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700201 num_candidates_removed_ += candidates.size();
202 }
203
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000204 bool oncandidatesready_;
205 std::vector<cricket::Candidate> mline_0_candidates_;
206 std::vector<cricket::Candidate> mline_1_candidates_;
207 PeerConnectionInterface::IceConnectionState ice_connection_state_;
208 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
skvlad6c87a672016-05-17 17:49:52 -0700209 std::vector<PeerConnectionInterface::IceConnectionState>
210 ice_connection_state_history_;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700211 size_t num_candidates_removed_ = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212};
213
214class WebRtcSessionForTest : public webrtc::WebRtcSession {
215 public:
zhihuang29ff8442016-07-27 11:07:25 -0700216 WebRtcSessionForTest(
217 webrtc::MediaControllerInterface* media_controller,
218 rtc::Thread* network_thread,
219 rtc::Thread* worker_thread,
220 rtc::Thread* signaling_thread,
221 cricket::PortAllocator* port_allocator,
222 webrtc::IceObserver* ice_observer,
223 std::unique_ptr<cricket::TransportController> transport_controller)
stefanc1aeaf02015-10-15 07:26:07 -0700224 : WebRtcSession(media_controller,
danilchape9021a32016-05-17 01:52:02 -0700225 network_thread,
stefanc1aeaf02015-10-15 07:26:07 -0700226 worker_thread,
danilchape9021a32016-05-17 01:52:02 -0700227 signaling_thread,
zhihuang29ff8442016-07-27 11:07:25 -0700228 port_allocator,
229 std::move(transport_controller)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000230 RegisterIceObserver(ice_observer);
231 }
232 virtual ~WebRtcSessionForTest() {}
233
deadbeefcbecd352015-09-23 11:50:27 -0700234 // Note that these methods are only safe to use if the signaling thread
235 // is the same as the worker thread
johan669d69b2016-11-08 14:14:08 -0800236 rtc::PacketTransportInterface* voice_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700237 return rtp_transport_channel(voice_channel());
238 }
239
johan669d69b2016-11-08 14:14:08 -0800240 rtc::PacketTransportInterface* voice_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700241 return rtcp_transport_channel(voice_channel());
242 }
243
johan669d69b2016-11-08 14:14:08 -0800244 rtc::PacketTransportInterface* video_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700245 return rtp_transport_channel(video_channel());
246 }
247
johan669d69b2016-11-08 14:14:08 -0800248 rtc::PacketTransportInterface* video_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700249 return rtcp_transport_channel(video_channel());
250 }
251
johan669d69b2016-11-08 14:14:08 -0800252 rtc::PacketTransportInterface* data_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700253 return rtp_transport_channel(data_channel());
254 }
255
johan669d69b2016-11-08 14:14:08 -0800256 rtc::PacketTransportInterface* data_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700257 return rtcp_transport_channel(data_channel());
258 }
259
deadbeefcbecd352015-09-23 11:50:27 -0700260 private:
johan669d69b2016-11-08 14:14:08 -0800261 rtc::PacketTransportInterface* rtp_transport_channel(
262 cricket::BaseChannel* ch) {
deadbeefcbecd352015-09-23 11:50:27 -0700263 if (!ch) {
264 return nullptr;
265 }
266 return ch->transport_channel();
267 }
268
johan669d69b2016-11-08 14:14:08 -0800269 rtc::PacketTransportInterface* rtcp_transport_channel(
270 cricket::BaseChannel* ch) {
deadbeefcbecd352015-09-23 11:50:27 -0700271 if (!ch) {
272 return nullptr;
273 }
274 return ch->rtcp_transport_channel();
275 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000276};
277
wu@webrtc.org91053e72013-08-10 07:18:04 +0000278class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000279 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000280 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000281 enum State {
282 kInit,
283 kFailed,
284 kSucceeded,
285 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000286 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000287
288 // CreateSessionDescriptionObserver implementation.
289 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000290 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000291 state_ = kSucceeded;
292 }
293 virtual void OnFailure(const std::string& error) {
294 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295 }
296
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000297 SessionDescriptionInterface* description() { return description_.get(); }
298
299 SessionDescriptionInterface* ReleaseDescription() {
300 return description_.release();
301 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302
wu@webrtc.org91053e72013-08-10 07:18:04 +0000303 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304
wu@webrtc.org91053e72013-08-10 07:18:04 +0000305 protected:
306 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000307
308 private:
kwibergd1fe2812016-04-27 06:47:29 -0700309 std::unique_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000310 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311};
312
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800313class FakeAudioSource : public cricket::AudioSource {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000314 public:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800315 FakeAudioSource() : sink_(NULL) {}
316 virtual ~FakeAudioSource() {
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000317 if (sink_)
318 sink_->OnClose();
319 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000320
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000321 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000322
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800323 const cricket::AudioSource::Sink* sink() const { return sink_; }
324
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000325 private:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800326 cricket::AudioSource::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000327};
328
Henrik Boström87713d02015-08-25 09:53:21 +0200329class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700330 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
331 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000332 protected:
333 // TODO Investigate why ChannelManager crashes, if it's created
334 // after stun_server.
335 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700336 : media_engine_(new cricket::FakeMediaEngine()),
337 data_engine_(new cricket::FakeDataEngine()),
skvlad11a9cbf2016-10-07 11:53:05 -0700338 channel_manager_(new cricket::ChannelManager(media_engine_,
339 data_engine_,
340 rtc::Thread::Current())),
341 fake_call_(webrtc::Call::Config(&event_log_)),
stefanc1aeaf02015-10-15 07:26:07 -0700342 media_controller_(
nisse51542be2016-02-12 02:27:06 -0800343 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
344 rtc::Thread::Current(),
skvlad11a9cbf2016-10-07 11:53:05 -0700345 channel_manager_.get(),
346 &event_log_)),
stefanc1aeaf02015-10-15 07:26:07 -0700347 tdesc_factory_(new cricket::TransportDescriptionFactory()),
348 desc_factory_(
349 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
350 tdesc_factory_.get())),
351 pss_(new rtc::PhysicalSocketServer),
352 vss_(new rtc::VirtualSocketServer(pss_.get())),
353 fss_(new rtc::FirewallSocketServer(vss_.get())),
354 ss_scope_(fss_.get()),
355 stun_socket_addr_(
356 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
357 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
358 stun_socket_addr_)),
359 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
360 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000361 cricket::ServerAddresses stun_servers;
362 stun_servers.insert(stun_socket_addr_);
363 allocator_.reset(new cricket::BasicPortAllocator(
364 &network_manager_,
365 stun_servers,
366 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000367 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700368 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369 EXPECT_TRUE(channel_manager_->Init());
370 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000371 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000372 }
373
374 void AddInterface(const SocketAddress& addr) {
375 network_manager_.AddInterface(addr);
376 }
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700377 void RemoveInterface(const SocketAddress& addr) {
378 network_manager_.RemoveInterface(addr);
379 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000380
Henrik Boströmd79599d2016-06-01 13:58:50 +0200381 // If |cert_generator| != null or |rtc_configuration| contains |certificates|
382 // then DTLS will be enabled unless explicitly disabled by |rtc_configuration|
383 // options. When DTLS is enabled a certificate will be used if provided,
384 // otherwise one will be generated using the |cert_generator|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000385 void Init(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200386 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000387 ASSERT_TRUE(session_.get() == NULL);
388 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700389 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
zhihuang29ff8442016-07-27 11:07:25 -0700390 rtc::Thread::Current(), allocator_.get(), &observer_,
391 std::unique_ptr<cricket::TransportController>(
392 new cricket::TransportController(rtc::Thread::Current(),
393 rtc::Thread::Current(),
394 allocator_.get()))));
deadbeefab9b2d12015-10-14 11:33:11 -0700395 session_->SignalDataChannelOpenMessage.connect(
396 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
deadbeef057ecf02016-01-20 14:30:43 -0800397 session_->GetOnDestroyedSignal()->connect(
398 this, &WebRtcSessionTest::OnSessionDestroyed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000399
400 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
401 observer_.ice_connection_state_);
402 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
403 observer_.ice_gathering_state_);
404
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200405 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator),
htaa2a49d92016-03-04 02:51:39 -0800406 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700407 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000408 }
409
deadbeefab9b2d12015-10-14 11:33:11 -0700410 void OnDataChannelOpenMessage(const std::string& label,
411 const InternalDataChannelInit& config) {
412 last_data_channel_label_ = label;
413 last_data_channel_config_ = config;
414 }
415
deadbeef057ecf02016-01-20 14:30:43 -0800416 void OnSessionDestroyed() { session_destroyed_ = true; }
417
htaa2a49d92016-03-04 02:51:39 -0800418 void Init() { Init(nullptr); }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000419
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000420 void InitWithBundlePolicy(
421 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800422 configuration_.bundle_policy = bundle_policy;
423 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700424 }
425
426 void InitWithRtcpMuxPolicy(
427 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
428 PeerConnectionInterface::RTCConfiguration configuration;
htaa2a49d92016-03-04 02:51:39 -0800429 configuration_.rtcp_mux_policy = rtcp_mux_policy;
430 Init();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000431 }
432
Henrik Boström87713d02015-08-25 09:53:21 +0200433 // Successfully init with DTLS; with a certificate generated and supplied or
434 // with a store that generates it for us.
435 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200436 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator;
Henrik Boström87713d02015-08-25 09:53:21 +0200437 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800438 configuration_.certificates.push_back(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200439 FakeRTCCertificateGenerator::GenerateCertificate());
Henrik Boström87713d02015-08-25 09:53:21 +0200440 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200441 cert_generator.reset(new FakeRTCCertificateGenerator());
442 cert_generator->set_should_fail(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200443 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700444 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200445 }
Henrik Boströmd79599d2016-06-01 13:58:50 +0200446 Init(std::move(cert_generator));
Henrik Boström87713d02015-08-25 09:53:21 +0200447 }
448
449 // Init with DTLS with a store that will fail to generate a certificate.
450 void InitWithDtlsIdentityGenFail() {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200451 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
452 new FakeRTCCertificateGenerator());
453 cert_generator->set_should_fail(true);
454 Init(std::move(cert_generator));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000455 }
456
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000457 void InitWithDtmfCodec() {
458 // Add kTelephoneEventCodec for dtmf test.
deadbeef67cf2c12016-04-13 10:07:16 -0700459 const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000,
460 0, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000461 std::vector<cricket::AudioCodec> codecs;
462 codecs.push_back(kTelephoneEventCodec);
463 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -0700464 desc_factory_->set_audio_codecs(codecs, codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000465 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000466 }
467
jbauchcb560652016-08-04 05:20:32 -0700468 void InitWithGcm() {
469 rtc::CryptoOptions crypto_options;
470 crypto_options.enable_gcm_crypto_suites = true;
471 channel_manager_->SetCryptoOptions(crypto_options);
472 with_gcm_ = true;
473 Init();
474 }
475
deadbeefab9b2d12015-10-14 11:33:11 -0700476 void SendAudioVideoStream1() {
477 send_stream_1_ = true;
478 send_stream_2_ = false;
479 send_audio_ = true;
480 send_video_ = true;
481 }
482
483 void SendAudioVideoStream2() {
484 send_stream_1_ = false;
485 send_stream_2_ = true;
486 send_audio_ = true;
487 send_video_ = true;
488 }
489
490 void SendAudioVideoStream1And2() {
491 send_stream_1_ = true;
492 send_stream_2_ = true;
493 send_audio_ = true;
494 send_video_ = true;
495 }
496
497 void SendNothing() {
498 send_stream_1_ = false;
499 send_stream_2_ = false;
500 send_audio_ = false;
501 send_video_ = false;
502 }
503
504 void SendAudioOnlyStream2() {
505 send_stream_1_ = false;
506 send_stream_2_ = true;
507 send_audio_ = true;
508 send_video_ = false;
509 }
510
511 void SendVideoOnlyStream2() {
512 send_stream_1_ = false;
513 send_stream_2_ = true;
514 send_audio_ = false;
515 send_video_ = true;
516 }
517
518 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
519 if (send_stream_1_ && send_audio_) {
520 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
521 kStream1);
522 }
523 if (send_stream_1_ && send_video_) {
524 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
525 kStream1);
526 }
527 if (send_stream_2_ && send_audio_) {
528 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
529 kStream2);
530 }
531 if (send_stream_2_ && send_video_) {
532 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
533 kStream2);
534 }
535 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
536 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
537 data_channel_->label(),
538 data_channel_->label());
539 }
540 }
541
542 void GetOptionsForOffer(
543 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
544 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800545 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700546
deadbeefc80741f2015-10-22 13:14:45 -0700547 AddStreamsToOptions(session_options);
548 if (rtc_options.offer_to_receive_audio ==
549 RTCOfferAnswerOptions::kUndefined) {
550 session_options->recv_audio =
551 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
552 }
553 if (rtc_options.offer_to_receive_video ==
554 RTCOfferAnswerOptions::kUndefined) {
555 session_options->recv_video =
556 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
557 }
558 session_options->bundle_enabled =
559 session_options->bundle_enabled &&
560 (session_options->has_audio() || session_options->has_video() ||
561 session_options->has_data());
562
deadbeefab9b2d12015-10-14 11:33:11 -0700563 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
564 session_options->data_channel_type = cricket::DCT_SCTP;
zhihuang9763d562016-08-05 11:14:50 -0700565 } else if (session_->data_channel_type() == cricket::DCT_QUIC) {
566 session_options->data_channel_type = cricket::DCT_QUIC;
deadbeefab9b2d12015-10-14 11:33:11 -0700567 }
jbauchcb560652016-08-04 05:20:32 -0700568
569 if (with_gcm_) {
570 session_options->crypto_options.enable_gcm_crypto_suites = true;
571 }
deadbeefab9b2d12015-10-14 11:33:11 -0700572 }
573
htaa2a49d92016-03-04 02:51:39 -0800574 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
575 // ParseConstraintsForAnswer is used to set some defaults.
576 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700577
deadbeefc80741f2015-10-22 13:14:45 -0700578 AddStreamsToOptions(session_options);
579 session_options->bundle_enabled =
580 session_options->bundle_enabled &&
581 (session_options->has_audio() || session_options->has_video() ||
582 session_options->has_data());
583
zhihuang9763d562016-08-05 11:14:50 -0700584 if (session_->data_channel_type() != cricket::DCT_RTP) {
585 session_options->data_channel_type = session_->data_channel_type();
deadbeef907abe42016-08-04 12:22:18 -0700586 }
jbauchcb560652016-08-04 05:20:32 -0700587
588 if (with_gcm_) {
589 session_options->crypto_options.enable_gcm_crypto_suites = true;
590 }
deadbeefab9b2d12015-10-14 11:33:11 -0700591 }
592
593 // Creates a local offer and applies it. Starts ICE.
594 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000595 // to decide which streams to create.
596 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000597 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000598 SetLocalDescriptionWithoutError(offer);
599 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
600 observer_.ice_gathering_state_,
601 kIceCandidatesTimeout);
602 }
603
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000604 SessionDescriptionInterface* CreateOffer() {
605 PeerConnectionInterface::RTCOfferAnswerOptions options;
606 options.offer_to_receive_audio =
607 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
608
609 return CreateOffer(options);
610 }
611
wu@webrtc.org91053e72013-08-10 07:18:04 +0000612 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800613 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000614 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000615 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700616 cricket::MediaSessionOptions session_options;
617 GetOptionsForOffer(options, &session_options);
618 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000619 EXPECT_TRUE_WAIT(
620 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000621 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000622 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000623 }
624
625 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800626 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000627 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000628 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800629 cricket::MediaSessionOptions session_options = options;
630 GetOptionsForAnswer(&session_options);
631 // Overwrite recv_audio and recv_video with passed-in values.
632 session_options.recv_video = options.recv_video;
633 session_options.recv_audio = options.recv_audio;
634 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000635 EXPECT_TRUE_WAIT(
636 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000637 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000638 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000639 }
640
htaa2a49d92016-03-04 02:51:39 -0800641 SessionDescriptionInterface* CreateAnswer() {
642 cricket::MediaSessionOptions options;
643 options.recv_video = true;
644 options.recv_audio = true;
645 return CreateAnswer(options);
646 }
647
wu@webrtc.org364f2042013-11-20 21:49:41 +0000648 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000649 return (session_->voice_channel() != NULL &&
650 session_->video_channel() != NULL);
651 }
652
jbauchcb560652016-08-04 05:20:32 -0700653 void VerifyCryptoParams(const cricket::SessionDescription* sdp,
654 bool gcm_enabled = false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000655 ASSERT_TRUE(session_.get() != NULL);
656 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
657 ASSERT_TRUE(content != NULL);
658 const cricket::AudioContentDescription* audio_content =
659 static_cast<const cricket::AudioContentDescription*>(
660 content->description);
661 ASSERT_TRUE(audio_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700662 if (!gcm_enabled) {
663 ASSERT_EQ(1U, audio_content->cryptos().size());
664 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
665 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
666 audio_content->cryptos()[0].cipher_suite);
667 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
668 audio_content->protocol());
669 } else {
670 // The offer contains 3 possible crypto suites, the answer 1.
671 EXPECT_LE(1U, audio_content->cryptos().size());
672 EXPECT_NE(2U, audio_content->cryptos().size());
673 EXPECT_GE(3U, audio_content->cryptos().size());
674 ASSERT_EQ(67U, audio_content->cryptos()[0].key_params.size());
675 ASSERT_EQ("AEAD_AES_256_GCM",
676 audio_content->cryptos()[0].cipher_suite);
677 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
678 audio_content->protocol());
679 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000680
681 content = cricket::GetFirstVideoContent(sdp);
682 ASSERT_TRUE(content != NULL);
683 const cricket::VideoContentDescription* video_content =
684 static_cast<const cricket::VideoContentDescription*>(
685 content->description);
686 ASSERT_TRUE(video_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700687 if (!gcm_enabled) {
688 ASSERT_EQ(1U, video_content->cryptos().size());
689 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
690 video_content->cryptos()[0].cipher_suite);
691 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
692 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
693 video_content->protocol());
694 } else {
695 // The offer contains 3 possible crypto suites, the answer 1.
696 EXPECT_LE(1U, video_content->cryptos().size());
697 EXPECT_NE(2U, video_content->cryptos().size());
698 EXPECT_GE(3U, video_content->cryptos().size());
699 ASSERT_EQ("AEAD_AES_256_GCM",
700 video_content->cryptos()[0].cipher_suite);
701 ASSERT_EQ(67U, video_content->cryptos()[0].key_params.size());
702 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
703 video_content->protocol());
704 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000705 }
706
707 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
708 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
709 ASSERT_TRUE(content != NULL);
710 const cricket::AudioContentDescription* audio_content =
711 static_cast<const cricket::AudioContentDescription*>(
712 content->description);
713 ASSERT_TRUE(audio_content != NULL);
714 ASSERT_EQ(0U, audio_content->cryptos().size());
715
716 content = cricket::GetFirstVideoContent(sdp);
717 ASSERT_TRUE(content != NULL);
718 const cricket::VideoContentDescription* video_content =
719 static_cast<const cricket::VideoContentDescription*>(
720 content->description);
721 ASSERT_TRUE(video_content != NULL);
722 ASSERT_EQ(0U, video_content->cryptos().size());
723
724 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700725 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000726 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700727 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000728 video_content->protocol());
729 } else {
730 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
731 audio_content->protocol());
732 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
733 video_content->protocol());
734 }
735 }
736
737 // Set the internal fake description factories to do DTLS-SRTP.
738 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000739 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000740 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000741 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200742 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800743 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700744 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800745 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000746 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
747 }
748
749 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
750 bool expected) {
751 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
752 ASSERT_TRUE(audio != NULL);
753 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754 const TransportInfo* video = sdp->GetTransportInfoByName("video");
755 ASSERT_TRUE(video != NULL);
756 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000757 }
758
759 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000760 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000761 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000762 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000763 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000764 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000765 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000766 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000767 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
768 offer);
htaa2a49d92016-03-04 02:51:39 -0800769 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000770 // Answer should be NULL as no crypto params in offer.
771 ASSERT_TRUE(answer == NULL);
772 }
773
774 void VerifyAnswerFromCryptoOffer() {
775 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000776 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000777 options.bundle_enabled = true;
kwibergd1fe2812016-04-27 06:47:29 -0700778 std::unique_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000779 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
780 ASSERT_TRUE(offer.get() != NULL);
781 VerifyCryptoParams(offer->description());
782 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -0700783 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000784 ASSERT_TRUE(answer.get() != NULL);
785 VerifyCryptoParams(answer->description());
786 }
787
deadbeef0ed85b22016-02-23 17:24:52 -0800788 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
789 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800791 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000792 }
793
794 const cricket::ContentInfos& contents = desc1->contents();
795 cricket::ContentInfos::const_iterator it = contents.begin();
796
797 for (; it != contents.end(); ++it) {
798 const cricket::TransportDescription* transport_desc1 =
799 desc1->GetTransportDescriptionByName(it->name);
800 const cricket::TransportDescription* transport_desc2 =
801 desc2->GetTransportDescriptionByName(it->name);
802 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800803 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 }
805 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
806 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800807 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000808 }
809 }
deadbeef0ed85b22016-02-23 17:24:52 -0800810 return true;
811 }
812
813 // Compares ufrag/password only for the specified |media_type|.
814 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
815 const cricket::SessionDescription* desc2,
816 cricket::MediaType media_type) {
817 if (desc1->contents().size() != desc2->contents().size()) {
818 return false;
819 }
820
821 const cricket::ContentInfo* cinfo =
822 cricket::GetFirstMediaContent(desc1->contents(), media_type);
823 const cricket::TransportDescription* transport_desc1 =
824 desc1->GetTransportDescriptionByName(cinfo->name);
825 const cricket::TransportDescription* transport_desc2 =
826 desc2->GetTransportDescriptionByName(cinfo->name);
827 if (!transport_desc1 || !transport_desc2) {
828 return false;
829 }
830 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
831 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
832 return false;
833 }
834 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000836
837 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
838 std::string *sdp) {
839 const cricket::SessionDescription* desc = current_desc->description();
840 EXPECT_TRUE(current_desc->ToString(sdp));
841
842 const cricket::ContentInfos& contents = desc->contents();
843 cricket::ContentInfos::const_iterator it = contents.begin();
844 // Replace ufrag and pwd lines with empty strings.
845 for (; it != contents.end(); ++it) {
846 const cricket::TransportDescription* transport_desc =
847 desc->GetTransportDescriptionByName(it->name);
848 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
849 + "\r\n";
850 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
851 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000852 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000853 "", 0,
854 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000855 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000856 "", 0,
857 sdp);
858 }
859 }
860
deadbeef0ed85b22016-02-23 17:24:52 -0800861 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
862 const std::string& ufrag,
863 const std::string& pwd) {
864 cricket::SessionDescription* desc = current_desc->description();
865 for (TransportInfo& transport_info : desc->transport_infos()) {
866 cricket::TransportDescription& transport_desc =
867 transport_info.description;
868 transport_desc.ice_ufrag = ufrag;
869 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000870 }
871 }
872
deadbeef0ed85b22016-02-23 17:24:52 -0800873 // Sets ufrag/pwd for specified |media_type|.
874 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
875 cricket::MediaType media_type,
876 const std::string& ufrag,
877 const std::string& pwd) {
878 cricket::SessionDescription* desc = current_desc->description();
879 const cricket::ContentInfo* cinfo =
880 cricket::GetFirstMediaContent(desc->contents(), media_type);
881 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
882 cricket::TransportDescription* transport_desc =
883 &transport_info->description;
884 transport_desc->ice_ufrag = ufrag;
885 transport_desc->ice_pwd = pwd;
886 }
887
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888 // Creates a remote offer and and applies it as a remote description,
889 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700890 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000891 // to decide which local and remote streams to create.
892 void CreateAndSetRemoteOfferAndLocalAnswer() {
893 SessionDescriptionInterface* offer = CreateRemoteOffer();
894 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800895 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896 SetLocalDescriptionWithoutError(answer);
897 }
898 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
899 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700900 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000901 }
902 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700903 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904 SetLocalDescriptionWithoutError(desc);
905 EXPECT_EQ(expected_state, session_->state());
906 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000907 void SetLocalDescriptionExpectError(const std::string& action,
908 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000909 SessionDescriptionInterface* desc) {
910 std::string error;
911 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000912 std::string sdp_type = "local ";
913 sdp_type.append(action);
914 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 EXPECT_NE(std::string::npos, error.find(expected_error));
916 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000917 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
918 SessionDescriptionInterface* desc) {
919 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
920 expected_error, desc);
921 }
922 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
923 SessionDescriptionInterface* desc) {
924 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
925 expected_error, desc);
926 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000927 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
928 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
929 }
930 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700931 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000932 SetRemoteDescriptionWithoutError(desc);
933 EXPECT_EQ(expected_state, session_->state());
934 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000935 void SetRemoteDescriptionExpectError(const std::string& action,
936 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000937 SessionDescriptionInterface* desc) {
938 std::string error;
939 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000940 std::string sdp_type = "remote ";
941 sdp_type.append(action);
942 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000943 EXPECT_NE(std::string::npos, error.find(expected_error));
944 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000945 void SetRemoteDescriptionOfferExpectError(
946 const std::string& expected_error, SessionDescriptionInterface* desc) {
947 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
948 expected_error, desc);
949 }
950 void SetRemoteDescriptionPranswerExpectError(
951 const std::string& expected_error, SessionDescriptionInterface* desc) {
952 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
953 expected_error, desc);
954 }
955 void SetRemoteDescriptionAnswerExpectError(
956 const std::string& expected_error, SessionDescriptionInterface* desc) {
957 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
958 expected_error, desc);
959 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000960
961 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
962 SessionDescriptionInterface** nocrypto_answer) {
963 // Create a SDP without Crypto.
964 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000965 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000966 options.bundle_enabled = true;
967 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
968 ASSERT_TRUE(*offer != NULL);
969 VerifyCryptoParams((*offer)->description());
970
971 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
972 cricket::SEC_DISABLED);
973 EXPECT_TRUE(*nocrypto_answer != NULL);
974 }
975
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000976 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
977 SessionDescriptionInterface** nodtls_answer) {
978 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000979 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000980 options.bundle_enabled = true;
981
kwibergd1fe2812016-04-27 06:47:29 -0700982 std::unique_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000983 CreateRemoteOffer(options, cricket::SEC_ENABLED));
984
985 *nodtls_answer =
986 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
987 EXPECT_TRUE(*nodtls_answer != NULL);
988 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
989 VerifyCryptoParams((*nodtls_answer)->description());
990
991 SetFactoryDtlsSrtp();
992 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
993 ASSERT_TRUE(*offer != NULL);
994 VerifyFingerprintStatus((*offer)->description(), true);
995 VerifyCryptoParams((*offer)->description());
996 }
997
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000998 JsepSessionDescription* CreateRemoteOfferWithVersion(
999 cricket::MediaSessionOptions options,
1000 cricket::SecurePolicy secure_policy,
1001 const std::string& session_version,
1002 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001003 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001004 const cricket::SessionDescription* cricket_desc = NULL;
1005 if (current_desc) {
1006 cricket_desc = current_desc->description();
1007 session_id = current_desc->session_id();
1008 }
1009
1010 desc_factory_->set_secure(secure_policy);
1011 JsepSessionDescription* offer(
1012 new JsepSessionDescription(JsepSessionDescription::kOffer));
1013 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
1014 session_id, session_version)) {
1015 delete offer;
1016 offer = NULL;
1017 }
1018 return offer;
1019 }
1020 JsepSessionDescription* CreateRemoteOffer(
1021 cricket::MediaSessionOptions options) {
1022 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1023 kSessionVersion, NULL);
1024 }
1025 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001026 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
1027 return CreateRemoteOfferWithVersion(
1028 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001029 }
1030 JsepSessionDescription* CreateRemoteOffer(
1031 cricket::MediaSessionOptions options,
1032 const SessionDescriptionInterface* current_desc) {
1033 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1034 kSessionVersion, current_desc);
1035 }
1036
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001037 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
1038 const char* sctp_stream_name, int new_port,
1039 cricket::MediaSessionOptions options) {
1040 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001041 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
1042 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001043 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
1044 }
1045
1046 // Takes ownership of offer_basis (and deletes it).
1047 JsepSessionDescription* ChangeSDPSctpPort(
1048 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1049 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1050 // SessionDescription from the mutated string.
1051 const char* default_port_str = "5000";
1052 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001053 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001054 std::string offer_str;
1055 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001056 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001057 new_port_str, strlen(new_port_str),
1058 &offer_str);
1059 JsepSessionDescription* offer = new JsepSessionDescription(
1060 offer_basis->type());
1061 delete offer_basis;
1062 offer->Initialize(offer_str, NULL);
1063 return offer;
1064 }
1065
deadbeefab9b2d12015-10-14 11:33:11 -07001066 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001067 // before this function to decide which streams to create.
1068 JsepSessionDescription* CreateRemoteOffer() {
1069 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001070 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001071 return CreateRemoteOffer(options, session_->remote_description());
1072 }
1073
1074 JsepSessionDescription* CreateRemoteAnswer(
1075 const SessionDescriptionInterface* offer,
1076 cricket::MediaSessionOptions options,
1077 cricket::SecurePolicy policy) {
1078 desc_factory_->set_secure(policy);
1079 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001080 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001081 JsepSessionDescription* answer(
1082 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1083 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1084 options, NULL),
1085 session_id, kSessionVersion)) {
1086 delete answer;
1087 answer = NULL;
1088 }
1089 return answer;
1090 }
1091
1092 JsepSessionDescription* CreateRemoteAnswer(
1093 const SessionDescriptionInterface* offer,
1094 cricket::MediaSessionOptions options) {
1095 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1096 }
1097
deadbeefab9b2d12015-10-14 11:33:11 -07001098 // Creates an answer session description.
1099 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001100 // to decide which streams to create.
1101 JsepSessionDescription* CreateRemoteAnswer(
1102 const SessionDescriptionInterface* offer) {
1103 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001104 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001105 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1106 }
1107
1108 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001109 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001110 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001111 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001112
1113 PeerConnectionInterface::RTCOfferAnswerOptions options;
1114 options.use_rtp_mux = bundle;
1115
1116 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001117 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1118 // and answer.
1119 SetLocalDescriptionWithoutError(offer);
1120
kwibergd1fe2812016-04-27 06:47:29 -07001121 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001122 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001123 std::string sdp;
1124 EXPECT_TRUE(answer->ToString(&sdp));
1125
1126 size_t expected_candidate_num = 2;
1127 if (!rtcp_mux) {
1128 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1129 // for rtp and rtcp.
1130 expected_candidate_num = 4;
1131 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001132 const std::string kRtcpMux = "a=rtcp-mux";
1133 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001134 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001135 kXRtcpMux.c_str(), kXRtcpMux.length(),
1136 &sdp);
1137 }
1138
1139 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1140 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001141
1142 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001143 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001144 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1145 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001146 if (bundle) {
1147 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1148 } else {
1149 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001150 }
1151 }
1152 // Tests that we can only send DTMF when the dtmf codec is supported.
1153 void TestCanInsertDtmf(bool can) {
1154 if (can) {
1155 InitWithDtmfCodec();
1156 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001157 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001158 }
deadbeefab9b2d12015-10-14 11:33:11 -07001159 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001160 CreateAndSetRemoteOfferAndLocalAnswer();
1161 EXPECT_FALSE(session_->CanInsertDtmf(""));
1162 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1163 }
1164
zhihuang3a334652016-05-05 18:37:49 -07001165 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1166 const std::string& codec_name) {
1167 for (const auto& content : desc->description()->contents()) {
1168 if (static_cast<cricket::MediaContentDescription*>(content.description)
1169 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1170 const auto* mdesc =
1171 static_cast<cricket::VideoContentDescription*>(content.description);
1172 for (const auto& codec : mdesc->codecs()) {
1173 if (codec.name == codec_name) {
1174 return true;
1175 }
1176 }
1177 }
1178 }
1179 return false;
1180 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001181 // Helper class to configure loopback network and verify Best
1182 // Connection using right IP protocol for TestLoopbackCall
1183 // method. LoopbackNetworkManager applies firewall rules to block
1184 // all ping traffic once ICE completed, and remove them to observe
1185 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1186 // verifies the best connection is using the right IP protocol after
1187 // initial ICE convergences.
1188
1189 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001190 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001191 LoopbackNetworkConfiguration()
1192 : test_ipv6_network_(false),
1193 test_extra_ipv4_network_(false),
1194 best_connection_after_initial_ice_converged_(1, 0) {}
1195
1196 // Used to track the expected best connection count in each IP protocol.
1197 struct ExpectedBestConnection {
1198 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1199 : ipv4_count_(ipv4_count),
1200 ipv6_count_(ipv6_count) {}
1201
1202 int ipv4_count_;
1203 int ipv6_count_;
1204 };
1205
1206 bool test_ipv6_network_;
1207 bool test_extra_ipv4_network_;
1208 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1209
1210 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001211 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001212 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1213 }
1214
1215 private:
jbauchac8869e2015-07-03 01:36:14 -07001216 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001217 const ExpectedBestConnection& expected) const {
1218 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001219 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1220 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001221 expected.ipv4_count_);
1222 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001223 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1224 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001225 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001226 // This is used in the loopback call so there is only single host to host
1227 // candidate pair.
1228 EXPECT_EQ(metrics_observer->GetEnumCounter(
1229 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1230 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001231 0);
1232 EXPECT_EQ(metrics_observer->GetEnumCounter(
1233 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1234 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001235 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001236 }
1237 };
1238
1239 class LoopbackNetworkManager {
1240 public:
1241 LoopbackNetworkManager(WebRtcSessionTest* session,
1242 const LoopbackNetworkConfiguration& config)
1243 : config_(config) {
1244 session->AddInterface(
1245 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1246 if (config_.test_extra_ipv4_network_) {
1247 session->AddInterface(
1248 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1249 }
1250 if (config_.test_ipv6_network_) {
1251 session->AddInterface(
1252 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1253 }
1254 }
1255
1256 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1257 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1258 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1259 if (config_.test_extra_ipv4_network_) {
1260 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1261 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1262 }
1263 if (config_.test_ipv6_network_) {
1264 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1265 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1266 }
1267 }
1268
1269 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1270
1271 private:
1272 LoopbackNetworkConfiguration config_;
1273 };
1274
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001275 // The method sets up a call from the session to itself, in a loopback
1276 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001277 // disconnection, and then a permanent disconnection.
1278 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001279 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1280 // While running the call, this method also checks if the session goes through
1281 // the correct sequence of ICE states when a connection is established,
1282 // broken, and re-established.
1283 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001284 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1285 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001286 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001287
stefanc1aeaf02015-10-15 07:26:07 -07001288 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001289 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001290 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001291 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001292
1293 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1294 observer_.ice_gathering_state_);
1295 SetLocalDescriptionWithoutError(offer);
1296 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1297 observer_.ice_connection_state_);
1298 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001299 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001300 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1301 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001302 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001303
1304 std::string sdp;
1305 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001306 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1307 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001308 ASSERT_TRUE(desc != NULL);
1309 SetRemoteDescriptionWithoutError(desc);
1310
1311 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001312 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001313
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001314 // The ice connection state is "Connected" too briefly to catch in a test.
1315 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001316 observer_.ice_connection_state_, kIceCandidatesTimeout);
1317 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001318
stefanc1aeaf02015-10-15 07:26:07 -07001319 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1320 LoopbackNetworkManager loopback_network_manager(this, config);
1321 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001322 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001323 // Adding firewall rule to block ping requests, which should cause
1324 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001325
1326 loopback_network_manager.ApplyFirewallRules(fss_.get());
1327
1328 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001329 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1330 observer_.ice_connection_state_,
1331 kIceCandidatesTimeout);
1332
jbauchac8869e2015-07-03 01:36:14 -07001333 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001334
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001335 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001336 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001337
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001338 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001339 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001340 observer_.ice_connection_state_,
1341 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001342
1343 // Now we block ping requests and wait until the ICE connection transitions
1344 // to the Failed state. This will take at least 30 seconds because it must
1345 // wait for the Port to timeout.
1346 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001347
1348 loopback_network_manager.ApplyFirewallRules(fss_.get());
1349 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001350 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001351 observer_.ice_connection_state_,
1352 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001353 }
1354
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001355 void TestLoopbackCall() {
1356 LoopbackNetworkConfiguration config;
1357 TestLoopbackCall(config);
1358 }
1359
stefanc1aeaf02015-10-15 07:26:07 -07001360 void TestPacketOptions() {
1361 media_controller_.reset(
1362 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1363 LoopbackNetworkConfiguration config;
1364 LoopbackNetworkManager loopback_network_manager(this, config);
1365
1366 SetupLoopbackCall();
1367
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001368 // Wait for channel to be ready for sending.
1369 EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
stefanc1aeaf02015-10-15 07:26:07 -07001370 uint8_t test_packet[15] = {0};
1371 rtc::PacketOptions options;
1372 options.packet_id = 10;
1373 media_engine_->GetVideoChannel(0)
1374 ->SendRtp(test_packet, sizeof(test_packet), options);
1375
1376 const int kPacketTimeout = 2000;
deadbeef14461d42016-06-15 11:06:57 -07001377 EXPECT_EQ_WAIT(10, fake_call_.last_sent_nonnegative_packet_id(),
1378 kPacketTimeout);
stefanc1aeaf02015-10-15 07:26:07 -07001379 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1380 }
1381
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001382 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1383 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001384 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1385 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001386
1387 // Add kCNCodec for dtmf test.
ossudedfd282016-06-14 07:12:39 -07001388 std::vector<cricket::AudioCodec> codecs =
1389 media_engine_->audio_send_codecs();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001390 codecs.push_back(kCNCodec1);
1391 codecs.push_back(kCNCodec2);
1392 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -07001393 desc_factory_->set_audio_codecs(codecs, codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001394 }
1395
1396 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1397 const cricket::ContentDescription* description = content->description;
1398 ASSERT(description != NULL);
1399 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001400 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001401 ASSERT(audio_content_desc != NULL);
1402 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1403 if (audio_content_desc->codecs()[i].name == "CN")
1404 return false;
1405 }
1406 return true;
1407 }
1408
deadbeefab9b2d12015-10-14 11:33:11 -07001409 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001410 webrtc::InternalDataChannelInit dci;
htaa2a49d92016-03-04 02:51:39 -08001411 ASSERT(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001412 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1413 data_channel_ = DataChannel::Create(
1414 session_.get(), session_->data_channel_type(), "datachannel", dci);
1415 }
1416
1417 void SetLocalDescriptionWithDataChannel() {
1418 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001419 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001420 SetLocalDescriptionWithoutError(offer);
1421 }
1422
wu@webrtc.org91053e72013-08-10 07:18:04 +00001423 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001424 RTCCertificateGenerationMethod cert_gen_method,
1425 CreateSessionDescriptionRequest::Type type) {
1426 InitWithDtls(cert_gen_method);
1427 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1428 }
1429
1430 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1431 CreateSessionDescriptionRequest::Type type) {
1432 InitWithDtlsIdentityGenFail();
1433 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1434 }
1435
1436 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001437 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001438 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001439 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001440 if (type == CreateSessionDescriptionRequest::kAnswer) {
1441 cricket::MediaSessionOptions options;
kwibergd1fe2812016-04-27 06:47:29 -07001442 std::unique_ptr<JsepSessionDescription> offer(
1443 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001444 ASSERT_TRUE(offer.get() != NULL);
1445 SetRemoteDescriptionWithoutError(offer.release());
1446 }
1447
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001448 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001449 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001450 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001451 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001452 observers[kNumber];
1453 for (int i = 0; i < kNumber; ++i) {
1454 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1455 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001456 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001457 } else {
htaa2a49d92016-03-04 02:51:39 -08001458 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001459 }
1460 }
1461
1462 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1463 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1464 WebRtcSessionCreateSDPObserverForTest::kFailed;
1465
1466 for (int i = 0; i < kNumber; ++i) {
1467 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1468 if (success) {
1469 EXPECT_TRUE(observers[i]->description() != NULL);
1470 } else {
1471 EXPECT_TRUE(observers[i]->description() == NULL);
1472 }
1473 }
1474 }
1475
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001476 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001477 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001478 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001479 turn_server.credentials = credentials;
1480 turn_server.ports.push_back(
1481 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1482 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001483 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001484 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001485 }
1486
skvlad11a9cbf2016-10-07 11:53:05 -07001487 webrtc::RtcEventLogNullImpl event_log_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001488 cricket::FakeMediaEngine* media_engine_;
1489 cricket::FakeDataEngine* data_engine_;
kwibergd1fe2812016-04-27 06:47:29 -07001490 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001491 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001492 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_;
1493 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1494 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1495 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1496 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1497 std::unique_ptr<rtc::FirewallSocketServer> fss_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001498 rtc::SocketServerScope ss_scope_;
1499 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001500 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001501 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001502 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001503 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001504 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001505 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001506 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001507 MockIceObserver observer_;
1508 cricket::FakeVideoMediaChannel* video_channel_;
1509 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001510 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001511 // The following flags affect options created for CreateOffer/CreateAnswer.
1512 bool send_stream_1_ = false;
1513 bool send_stream_2_ = false;
1514 bool send_audio_ = false;
1515 bool send_video_ = false;
1516 rtc::scoped_refptr<DataChannel> data_channel_;
1517 // Last values received from data channel creation signal.
1518 std::string last_data_channel_label_;
1519 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001520 bool session_destroyed_ = false;
jbauchcb560652016-08-04 05:20:32 -07001521 bool with_gcm_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001522};
1523
Henrik Boström87713d02015-08-25 09:53:21 +02001524TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1525 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001526 // SDES is disabled when DTLS is on.
1527 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001528}
1529
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001530TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001531 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001532 // SDES is required if DTLS is off.
1533 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001534}
1535
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001536TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1537 TestSessionCandidatesWithBundleRtcpMux(false, false);
1538}
1539
1540// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1541// with rtcp-mux and/or bundle.
1542TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1543 TestSessionCandidatesWithBundleRtcpMux(false, true);
1544}
1545
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001546TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1547 TestSessionCandidatesWithBundleRtcpMux(true, true);
1548}
1549
1550TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001551 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1552 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001553 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001554 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001555 InitiateCall();
1556 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1557 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1558 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1559}
1560
deadbeeff5f03e82016-06-06 11:16:06 -07001561TEST_F(WebRtcSessionTest, TestStunError) {
1562 rtc::ScopedFakeClock clock;
1563
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001564 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1565 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001566 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001567 rtc::FP_UDP,
1568 rtc::FD_ANY,
1569 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001570 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001571 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001572 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001573 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
deadbeeff5f03e82016-06-06 11:16:06 -07001574 EXPECT_TRUE_SIMULATED_WAIT(observer_.oncandidatesready_, kStunTimeout, clock);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001575 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1576 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
deadbeeff5f03e82016-06-06 11:16:06 -07001577 // Destroy session before scoped fake clock goes out of scope to avoid TSan
1578 // warning.
1579 session_->Close();
1580 session_.reset(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001581}
1582
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001583TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001584 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001585 SessionDescriptionInterface* offer = NULL;
1586 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1587 std::string unknown_action;
1588 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1589 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1590}
1591
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001592// Test creating offers and receive answers and make sure the
1593// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001594TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001595 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001596 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001597 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001598 const std::string session_id_orig = offer->session_id();
1599 const std::string session_version_orig = offer->session_version();
1600 SetLocalDescriptionWithoutError(offer);
1601
deadbeefab9b2d12015-10-14 11:33:11 -07001602 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001603 SessionDescriptionInterface* answer =
1604 CreateRemoteAnswer(session_->local_description());
1605 SetRemoteDescriptionWithoutError(answer);
1606
1607 video_channel_ = media_engine_->GetVideoChannel(0);
1608 voice_channel_ = media_engine_->GetVoiceChannel(0);
1609
1610 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1611 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1612
1613 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1614 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1615
1616 ASSERT_EQ(1u, video_channel_->send_streams().size());
1617 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1618 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1619 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1620
1621 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001622 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001623 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001624
1625 // Verify the session id is the same and the session version is
1626 // increased.
1627 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001628 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1629 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001630
1631 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001632 EXPECT_EQ(0u, video_channel_->send_streams().size());
1633 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001634
deadbeefab9b2d12015-10-14 11:33:11 -07001635 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001636 answer = CreateRemoteAnswer(session_->local_description());
1637 SetRemoteDescriptionWithoutError(answer);
1638
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001639 // Make sure the receive streams have not changed.
1640 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1641 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1642 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1643 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1644}
1645
1646// Test receiving offers and creating answers and make sure the
1647// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001648TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001649 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001650 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001651 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001652 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001653 SetRemoteDescriptionWithoutError(offer);
1654
deadbeefab9b2d12015-10-14 11:33:11 -07001655 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001656 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001657 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001658 SetLocalDescriptionWithoutError(answer);
1659
1660 const std::string session_id_orig = answer->session_id();
1661 const std::string session_version_orig = answer->session_version();
1662
1663 video_channel_ = media_engine_->GetVideoChannel(0);
1664 voice_channel_ = media_engine_->GetVoiceChannel(0);
1665
htaa2a49d92016-03-04 02:51:39 -08001666 ASSERT_TRUE(video_channel_);
1667 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001668 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1669 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1670
1671 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1672 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1673
1674 ASSERT_EQ(1u, video_channel_->send_streams().size());
1675 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1676 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1677 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1678
deadbeefab9b2d12015-10-14 11:33:11 -07001679 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001680 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001681 SetRemoteDescriptionWithoutError(offer);
1682
1683 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001684 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001685 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001686
1687 // Verify the session id is the same and the session version is
1688 // increased.
1689 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001690 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1691 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001692 SetLocalDescriptionWithoutError(answer);
1693
1694 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1695 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1696 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1697 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1698 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1699 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1700
1701 // Make sure we have no send streams.
1702 EXPECT_EQ(0u, video_channel_->send_streams().size());
1703 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1704}
1705
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001706TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001707 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001708 media_engine_->set_fail_create_channel(true);
1709
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001710 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001711 ASSERT_TRUE(offer != NULL);
1712 // SetRemoteDescription and SetLocalDescription will take the ownership of
1713 // the offer.
1714 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001715 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001716 ASSERT_TRUE(offer != NULL);
1717 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1718}
1719
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001720//
1721// Tests for creating/setting SDP under different SDES/DTLS polices:
1722//
1723// --DTLS off and SDES on
1724// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1725// set local/remote offer/answer with crypto --> success
1726// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1727// failure
1728// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1729// failure
1730// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1731// failure
1732//
1733// --DTLS on and SDES off
1734// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1735// set local/remote offer/answer with DTLS fingerprint --> success
1736// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1737// fingerprint --> failure
1738// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1739// --> failure
1740// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1741// --> failure
1742//
1743// --Encryption disabled: DTLS off and SDES off
1744// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1745// answer without SDES or DTLS --> success
1746// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1747// answer without SDES or DTLS --> success
1748//
1749
1750// Test that we return a failure when applying a remote/local offer that doesn't
1751// have cryptos enabled when DTLS is off.
1752TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001753 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001754 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001755 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001756 JsepSessionDescription* offer = CreateRemoteOffer(
1757 options, cricket::SEC_DISABLED);
1758 ASSERT_TRUE(offer != NULL);
1759 VerifyNoCryptoParams(offer->description(), false);
1760 // SetRemoteDescription and SetLocalDescription will take the ownership of
1761 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001762 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1764 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001765 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766}
1767
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001768// Test that we return a failure when applying a local answer that doesn't have
1769// cryptos enabled when DTLS is off.
1770TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001771 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772 SessionDescriptionInterface* offer = NULL;
1773 SessionDescriptionInterface* answer = NULL;
1774 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1775 // SetRemoteDescription and SetLocalDescription will take the ownership of
1776 // the offer.
1777 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001778 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001779}
1780
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001781// Test we will return fail when apply an remote answer that doesn't have
1782// crypto enabled when DTLS is off.
1783TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001784 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785 SessionDescriptionInterface* offer = NULL;
1786 SessionDescriptionInterface* answer = NULL;
1787 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1788 // SetRemoteDescription and SetLocalDescription will take the ownership of
1789 // the offer.
1790 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001791 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792}
1793
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001794// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1795// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001796TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001797 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001798 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001799 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001800 SetFactoryDtlsSrtp();
1801 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001802 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001803 JsepSessionDescription* offer =
1804 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001805 ASSERT_TRUE(offer != NULL);
1806 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001807 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001808
1809 // SetRemoteDescription will take the ownership of the offer.
1810 SetRemoteDescriptionWithoutError(offer);
1811
1812 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001813 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001814 ASSERT_TRUE(answer != NULL);
1815 VerifyFingerprintStatus(answer->description(), true);
1816 // Check that we don't have an a=crypto line in the answer.
1817 VerifyNoCryptoParams(answer->description(), true);
1818
1819 // Now set the local description, which should work, even without a=crypto.
1820 SetLocalDescriptionWithoutError(answer);
1821}
1822
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001823// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1824// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001825TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001826 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001827 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001828 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001829 SetFactoryDtlsSrtp();
1830
1831 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001832 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001833 ASSERT_TRUE(offer != NULL);
1834 VerifyFingerprintStatus(offer->description(), true);
1835 // Check that we don't have an a=crypto line in the offer.
1836 VerifyNoCryptoParams(offer->description(), true);
1837
1838 // Now set the local description, which should work, even without a=crypto.
1839 SetLocalDescriptionWithoutError(offer);
1840
1841 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001842 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001843 JsepSessionDescription* answer =
1844 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1845 ASSERT_TRUE(answer != NULL);
1846 VerifyFingerprintStatus(answer->description(), true);
1847 VerifyNoCryptoParams(answer->description(), true);
1848
1849 // SetRemoteDescription will take the ownership of the answer.
1850 SetRemoteDescriptionWithoutError(answer);
1851}
1852
1853// Test that if we support DTLS and the other side didn't offer a fingerprint,
1854// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001855TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001856 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001857 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001858 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001859 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001860 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001861 JsepSessionDescription* offer = CreateRemoteOffer(
1862 options, cricket::SEC_REQUIRED);
1863 ASSERT_TRUE(offer != NULL);
1864 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001865 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001866
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001867 // SetRemoteDescription will take the ownership of the offer.
1868 SetRemoteDescriptionOfferExpectError(
1869 kSdpWithoutDtlsFingerprint, offer);
1870
1871 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1872 // SetLocalDescription will take the ownership of the offer.
1873 SetLocalDescriptionOfferExpectError(
1874 kSdpWithoutDtlsFingerprint, offer);
1875}
1876
1877// Test that we return a failure when applying a local answer that doesn't have
1878// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001879TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001880 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001881 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001882 SessionDescriptionInterface* offer = NULL;
1883 SessionDescriptionInterface* answer = NULL;
1884 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1885
1886 // SetRemoteDescription and SetLocalDescription will take the ownership of
1887 // the offer and answer.
1888 SetRemoteDescriptionWithoutError(offer);
1889 SetLocalDescriptionAnswerExpectError(
1890 kSdpWithoutDtlsFingerprint, answer);
1891}
1892
1893// Test that we return a failure when applying a remote answer that doesn't have
1894// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001895TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001896 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001897 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001898 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001899 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001900 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07001901 std::unique_ptr<SessionDescriptionInterface> temp_offer(
deadbeefcbecd352015-09-23 11:50:27 -07001902 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001903 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001904 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001905
1906 // SetRemoteDescription and SetLocalDescription will take the ownership of
1907 // the offer and answer.
1908 SetLocalDescriptionWithoutError(offer);
1909 SetRemoteDescriptionAnswerExpectError(
1910 kSdpWithoutDtlsFingerprint, answer);
1911}
1912
1913// Test that we create a local offer without SDES or DTLS and accept a remote
1914// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001915TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001916 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001917 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001918 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001919
1920 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001921 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001922 ASSERT_TRUE(offer != NULL);
1923 VerifyFingerprintStatus(offer->description(), false);
1924 // Check that we don't have an a=crypto line in the offer.
1925 VerifyNoCryptoParams(offer->description(), false);
1926
1927 // Now set the local description, which should work, even without a=crypto.
1928 SetLocalDescriptionWithoutError(offer);
1929
1930 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001931 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001932 JsepSessionDescription* answer =
1933 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1934 ASSERT_TRUE(answer != NULL);
1935 VerifyFingerprintStatus(answer->description(), false);
1936 VerifyNoCryptoParams(answer->description(), false);
1937
1938 // SetRemoteDescription will take the ownership of the answer.
1939 SetRemoteDescriptionWithoutError(answer);
1940}
1941
1942// Test that we create a local answer without SDES or DTLS and accept a remote
1943// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001944TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001945 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001946 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001947
1948 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001949 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001950 JsepSessionDescription* offer =
1951 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1952 ASSERT_TRUE(offer != NULL);
1953 VerifyFingerprintStatus(offer->description(), false);
1954 VerifyNoCryptoParams(offer->description(), false);
1955
1956 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001957 SetRemoteDescriptionWithoutError(offer);
1958
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001959 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001960 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001961 ASSERT_TRUE(answer != NULL);
1962 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001963 // Check that we don't have an a=crypto line in the answer.
1964 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001965
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001966 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001967 SetLocalDescriptionWithoutError(answer);
1968}
1969
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001970// Test that we can create and set an answer correctly when different
1971// SSL roles have been negotiated for different transports.
1972// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1973TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1974 SendAudioVideoStream1();
1975 InitWithDtls(GetParam());
1976 SetFactoryDtlsSrtp();
1977
1978 SessionDescriptionInterface* offer = CreateOffer();
1979 SetLocalDescriptionWithoutError(offer);
1980
1981 cricket::MediaSessionOptions options;
1982 options.recv_video = true;
1983
1984 // First, negotiate different SSL roles.
1985 SessionDescriptionInterface* answer =
1986 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1987 TransportInfo* audio_transport_info =
1988 answer->description()->GetTransportInfoByName("audio");
1989 audio_transport_info->description.connection_role =
1990 cricket::CONNECTIONROLE_ACTIVE;
1991 TransportInfo* video_transport_info =
1992 answer->description()->GetTransportInfoByName("video");
1993 video_transport_info->description.connection_role =
1994 cricket::CONNECTIONROLE_PASSIVE;
1995 SetRemoteDescriptionWithoutError(answer);
1996
1997 // Now create an offer in the reverse direction, and ensure the initial
1998 // offerer responds with an answer with correct SSL roles.
1999 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2000 kSessionVersion,
2001 session_->remote_description());
2002 SetRemoteDescriptionWithoutError(offer);
2003
htaa2a49d92016-03-04 02:51:39 -08002004 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002005 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2006 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2007 audio_transport_info->description.connection_role);
2008 video_transport_info = answer->description()->GetTransportInfoByName("video");
2009 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
2010 video_transport_info->description.connection_role);
2011 SetLocalDescriptionWithoutError(answer);
2012
2013 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
2014 // audio is transferred over to video in the answer that completes the BUNDLE
2015 // negotiation.
2016 options.bundle_enabled = true;
2017 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2018 kSessionVersion,
2019 session_->remote_description());
2020 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08002021 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002022 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2023 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2024 audio_transport_info->description.connection_role);
2025 video_transport_info = answer->description()->GetTransportInfoByName("video");
2026 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2027 video_transport_info->description.connection_role);
2028 SetLocalDescriptionWithoutError(answer);
2029}
2030
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002032 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002033 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002034 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002035 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002036 SetLocalDescriptionWithoutError(offer);
2037
2038 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002039 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002040 SetLocalDescriptionWithoutError(offer2);
2041}
2042
2043TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002044 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002045 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002046 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002047 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048 SetRemoteDescriptionWithoutError(offer);
2049
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002050 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002051 SetRemoteDescriptionWithoutError(offer2);
2052}
2053
2054TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002055 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002056 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002057 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002059 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002060 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2061 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002062}
2063
2064TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002065 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002066 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002067 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002068 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002069 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002070 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002071 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072}
2073
2074TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002075 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002076 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002077 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002078 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079
htaa2a49d92016-03-04 02:51:39 -08002080 JsepSessionDescription* pranswer =
2081 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002082 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002083 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084
deadbeefab9b2d12015-10-14 11:33:11 -07002085 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002086 JsepSessionDescription* pranswer2 =
2087 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002088 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2089
deadbeefd59daf82015-10-14 15:02:44 -07002090 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091
deadbeefab9b2d12015-10-14 11:33:11 -07002092 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002093 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002094 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002095}
2096
2097TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002098 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002099 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002100 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002101 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002102
2103 JsepSessionDescription* pranswer =
2104 CreateRemoteAnswer(session_->local_description());
2105 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2106
2107 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002108 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002109
deadbeefab9b2d12015-10-14 11:33:11 -07002110 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002111 JsepSessionDescription* pranswer2 =
2112 CreateRemoteAnswer(session_->local_description());
2113 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2114
2115 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002116 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002117
deadbeefab9b2d12015-10-14 11:33:11 -07002118 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002119 SessionDescriptionInterface* answer =
2120 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002121 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002122}
2123
2124TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002125 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002126 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002127 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002128
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129 SessionDescriptionInterface* answer =
2130 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002131 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2132 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133}
2134
2135TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002136 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002137 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002138 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002139
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140 SessionDescriptionInterface* answer =
2141 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002142 SetRemoteDescriptionAnswerExpectError(
2143 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002144}
2145
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002146// Tests that the remote candidates are added and removed successfully.
2147TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002148 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002149 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002150
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002151 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
2152 "", "", "host", 0, "");
2153 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2155
deadbeefd59daf82015-10-14 15:02:44 -07002156 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002157 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2158
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002159 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002160 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002161
2162 // Fail since we have not set a remote description.
2163 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002164
2165 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2166 session_->local_description());
2167 SetRemoteDescriptionWithoutError(answer);
2168
deadbeefd59daf82015-10-14 15:02:44 -07002169 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2170 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002171 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002172 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2173 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2174
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002175 // Verifying the candidates are copied properly from internal vector.
2176 const SessionDescriptionInterface* remote_desc =
2177 session_->remote_description();
2178 ASSERT_TRUE(remote_desc != NULL);
2179 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2180 const IceCandidateCollection* candidates =
2181 remote_desc->candidates(kMediaContentIndex0);
2182 ASSERT_EQ(2u, candidates->count());
2183 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2184 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2185 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2186 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2187
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002188 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2189 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002190 candidate.set_component(2);
2191 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2192 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002193 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002194
2195 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2196 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002197
2198 // Remove candidate1 and candidate2
2199 std::vector<cricket::Candidate> remote_candidates;
2200 remote_candidates.push_back(ice_candidate1.candidate());
2201 remote_candidates.push_back(ice_candidate2.candidate());
2202 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2203 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002204}
2205
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002206// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002207// that it is retained if the remote session description is changed.
2208TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002209 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002210 cricket::Candidate candidate1;
2211 candidate1.set_component(1);
2212 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2213 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002214 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002215 CreateAndSetRemoteOfferAndLocalAnswer();
2216
2217 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2218 const SessionDescriptionInterface* remote_desc =
2219 session_->remote_description();
2220 ASSERT_TRUE(remote_desc != NULL);
2221 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2222 const IceCandidateCollection* candidates =
2223 remote_desc->candidates(kMediaContentIndex0);
2224 ASSERT_EQ(1u, candidates->count());
2225 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2226
2227 // Update the RemoteSessionDescription with a new session description and
2228 // a candidate and check that the new remote session description contains both
2229 // candidates.
2230 SessionDescriptionInterface* offer = CreateRemoteOffer();
2231 cricket::Candidate candidate2;
2232 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2233 candidate2);
2234 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2235 SetRemoteDescriptionWithoutError(offer);
2236
2237 remote_desc = session_->remote_description();
2238 ASSERT_TRUE(remote_desc != NULL);
2239 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2240 candidates = remote_desc->candidates(kMediaContentIndex0);
2241 ASSERT_EQ(2u, candidates->count());
2242 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2243 // Username and password have be updated with the TransportInfo of the
2244 // SessionDescription, won't be equal to the original one.
2245 candidate2.set_username(candidates->at(0)->candidate().username());
2246 candidate2.set_password(candidates->at(0)->candidate().password());
2247 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2248 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2249 // No need to verify the username and password.
2250 candidate1.set_username(candidates->at(1)->candidate().username());
2251 candidate1.set_password(candidates->at(1)->candidate().password());
2252 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2253
2254 // Test that the candidate is ignored if we can add the same candidate again.
2255 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2256}
2257
2258// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002259// that they are retained if the local session description is changed. And if
2260// continual gathering is enabled, they are removed from the local session
2261// description when the network is down.
2262TEST_F(WebRtcSessionTest,
2263 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002264 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002265 Init();
deadbeefb60a8192016-08-24 15:15:00 -07002266 // Enable Continual Gathering.
2267 cricket::IceConfig config;
2268 config.continual_gathering_policy = cricket::GATHER_CONTINUALLY;
2269 session_->SetIceConfig(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002270 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002271 CreateAndSetRemoteOfferAndLocalAnswer();
2272
2273 const SessionDescriptionInterface* local_desc = session_->local_description();
2274 const IceCandidateCollection* candidates =
2275 local_desc->candidates(kMediaContentIndex0);
2276 ASSERT_TRUE(candidates != NULL);
2277 EXPECT_EQ(0u, candidates->count());
2278
deadbeefb60a8192016-08-24 15:15:00 -07002279 // Since we're using continual gathering, we won't get "gathering done".
2280 EXPECT_EQ_WAIT(2u, candidates->count(), kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002281
2282 local_desc = session_->local_description();
2283 candidates = local_desc->candidates(kMediaContentIndex0);
2284 ASSERT_TRUE(candidates != NULL);
2285 EXPECT_LT(0u, candidates->count());
2286 candidates = local_desc->candidates(1);
2287 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002288 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002289
2290 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002291 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002292 CreateAndSetRemoteOfferAndLocalAnswer();
2293
2294 local_desc = session_->local_description();
2295 candidates = local_desc->candidates(kMediaContentIndex0);
2296 ASSERT_TRUE(candidates != NULL);
2297 EXPECT_LT(0u, candidates->count());
2298 candidates = local_desc->candidates(1);
2299 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002300 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002301
2302 candidates = local_desc->candidates(kMediaContentIndex0);
2303 size_t num_local_candidates = candidates->count();
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002304 // Bring down the network interface to trigger candidate removals.
2305 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2306 // Verify that all local candidates are removed.
2307 EXPECT_EQ(0, observer_.num_candidates_removed_);
2308 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2309 kIceCandidatesTimeout);
2310 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2311}
2312
2313// Tests that if continual gathering is disabled, local candidates won't be
2314// removed when the interface is turned down.
2315TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2316 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2317 Init();
2318 SendAudioVideoStream1();
2319 CreateAndSetRemoteOfferAndLocalAnswer();
2320
2321 const SessionDescriptionInterface* local_desc = session_->local_description();
2322 const IceCandidateCollection* candidates =
2323 local_desc->candidates(kMediaContentIndex0);
2324 ASSERT_TRUE(candidates != NULL);
2325 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2326
2327 size_t num_local_candidates = candidates->count();
2328 EXPECT_LT(0u, num_local_candidates);
2329 // By default, Continual Gathering is disabled.
2330 // Bring down the network interface.
2331 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2332 // Verify that the local candidates are not removed.
2333 rtc::Thread::Current()->ProcessMessages(1000);
2334 EXPECT_EQ(0, observer_.num_candidates_removed_);
2335 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002336}
2337
2338// Test that we can set a remote session description with remote candidates.
2339TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002340 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002341
2342 cricket::Candidate candidate1;
2343 candidate1.set_component(1);
2344 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2345 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002346 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002347 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002348
2349 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2350 SetRemoteDescriptionWithoutError(offer);
2351
2352 const SessionDescriptionInterface* remote_desc =
2353 session_->remote_description();
2354 ASSERT_TRUE(remote_desc != NULL);
2355 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2356 const IceCandidateCollection* candidates =
2357 remote_desc->candidates(kMediaContentIndex0);
2358 ASSERT_EQ(1u, candidates->count());
2359 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2360
htaa2a49d92016-03-04 02:51:39 -08002361 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002362 SetLocalDescriptionWithoutError(answer);
2363}
2364
2365// Test that offers and answers contains ice candidates when Ice candidates have
2366// been gathered.
2367TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002368 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002369 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002370 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002371 // Ice is started but candidates are not provided until SetLocalDescription
2372 // is called.
2373 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2374 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2375 CreateAndSetRemoteOfferAndLocalAnswer();
2376 // Wait until at least one local candidate has been collected.
2377 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2378 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002379
kwibergd1fe2812016-04-27 06:47:29 -07002380 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002381
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002382 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2383 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002384
2385 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2386 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002387 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002388 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2389 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002390 SetLocalDescriptionWithoutError(answer);
2391}
2392
2393// Verifies TransportProxy and media channels are created with content names
2394// present in the SessionDescription.
2395TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002396 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002397 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002398 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002399
2400 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002401 // "video". Goal is to modify these content names and verify transport
2402 // channels
2403 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002404 // present in SDP.
2405 std::string sdp;
2406 EXPECT_TRUE(offer->ToString(&sdp));
2407 const std::string kAudioMid = "a=mid:audio";
2408 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2409 const std::string kVideoMid = "a=mid:video";
2410 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2411
2412 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002413 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002414 kAudioMidReplaceStr.c_str(),
2415 kAudioMidReplaceStr.length(),
2416 &sdp);
2417 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002418 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002419 kVideoMidReplaceStr.c_str(),
2420 kVideoMidReplaceStr.length(),
2421 &sdp);
2422
2423 SessionDescriptionInterface* modified_offer =
2424 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2425
2426 SetRemoteDescriptionWithoutError(modified_offer);
2427
htaa2a49d92016-03-04 02:51:39 -08002428 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002429 SetLocalDescriptionWithoutError(answer);
2430
johan669d69b2016-11-08 14:14:08 -08002431 rtc::PacketTransportInterface* voice_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002432 session_->voice_rtp_transport_channel();
2433 EXPECT_TRUE(voice_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002434 EXPECT_EQ(voice_transport_channel->debug_name(),
2435 "audio_content_name " +
2436 std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
2437 rtc::PacketTransportInterface* video_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002438 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002439 ASSERT_TRUE(video_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002440 EXPECT_EQ(video_transport_channel->debug_name(),
2441 "video_content_name " +
2442 std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002443 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2444 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2445}
2446
2447// Test that an offer contains the correct media content descriptions based on
2448// the send streams when no constraints have been set.
2449TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002450 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002451 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002452
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002453 ASSERT_TRUE(offer != NULL);
2454 const cricket::ContentInfo* content =
2455 cricket::GetFirstAudioContent(offer->description());
2456 EXPECT_TRUE(content != NULL);
2457 content = cricket::GetFirstVideoContent(offer->description());
2458 EXPECT_TRUE(content == NULL);
2459}
2460
2461// Test that an offer contains the correct media content descriptions based on
2462// the send streams when no constraints have been set.
2463TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002464 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002465 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002466 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002467 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002468
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002469 const cricket::ContentInfo* content =
2470 cricket::GetFirstAudioContent(offer->description());
2471 EXPECT_TRUE(content != NULL);
2472 content = cricket::GetFirstVideoContent(offer->description());
2473 EXPECT_TRUE(content == NULL);
2474
2475 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002476 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002477 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002478 content = cricket::GetFirstAudioContent(offer->description());
2479 EXPECT_TRUE(content != NULL);
2480 content = cricket::GetFirstVideoContent(offer->description());
2481 EXPECT_TRUE(content != NULL);
2482}
2483
2484// Test that an offer contains no media content descriptions if
2485// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2486TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002487 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002488 PeerConnectionInterface::RTCOfferAnswerOptions options;
2489 options.offer_to_receive_audio = 0;
2490 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002491
kwibergd1fe2812016-04-27 06:47:29 -07002492 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002493
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002494 ASSERT_TRUE(offer != NULL);
2495 const cricket::ContentInfo* content =
2496 cricket::GetFirstAudioContent(offer->description());
2497 EXPECT_TRUE(content == NULL);
2498 content = cricket::GetFirstVideoContent(offer->description());
2499 EXPECT_TRUE(content == NULL);
2500}
2501
2502// Test that an offer contains only audio media content descriptions if
2503// kOfferToReceiveAudio constraints are set to true.
2504TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002505 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002506 PeerConnectionInterface::RTCOfferAnswerOptions options;
2507 options.offer_to_receive_audio =
2508 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2509
kwibergd1fe2812016-04-27 06:47:29 -07002510 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002511
2512 const cricket::ContentInfo* content =
2513 cricket::GetFirstAudioContent(offer->description());
2514 EXPECT_TRUE(content != NULL);
2515 content = cricket::GetFirstVideoContent(offer->description());
2516 EXPECT_TRUE(content == NULL);
2517}
2518
2519// Test that an offer contains audio and video media content descriptions if
2520// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2521TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002522 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002523 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002524 PeerConnectionInterface::RTCOfferAnswerOptions options;
2525 options.offer_to_receive_audio =
2526 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2527 options.offer_to_receive_video =
2528 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2529
kwibergd1fe2812016-04-27 06:47:29 -07002530 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002531
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002532 const cricket::ContentInfo* content =
2533 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002534 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002535
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002536 content = cricket::GetFirstVideoContent(offer->description());
2537 EXPECT_TRUE(content != NULL);
2538
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002539 // Sets constraints to false and verifies that audio/video contents are
2540 // removed.
2541 options.offer_to_receive_audio = 0;
2542 options.offer_to_receive_video = 0;
2543 offer.reset(CreateOffer(options));
2544
2545 content = cricket::GetFirstAudioContent(offer->description());
2546 EXPECT_TRUE(content == NULL);
2547 content = cricket::GetFirstVideoContent(offer->description());
2548 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002549}
2550
2551// Test that an answer can not be created if the last remote description is not
2552// an offer.
2553TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002554 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002555 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002556 SetLocalDescriptionWithoutError(offer);
2557 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2558 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002559 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002560}
2561
2562// Test that an answer contains the correct media content descriptions when no
2563// constraints have been set.
2564TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002565 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002566 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002567 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002568 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002569 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002570 const cricket::ContentInfo* content =
2571 cricket::GetFirstAudioContent(answer->description());
2572 ASSERT_TRUE(content != NULL);
2573 EXPECT_FALSE(content->rejected);
2574
2575 content = cricket::GetFirstVideoContent(answer->description());
2576 ASSERT_TRUE(content != NULL);
2577 EXPECT_FALSE(content->rejected);
2578}
2579
2580// Test that an answer contains the correct media content descriptions when no
2581// constraints have been set and the offer only contain audio.
2582TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002583 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002584 // Create a remote offer with audio only.
2585 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002586
kwibergd1fe2812016-04-27 06:47:29 -07002587 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002588 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2589 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2590
2591 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002592 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002593 const cricket::ContentInfo* content =
2594 cricket::GetFirstAudioContent(answer->description());
2595 ASSERT_TRUE(content != NULL);
2596 EXPECT_FALSE(content->rejected);
2597
2598 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2599}
2600
2601// Test that an answer contains the correct media content descriptions when no
2602// constraints have been set.
2603TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002604 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002605 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002606 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002607 SetRemoteDescriptionWithoutError(offer.release());
2608 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002609 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002610 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002611 const cricket::ContentInfo* content =
2612 cricket::GetFirstAudioContent(answer->description());
2613 ASSERT_TRUE(content != NULL);
2614 EXPECT_FALSE(content->rejected);
2615
2616 content = cricket::GetFirstVideoContent(answer->description());
2617 ASSERT_TRUE(content != NULL);
2618 EXPECT_FALSE(content->rejected);
2619}
2620
2621// Test that an answer contains the correct media content descriptions when
2622// constraints have been set but no stream is sent.
2623TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002624 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002625 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002626 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002627 SetRemoteDescriptionWithoutError(offer.release());
2628
htaa2a49d92016-03-04 02:51:39 -08002629 cricket::MediaSessionOptions session_options;
2630 session_options.recv_audio = false;
2631 session_options.recv_video = false;
kwibergd1fe2812016-04-27 06:47:29 -07002632 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002633 CreateAnswer(session_options));
2634
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002635 const cricket::ContentInfo* content =
2636 cricket::GetFirstAudioContent(answer->description());
2637 ASSERT_TRUE(content != NULL);
2638 EXPECT_TRUE(content->rejected);
2639
2640 content = cricket::GetFirstVideoContent(answer->description());
2641 ASSERT_TRUE(content != NULL);
2642 EXPECT_TRUE(content->rejected);
2643}
2644
2645// Test that an answer contains the correct media content descriptions when
2646// constraints have been set and streams are sent.
2647TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002648 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002649 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002650 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002651 SetRemoteDescriptionWithoutError(offer.release());
2652
htaa2a49d92016-03-04 02:51:39 -08002653 cricket::MediaSessionOptions options;
2654 options.recv_audio = false;
2655 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002656
2657 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002658 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002659 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002660
2661 // TODO(perkj): Should the direction be set to SEND_ONLY?
2662 const cricket::ContentInfo* content =
2663 cricket::GetFirstAudioContent(answer->description());
2664 ASSERT_TRUE(content != NULL);
2665 EXPECT_FALSE(content->rejected);
2666
2667 // TODO(perkj): Should the direction be set to SEND_ONLY?
2668 content = cricket::GetFirstVideoContent(answer->description());
2669 ASSERT_TRUE(content != NULL);
2670 EXPECT_FALSE(content->rejected);
2671}
2672
2673TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2674 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002675 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002676 PeerConnectionInterface::RTCOfferAnswerOptions options;
2677 options.offer_to_receive_audio =
2678 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2679 options.voice_activity_detection = false;
2680
kwibergd1fe2812016-04-27 06:47:29 -07002681 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002682
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002683 const cricket::ContentInfo* content =
2684 cricket::GetFirstAudioContent(offer->description());
2685 EXPECT_TRUE(content != NULL);
2686 EXPECT_TRUE(VerifyNoCNCodecs(content));
2687}
2688
2689TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2690 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002691 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002692 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002693 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002694 SetRemoteDescriptionWithoutError(offer.release());
2695
htaa2a49d92016-03-04 02:51:39 -08002696 cricket::MediaSessionOptions options;
2697 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002698 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002699 const cricket::ContentInfo* content =
2700 cricket::GetFirstAudioContent(answer->description());
2701 ASSERT_TRUE(content != NULL);
2702 EXPECT_TRUE(VerifyNoCNCodecs(content));
2703}
2704
2705// This test verifies the call setup when remote answer with audio only and
2706// later updates with video.
2707TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002708 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002709 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2710 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2711
deadbeefab9b2d12015-10-14 11:33:11 -07002712 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002713 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002714
2715 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002716 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2717
2718 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2719 // and answer;
2720 SetLocalDescriptionWithoutError(offer);
2721 SetRemoteDescriptionWithoutError(answer);
2722
2723 video_channel_ = media_engine_->GetVideoChannel(0);
2724 voice_channel_ = media_engine_->GetVoiceChannel(0);
2725
2726 ASSERT_TRUE(video_channel_ == NULL);
2727
2728 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2729 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2730 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2731
2732 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002733 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002734 CreateAndSetRemoteOfferAndLocalAnswer();
2735
2736 video_channel_ = media_engine_->GetVideoChannel(0);
2737 voice_channel_ = media_engine_->GetVoiceChannel(0);
2738
2739 ASSERT_TRUE(video_channel_ != NULL);
2740 ASSERT_TRUE(voice_channel_ != NULL);
2741
2742 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2743 ASSERT_EQ(1u, video_channel_->send_streams().size());
2744 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2745 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2746 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2747 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2748 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2749 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2750
2751 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002752 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002753 CreateAndSetRemoteOfferAndLocalAnswer();
2754
2755 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2756 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2757 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2758 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2759 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2760}
2761
2762// This test verifies the call setup when remote answer with video only and
2763// later updates with audio.
2764TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002765 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002766 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2767 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
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;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002772 options.recv_audio = false;
2773 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002774 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2775 offer, options, cricket::SEC_ENABLED);
2776
2777 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2778 // and answer.
2779 SetLocalDescriptionWithoutError(offer);
2780 SetRemoteDescriptionWithoutError(answer);
2781
2782 video_channel_ = media_engine_->GetVideoChannel(0);
2783 voice_channel_ = media_engine_->GetVoiceChannel(0);
2784
2785 ASSERT_TRUE(voice_channel_ == NULL);
2786 ASSERT_TRUE(video_channel_ != NULL);
2787
2788 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2789 ASSERT_EQ(1u, video_channel_->send_streams().size());
2790 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2791
2792 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002793 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002794 CreateAndSetRemoteOfferAndLocalAnswer();
2795
2796 voice_channel_ = media_engine_->GetVoiceChannel(0);
2797 ASSERT_TRUE(voice_channel_ != NULL);
2798
2799 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2800 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2801 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2802 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2803
2804 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002805 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002806 CreateAndSetRemoteOfferAndLocalAnswer();
2807
2808 video_channel_ = media_engine_->GetVideoChannel(0);
2809 voice_channel_ = media_engine_->GetVoiceChannel(0);
2810
2811 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2812 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2813 ASSERT_EQ(1u, video_channel_->send_streams().size());
2814 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2815}
2816
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002817TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002818 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002819 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002820 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002821 VerifyCryptoParams(offer->description());
2822 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002823 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002824 VerifyCryptoParams(answer->description());
2825}
2826
jbauchcb560652016-08-04 05:20:32 -07002827TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDPGcm) {
2828 InitWithGcm();
2829 SendAudioVideoStream1();
2830 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
2831 VerifyCryptoParams(offer->description(), true);
2832 SetRemoteDescriptionWithoutError(offer.release());
2833 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
2834 VerifyCryptoParams(answer->description(), true);
2835}
2836
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002837TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002838 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002839 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002840 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002841 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002842 VerifyNoCryptoParams(offer->description(), false);
2843}
2844
2845TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002846 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002847 VerifyAnswerFromNonCryptoOffer();
2848}
2849
2850TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002851 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002852 VerifyAnswerFromCryptoOffer();
2853}
2854
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002855// This test verifies that setLocalDescription fails if
2856// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2857TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002858 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002859 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002860 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002861
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002862 std::string sdp;
2863 RemoveIceUfragPwdLines(offer.get(), &sdp);
2864 SessionDescriptionInterface* modified_offer =
2865 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002866 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002867}
2868
2869// This test verifies that setRemoteDescription fails if
2870// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2871TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002872 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002873 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002874 std::string sdp;
2875 RemoveIceUfragPwdLines(offer.get(), &sdp);
2876 SessionDescriptionInterface* modified_offer =
2877 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002878 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002879}
2880
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002881// This test verifies that setLocalDescription fails if local offer has
2882// too short ice ufrag and pwd strings.
2883TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002884 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002885 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002886 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002887 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2888 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002889 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002890 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002891 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002892
2893 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002894 offer.reset(CreateOffer());
2895 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2896 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002897}
2898
2899// This test verifies that setRemoteDescription fails if remote offer has
2900// too short ice ufrag and pwd strings.
2901TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002902 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002903 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002904 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2905 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002906 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002907 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002908 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002909
deadbeef0ed85b22016-02-23 17:24:52 -08002910 offer.reset(CreateRemoteOffer());
2911 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2912 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002913}
2914
Honghai Zhang04e91462015-12-11 14:26:22 -08002915// Test that if the remote offer indicates the peer requested ICE restart (via
2916// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2917TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002918 Init();
honghaiz503726c2015-07-31 12:37:38 -07002919
2920 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07002921 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08002922 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002923 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2924 0, "", "", "relay", 0, "");
2925 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2926 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002927 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2928 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002929 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2930
2931 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002932 offer.reset(CreateRemoteOffer());
2933 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002934 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2935 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2936 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002937 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2938 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002939 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2940
2941 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002942 offer.reset(CreateRemoteOffer());
2943 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002944 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2945 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2946 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002947 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2948 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002949 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2950
2951 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002952 offer.reset(CreateRemoteOffer());
2953 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2954 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002955 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2956}
2957
Honghai Zhang04e91462015-12-11 14:26:22 -08002958// Test that if the remote answer indicates the peer requested ICE restart (via
2959// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2960TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2961 Init();
2962 SessionDescriptionInterface* offer = CreateOffer();
2963 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002964
2965 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07002966 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08002967 answer->set_type(JsepSessionDescription::kPrAnswer);
2968 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002969 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2970 0, "", "", "relay", 0, "");
2971 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2972 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002973 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2974 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002975 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2976
2977 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002978 answer.reset(CreateRemoteAnswer(offer));
2979 answer->set_type(JsepSessionDescription::kPrAnswer);
2980 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002981 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2982 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2983 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002984 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
2985 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002986 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2987
2988 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002989 answer.reset(CreateRemoteAnswer(offer));
2990 answer->set_type(JsepSessionDescription::kPrAnswer);
2991 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002992 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2993 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2994 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002995 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
2996 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002997 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2998
2999 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08003000 answer.reset(CreateRemoteAnswer(offer));
3001 answer->set_type(JsepSessionDescription::kPrAnswer);
3002 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
3003 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003004 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
3005}
3006
Donald Curtisd4f769d2015-05-28 09:48:21 -07003007// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07003008// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07003009TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
3010 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
3011
3012 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003013 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003014
3015 PeerConnectionInterface::RTCOfferAnswerOptions options;
3016 options.use_rtp_mux = true;
3017
3018 SessionDescriptionInterface* offer = CreateRemoteOffer();
3019 SetRemoteDescriptionWithoutError(offer);
3020
htaa2a49d92016-03-04 02:51:39 -08003021 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003022 SetLocalDescriptionWithoutError(answer);
3023
deadbeefcbecd352015-09-23 11:50:27 -07003024 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3025 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07003026
deadbeefcbecd352015-09-23 11:50:27 -07003027 cricket::BaseChannel* voice_channel = session_->voice_channel();
3028 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003029
3030 // Checks if one of the transport channels contains a connection using a given
3031 // port.
deadbeefcbecd352015-09-23 11:50:27 -07003032 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07003033 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07003034 session_->GetChannelTransportStats(voice_channel, &stats);
3035 for (auto& kv : stats.transport_stats) {
3036 for (auto& chan_stat : kv.second.channel_stats) {
3037 for (auto& conn_info : chan_stat.connection_infos) {
3038 if (conn_info.remote_candidate.address().port() == port) {
3039 return true;
3040 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07003041 }
3042 }
3043 }
3044 return false;
3045 };
3046
3047 EXPECT_FALSE(connection_with_remote_port(5000));
3048 EXPECT_FALSE(connection_with_remote_port(5001));
3049 EXPECT_FALSE(connection_with_remote_port(6000));
3050
3051 // The way the *_WAIT checks work is they only wait if the condition fails,
3052 // which does not help in the case where state is not changing. This is
3053 // problematic in this test since we want to verify that adding a video
3054 // candidate does _not_ change state. So we interleave candidates and assume
3055 // that messages are executed in the order they were posted.
3056
3057 // First audio candidate.
3058 cricket::Candidate candidate0;
3059 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3060 candidate0.set_component(1);
3061 candidate0.set_protocol("udp");
3062 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3063 candidate0);
3064 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3065
3066 // Video candidate.
3067 cricket::Candidate candidate1;
3068 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3069 candidate1.set_component(1);
3070 candidate1.set_protocol("udp");
3071 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3072 candidate1);
3073 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3074
3075 // Second audio candidate.
3076 cricket::Candidate candidate2;
3077 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3078 candidate2.set_component(1);
3079 candidate2.set_protocol("udp");
3080 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3081 candidate2);
3082 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3083
3084 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3085 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3086
3087 // No need here for a _WAIT check since we are checking that state hasn't
3088 // changed: if this is false we would be doing waits for nothing and if this
3089 // is true then there will be no messages processed anyways.
3090 EXPECT_FALSE(connection_with_remote_port(6000));
3091}
3092
deadbeefcbecd352015-09-23 11:50:27 -07003093// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003094TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3095 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003096 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003097
3098 PeerConnectionInterface::RTCOfferAnswerOptions options;
3099 options.use_rtp_mux = true;
3100
3101 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003102 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003103
deadbeefcbecd352015-09-23 11:50:27 -07003104 EXPECT_NE(session_->voice_rtp_transport_channel(),
3105 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003106
deadbeefab9b2d12015-10-14 11:33:11 -07003107 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003108 SessionDescriptionInterface* answer =
3109 CreateRemoteAnswer(session_->local_description());
3110 SetRemoteDescriptionWithoutError(answer);
3111
deadbeefcbecd352015-09-23 11:50:27 -07003112 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3113 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003114}
3115
deadbeefcbecd352015-09-23 11:50:27 -07003116// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003117TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3118 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003119 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003120
Donald Curtis0e209b02015-03-24 09:29:54 -07003121 PeerConnectionInterface::RTCOfferAnswerOptions options;
3122 options.use_rtp_mux = true;
3123
3124 SessionDescriptionInterface* offer = CreateOffer(options);
3125 SetLocalDescriptionWithoutError(offer);
3126
deadbeefcbecd352015-09-23 11:50:27 -07003127 EXPECT_NE(session_->voice_rtp_transport_channel(),
3128 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003129
deadbeefab9b2d12015-10-14 11:33:11 -07003130 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003131
3132 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003133 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003134 CreateRemoteAnswer(session_->local_description()));
3135 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3136 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3137 JsepSessionDescription* modified_answer =
3138 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3139 modified_answer->Initialize(answer_copy, "1", "1");
3140 SetRemoteDescriptionWithoutError(modified_answer); //
3141
deadbeefcbecd352015-09-23 11:50:27 -07003142 EXPECT_NE(session_->voice_rtp_transport_channel(),
3143 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003144}
3145
3146// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3147TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3148 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003149 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003150
3151 PeerConnectionInterface::RTCOfferAnswerOptions options;
3152 options.use_rtp_mux = true;
3153
3154 SessionDescriptionInterface* offer = CreateOffer(options);
3155 SetLocalDescriptionWithoutError(offer);
3156
deadbeefcbecd352015-09-23 11:50:27 -07003157 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3158 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003159
deadbeefab9b2d12015-10-14 11:33:11 -07003160 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003161 SessionDescriptionInterface* answer =
3162 CreateRemoteAnswer(session_->local_description());
3163 SetRemoteDescriptionWithoutError(answer);
3164
deadbeefcbecd352015-09-23 11:50:27 -07003165 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3166 session_->video_rtp_transport_channel());
3167}
3168
3169// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3170// audio content in the answer.
3171TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3172 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003173 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003174
3175 PeerConnectionInterface::RTCOfferAnswerOptions options;
3176 options.use_rtp_mux = true;
3177
3178 SessionDescriptionInterface* offer = CreateOffer(options);
3179 SetLocalDescriptionWithoutError(offer);
3180
3181 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3182 session_->video_rtp_transport_channel());
3183
deadbeefab9b2d12015-10-14 11:33:11 -07003184 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003185 cricket::MediaSessionOptions recv_options;
3186 recv_options.recv_audio = false;
3187 recv_options.recv_video = true;
3188 SessionDescriptionInterface* answer =
3189 CreateRemoteAnswer(session_->local_description(), recv_options);
3190 SetRemoteDescriptionWithoutError(answer);
3191
deadbeefd59daf82015-10-14 15:02:44 -07003192 EXPECT_TRUE(nullptr == session_->voice_channel());
3193 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003194
deadbeefd59daf82015-10-14 15:02:44 -07003195 session_->Close();
3196 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3197 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3198 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3199 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003200}
3201
3202// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3203TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3204 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003205 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003206
Donald Curtis0e209b02015-03-24 09:29:54 -07003207 PeerConnectionInterface::RTCOfferAnswerOptions options;
3208 options.use_rtp_mux = true;
3209
3210 SessionDescriptionInterface* offer = CreateOffer(options);
3211 SetLocalDescriptionWithoutError(offer);
3212
deadbeefcbecd352015-09-23 11:50:27 -07003213 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3214 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003215
deadbeefab9b2d12015-10-14 11:33:11 -07003216 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003217
3218 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003219 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003220 CreateRemoteAnswer(session_->local_description()));
3221 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3222 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3223 JsepSessionDescription* modified_answer =
3224 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3225 modified_answer->Initialize(answer_copy, "1", "1");
3226 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003227
deadbeefcbecd352015-09-23 11:50:27 -07003228 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3229 session_->video_rtp_transport_channel());
3230}
3231
3232// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3233TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3234 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003235 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003236
3237 SessionDescriptionInterface* offer = CreateRemoteOffer();
3238 SetRemoteDescriptionWithoutError(offer);
3239
3240 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3241 session_->video_rtp_transport_channel());
3242
deadbeefab9b2d12015-10-14 11:33:11 -07003243 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003244 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003245 SetLocalDescriptionWithoutError(answer);
3246
3247 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3248 session_->video_rtp_transport_channel());
3249}
3250
3251// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3252TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3253 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003254 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003255
3256 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003257 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003258 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3259 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3260 JsepSessionDescription* modified_offer =
3261 new JsepSessionDescription(JsepSessionDescription::kOffer);
3262 modified_offer->Initialize(offer_copy, "1", "1");
3263
3264 // Expect an error when applying the remote description
3265 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3266 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003267}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003268
Peter Thatcher4eddf182015-04-30 10:55:59 -07003269// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003270TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3271 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003272 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003273
Donald Curtis0e209b02015-03-24 09:29:54 -07003274 PeerConnectionInterface::RTCOfferAnswerOptions options;
3275 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003276
Donald Curtis0e209b02015-03-24 09:29:54 -07003277 SessionDescriptionInterface* offer = CreateOffer(options);
3278 SetLocalDescriptionWithoutError(offer);
3279
deadbeefcbecd352015-09-23 11:50:27 -07003280 EXPECT_NE(session_->voice_rtp_transport_channel(),
3281 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003282
deadbeefab9b2d12015-10-14 11:33:11 -07003283 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003284 SessionDescriptionInterface* answer =
3285 CreateRemoteAnswer(session_->local_description());
3286 SetRemoteDescriptionWithoutError(answer);
3287
3288 // This should lead to an audio-only call but isn't implemented
3289 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003290 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3291 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003292}
3293
deadbeefcbecd352015-09-23 11:50:27 -07003294// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003295TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3296 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003297 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003298 PeerConnectionInterface::RTCOfferAnswerOptions options;
3299 options.use_rtp_mux = true;
3300
3301 SessionDescriptionInterface* offer = CreateOffer(options);
3302 SetLocalDescriptionWithoutError(offer);
3303
deadbeefcbecd352015-09-23 11:50:27 -07003304 EXPECT_NE(session_->voice_rtp_transport_channel(),
3305 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003306
deadbeefab9b2d12015-10-14 11:33:11 -07003307 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003308
3309 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003310 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003311 CreateRemoteAnswer(session_->local_description()));
3312 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3313 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3314 JsepSessionDescription* modified_answer =
3315 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3316 modified_answer->Initialize(answer_copy, "1", "1");
3317 SetRemoteDescriptionWithoutError(modified_answer); //
3318
deadbeefcbecd352015-09-23 11:50:27 -07003319 EXPECT_NE(session_->voice_rtp_transport_channel(),
3320 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003321}
3322
Peter Thatcher4eddf182015-04-30 10:55:59 -07003323// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3324TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3325 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003326 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003327
3328 PeerConnectionInterface::RTCOfferAnswerOptions options;
3329 options.use_rtp_mux = true;
3330
3331 SessionDescriptionInterface* offer = CreateOffer(options);
3332 SetRemoteDescriptionWithoutError(offer);
3333
deadbeefcbecd352015-09-23 11:50:27 -07003334 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3335 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003336}
3337
skvlad6c87a672016-05-17 17:49:52 -07003338// Adding a new channel to a BUNDLE which is already connected should directly
3339// assign the bundle transport to the channel, without first setting a
3340// disconnected non-bundle transport and then replacing it. The application
3341// should not receive any changes in the ICE state.
3342TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) {
3343 LoopbackNetworkConfiguration config;
3344 LoopbackNetworkManager loopback_network_manager(this, config);
3345 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain
3346 // connected. Disabling either of these two means that we need to wait for the
3347 // answer to find out if more transports are needed.
3348 configuration_.bundle_policy =
3349 PeerConnectionInterface::kBundlePolicyMaxBundle;
3350 configuration_.rtcp_mux_policy =
3351 PeerConnectionInterface::kRtcpMuxPolicyRequire;
3352 options_.disable_encryption = true;
3353 Init();
3354
3355 // Negotiate an audio channel with MAX_BUNDLE enabled.
3356 SendAudioOnlyStream2();
3357 SessionDescriptionInterface* offer = CreateOffer();
3358 SetLocalDescriptionWithoutError(offer);
3359 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
3360 observer_.ice_gathering_state_, kIceCandidatesTimeout);
3361 std::string sdp;
3362 offer->ToString(&sdp);
3363 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription(
3364 JsepSessionDescription::kAnswer, sdp, nullptr);
3365 ASSERT_TRUE(answer != NULL);
3366 SetRemoteDescriptionWithoutError(answer);
3367
3368 // Wait for the ICE state to stabilize.
3369 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3370 observer_.ice_connection_state_, kIceCandidatesTimeout);
3371 observer_.ice_connection_state_history_.clear();
3372
3373 // Now add a video channel which should be using the same bundle transport.
3374 SendAudioVideoStream2();
3375 offer = CreateOffer();
3376 offer->ToString(&sdp);
3377 SetLocalDescriptionWithoutError(offer);
3378 answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer,
3379 sdp, nullptr);
3380 ASSERT_TRUE(answer != NULL);
3381 SetRemoteDescriptionWithoutError(answer);
3382
3383 // Wait for ICE state to stabilize
3384 rtc::Thread::Current()->ProcessMessages(0);
3385 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3386 observer_.ice_connection_state_, kIceCandidatesTimeout);
3387
3388 // No ICE state changes are expected to happen.
3389 EXPECT_EQ(0, observer_.ice_connection_state_history_.size());
3390}
3391
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003392TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3393 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003394 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003395
3396 PeerConnectionInterface::RTCOfferAnswerOptions options;
3397 SessionDescriptionInterface* offer = CreateOffer(options);
3398 SetLocalDescriptionWithoutError(offer);
3399
deadbeefcbecd352015-09-23 11:50:27 -07003400 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3401 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003402
deadbeefab9b2d12015-10-14 11:33:11 -07003403 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003404 SessionDescriptionInterface* answer =
3405 CreateRemoteAnswer(session_->local_description());
3406 SetRemoteDescriptionWithoutError(answer);
3407
deadbeefcbecd352015-09-23 11:50:27 -07003408 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3409 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003410}
3411
3412TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3413 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003414 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003415
3416 PeerConnectionInterface::RTCOfferAnswerOptions options;
3417 SessionDescriptionInterface* offer = CreateOffer(options);
3418 SetLocalDescriptionWithoutError(offer);
3419
deadbeefcbecd352015-09-23 11:50:27 -07003420 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3421 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003422
deadbeefab9b2d12015-10-14 11:33:11 -07003423 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003424 SessionDescriptionInterface* answer =
3425 CreateRemoteAnswer(session_->local_description());
3426 SetRemoteDescriptionWithoutError(answer);
3427
deadbeefcbecd352015-09-23 11:50:27 -07003428 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3429 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003430}
3431
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003432// This test verifies that SetLocalDescription and SetRemoteDescription fails
3433// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3434TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003435 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003436 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003437
3438 PeerConnectionInterface::RTCOfferAnswerOptions options;
3439 options.use_rtp_mux = true;
3440
3441 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003442 std::string offer_str;
3443 offer->ToString(&offer_str);
3444 // Disable rtcp-mux
3445 const std::string rtcp_mux = "rtcp-mux";
3446 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003447 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003448 xrtcp_mux.c_str(), xrtcp_mux.length(),
3449 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003450 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003451 new JsepSessionDescription(JsepSessionDescription::kOffer);
3452 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003453 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003454 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003455 new JsepSessionDescription(JsepSessionDescription::kOffer);
3456 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003457 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003458 // Trying unmodified SDP.
3459 SetLocalDescriptionWithoutError(offer);
3460}
3461
jbauchcb560652016-08-04 05:20:32 -07003462TEST_F(WebRtcSessionTest, SetSetupGcm) {
3463 InitWithGcm();
3464 SendAudioVideoStream1();
3465 CreateAndSetRemoteOfferAndLocalAnswer();
3466}
3467
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003468TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3469 TestCanInsertDtmf(false);
3470}
3471
3472TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3473 TestCanInsertDtmf(true);
3474}
3475
3476TEST_F(WebRtcSessionTest, InsertDtmf) {
3477 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003478 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003479 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003480 CreateAndSetRemoteOfferAndLocalAnswer();
3481 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3482 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3483
3484 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003485 const int expected_duration = 90;
3486 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3487 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3488 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3489
3490 // Verify
3491 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003492 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003493 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003494 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003495 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003496 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003497 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003498 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003499}
3500
deadbeefd59daf82015-10-14 15:02:44 -07003501// This test verifies the |initial_offerer| flag when session initiates the
3502// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003503TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003504 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003505 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003506 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003507 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3508 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003509 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003510 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003511 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003512}
3513
deadbeefd59daf82015-10-14 15:02:44 -07003514// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003515TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003516 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003517 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003518 SessionDescriptionInterface* offer = CreateRemoteOffer();
3519 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003520 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003521
deadbeefd59daf82015-10-14 15:02:44 -07003522 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003523 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003524 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003525}
3526
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003527// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3528TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003529 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003530 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003531 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003532 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003533 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003534 CreateRemoteAnswer(session_->local_description()));
3535
3536 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3537 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003538 JsepSessionDescription* modified_answer =
3539 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003540
3541 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3542 answer->session_id(),
3543 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003544 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003545
wu@webrtc.org4e393072014-04-07 17:04:35 +00003546 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003547 std::string sdp;
3548 EXPECT_TRUE(answer->ToString(&sdp));
3549 const std::string kAudioMid = "a=mid:audio";
3550 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003551 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003552 kAudioMidReplaceStr.c_str(),
3553 kAudioMidReplaceStr.length(),
3554 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003555 SessionDescriptionInterface* modified_answer1 =
3556 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003557 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003558
wu@webrtc.org4e393072014-04-07 17:04:35 +00003559 // Different media types.
3560 EXPECT_TRUE(answer->ToString(&sdp));
3561 const std::string kAudioMline = "m=audio";
3562 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003563 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003564 kAudioMlineReplaceStr.c_str(),
3565 kAudioMlineReplaceStr.length(),
3566 &sdp);
3567 SessionDescriptionInterface* modified_answer2 =
3568 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3569 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3570
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003571 SetRemoteDescriptionWithoutError(answer.release());
3572}
3573
3574// Verifying remote offer and local answer have matching m-lines as per
3575// RFC 3264.
3576TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003577 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003578 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003579 SessionDescriptionInterface* offer = CreateRemoteOffer();
3580 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003581 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003582
3583 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3584 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003585 JsepSessionDescription* modified_answer =
3586 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003587
3588 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3589 answer->session_id(),
3590 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003591 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003592 SetLocalDescriptionWithoutError(answer);
3593}
3594
3595// This test verifies that WebRtcSession does not start candidate allocation
3596// before SetLocalDescription is called.
3597TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003598 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003599 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003600 SessionDescriptionInterface* offer = CreateRemoteOffer();
3601 cricket::Candidate candidate;
3602 candidate.set_component(1);
3603 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3604 candidate);
3605 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3606 cricket::Candidate candidate1;
3607 candidate1.set_component(1);
3608 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3609 candidate1);
3610 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3611 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003612 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3613 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003614
3615 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003616 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003617 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3618 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3619
htaa2a49d92016-03-04 02:51:39 -08003620 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003621 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003622 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3623}
3624
3625// This test verifies that crypto parameter is updated in local session
3626// description as per security policy set in MediaSessionDescriptionFactory.
3627TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003628 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003629 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003630 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003631
3632 // Making sure SetLocalDescription correctly sets crypto value in
3633 // SessionDescription object after de-serialization of sdp string. The value
3634 // will be set as per MediaSessionDescriptionFactory.
3635 std::string offer_str;
3636 offer->ToString(&offer_str);
3637 SessionDescriptionInterface* jsep_offer_str =
3638 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3639 SetLocalDescriptionWithoutError(jsep_offer_str);
3640 EXPECT_TRUE(session_->voice_channel()->secure_required());
3641 EXPECT_TRUE(session_->video_channel()->secure_required());
3642}
3643
3644// This test verifies the crypto parameter when security is disabled.
3645TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003646 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003647 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003648 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003649 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003650
3651 // Making sure SetLocalDescription correctly sets crypto value in
3652 // SessionDescription object after de-serialization of sdp string. The value
3653 // will be set as per MediaSessionDescriptionFactory.
3654 std::string offer_str;
3655 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003656 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003657 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3658 SetLocalDescriptionWithoutError(jsep_offer_str);
3659 EXPECT_FALSE(session_->voice_channel()->secure_required());
3660 EXPECT_FALSE(session_->video_channel()->secure_required());
3661}
3662
3663// This test verifies that an answer contains new ufrag and password if an offer
3664// with new ufrag and password is received.
3665TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003666 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003667 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003668 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003669 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003670 SetRemoteDescriptionWithoutError(offer.release());
3671
deadbeefab9b2d12015-10-14 11:33:11 -07003672 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003673 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003674 SetLocalDescriptionWithoutError(answer.release());
3675
3676 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003677 for (const cricket::ContentInfo& content :
3678 session_->local_description()->description()->contents()) {
3679 options.transport_options[content.name].ice_restart = true;
3680 }
kwibergd1fe2812016-04-27 06:47:29 -07003681 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003682 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003683 SetRemoteDescriptionWithoutError(updated_offer1.release());
3684
kwibergd1fe2812016-04-27 06:47:29 -07003685 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003686
deadbeef0ed85b22016-02-23 17:24:52 -08003687 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3688 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003689
deadbeef0ed85b22016-02-23 17:24:52 -08003690 // Even a second answer (created before the description is set) should have
3691 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003692 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003693
3694 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3695 session_->local_description()->description()));
3696
3697 SetLocalDescriptionWithoutError(updated_answer2.release());
3698}
3699
3700// This test verifies that an answer contains new ufrag and password if an offer
3701// that changes either the ufrag or password (but not both) is received.
3702// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3703// a=ice-pwd attributes compared to the previous SDP from the peer, it
3704// indicates that ICE is restarting for this media stream."
3705TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3706 Init();
3707 cricket::MediaSessionOptions options;
3708 options.recv_audio = true;
3709 options.recv_video = true;
3710 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003711 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003712 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3713 SetRemoteDescriptionWithoutError(offer.release());
3714
3715 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003716 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003717 SetLocalDescriptionWithoutError(answer.release());
3718
3719 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003720 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003721 CreateRemoteOffer(options, session_->remote_description()));
3722 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3723 "original_password12345");
3724 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3725
kwibergd1fe2812016-04-27 06:47:29 -07003726 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003727 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3728 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003729 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003730
3731 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003732 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003733 CreateRemoteOffer(options, session_->remote_description()));
3734 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3735 "modified_password12345");
3736 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3737
kwibergd1fe2812016-04-27 06:47:29 -07003738 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003739 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3740 session_->local_description()->description()));
3741 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003742}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003743
wu@webrtc.org91053e72013-08-10 07:18:04 +00003744// This test verifies that an answer contains old ufrag and password if an offer
3745// with old ufrag and password is received.
3746TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003747 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003748 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003749 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003750 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003751 SetRemoteDescriptionWithoutError(offer.release());
3752
deadbeefab9b2d12015-10-14 11:33:11 -07003753 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003754 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003755 SetLocalDescriptionWithoutError(answer.release());
3756
3757 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003758 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003759 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003760 SetRemoteDescriptionWithoutError(updated_offer2.release());
3761
kwibergd1fe2812016-04-27 06:47:29 -07003762 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003763
deadbeef0ed85b22016-02-23 17:24:52 -08003764 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3765 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003766
3767 SetLocalDescriptionWithoutError(updated_answer2.release());
3768}
3769
deadbeef0ed85b22016-02-23 17:24:52 -08003770// This test verifies that if an offer does an ICE restart on some, but not all
3771// media sections, the answer will change the ufrag/password in the correct
3772// media sections.
3773TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3774 Init();
3775 cricket::MediaSessionOptions options;
3776 options.recv_video = true;
3777 options.recv_audio = true;
3778 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003779 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003780
3781 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3782 "aaaaaaaaaaaaaaaaaaaaaa");
3783 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3784 "bbbbbbbbbbbbbbbbbbbbbb");
3785 SetRemoteDescriptionWithoutError(offer.release());
3786
3787 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003788 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003789 SetLocalDescriptionWithoutError(answer.release());
3790
3791 // Receive an offer with new ufrag and password, but only for the video media
3792 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003793 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003794 CreateRemoteOffer(options, session_->remote_description()));
3795 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3796 "cccccccccccccccccccccc");
3797 SetRemoteDescriptionWithoutError(updated_offer.release());
3798
kwibergd1fe2812016-04-27 06:47:29 -07003799 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003800
3801 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3802 session_->local_description()->description(),
3803 cricket::MEDIA_TYPE_AUDIO));
3804
3805 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3806 session_->local_description()->description(),
3807 cricket::MEDIA_TYPE_VIDEO));
3808
3809 SetLocalDescriptionWithoutError(updated_answer.release());
3810}
3811
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003812TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003813 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003814 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003815 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003816 const std::string session_id_orig = offer->session_id();
3817 const std::string session_version_orig = offer->session_version();
3818 SetLocalDescriptionWithoutError(offer);
3819
3820 video_channel_ = media_engine_->GetVideoChannel(0);
3821 video_channel_->set_fail_set_send_codecs(true);
3822
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003823 SessionDescriptionInterface* answer =
3824 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003825 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003826
3827 // Test that after a content error, setting any description will
3828 // result in an error.
3829 video_channel_->set_fail_set_send_codecs(false);
3830 answer = CreateRemoteAnswer(session_->local_description());
3831 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3832 offer = CreateRemoteOffer();
3833 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003834}
3835
3836// Runs the loopback call test with BUNDLE and STUN disabled.
3837TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3838 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003839 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003840 cricket::PORTALLOCATOR_DISABLE_STUN |
3841 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003842 TestLoopbackCall();
3843}
3844
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003845TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003846 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003847 cricket::PORTALLOCATOR_DISABLE_STUN |
3848 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3849 cricket::PORTALLOCATOR_DISABLE_RELAY);
3850
3851 // best connection is IPv6 since it has higher network preference.
3852 LoopbackNetworkConfiguration config;
3853 config.test_ipv6_network_ = true;
3854 config.best_connection_after_initial_ice_converged_ =
3855 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3856
3857 TestLoopbackCall(config);
3858}
3859
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003860// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003861TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003862 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3863 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003864 TestLoopbackCall();
3865}
3866
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003867TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003868 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003869 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003870 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003871 ASSERT_TRUE(data_engine_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003872 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3873}
3874
Henrik Boström87713d02015-08-25 09:53:21 +02003875TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003876 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003877
htaa2a49d92016-03-04 02:51:39 -08003878 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003879 options_.disable_sctp_data_channels = false;
3880
Henrik Boström87713d02015-08-25 09:53:21 +02003881 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003882
3883 SetLocalDescriptionWithDataChannel();
3884 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3885}
3886
Henrik Boström87713d02015-08-25 09:53:21 +02003887TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003888 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003889
Henrik Boström87713d02015-08-25 09:53:21 +02003890 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003891
kwibergd1fe2812016-04-27 06:47:29 -07003892 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003893 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003894 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3895}
3896
Henrik Boström87713d02015-08-25 09:53:21 +02003897TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003898 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003899 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003900 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003901
3902 // Create remote offer with SCTP.
3903 cricket::MediaSessionOptions options;
3904 options.data_channel_type = cricket::DCT_SCTP;
3905 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003906 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003907 SetRemoteDescriptionWithoutError(offer);
3908
3909 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07003910 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003911 EXPECT_TRUE(answer != NULL);
3912 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3913 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003914}
3915
Henrik Boström87713d02015-08-25 09:53:21 +02003916TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003917 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003918 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003919
3920 SetLocalDescriptionWithDataChannel();
3921 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3922}
3923
Henrik Boström87713d02015-08-25 09:53:21 +02003924TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003925 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003926
Henrik Boström87713d02015-08-25 09:53:21 +02003927 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003928
3929 SetLocalDescriptionWithDataChannel();
3930 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3931}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003932
Henrik Boström87713d02015-08-25 09:53:21 +02003933TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003934 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003935 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003936 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003937
3938 SetLocalDescriptionWithDataChannel();
3939 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3940}
3941
Henrik Boström87713d02015-08-25 09:53:21 +02003942TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003943 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003944 const int new_send_port = 9998;
3945 const int new_recv_port = 7775;
3946
Henrik Boström87713d02015-08-25 09:53:21 +02003947 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003948 SetFactoryDtlsSrtp();
3949
3950 // By default, don't actually add the codecs to desc_factory_; they don't
3951 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3952 // let the session description get parsed. That'll get the proper codecs
3953 // into the stream.
3954 cricket::MediaSessionOptions options;
3955 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3956 "stream1", new_send_port, options);
3957
3958 // SetRemoteDescription will take the ownership of the offer.
3959 SetRemoteDescriptionWithoutError(offer);
3960
htaa2a49d92016-03-04 02:51:39 -08003961 SessionDescriptionInterface* answer =
3962 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003963 ASSERT_TRUE(answer != NULL);
3964
3965 // Now set the local description, which'll take ownership of the answer.
3966 SetLocalDescriptionWithoutError(answer);
3967
3968 // TEST PLAN: Set the port number to something new, set it in the SDP,
3969 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003970 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003971 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003972
3973 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3974 int portnum = -1;
3975 ASSERT_TRUE(ch != NULL);
3976 ASSERT_EQ(1UL, ch->send_codecs().size());
solenberg9fa49752016-10-08 13:02:44 -07003977 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003978 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003979 ch->send_codecs()[0].name.c_str()));
3980 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3981 &portnum));
3982 EXPECT_EQ(new_send_port, portnum);
3983
3984 ASSERT_EQ(1UL, ch->recv_codecs().size());
solenberg9fa49752016-10-08 13:02:44 -07003985 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003986 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003987 ch->recv_codecs()[0].name.c_str()));
3988 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3989 &portnum));
3990 EXPECT_EQ(new_recv_port, portnum);
3991}
3992
deadbeefab9b2d12015-10-14 11:33:11 -07003993// Verifies that when a session's DataChannel receives an OPEN message,
3994// WebRtcSession signals the DataChannel creation request with the expected
3995// config.
3996TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
3997 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3998
3999 InitWithDtls(GetParam());
4000
4001 SetLocalDescriptionWithDataChannel();
4002 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
4003
4004 webrtc::DataChannelInit config;
4005 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07004006 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07004007 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4008 cricket::ReceiveDataParams params;
4009 params.ssrc = config.id;
4010 params.type = cricket::DMT_CONTROL;
4011
4012 cricket::DataChannel* data_channel = session_->data_channel();
4013 data_channel->SignalDataReceived(data_channel, params, payload);
4014
4015 EXPECT_EQ("a", last_data_channel_label_);
4016 EXPECT_EQ(config.id, last_data_channel_config_.id);
4017 EXPECT_FALSE(last_data_channel_config_.negotiated);
4018 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4019 last_data_channel_config_.open_handshake_role);
4020}
4021
4022TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004023 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
Henrik Boströmd79599d2016-06-01 13:58:50 +02004024 FakeRTCCertificateGenerator::GenerateCertificate();
Henrik Boströmd8281982015-08-27 10:12:24 +02004025
htaa2a49d92016-03-04 02:51:39 -08004026 configuration_.certificates.push_back(certificate);
4027 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004028 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4029
4030 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4031}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004032
Henrik Boström87713d02015-08-25 09:53:21 +02004033// Verifies that CreateOffer succeeds when CreateOffer is called before async
4034// identity generation is finished (even if a certificate is provided this is
4035// an async op).
4036TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
4037 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4038 InitWithDtls(GetParam());
4039
Henrik Boströmd8281982015-08-27 10:12:24 +02004040 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004041 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07004042 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004043
wu@webrtc.org91053e72013-08-10 07:18:04 +00004044 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004045 VerifyNoCryptoParams(offer->description(), true);
4046 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004047}
4048
4049// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004050// identity generation is finished (even if a certificate is provided this is
4051// an async op).
4052TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004053 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004054 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004055 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004056
4057 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004058 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07004059 std::unique_ptr<JsepSessionDescription> offer(
4060 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004061 ASSERT_TRUE(offer.get() != NULL);
4062 SetRemoteDescriptionWithoutError(offer.release());
4063
kwibergd1fe2812016-04-27 06:47:29 -07004064 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004065 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004066 VerifyNoCryptoParams(answer->description(), true);
4067 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004068}
4069
4070// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004071// identity generation is finished (even if a certificate is provided this is
4072// an async op).
4073TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004074 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004075 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004076
Henrik Boströmd8281982015-08-27 10:12:24 +02004077 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004078
kwibergd1fe2812016-04-27 06:47:29 -07004079 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004080 EXPECT_TRUE(offer != NULL);
4081}
4082
4083// Verifies that CreateOffer fails when CreateOffer is called after async
4084// identity generation fails.
4085TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004086 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004087 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004088
Henrik Boströmd8281982015-08-27 10:12:24 +02004089 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004090
kwibergd1fe2812016-04-27 06:47:29 -07004091 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004092 EXPECT_TRUE(offer == NULL);
4093}
4094
4095// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4096// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004097TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004098 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004099 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004100 VerifyMultipleAsyncCreateDescription(GetParam(),
4101 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004102}
4103
4104// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4105// before async identity generation fails.
4106TEST_F(WebRtcSessionTest,
4107 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004108 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004109 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4110 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004111}
4112
4113// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4114// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004115TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004116 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004117 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004118 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004119 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004120}
4121
4122// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4123// before async identity generation fails.
4124TEST_F(WebRtcSessionTest,
4125 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004126 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004127 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4128 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004129}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004130
4131// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4132// offer has no SDES crypto but only DTLS fingerprint.
4133TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4134 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004135 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004136 // Create a remote offer with secured transport disabled.
4137 cricket::MediaSessionOptions options;
4138 JsepSessionDescription* offer(CreateRemoteOffer(
4139 options, cricket::SEC_DISABLED));
4140 // Adds a DTLS fingerprint to the remote offer.
4141 cricket::SessionDescription* sdp = offer->description();
4142 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4143 ASSERT_TRUE(audio != NULL);
4144 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4145 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004146 rtc::SSLFingerprint::CreateFromRfc4572(
4147 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004148 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004149 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004150}
4151
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004152TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004153 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004154 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004155 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004156 SessionDescriptionInterface* offer = CreateOffer();
4157
4158 SetLocalDescriptionWithoutError(offer);
4159
4160 voice_channel_ = media_engine_->GetVoiceChannel(0);
4161
4162 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004163 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004164 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004165}
4166
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004167// Tests that we can renegotiate new media content with ICE candidates in the
4168// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004169TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004170 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004171 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004172 SetFactoryDtlsSrtp();
4173
deadbeefab9b2d12015-10-14 11:33:11 -07004174 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004175 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004176 SetLocalDescriptionWithoutError(offer);
4177
4178 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4179 SetRemoteDescriptionWithoutError(answer);
4180
4181 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004182 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004183 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4184
4185 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004186 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004187 candidate1.set_component(1);
4188 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4189 candidate1);
4190 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4191 SetRemoteDescriptionWithoutError(offer);
4192
htaa2a49d92016-03-04 02:51:39 -08004193 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004194 SetLocalDescriptionWithoutError(answer);
4195}
4196
4197// Tests that we can renegotiate new media content with ICE candidates separated
4198// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004199TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004200 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004201 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004202 SetFactoryDtlsSrtp();
4203
deadbeefab9b2d12015-10-14 11:33:11 -07004204 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004205 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004206 SetLocalDescriptionWithoutError(offer);
4207
4208 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4209 SetRemoteDescriptionWithoutError(answer);
4210
4211 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004212 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004213 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4214 SetRemoteDescriptionWithoutError(offer);
4215
4216 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004217 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004218 candidate1.set_component(1);
4219 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4220 candidate1);
4221 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4222
htaa2a49d92016-03-04 02:51:39 -08004223 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004224 SetLocalDescriptionWithoutError(answer);
4225}
honghaiz7f777492016-02-02 21:54:01 -08004226
zhihuang9763d562016-08-05 11:14:50 -07004227#ifdef HAVE_QUIC
4228TEST_P(WebRtcSessionTest, TestNegotiateQuic) {
4229 configuration_.enable_quic = true;
4230 InitWithDtls(GetParam());
4231 EXPECT_TRUE(session_->data_channel_type() == cricket::DCT_QUIC);
4232 SessionDescriptionInterface* offer = CreateOffer();
4233 ASSERT_TRUE(offer);
4234 ASSERT_TRUE(offer->description());
4235 SetLocalDescriptionWithoutError(offer);
4236 cricket::MediaSessionOptions options;
4237 options.recv_audio = true;
4238 options.recv_video = true;
4239 SessionDescriptionInterface* answer =
4240 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
4241 ASSERT_TRUE(answer);
4242 ASSERT_TRUE(answer->description());
4243 SetRemoteDescriptionWithoutError(answer);
4244}
4245#endif // HAVE_QUIC
4246
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004247// Tests that RTX codec is removed from the answer when it isn't supported
4248// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004249TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004250 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004251 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004252 std::string offer_sdp(kSdpWithRtx);
4253
4254 SessionDescriptionInterface* offer =
4255 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4256 EXPECT_TRUE(offer->ToString(&offer_sdp));
4257
4258 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004259 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004260 SetRemoteDescriptionWithoutError(offer);
4261
htaa2a49d92016-03-04 02:51:39 -08004262 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004263 // Answer SDP does not contain the RTX codec.
4264 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004265 SetLocalDescriptionWithoutError(answer);
4266}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004267
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004268// This verifies that the voice channel after bundle has both options from video
4269// and voice channels.
4270TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4271 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004272 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004273
4274 PeerConnectionInterface::RTCOfferAnswerOptions options;
4275 options.use_rtp_mux = true;
4276
4277 SessionDescriptionInterface* offer = CreateOffer(options);
4278 SetLocalDescriptionWithoutError(offer);
4279
4280 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4281 rtc::Socket::Option::OPT_SNDBUF, 4000);
4282
4283 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4284 rtc::Socket::Option::OPT_RCVBUF, 8000);
4285
4286 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004287 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004288 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4289 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004290 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004291 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4292
deadbeefcbecd352015-09-23 11:50:27 -07004293 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004294 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4295 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004296 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004297 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4298
deadbeefcbecd352015-09-23 11:50:27 -07004299 EXPECT_NE(session_->voice_rtp_transport_channel(),
4300 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004301
deadbeefab9b2d12015-10-14 11:33:11 -07004302 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004303 SessionDescriptionInterface* answer =
4304 CreateRemoteAnswer(session_->local_description());
4305 SetRemoteDescriptionWithoutError(answer);
4306
deadbeefcbecd352015-09-23 11:50:27 -07004307 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004308 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4309 EXPECT_EQ(4000, option_val);
4310
deadbeefcbecd352015-09-23 11:50:27 -07004311 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004312 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4313 EXPECT_EQ(8000, option_val);
4314}
4315
tommi0f620f42015-07-09 03:25:02 -07004316// Test creating a session, request multiple offers, destroy the session
4317// and make sure we got success/failure callbacks for all of the requests.
4318// Background: crbug.com/507307
4319TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4320 Init();
4321
4322 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4323 PeerConnectionInterface::RTCOfferAnswerOptions options;
4324 options.offer_to_receive_audio =
4325 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004326 cricket::MediaSessionOptions session_options;
4327 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004328
4329 for (auto& o : observers) {
4330 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004331 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004332 }
4333
4334 session_.reset();
4335
tommi0f620f42015-07-09 03:25:02 -07004336 for (auto& o : observers) {
4337 // We expect to have received a notification now even if the session was
4338 // terminated. The offer creation may or may not have succeeded, but we
4339 // must have received a notification which, so the only invalid state
4340 // is kInit.
4341 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4342 }
4343}
4344
stefanc1aeaf02015-10-15 07:26:07 -07004345TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4346 TestPacketOptions();
4347}
4348
deadbeef057ecf02016-01-20 14:30:43 -08004349// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4350// is destroyed.
4351TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4352 Init();
4353 session_.reset();
4354 EXPECT_TRUE(session_destroyed_);
4355}
4356
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004357// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4358// currently fails because upon disconnection and reconnection OnIceComplete is
4359// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004360
deadbeefcbecd352015-09-23 11:50:27 -07004361INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4362 WebRtcSessionTest,
4363 testing::Values(ALREADY_GENERATED,
4364 DTLS_IDENTITY_STORE));