blob: 116c8d57391da9ecd2d43cf250317d69221d84db [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,
deadbeefc0dad892017-01-04 20:28:21 -0800223 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,
deadbeefc0dad892017-01-04 20:28:21 -0800229 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
deadbeefc0dad892017-01-04 20:28:21 -0800252 rtc::PacketTransportInterface* data_rtp_transport_channel() {
253 return rtp_transport_channel(data_channel());
254 }
255
256 rtc::PacketTransportInterface* data_rtcp_transport_channel() {
257 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(
zhihuang4dfb8ce2016-11-23 10:30:12 -0800386 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
387 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 ASSERT_TRUE(session_.get() == NULL);
389 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700390 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
zhihuang29ff8442016-07-27 11:07:25 -0700391 rtc::Thread::Current(), allocator_.get(), &observer_,
392 std::unique_ptr<cricket::TransportController>(
393 new cricket::TransportController(rtc::Thread::Current(),
394 rtc::Thread::Current(),
deadbeefc0dad892017-01-04 20:28:21 -0800395 allocator_.get()))));
deadbeefab9b2d12015-10-14 11:33:11 -0700396 session_->SignalDataChannelOpenMessage.connect(
397 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
deadbeef057ecf02016-01-20 14:30:43 -0800398 session_->GetOnDestroyedSignal()->connect(
399 this, &WebRtcSessionTest::OnSessionDestroyed);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000400
zhihuang4dfb8ce2016-11-23 10:30:12 -0800401 configuration_.rtcp_mux_policy = rtcp_mux_policy;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000402 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
403 observer_.ice_connection_state_);
404 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
405 observer_.ice_gathering_state_);
406
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200407 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator),
htaa2a49d92016-03-04 02:51:39 -0800408 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700409 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000410 }
411
deadbeefab9b2d12015-10-14 11:33:11 -0700412 void OnDataChannelOpenMessage(const std::string& label,
413 const InternalDataChannelInit& config) {
414 last_data_channel_label_ = label;
415 last_data_channel_config_ = config;
416 }
417
deadbeef057ecf02016-01-20 14:30:43 -0800418 void OnSessionDestroyed() { session_destroyed_ = true; }
419
zhihuang4dfb8ce2016-11-23 10:30:12 -0800420 void Init() {
421 Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
422 }
423
424 void Init(PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
425 Init(nullptr, rtcp_mux_policy);
426 }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000427
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000428 void InitWithBundlePolicy(
429 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800430 configuration_.bundle_policy = bundle_policy;
431 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700432 }
433
434 void InitWithRtcpMuxPolicy(
435 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
436 PeerConnectionInterface::RTCConfiguration configuration;
zhihuang4dfb8ce2016-11-23 10:30:12 -0800437 Init(rtcp_mux_policy);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000438 }
439
Henrik Boström87713d02015-08-25 09:53:21 +0200440 // Successfully init with DTLS; with a certificate generated and supplied or
441 // with a store that generates it for us.
442 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200443 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator;
Henrik Boström87713d02015-08-25 09:53:21 +0200444 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800445 configuration_.certificates.push_back(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200446 FakeRTCCertificateGenerator::GenerateCertificate());
Henrik Boström87713d02015-08-25 09:53:21 +0200447 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200448 cert_generator.reset(new FakeRTCCertificateGenerator());
449 cert_generator->set_should_fail(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200450 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700451 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200452 }
zhihuang4dfb8ce2016-11-23 10:30:12 -0800453 Init(std::move(cert_generator),
454 PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
Henrik Boström87713d02015-08-25 09:53:21 +0200455 }
456
457 // Init with DTLS with a store that will fail to generate a certificate.
458 void InitWithDtlsIdentityGenFail() {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200459 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
460 new FakeRTCCertificateGenerator());
461 cert_generator->set_should_fail(true);
zhihuang4dfb8ce2016-11-23 10:30:12 -0800462 Init(std::move(cert_generator),
463 PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000464 }
465
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000466 void InitWithDtmfCodec() {
467 // Add kTelephoneEventCodec for dtmf test.
deadbeef67cf2c12016-04-13 10:07:16 -0700468 const cricket::AudioCodec kTelephoneEventCodec(106, "telephone-event", 8000,
469 0, 1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000470 std::vector<cricket::AudioCodec> codecs;
471 codecs.push_back(kTelephoneEventCodec);
472 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -0700473 desc_factory_->set_audio_codecs(codecs, codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000474 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000475 }
476
jbauchcb560652016-08-04 05:20:32 -0700477 void InitWithGcm() {
478 rtc::CryptoOptions crypto_options;
479 crypto_options.enable_gcm_crypto_suites = true;
480 channel_manager_->SetCryptoOptions(crypto_options);
481 with_gcm_ = true;
482 Init();
483 }
484
deadbeefab9b2d12015-10-14 11:33:11 -0700485 void SendAudioVideoStream1() {
486 send_stream_1_ = true;
487 send_stream_2_ = false;
488 send_audio_ = true;
489 send_video_ = true;
490 }
491
492 void SendAudioVideoStream2() {
493 send_stream_1_ = false;
494 send_stream_2_ = true;
495 send_audio_ = true;
496 send_video_ = true;
497 }
498
499 void SendAudioVideoStream1And2() {
500 send_stream_1_ = true;
501 send_stream_2_ = true;
502 send_audio_ = true;
503 send_video_ = true;
504 }
505
506 void SendNothing() {
507 send_stream_1_ = false;
508 send_stream_2_ = false;
509 send_audio_ = false;
510 send_video_ = false;
511 }
512
513 void SendAudioOnlyStream2() {
514 send_stream_1_ = false;
515 send_stream_2_ = true;
516 send_audio_ = true;
517 send_video_ = false;
518 }
519
520 void SendVideoOnlyStream2() {
521 send_stream_1_ = false;
522 send_stream_2_ = true;
523 send_audio_ = false;
524 send_video_ = true;
525 }
526
527 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
528 if (send_stream_1_ && send_audio_) {
529 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
530 kStream1);
531 }
532 if (send_stream_1_ && send_video_) {
533 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
534 kStream1);
535 }
536 if (send_stream_2_ && send_audio_) {
537 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
538 kStream2);
539 }
540 if (send_stream_2_ && send_video_) {
541 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
542 kStream2);
543 }
544 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
545 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
546 data_channel_->label(),
547 data_channel_->label());
548 }
549 }
550
551 void GetOptionsForOffer(
552 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
553 cricket::MediaSessionOptions* session_options) {
htaaac2dea2016-03-10 13:35:55 -0800554 ASSERT_TRUE(ExtractMediaSessionOptions(rtc_options, true, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700555
deadbeefc80741f2015-10-22 13:14:45 -0700556 AddStreamsToOptions(session_options);
557 if (rtc_options.offer_to_receive_audio ==
558 RTCOfferAnswerOptions::kUndefined) {
559 session_options->recv_audio =
560 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
561 }
562 if (rtc_options.offer_to_receive_video ==
563 RTCOfferAnswerOptions::kUndefined) {
564 session_options->recv_video =
565 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
566 }
567 session_options->bundle_enabled =
568 session_options->bundle_enabled &&
569 (session_options->has_audio() || session_options->has_video() ||
570 session_options->has_data());
571
deadbeefab9b2d12015-10-14 11:33:11 -0700572 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
573 session_options->data_channel_type = cricket::DCT_SCTP;
zhihuang9763d562016-08-05 11:14:50 -0700574 } else if (session_->data_channel_type() == cricket::DCT_QUIC) {
575 session_options->data_channel_type = cricket::DCT_QUIC;
deadbeefab9b2d12015-10-14 11:33:11 -0700576 }
jbauchcb560652016-08-04 05:20:32 -0700577
578 if (with_gcm_) {
579 session_options->crypto_options.enable_gcm_crypto_suites = true;
580 }
deadbeefab9b2d12015-10-14 11:33:11 -0700581 }
582
htaa2a49d92016-03-04 02:51:39 -0800583 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
584 // ParseConstraintsForAnswer is used to set some defaults.
585 ASSERT_TRUE(webrtc::ParseConstraintsForAnswer(nullptr, session_options));
deadbeefab9b2d12015-10-14 11:33:11 -0700586
deadbeefc80741f2015-10-22 13:14:45 -0700587 AddStreamsToOptions(session_options);
588 session_options->bundle_enabled =
589 session_options->bundle_enabled &&
590 (session_options->has_audio() || session_options->has_video() ||
591 session_options->has_data());
592
zhihuang9763d562016-08-05 11:14:50 -0700593 if (session_->data_channel_type() != cricket::DCT_RTP) {
594 session_options->data_channel_type = session_->data_channel_type();
deadbeef907abe42016-08-04 12:22:18 -0700595 }
jbauchcb560652016-08-04 05:20:32 -0700596
597 if (with_gcm_) {
598 session_options->crypto_options.enable_gcm_crypto_suites = true;
599 }
deadbeefab9b2d12015-10-14 11:33:11 -0700600 }
601
602 // Creates a local offer and applies it. Starts ICE.
603 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000604 // to decide which streams to create.
605 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000606 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000607 SetLocalDescriptionWithoutError(offer);
608 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
609 observer_.ice_gathering_state_,
610 kIceCandidatesTimeout);
611 }
612
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000613 SessionDescriptionInterface* CreateOffer() {
614 PeerConnectionInterface::RTCOfferAnswerOptions options;
615 options.offer_to_receive_audio =
616 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
617
618 return CreateOffer(options);
619 }
620
wu@webrtc.org91053e72013-08-10 07:18:04 +0000621 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800622 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000623 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000624 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700625 cricket::MediaSessionOptions session_options;
626 GetOptionsForOffer(options, &session_options);
627 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000628 EXPECT_TRUE_WAIT(
629 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000630 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000631 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000632 }
633
634 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800635 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000636 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000637 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800638 cricket::MediaSessionOptions session_options = options;
639 GetOptionsForAnswer(&session_options);
640 // Overwrite recv_audio and recv_video with passed-in values.
641 session_options.recv_video = options.recv_video;
642 session_options.recv_audio = options.recv_audio;
643 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000644 EXPECT_TRUE_WAIT(
645 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000646 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000647 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000648 }
649
htaa2a49d92016-03-04 02:51:39 -0800650 SessionDescriptionInterface* CreateAnswer() {
651 cricket::MediaSessionOptions options;
652 options.recv_video = true;
653 options.recv_audio = true;
654 return CreateAnswer(options);
655 }
656
wu@webrtc.org364f2042013-11-20 21:49:41 +0000657 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000658 return (session_->voice_channel() != NULL &&
659 session_->video_channel() != NULL);
660 }
661
jbauchcb560652016-08-04 05:20:32 -0700662 void VerifyCryptoParams(const cricket::SessionDescription* sdp,
663 bool gcm_enabled = false) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000664 ASSERT_TRUE(session_.get() != NULL);
665 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
666 ASSERT_TRUE(content != NULL);
667 const cricket::AudioContentDescription* audio_content =
668 static_cast<const cricket::AudioContentDescription*>(
669 content->description);
670 ASSERT_TRUE(audio_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700671 if (!gcm_enabled) {
672 ASSERT_EQ(1U, audio_content->cryptos().size());
673 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
674 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
675 audio_content->cryptos()[0].cipher_suite);
676 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
677 audio_content->protocol());
678 } else {
679 // The offer contains 3 possible crypto suites, the answer 1.
680 EXPECT_LE(1U, audio_content->cryptos().size());
681 EXPECT_NE(2U, audio_content->cryptos().size());
682 EXPECT_GE(3U, audio_content->cryptos().size());
683 ASSERT_EQ(67U, audio_content->cryptos()[0].key_params.size());
684 ASSERT_EQ("AEAD_AES_256_GCM",
685 audio_content->cryptos()[0].cipher_suite);
686 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
687 audio_content->protocol());
688 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000689
690 content = cricket::GetFirstVideoContent(sdp);
691 ASSERT_TRUE(content != NULL);
692 const cricket::VideoContentDescription* video_content =
693 static_cast<const cricket::VideoContentDescription*>(
694 content->description);
695 ASSERT_TRUE(video_content != NULL);
jbauchcb560652016-08-04 05:20:32 -0700696 if (!gcm_enabled) {
697 ASSERT_EQ(1U, video_content->cryptos().size());
698 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
699 video_content->cryptos()[0].cipher_suite);
700 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
701 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
702 video_content->protocol());
703 } else {
704 // The offer contains 3 possible crypto suites, the answer 1.
705 EXPECT_LE(1U, video_content->cryptos().size());
706 EXPECT_NE(2U, video_content->cryptos().size());
707 EXPECT_GE(3U, video_content->cryptos().size());
708 ASSERT_EQ("AEAD_AES_256_GCM",
709 video_content->cryptos()[0].cipher_suite);
710 ASSERT_EQ(67U, video_content->cryptos()[0].key_params.size());
711 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
712 video_content->protocol());
713 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000714 }
715
716 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
717 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
718 ASSERT_TRUE(content != NULL);
719 const cricket::AudioContentDescription* audio_content =
720 static_cast<const cricket::AudioContentDescription*>(
721 content->description);
722 ASSERT_TRUE(audio_content != NULL);
723 ASSERT_EQ(0U, audio_content->cryptos().size());
724
725 content = cricket::GetFirstVideoContent(sdp);
726 ASSERT_TRUE(content != NULL);
727 const cricket::VideoContentDescription* video_content =
728 static_cast<const cricket::VideoContentDescription*>(
729 content->description);
730 ASSERT_TRUE(video_content != NULL);
731 ASSERT_EQ(0U, video_content->cryptos().size());
732
733 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700734 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000735 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700736 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000737 video_content->protocol());
738 } else {
739 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
740 audio_content->protocol());
741 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
742 video_content->protocol());
743 }
744 }
745
746 // Set the internal fake description factories to do DTLS-SRTP.
747 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000748 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000749 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000750 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200751 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800752 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700753 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800754 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000755 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
756 }
757
758 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
759 bool expected) {
760 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
761 ASSERT_TRUE(audio != NULL);
762 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763 const TransportInfo* video = sdp->GetTransportInfoByName("video");
764 ASSERT_TRUE(video != NULL);
765 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000766 }
767
768 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000769 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000770 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000771 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000772 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000773 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000774 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000775 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000776 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
777 offer);
htaa2a49d92016-03-04 02:51:39 -0800778 const webrtc::SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000779 // Answer should be NULL as no crypto params in offer.
780 ASSERT_TRUE(answer == NULL);
781 }
782
783 void VerifyAnswerFromCryptoOffer() {
784 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000785 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000786 options.bundle_enabled = true;
kwibergd1fe2812016-04-27 06:47:29 -0700787 std::unique_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
789 ASSERT_TRUE(offer.get() != NULL);
790 VerifyCryptoParams(offer->description());
791 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -0700792 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793 ASSERT_TRUE(answer.get() != NULL);
794 VerifyCryptoParams(answer->description());
795 }
796
deadbeef0ed85b22016-02-23 17:24:52 -0800797 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
798 const cricket::SessionDescription* desc2) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799 if (desc1->contents().size() != desc2->contents().size()) {
deadbeef0ed85b22016-02-23 17:24:52 -0800800 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 }
802
803 const cricket::ContentInfos& contents = desc1->contents();
804 cricket::ContentInfos::const_iterator it = contents.begin();
805
806 for (; it != contents.end(); ++it) {
807 const cricket::TransportDescription* transport_desc1 =
808 desc1->GetTransportDescriptionByName(it->name);
809 const cricket::TransportDescription* transport_desc2 =
810 desc2->GetTransportDescriptionByName(it->name);
811 if (!transport_desc1 || !transport_desc2) {
deadbeef0ed85b22016-02-23 17:24:52 -0800812 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000813 }
814 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
815 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
deadbeef0ed85b22016-02-23 17:24:52 -0800816 return false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000817 }
818 }
deadbeef0ed85b22016-02-23 17:24:52 -0800819 return true;
820 }
821
822 // Compares ufrag/password only for the specified |media_type|.
823 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
824 const cricket::SessionDescription* desc2,
825 cricket::MediaType media_type) {
826 if (desc1->contents().size() != desc2->contents().size()) {
827 return false;
828 }
829
830 const cricket::ContentInfo* cinfo =
831 cricket::GetFirstMediaContent(desc1->contents(), media_type);
832 const cricket::TransportDescription* transport_desc1 =
833 desc1->GetTransportDescriptionByName(cinfo->name);
834 const cricket::TransportDescription* transport_desc2 =
835 desc2->GetTransportDescriptionByName(cinfo->name);
836 if (!transport_desc1 || !transport_desc2) {
837 return false;
838 }
839 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
840 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
841 return false;
842 }
843 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000844 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000845
846 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
847 std::string *sdp) {
848 const cricket::SessionDescription* desc = current_desc->description();
849 EXPECT_TRUE(current_desc->ToString(sdp));
850
851 const cricket::ContentInfos& contents = desc->contents();
852 cricket::ContentInfos::const_iterator it = contents.begin();
853 // Replace ufrag and pwd lines with empty strings.
854 for (; it != contents.end(); ++it) {
855 const cricket::TransportDescription* transport_desc =
856 desc->GetTransportDescriptionByName(it->name);
857 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
858 + "\r\n";
859 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
860 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000861 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000862 "", 0,
863 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000864 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000865 "", 0,
866 sdp);
867 }
868 }
869
deadbeef0ed85b22016-02-23 17:24:52 -0800870 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
871 const std::string& ufrag,
872 const std::string& pwd) {
873 cricket::SessionDescription* desc = current_desc->description();
874 for (TransportInfo& transport_info : desc->transport_infos()) {
875 cricket::TransportDescription& transport_desc =
876 transport_info.description;
877 transport_desc.ice_ufrag = ufrag;
878 transport_desc.ice_pwd = pwd;
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000879 }
880 }
881
deadbeef0ed85b22016-02-23 17:24:52 -0800882 // Sets ufrag/pwd for specified |media_type|.
883 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
884 cricket::MediaType media_type,
885 const std::string& ufrag,
886 const std::string& pwd) {
887 cricket::SessionDescription* desc = current_desc->description();
888 const cricket::ContentInfo* cinfo =
889 cricket::GetFirstMediaContent(desc->contents(), media_type);
890 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
891 cricket::TransportDescription* transport_desc =
892 &transport_info->description;
893 transport_desc->ice_ufrag = ufrag;
894 transport_desc->ice_pwd = pwd;
895 }
896
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000897 // Creates a remote offer and and applies it as a remote description,
898 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700899 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000900 // to decide which local and remote streams to create.
901 void CreateAndSetRemoteOfferAndLocalAnswer() {
902 SessionDescriptionInterface* offer = CreateRemoteOffer();
903 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800904 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000905 SetLocalDescriptionWithoutError(answer);
906 }
907 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
908 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700909 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000910 }
911 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700912 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913 SetLocalDescriptionWithoutError(desc);
914 EXPECT_EQ(expected_state, session_->state());
915 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000916 void SetLocalDescriptionExpectError(const std::string& action,
917 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000918 SessionDescriptionInterface* desc) {
919 std::string error;
920 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000921 std::string sdp_type = "local ";
922 sdp_type.append(action);
923 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000924 EXPECT_NE(std::string::npos, error.find(expected_error));
925 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000926 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
927 SessionDescriptionInterface* desc) {
928 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
929 expected_error, desc);
930 }
931 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
932 SessionDescriptionInterface* desc) {
933 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
934 expected_error, desc);
935 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000936 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
937 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
938 }
939 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700940 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941 SetRemoteDescriptionWithoutError(desc);
942 EXPECT_EQ(expected_state, session_->state());
943 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000944 void SetRemoteDescriptionExpectError(const std::string& action,
945 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000946 SessionDescriptionInterface* desc) {
947 std::string error;
948 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000949 std::string sdp_type = "remote ";
950 sdp_type.append(action);
951 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000952 EXPECT_NE(std::string::npos, error.find(expected_error));
953 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000954 void SetRemoteDescriptionOfferExpectError(
955 const std::string& expected_error, SessionDescriptionInterface* desc) {
956 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
957 expected_error, desc);
958 }
959 void SetRemoteDescriptionPranswerExpectError(
960 const std::string& expected_error, SessionDescriptionInterface* desc) {
961 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
962 expected_error, desc);
963 }
964 void SetRemoteDescriptionAnswerExpectError(
965 const std::string& expected_error, SessionDescriptionInterface* desc) {
966 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
967 expected_error, desc);
968 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969
970 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
971 SessionDescriptionInterface** nocrypto_answer) {
972 // Create a SDP without Crypto.
973 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000974 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 options.bundle_enabled = true;
976 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
977 ASSERT_TRUE(*offer != NULL);
978 VerifyCryptoParams((*offer)->description());
979
980 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
981 cricket::SEC_DISABLED);
982 EXPECT_TRUE(*nocrypto_answer != NULL);
983 }
984
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000985 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
986 SessionDescriptionInterface** nodtls_answer) {
987 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000988 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000989 options.bundle_enabled = true;
990
kwibergd1fe2812016-04-27 06:47:29 -0700991 std::unique_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000992 CreateRemoteOffer(options, cricket::SEC_ENABLED));
993
994 *nodtls_answer =
995 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
996 EXPECT_TRUE(*nodtls_answer != NULL);
997 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
998 VerifyCryptoParams((*nodtls_answer)->description());
999
1000 SetFactoryDtlsSrtp();
1001 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
1002 ASSERT_TRUE(*offer != NULL);
1003 VerifyFingerprintStatus((*offer)->description(), true);
1004 VerifyCryptoParams((*offer)->description());
1005 }
1006
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001007 JsepSessionDescription* CreateRemoteOfferWithVersion(
1008 cricket::MediaSessionOptions options,
1009 cricket::SecurePolicy secure_policy,
1010 const std::string& session_version,
1011 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001012 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001013 const cricket::SessionDescription* cricket_desc = NULL;
1014 if (current_desc) {
1015 cricket_desc = current_desc->description();
1016 session_id = current_desc->session_id();
1017 }
1018
1019 desc_factory_->set_secure(secure_policy);
1020 JsepSessionDescription* offer(
1021 new JsepSessionDescription(JsepSessionDescription::kOffer));
1022 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
1023 session_id, session_version)) {
1024 delete offer;
1025 offer = NULL;
1026 }
1027 return offer;
1028 }
1029 JsepSessionDescription* CreateRemoteOffer(
1030 cricket::MediaSessionOptions options) {
1031 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1032 kSessionVersion, NULL);
1033 }
1034 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001035 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
1036 return CreateRemoteOfferWithVersion(
1037 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001038 }
1039 JsepSessionDescription* CreateRemoteOffer(
1040 cricket::MediaSessionOptions options,
1041 const SessionDescriptionInterface* current_desc) {
1042 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1043 kSessionVersion, current_desc);
1044 }
1045
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001046 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
1047 const char* sctp_stream_name, int new_port,
1048 cricket::MediaSessionOptions options) {
1049 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001050 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
1051 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001052 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
1053 }
1054
1055 // Takes ownership of offer_basis (and deletes it).
1056 JsepSessionDescription* ChangeSDPSctpPort(
1057 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1058 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1059 // SessionDescription from the mutated string.
1060 const char* default_port_str = "5000";
1061 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001062 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001063 std::string offer_str;
1064 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001065 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001066 new_port_str, strlen(new_port_str),
1067 &offer_str);
1068 JsepSessionDescription* offer = new JsepSessionDescription(
1069 offer_basis->type());
1070 delete offer_basis;
1071 offer->Initialize(offer_str, NULL);
1072 return offer;
1073 }
1074
deadbeefab9b2d12015-10-14 11:33:11 -07001075 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001076 // before this function to decide which streams to create.
1077 JsepSessionDescription* CreateRemoteOffer() {
1078 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001079 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001080 return CreateRemoteOffer(options, session_->remote_description());
1081 }
1082
1083 JsepSessionDescription* CreateRemoteAnswer(
1084 const SessionDescriptionInterface* offer,
1085 cricket::MediaSessionOptions options,
1086 cricket::SecurePolicy policy) {
1087 desc_factory_->set_secure(policy);
1088 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001089 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001090 JsepSessionDescription* answer(
1091 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1092 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1093 options, NULL),
1094 session_id, kSessionVersion)) {
1095 delete answer;
1096 answer = NULL;
1097 }
1098 return answer;
1099 }
1100
1101 JsepSessionDescription* CreateRemoteAnswer(
1102 const SessionDescriptionInterface* offer,
1103 cricket::MediaSessionOptions options) {
1104 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1105 }
1106
deadbeefab9b2d12015-10-14 11:33:11 -07001107 // Creates an answer session description.
1108 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001109 // to decide which streams to create.
1110 JsepSessionDescription* CreateRemoteAnswer(
1111 const SessionDescriptionInterface* offer) {
1112 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -08001113 GetOptionsForAnswer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001114 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1115 }
1116
1117 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001118 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001119 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001120 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001121
1122 PeerConnectionInterface::RTCOfferAnswerOptions options;
1123 options.use_rtp_mux = bundle;
1124
1125 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001126 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1127 // and answer.
1128 SetLocalDescriptionWithoutError(offer);
1129
kwibergd1fe2812016-04-27 06:47:29 -07001130 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001131 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001132 std::string sdp;
1133 EXPECT_TRUE(answer->ToString(&sdp));
1134
1135 size_t expected_candidate_num = 2;
1136 if (!rtcp_mux) {
1137 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1138 // for rtp and rtcp.
1139 expected_candidate_num = 4;
1140 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001141 const std::string kRtcpMux = "a=rtcp-mux";
1142 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001143 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001144 kXRtcpMux.c_str(), kXRtcpMux.length(),
1145 &sdp);
1146 }
1147
1148 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1149 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001150
1151 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001152 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001153 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1154 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001155 if (bundle) {
1156 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1157 } else {
1158 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001159 }
1160 }
1161 // Tests that we can only send DTMF when the dtmf codec is supported.
1162 void TestCanInsertDtmf(bool can) {
1163 if (can) {
1164 InitWithDtmfCodec();
1165 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001166 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001167 }
deadbeefab9b2d12015-10-14 11:33:11 -07001168 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001169 CreateAndSetRemoteOfferAndLocalAnswer();
1170 EXPECT_FALSE(session_->CanInsertDtmf(""));
1171 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1172 }
1173
zhihuang3a334652016-05-05 18:37:49 -07001174 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1175 const std::string& codec_name) {
1176 for (const auto& content : desc->description()->contents()) {
1177 if (static_cast<cricket::MediaContentDescription*>(content.description)
1178 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1179 const auto* mdesc =
1180 static_cast<cricket::VideoContentDescription*>(content.description);
1181 for (const auto& codec : mdesc->codecs()) {
1182 if (codec.name == codec_name) {
1183 return true;
1184 }
1185 }
1186 }
1187 }
1188 return false;
1189 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001190 // Helper class to configure loopback network and verify Best
1191 // Connection using right IP protocol for TestLoopbackCall
1192 // method. LoopbackNetworkManager applies firewall rules to block
1193 // all ping traffic once ICE completed, and remove them to observe
1194 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1195 // verifies the best connection is using the right IP protocol after
1196 // initial ICE convergences.
1197
1198 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001199 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001200 LoopbackNetworkConfiguration()
1201 : test_ipv6_network_(false),
1202 test_extra_ipv4_network_(false),
1203 best_connection_after_initial_ice_converged_(1, 0) {}
1204
1205 // Used to track the expected best connection count in each IP protocol.
1206 struct ExpectedBestConnection {
1207 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1208 : ipv4_count_(ipv4_count),
1209 ipv6_count_(ipv6_count) {}
1210
1211 int ipv4_count_;
1212 int ipv6_count_;
1213 };
1214
1215 bool test_ipv6_network_;
1216 bool test_extra_ipv4_network_;
1217 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1218
1219 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001220 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001221 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1222 }
1223
1224 private:
jbauchac8869e2015-07-03 01:36:14 -07001225 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001226 const ExpectedBestConnection& expected) const {
1227 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001228 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1229 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001230 expected.ipv4_count_);
1231 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001232 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1233 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001234 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001235 // This is used in the loopback call so there is only single host to host
1236 // candidate pair.
1237 EXPECT_EQ(metrics_observer->GetEnumCounter(
1238 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1239 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001240 0);
1241 EXPECT_EQ(metrics_observer->GetEnumCounter(
1242 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1243 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001244 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001245 }
1246 };
1247
1248 class LoopbackNetworkManager {
1249 public:
1250 LoopbackNetworkManager(WebRtcSessionTest* session,
1251 const LoopbackNetworkConfiguration& config)
1252 : config_(config) {
1253 session->AddInterface(
1254 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1255 if (config_.test_extra_ipv4_network_) {
1256 session->AddInterface(
1257 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1258 }
1259 if (config_.test_ipv6_network_) {
1260 session->AddInterface(
1261 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1262 }
1263 }
1264
1265 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1266 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1267 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1268 if (config_.test_extra_ipv4_network_) {
1269 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1270 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1271 }
1272 if (config_.test_ipv6_network_) {
1273 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1274 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1275 }
1276 }
1277
1278 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1279
1280 private:
1281 LoopbackNetworkConfiguration config_;
1282 };
1283
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001284 // The method sets up a call from the session to itself, in a loopback
1285 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001286 // disconnection, and then a permanent disconnection.
1287 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001288 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1289 // While running the call, this method also checks if the session goes through
1290 // the correct sequence of ICE states when a connection is established,
1291 // broken, and re-established.
1292 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001293 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1294 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001295 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001296
stefanc1aeaf02015-10-15 07:26:07 -07001297 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001298 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001299 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001300 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001301
1302 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1303 observer_.ice_gathering_state_);
1304 SetLocalDescriptionWithoutError(offer);
1305 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1306 observer_.ice_connection_state_);
1307 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001308 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001309 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1310 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001311 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001312
1313 std::string sdp;
1314 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001315 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1316 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001317 ASSERT_TRUE(desc != NULL);
1318 SetRemoteDescriptionWithoutError(desc);
1319
1320 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001321 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001322
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001323 // The ice connection state is "Connected" too briefly to catch in a test.
1324 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001325 observer_.ice_connection_state_, kIceCandidatesTimeout);
1326 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001327
stefanc1aeaf02015-10-15 07:26:07 -07001328 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1329 LoopbackNetworkManager loopback_network_manager(this, config);
1330 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001331 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001332 // Adding firewall rule to block ping requests, which should cause
1333 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001334
1335 loopback_network_manager.ApplyFirewallRules(fss_.get());
1336
1337 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001338 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1339 observer_.ice_connection_state_,
1340 kIceCandidatesTimeout);
1341
jbauchac8869e2015-07-03 01:36:14 -07001342 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001343
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001344 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001345 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001346
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001347 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001348 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001349 observer_.ice_connection_state_,
1350 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001351
1352 // Now we block ping requests and wait until the ICE connection transitions
1353 // to the Failed state. This will take at least 30 seconds because it must
1354 // wait for the Port to timeout.
1355 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001356
1357 loopback_network_manager.ApplyFirewallRules(fss_.get());
1358 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001359 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001360 observer_.ice_connection_state_,
1361 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001362 }
1363
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001364 void TestLoopbackCall() {
1365 LoopbackNetworkConfiguration config;
1366 TestLoopbackCall(config);
1367 }
1368
stefanc1aeaf02015-10-15 07:26:07 -07001369 void TestPacketOptions() {
1370 media_controller_.reset(
1371 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1372 LoopbackNetworkConfiguration config;
1373 LoopbackNetworkManager loopback_network_manager(this, config);
1374
1375 SetupLoopbackCall();
1376
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001377 // Wait for channel to be ready for sending.
1378 EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
stefanc1aeaf02015-10-15 07:26:07 -07001379 uint8_t test_packet[15] = {0};
1380 rtc::PacketOptions options;
1381 options.packet_id = 10;
1382 media_engine_->GetVideoChannel(0)
1383 ->SendRtp(test_packet, sizeof(test_packet), options);
1384
1385 const int kPacketTimeout = 2000;
deadbeef14461d42016-06-15 11:06:57 -07001386 EXPECT_EQ_WAIT(10, fake_call_.last_sent_nonnegative_packet_id(),
1387 kPacketTimeout);
stefanc1aeaf02015-10-15 07:26:07 -07001388 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1389 }
1390
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001391 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1392 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001393 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1394 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001395
1396 // Add kCNCodec for dtmf test.
ossudedfd282016-06-14 07:12:39 -07001397 std::vector<cricket::AudioCodec> codecs =
1398 media_engine_->audio_send_codecs();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001399 codecs.push_back(kCNCodec1);
1400 codecs.push_back(kCNCodec2);
1401 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -07001402 desc_factory_->set_audio_codecs(codecs, codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001403 }
1404
1405 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1406 const cricket::ContentDescription* description = content->description;
1407 ASSERT(description != NULL);
1408 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001409 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001410 ASSERT(audio_content_desc != NULL);
1411 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1412 if (audio_content_desc->codecs()[i].name == "CN")
1413 return false;
1414 }
1415 return true;
1416 }
1417
deadbeefab9b2d12015-10-14 11:33:11 -07001418 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001419 webrtc::InternalDataChannelInit dci;
htaa2a49d92016-03-04 02:51:39 -08001420 ASSERT(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001421 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1422 data_channel_ = DataChannel::Create(
1423 session_.get(), session_->data_channel_type(), "datachannel", dci);
1424 }
1425
1426 void SetLocalDescriptionWithDataChannel() {
1427 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001428 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001429 SetLocalDescriptionWithoutError(offer);
1430 }
1431
wu@webrtc.org91053e72013-08-10 07:18:04 +00001432 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001433 RTCCertificateGenerationMethod cert_gen_method,
1434 CreateSessionDescriptionRequest::Type type) {
1435 InitWithDtls(cert_gen_method);
1436 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1437 }
1438
1439 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1440 CreateSessionDescriptionRequest::Type type) {
1441 InitWithDtlsIdentityGenFail();
1442 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1443 }
1444
1445 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001446 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001447 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001448 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001449 if (type == CreateSessionDescriptionRequest::kAnswer) {
1450 cricket::MediaSessionOptions options;
kwibergd1fe2812016-04-27 06:47:29 -07001451 std::unique_ptr<JsepSessionDescription> offer(
1452 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001453 ASSERT_TRUE(offer.get() != NULL);
1454 SetRemoteDescriptionWithoutError(offer.release());
1455 }
1456
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001457 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001458 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001459 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001460 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001461 observers[kNumber];
1462 for (int i = 0; i < kNumber; ++i) {
1463 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1464 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001465 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001466 } else {
htaa2a49d92016-03-04 02:51:39 -08001467 session_->CreateAnswer(observers[i], session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001468 }
1469 }
1470
1471 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1472 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1473 WebRtcSessionCreateSDPObserverForTest::kFailed;
1474
1475 for (int i = 0; i < kNumber; ++i) {
1476 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1477 if (success) {
1478 EXPECT_TRUE(observers[i]->description() != NULL);
1479 } else {
1480 EXPECT_TRUE(observers[i]->description() == NULL);
1481 }
1482 }
1483 }
1484
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001485 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001486 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001487 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001488 turn_server.credentials = credentials;
1489 turn_server.ports.push_back(
hnsl277b2502016-12-13 05:17:23 -08001490 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP));
deadbeef653b8e02015-11-11 12:55:10 -08001491 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001492 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001493 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001494 }
1495
skvlad11a9cbf2016-10-07 11:53:05 -07001496 webrtc::RtcEventLogNullImpl event_log_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001497 cricket::FakeMediaEngine* media_engine_;
1498 cricket::FakeDataEngine* data_engine_;
kwibergd1fe2812016-04-27 06:47:29 -07001499 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001500 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001501 std::unique_ptr<webrtc::MediaControllerInterface> media_controller_;
1502 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1503 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1504 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1505 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1506 std::unique_ptr<rtc::FirewallSocketServer> fss_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001507 rtc::SocketServerScope ss_scope_;
1508 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001509 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001510 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001511 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001512 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001513 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001514 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001515 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001516 MockIceObserver observer_;
1517 cricket::FakeVideoMediaChannel* video_channel_;
1518 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001519 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001520 // The following flags affect options created for CreateOffer/CreateAnswer.
1521 bool send_stream_1_ = false;
1522 bool send_stream_2_ = false;
1523 bool send_audio_ = false;
1524 bool send_video_ = false;
1525 rtc::scoped_refptr<DataChannel> data_channel_;
1526 // Last values received from data channel creation signal.
1527 std::string last_data_channel_label_;
1528 InternalDataChannelInit last_data_channel_config_;
deadbeef8947a012016-01-21 10:26:38 -08001529 bool session_destroyed_ = false;
jbauchcb560652016-08-04 05:20:32 -07001530 bool with_gcm_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001531};
1532
Henrik Boström87713d02015-08-25 09:53:21 +02001533TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1534 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001535 // SDES is disabled when DTLS is on.
1536 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001537}
1538
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001539TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001540 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001541 // SDES is required if DTLS is off.
1542 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001543}
1544
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001545TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1546 TestSessionCandidatesWithBundleRtcpMux(false, false);
1547}
1548
1549// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1550// with rtcp-mux and/or bundle.
1551TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1552 TestSessionCandidatesWithBundleRtcpMux(false, true);
1553}
1554
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001555TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1556 TestSessionCandidatesWithBundleRtcpMux(true, true);
1557}
1558
1559TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001560 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1561 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001562 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001563 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001564 InitiateCall();
1565 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1566 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1567 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1568}
1569
deadbeeff5f03e82016-06-06 11:16:06 -07001570TEST_F(WebRtcSessionTest, TestStunError) {
1571 rtc::ScopedFakeClock clock;
1572
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001573 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1574 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001575 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001576 rtc::FP_UDP,
1577 rtc::FD_ANY,
1578 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001579 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001580 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001581 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001582 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
deadbeeff5f03e82016-06-06 11:16:06 -07001583 EXPECT_TRUE_SIMULATED_WAIT(observer_.oncandidatesready_, kStunTimeout, clock);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001584 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1585 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
deadbeeff5f03e82016-06-06 11:16:06 -07001586 // Destroy session before scoped fake clock goes out of scope to avoid TSan
1587 // warning.
1588 session_->Close();
1589 session_.reset(nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001590}
1591
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001592TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001593 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001594 SessionDescriptionInterface* offer = NULL;
1595 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1596 std::string unknown_action;
1597 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1598 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1599}
1600
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601// Test creating offers and receive answers and make sure the
1602// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001603TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001604 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001605 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001606 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607 const std::string session_id_orig = offer->session_id();
1608 const std::string session_version_orig = offer->session_version();
1609 SetLocalDescriptionWithoutError(offer);
1610
deadbeefab9b2d12015-10-14 11:33:11 -07001611 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001612 SessionDescriptionInterface* answer =
1613 CreateRemoteAnswer(session_->local_description());
1614 SetRemoteDescriptionWithoutError(answer);
1615
1616 video_channel_ = media_engine_->GetVideoChannel(0);
1617 voice_channel_ = media_engine_->GetVoiceChannel(0);
1618
1619 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1620 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1621
1622 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1623 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1624
1625 ASSERT_EQ(1u, video_channel_->send_streams().size());
1626 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1627 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1628 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1629
1630 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001631 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001632 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001633
1634 // Verify the session id is the same and the session version is
1635 // increased.
1636 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001637 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1638 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001639
1640 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001641 EXPECT_EQ(0u, video_channel_->send_streams().size());
1642 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001643
deadbeefab9b2d12015-10-14 11:33:11 -07001644 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001645 answer = CreateRemoteAnswer(session_->local_description());
1646 SetRemoteDescriptionWithoutError(answer);
1647
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001648 // Make sure the receive streams have not changed.
1649 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1650 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1651 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1652 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1653}
1654
1655// Test receiving offers and creating answers and make sure the
1656// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001657TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001658 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001659 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001660 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001661 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001662 SetRemoteDescriptionWithoutError(offer);
1663
deadbeefab9b2d12015-10-14 11:33:11 -07001664 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001665 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001666 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001667 SetLocalDescriptionWithoutError(answer);
1668
1669 const std::string session_id_orig = answer->session_id();
1670 const std::string session_version_orig = answer->session_version();
1671
1672 video_channel_ = media_engine_->GetVideoChannel(0);
1673 voice_channel_ = media_engine_->GetVoiceChannel(0);
1674
htaa2a49d92016-03-04 02:51:39 -08001675 ASSERT_TRUE(video_channel_);
1676 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001677 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1678 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1679
1680 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1681 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1682
1683 ASSERT_EQ(1u, video_channel_->send_streams().size());
1684 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1685 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1686 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1687
deadbeefab9b2d12015-10-14 11:33:11 -07001688 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001689 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001690 SetRemoteDescriptionWithoutError(offer);
1691
1692 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001693 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001694 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001695
1696 // Verify the session id is the same and the session version is
1697 // increased.
1698 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001699 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1700 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001701 SetLocalDescriptionWithoutError(answer);
1702
1703 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1704 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1705 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1706 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1707 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1708 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1709
1710 // Make sure we have no send streams.
1711 EXPECT_EQ(0u, video_channel_->send_streams().size());
1712 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1713}
1714
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001715TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001716 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001717 media_engine_->set_fail_create_channel(true);
1718
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001719 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001720 ASSERT_TRUE(offer != NULL);
1721 // SetRemoteDescription and SetLocalDescription will take the ownership of
1722 // the offer.
1723 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001724 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001725 ASSERT_TRUE(offer != NULL);
1726 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1727}
1728
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001729//
1730// Tests for creating/setting SDP under different SDES/DTLS polices:
1731//
1732// --DTLS off and SDES on
1733// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1734// set local/remote offer/answer with crypto --> success
1735// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1736// failure
1737// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1738// failure
1739// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1740// failure
1741//
1742// --DTLS on and SDES off
1743// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1744// set local/remote offer/answer with DTLS fingerprint --> success
1745// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1746// fingerprint --> failure
1747// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1748// --> failure
1749// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1750// --> failure
1751//
1752// --Encryption disabled: DTLS off and SDES off
1753// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1754// answer without SDES or DTLS --> success
1755// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1756// answer without SDES or DTLS --> success
1757//
1758
1759// Test that we return a failure when applying a remote/local offer that doesn't
1760// have cryptos enabled when DTLS is off.
1761TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001762 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001764 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 JsepSessionDescription* offer = CreateRemoteOffer(
1766 options, cricket::SEC_DISABLED);
1767 ASSERT_TRUE(offer != NULL);
1768 VerifyNoCryptoParams(offer->description(), false);
1769 // SetRemoteDescription and SetLocalDescription will take the ownership of
1770 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001771 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1773 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001774 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775}
1776
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001777// Test that we return a failure when applying a local answer that doesn't have
1778// cryptos enabled when DTLS is off.
1779TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001780 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781 SessionDescriptionInterface* offer = NULL;
1782 SessionDescriptionInterface* answer = NULL;
1783 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1784 // SetRemoteDescription and SetLocalDescription will take the ownership of
1785 // the offer.
1786 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001787 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788}
1789
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001790// Test we will return fail when apply an remote answer that doesn't have
1791// crypto enabled when DTLS is off.
1792TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001793 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001794 SessionDescriptionInterface* offer = NULL;
1795 SessionDescriptionInterface* answer = NULL;
1796 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1797 // SetRemoteDescription and SetLocalDescription will take the ownership of
1798 // the offer.
1799 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001800 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001801}
1802
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001803// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1804// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001805TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001806 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001807 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001808 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001809 SetFactoryDtlsSrtp();
1810 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001811 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001812 JsepSessionDescription* offer =
1813 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001814 ASSERT_TRUE(offer != NULL);
1815 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001816 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001817
1818 // SetRemoteDescription will take the ownership of the offer.
1819 SetRemoteDescriptionWithoutError(offer);
1820
1821 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001822 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001823 ASSERT_TRUE(answer != NULL);
1824 VerifyFingerprintStatus(answer->description(), true);
1825 // Check that we don't have an a=crypto line in the answer.
1826 VerifyNoCryptoParams(answer->description(), true);
1827
1828 // Now set the local description, which should work, even without a=crypto.
1829 SetLocalDescriptionWithoutError(answer);
1830}
1831
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001832// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1833// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001834TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001835 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001836 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001837 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001838 SetFactoryDtlsSrtp();
1839
1840 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001841 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001842 ASSERT_TRUE(offer != NULL);
1843 VerifyFingerprintStatus(offer->description(), true);
1844 // Check that we don't have an a=crypto line in the offer.
1845 VerifyNoCryptoParams(offer->description(), true);
1846
1847 // Now set the local description, which should work, even without a=crypto.
1848 SetLocalDescriptionWithoutError(offer);
1849
1850 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001851 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001852 JsepSessionDescription* answer =
1853 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1854 ASSERT_TRUE(answer != NULL);
1855 VerifyFingerprintStatus(answer->description(), true);
1856 VerifyNoCryptoParams(answer->description(), true);
1857
1858 // SetRemoteDescription will take the ownership of the answer.
1859 SetRemoteDescriptionWithoutError(answer);
1860}
1861
1862// Test that if we support DTLS and the other side didn't offer a fingerprint,
1863// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001864TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001865 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001866 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001867 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001868 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001869 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001870 JsepSessionDescription* offer = CreateRemoteOffer(
1871 options, cricket::SEC_REQUIRED);
1872 ASSERT_TRUE(offer != NULL);
1873 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001874 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001875
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001876 // SetRemoteDescription will take the ownership of the offer.
1877 SetRemoteDescriptionOfferExpectError(
1878 kSdpWithoutDtlsFingerprint, offer);
1879
1880 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1881 // SetLocalDescription will take the ownership of the offer.
1882 SetLocalDescriptionOfferExpectError(
1883 kSdpWithoutDtlsFingerprint, offer);
1884}
1885
1886// Test that we return a failure when applying a local answer that doesn't have
1887// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001888TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001889 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001890 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001891 SessionDescriptionInterface* offer = NULL;
1892 SessionDescriptionInterface* answer = NULL;
1893 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1894
1895 // SetRemoteDescription and SetLocalDescription will take the ownership of
1896 // the offer and answer.
1897 SetRemoteDescriptionWithoutError(offer);
1898 SetLocalDescriptionAnswerExpectError(
1899 kSdpWithoutDtlsFingerprint, answer);
1900}
1901
1902// Test that we return a failure when applying a remote answer that doesn't have
1903// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001904TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001905 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001906 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001907 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001908 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001909 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07001910 std::unique_ptr<SessionDescriptionInterface> temp_offer(
deadbeefcbecd352015-09-23 11:50:27 -07001911 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001912 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001913 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001914
1915 // SetRemoteDescription and SetLocalDescription will take the ownership of
1916 // the offer and answer.
1917 SetLocalDescriptionWithoutError(offer);
1918 SetRemoteDescriptionAnswerExpectError(
1919 kSdpWithoutDtlsFingerprint, answer);
1920}
1921
1922// Test that we create a local offer without SDES or DTLS and accept a remote
1923// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001924TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001925 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001926 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001927 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001928
1929 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001930 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001931 ASSERT_TRUE(offer != NULL);
1932 VerifyFingerprintStatus(offer->description(), false);
1933 // Check that we don't have an a=crypto line in the offer.
1934 VerifyNoCryptoParams(offer->description(), false);
1935
1936 // Now set the local description, which should work, even without a=crypto.
1937 SetLocalDescriptionWithoutError(offer);
1938
1939 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001940 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001941 JsepSessionDescription* answer =
1942 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1943 ASSERT_TRUE(answer != NULL);
1944 VerifyFingerprintStatus(answer->description(), false);
1945 VerifyNoCryptoParams(answer->description(), false);
1946
1947 // SetRemoteDescription will take the ownership of the answer.
1948 SetRemoteDescriptionWithoutError(answer);
1949}
1950
1951// Test that we create a local answer without SDES or DTLS and accept a remote
1952// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001953TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001954 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001955 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001956
1957 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001958 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001959 JsepSessionDescription* offer =
1960 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1961 ASSERT_TRUE(offer != NULL);
1962 VerifyFingerprintStatus(offer->description(), false);
1963 VerifyNoCryptoParams(offer->description(), false);
1964
1965 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001966 SetRemoteDescriptionWithoutError(offer);
1967
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001968 // Verify that we get a crypto fingerprint in the answer.
htaa2a49d92016-03-04 02:51:39 -08001969 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001970 ASSERT_TRUE(answer != NULL);
1971 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001972 // Check that we don't have an a=crypto line in the answer.
1973 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001974
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001975 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001976 SetLocalDescriptionWithoutError(answer);
1977}
1978
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001979// Test that we can create and set an answer correctly when different
1980// SSL roles have been negotiated for different transports.
1981// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1982TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1983 SendAudioVideoStream1();
1984 InitWithDtls(GetParam());
1985 SetFactoryDtlsSrtp();
1986
1987 SessionDescriptionInterface* offer = CreateOffer();
1988 SetLocalDescriptionWithoutError(offer);
1989
1990 cricket::MediaSessionOptions options;
1991 options.recv_video = true;
1992
1993 // First, negotiate different SSL roles.
1994 SessionDescriptionInterface* answer =
1995 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1996 TransportInfo* audio_transport_info =
1997 answer->description()->GetTransportInfoByName("audio");
1998 audio_transport_info->description.connection_role =
1999 cricket::CONNECTIONROLE_ACTIVE;
2000 TransportInfo* video_transport_info =
2001 answer->description()->GetTransportInfoByName("video");
2002 video_transport_info->description.connection_role =
2003 cricket::CONNECTIONROLE_PASSIVE;
2004 SetRemoteDescriptionWithoutError(answer);
2005
2006 // Now create an offer in the reverse direction, and ensure the initial
2007 // offerer responds with an answer with correct SSL roles.
2008 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2009 kSessionVersion,
2010 session_->remote_description());
2011 SetRemoteDescriptionWithoutError(offer);
2012
htaa2a49d92016-03-04 02:51:39 -08002013 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002014 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2015 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2016 audio_transport_info->description.connection_role);
2017 video_transport_info = answer->description()->GetTransportInfoByName("video");
2018 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
2019 video_transport_info->description.connection_role);
2020 SetLocalDescriptionWithoutError(answer);
2021
2022 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
2023 // audio is transferred over to video in the answer that completes the BUNDLE
2024 // negotiation.
2025 options.bundle_enabled = true;
2026 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
2027 kSessionVersion,
2028 session_->remote_description());
2029 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08002030 answer = CreateAnswer();
Taylor Brandstetterf475d362016-01-08 15:35:57 -08002031 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
2032 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2033 audio_transport_info->description.connection_role);
2034 video_transport_info = answer->description()->GetTransportInfoByName("video");
2035 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
2036 video_transport_info->description.connection_role);
2037 SetLocalDescriptionWithoutError(answer);
2038}
2039
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002040TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002041 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002042 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002043 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002044 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002045 SetLocalDescriptionWithoutError(offer);
2046
2047 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002048 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049 SetLocalDescriptionWithoutError(offer2);
2050}
2051
2052TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002053 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002054 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002055 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002056 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002057 SetRemoteDescriptionWithoutError(offer);
2058
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002059 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002060 SetRemoteDescriptionWithoutError(offer2);
2061}
2062
2063TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002064 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002065 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002066 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002067 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002068 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002069 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
2070 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002071}
2072
2073TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002074 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002075 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002076 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002077 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002078 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002079 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002080 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002081}
2082
2083TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002084 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002085 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002086 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002087 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002088
htaa2a49d92016-03-04 02:51:39 -08002089 JsepSessionDescription* pranswer =
2090 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002092 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093
deadbeefab9b2d12015-10-14 11:33:11 -07002094 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08002095 JsepSessionDescription* pranswer2 =
2096 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002097 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2098
deadbeefd59daf82015-10-14 15:02:44 -07002099 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002100
deadbeefab9b2d12015-10-14 11:33:11 -07002101 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002102 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07002103 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002104}
2105
2106TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002107 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002108 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002109 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002110 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002111
2112 JsepSessionDescription* pranswer =
2113 CreateRemoteAnswer(session_->local_description());
2114 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2115
2116 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002117 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118
deadbeefab9b2d12015-10-14 11:33:11 -07002119 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120 JsepSessionDescription* pranswer2 =
2121 CreateRemoteAnswer(session_->local_description());
2122 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2123
2124 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002125 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002126
deadbeefab9b2d12015-10-14 11:33:11 -07002127 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002128 SessionDescriptionInterface* answer =
2129 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002130 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002131}
2132
2133TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002134 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002135 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002136 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002137
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138 SessionDescriptionInterface* answer =
2139 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002140 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2141 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002142}
2143
2144TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002145 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002146 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07002147 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002148
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002149 SessionDescriptionInterface* answer =
2150 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002151 SetRemoteDescriptionAnswerExpectError(
2152 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002153}
2154
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002155// Tests that the remote candidates are added and removed successfully.
2156TEST_F(WebRtcSessionTest, TestAddAndRemoveRemoteCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002157 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002158 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002159
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002160 cricket::Candidate candidate(1, "udp", rtc::SocketAddress("1.1.1.1", 5000), 0,
2161 "", "", "host", 0, "");
2162 candidate.set_transport_name("audio");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2164
deadbeefd59daf82015-10-14 15:02:44 -07002165 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002166 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2167
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002168 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002169 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002170
2171 // Fail since we have not set a remote description.
2172 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002173
2174 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2175 session_->local_description());
2176 SetRemoteDescriptionWithoutError(answer);
2177
deadbeefd59daf82015-10-14 15:02:44 -07002178 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2179 candidate.set_component(2);
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002180 candidate.set_address(rtc::SocketAddress("2.2.2.2", 6000));
deadbeefd59daf82015-10-14 15:02:44 -07002181 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2182 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2183
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002184 // Verifying the candidates are copied properly from internal vector.
2185 const SessionDescriptionInterface* remote_desc =
2186 session_->remote_description();
2187 ASSERT_TRUE(remote_desc != NULL);
2188 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2189 const IceCandidateCollection* candidates =
2190 remote_desc->candidates(kMediaContentIndex0);
2191 ASSERT_EQ(2u, candidates->count());
2192 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2193 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2194 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2195 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2196
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002197 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2198 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002199 candidate.set_component(2);
2200 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2201 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002202 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002203
2204 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2205 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002206
2207 // Remove candidate1 and candidate2
2208 std::vector<cricket::Candidate> remote_candidates;
2209 remote_candidates.push_back(ice_candidate1.candidate());
2210 remote_candidates.push_back(ice_candidate2.candidate());
2211 EXPECT_TRUE(session_->RemoveRemoteIceCandidates(remote_candidates));
2212 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002213}
2214
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002215// Tests that a remote candidate is added to the remote session description and
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002216// that it is retained if the remote session description is changed.
2217TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002218 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002219 cricket::Candidate candidate1;
2220 candidate1.set_component(1);
2221 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2222 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002223 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002224 CreateAndSetRemoteOfferAndLocalAnswer();
2225
2226 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2227 const SessionDescriptionInterface* remote_desc =
2228 session_->remote_description();
2229 ASSERT_TRUE(remote_desc != NULL);
2230 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2231 const IceCandidateCollection* candidates =
2232 remote_desc->candidates(kMediaContentIndex0);
2233 ASSERT_EQ(1u, candidates->count());
2234 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2235
2236 // Update the RemoteSessionDescription with a new session description and
2237 // a candidate and check that the new remote session description contains both
2238 // candidates.
2239 SessionDescriptionInterface* offer = CreateRemoteOffer();
2240 cricket::Candidate candidate2;
2241 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2242 candidate2);
2243 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2244 SetRemoteDescriptionWithoutError(offer);
2245
2246 remote_desc = session_->remote_description();
2247 ASSERT_TRUE(remote_desc != NULL);
2248 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2249 candidates = remote_desc->candidates(kMediaContentIndex0);
2250 ASSERT_EQ(2u, candidates->count());
2251 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2252 // Username and password have be updated with the TransportInfo of the
2253 // SessionDescription, won't be equal to the original one.
2254 candidate2.set_username(candidates->at(0)->candidate().username());
2255 candidate2.set_password(candidates->at(0)->candidate().password());
2256 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2257 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2258 // No need to verify the username and password.
2259 candidate1.set_username(candidates->at(1)->candidate().username());
2260 candidate1.set_password(candidates->at(1)->candidate().password());
2261 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2262
2263 // Test that the candidate is ignored if we can add the same candidate again.
2264 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2265}
2266
2267// Test that local candidates are added to the local session description and
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002268// that they are retained if the local session description is changed. And if
2269// continual gathering is enabled, they are removed from the local session
2270// description when the network is down.
2271TEST_F(WebRtcSessionTest,
2272 TestLocalCandidatesAddedAndRemovedIfGatherContinually) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002273 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002274 Init();
deadbeefb60a8192016-08-24 15:15:00 -07002275 // Enable Continual Gathering.
2276 cricket::IceConfig config;
2277 config.continual_gathering_policy = cricket::GATHER_CONTINUALLY;
2278 session_->SetIceConfig(config);
deadbeefab9b2d12015-10-14 11:33:11 -07002279 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002280 CreateAndSetRemoteOfferAndLocalAnswer();
2281
2282 const SessionDescriptionInterface* local_desc = session_->local_description();
2283 const IceCandidateCollection* candidates =
2284 local_desc->candidates(kMediaContentIndex0);
2285 ASSERT_TRUE(candidates != NULL);
2286 EXPECT_EQ(0u, candidates->count());
2287
deadbeefb60a8192016-08-24 15:15:00 -07002288 // Since we're using continual gathering, we won't get "gathering done".
2289 EXPECT_EQ_WAIT(2u, candidates->count(), kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002290
2291 local_desc = session_->local_description();
2292 candidates = local_desc->candidates(kMediaContentIndex0);
2293 ASSERT_TRUE(candidates != NULL);
2294 EXPECT_LT(0u, candidates->count());
2295 candidates = local_desc->candidates(1);
2296 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002297 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002298
2299 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002300 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002301 CreateAndSetRemoteOfferAndLocalAnswer();
2302
2303 local_desc = session_->local_description();
2304 candidates = local_desc->candidates(kMediaContentIndex0);
2305 ASSERT_TRUE(candidates != NULL);
2306 EXPECT_LT(0u, candidates->count());
2307 candidates = local_desc->candidates(1);
2308 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002309 EXPECT_EQ(0u, candidates->count());
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002310
2311 candidates = local_desc->candidates(kMediaContentIndex0);
2312 size_t num_local_candidates = candidates->count();
Honghai Zhang7fb69db2016-03-14 11:59:18 -07002313 // Bring down the network interface to trigger candidate removals.
2314 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2315 // Verify that all local candidates are removed.
2316 EXPECT_EQ(0, observer_.num_candidates_removed_);
2317 EXPECT_EQ_WAIT(num_local_candidates, observer_.num_candidates_removed_,
2318 kIceCandidatesTimeout);
2319 EXPECT_EQ_WAIT(0u, candidates->count(), kIceCandidatesTimeout);
2320}
2321
2322// Tests that if continual gathering is disabled, local candidates won't be
2323// removed when the interface is turned down.
2324TEST_F(WebRtcSessionTest, TestLocalCandidatesNotRemovedIfNotGatherContinually) {
2325 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2326 Init();
2327 SendAudioVideoStream1();
2328 CreateAndSetRemoteOfferAndLocalAnswer();
2329
2330 const SessionDescriptionInterface* local_desc = session_->local_description();
2331 const IceCandidateCollection* candidates =
2332 local_desc->candidates(kMediaContentIndex0);
2333 ASSERT_TRUE(candidates != NULL);
2334 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2335
2336 size_t num_local_candidates = candidates->count();
2337 EXPECT_LT(0u, num_local_candidates);
2338 // By default, Continual Gathering is disabled.
2339 // Bring down the network interface.
2340 RemoveInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2341 // Verify that the local candidates are not removed.
2342 rtc::Thread::Current()->ProcessMessages(1000);
2343 EXPECT_EQ(0, observer_.num_candidates_removed_);
2344 EXPECT_EQ(num_local_candidates, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002345}
2346
2347// Test that we can set a remote session description with remote candidates.
2348TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002349 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002350
2351 cricket::Candidate candidate1;
2352 candidate1.set_component(1);
2353 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2354 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002355 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002356 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002357
2358 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2359 SetRemoteDescriptionWithoutError(offer);
2360
2361 const SessionDescriptionInterface* remote_desc =
2362 session_->remote_description();
2363 ASSERT_TRUE(remote_desc != NULL);
2364 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2365 const IceCandidateCollection* candidates =
2366 remote_desc->candidates(kMediaContentIndex0);
2367 ASSERT_EQ(1u, candidates->count());
2368 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2369
htaa2a49d92016-03-04 02:51:39 -08002370 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002371 SetLocalDescriptionWithoutError(answer);
2372}
2373
2374// Test that offers and answers contains ice candidates when Ice candidates have
2375// been gathered.
2376TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002377 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002378 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002379 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002380 // Ice is started but candidates are not provided until SetLocalDescription
2381 // is called.
2382 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2383 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2384 CreateAndSetRemoteOfferAndLocalAnswer();
2385 // Wait until at least one local candidate has been collected.
2386 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2387 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002388
kwibergd1fe2812016-04-27 06:47:29 -07002389 std::unique_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002390
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002391 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2392 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002393
2394 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2395 SetRemoteDescriptionWithoutError(remote_offer);
htaa2a49d92016-03-04 02:51:39 -08002396 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002397 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2398 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002399 SetLocalDescriptionWithoutError(answer);
2400}
2401
2402// Verifies TransportProxy and media channels are created with content names
2403// present in the SessionDescription.
2404TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002405 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002406 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002407 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002408
2409 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002410 // "video". Goal is to modify these content names and verify transport
2411 // channels
2412 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002413 // present in SDP.
2414 std::string sdp;
2415 EXPECT_TRUE(offer->ToString(&sdp));
2416 const std::string kAudioMid = "a=mid:audio";
2417 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2418 const std::string kVideoMid = "a=mid:video";
2419 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2420
2421 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002422 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002423 kAudioMidReplaceStr.c_str(),
2424 kAudioMidReplaceStr.length(),
2425 &sdp);
2426 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002427 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002428 kVideoMidReplaceStr.c_str(),
2429 kVideoMidReplaceStr.length(),
2430 &sdp);
2431
2432 SessionDescriptionInterface* modified_offer =
2433 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2434
2435 SetRemoteDescriptionWithoutError(modified_offer);
2436
htaa2a49d92016-03-04 02:51:39 -08002437 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002438 SetLocalDescriptionWithoutError(answer);
2439
johan669d69b2016-11-08 14:14:08 -08002440 rtc::PacketTransportInterface* voice_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002441 session_->voice_rtp_transport_channel();
2442 EXPECT_TRUE(voice_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002443 EXPECT_EQ(voice_transport_channel->debug_name(),
2444 "audio_content_name " +
2445 std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
2446 rtc::PacketTransportInterface* video_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07002447 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08002448 ASSERT_TRUE(video_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08002449 EXPECT_EQ(video_transport_channel->debug_name(),
2450 "video_content_name " +
2451 std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002452 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2453 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2454}
2455
2456// Test that an offer contains the correct media content descriptions based on
2457// the send streams when no constraints have been set.
2458TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002459 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002460 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002461
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002462 ASSERT_TRUE(offer != NULL);
2463 const cricket::ContentInfo* content =
2464 cricket::GetFirstAudioContent(offer->description());
2465 EXPECT_TRUE(content != NULL);
2466 content = cricket::GetFirstVideoContent(offer->description());
2467 EXPECT_TRUE(content == NULL);
2468}
2469
2470// Test that an offer contains the correct media content descriptions based on
2471// the send streams when no constraints have been set.
2472TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002473 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002474 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002475 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07002476 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002477
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002478 const cricket::ContentInfo* content =
2479 cricket::GetFirstAudioContent(offer->description());
2480 EXPECT_TRUE(content != NULL);
2481 content = cricket::GetFirstVideoContent(offer->description());
2482 EXPECT_TRUE(content == NULL);
2483
2484 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002485 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002486 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002487 content = cricket::GetFirstAudioContent(offer->description());
2488 EXPECT_TRUE(content != NULL);
2489 content = cricket::GetFirstVideoContent(offer->description());
2490 EXPECT_TRUE(content != NULL);
2491}
2492
2493// Test that an offer contains no media content descriptions if
2494// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2495TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002496 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002497 PeerConnectionInterface::RTCOfferAnswerOptions options;
2498 options.offer_to_receive_audio = 0;
2499 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002500
kwibergd1fe2812016-04-27 06:47:29 -07002501 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002502
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002503 ASSERT_TRUE(offer != NULL);
2504 const cricket::ContentInfo* content =
2505 cricket::GetFirstAudioContent(offer->description());
2506 EXPECT_TRUE(content == NULL);
2507 content = cricket::GetFirstVideoContent(offer->description());
2508 EXPECT_TRUE(content == NULL);
2509}
2510
2511// Test that an offer contains only audio media content descriptions if
2512// kOfferToReceiveAudio constraints are set to true.
2513TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002514 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002515 PeerConnectionInterface::RTCOfferAnswerOptions options;
2516 options.offer_to_receive_audio =
2517 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2518
kwibergd1fe2812016-04-27 06:47:29 -07002519 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002520
2521 const cricket::ContentInfo* content =
2522 cricket::GetFirstAudioContent(offer->description());
2523 EXPECT_TRUE(content != NULL);
2524 content = cricket::GetFirstVideoContent(offer->description());
2525 EXPECT_TRUE(content == NULL);
2526}
2527
2528// Test that an offer contains audio and video media content descriptions if
2529// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2530TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002531 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002532 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002533 PeerConnectionInterface::RTCOfferAnswerOptions options;
2534 options.offer_to_receive_audio =
2535 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2536 options.offer_to_receive_video =
2537 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2538
kwibergd1fe2812016-04-27 06:47:29 -07002539 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002540
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002541 const cricket::ContentInfo* content =
2542 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002543 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002544
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002545 content = cricket::GetFirstVideoContent(offer->description());
2546 EXPECT_TRUE(content != NULL);
2547
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002548 // Sets constraints to false and verifies that audio/video contents are
2549 // removed.
2550 options.offer_to_receive_audio = 0;
2551 options.offer_to_receive_video = 0;
2552 offer.reset(CreateOffer(options));
2553
2554 content = cricket::GetFirstAudioContent(offer->description());
2555 EXPECT_TRUE(content == NULL);
2556 content = cricket::GetFirstVideoContent(offer->description());
2557 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002558}
2559
2560// Test that an answer can not be created if the last remote description is not
2561// an offer.
2562TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002563 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002564 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002565 SetLocalDescriptionWithoutError(offer);
2566 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2567 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08002568 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002569}
2570
2571// Test that an answer contains the correct media content descriptions when no
2572// constraints have been set.
2573TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002574 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002575 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002576 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002577 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002578 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002579 const cricket::ContentInfo* content =
2580 cricket::GetFirstAudioContent(answer->description());
2581 ASSERT_TRUE(content != NULL);
2582 EXPECT_FALSE(content->rejected);
2583
2584 content = cricket::GetFirstVideoContent(answer->description());
2585 ASSERT_TRUE(content != NULL);
2586 EXPECT_FALSE(content->rejected);
2587}
2588
2589// Test that an answer contains the correct media content descriptions when no
2590// constraints have been set and the offer only contain audio.
2591TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002592 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002593 // Create a remote offer with audio only.
2594 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002595
kwibergd1fe2812016-04-27 06:47:29 -07002596 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002597 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2598 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2599
2600 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002601 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002602 const cricket::ContentInfo* content =
2603 cricket::GetFirstAudioContent(answer->description());
2604 ASSERT_TRUE(content != NULL);
2605 EXPECT_FALSE(content->rejected);
2606
2607 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2608}
2609
2610// Test that an answer contains the correct media content descriptions when no
2611// constraints have been set.
2612TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002613 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002614 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002615 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002616 SetRemoteDescriptionWithoutError(offer.release());
2617 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002618 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002619 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002620 const cricket::ContentInfo* content =
2621 cricket::GetFirstAudioContent(answer->description());
2622 ASSERT_TRUE(content != NULL);
2623 EXPECT_FALSE(content->rejected);
2624
2625 content = cricket::GetFirstVideoContent(answer->description());
2626 ASSERT_TRUE(content != NULL);
2627 EXPECT_FALSE(content->rejected);
2628}
2629
2630// Test that an answer contains the correct media content descriptions when
2631// constraints have been set but no stream is sent.
2632TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002633 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002634 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002635 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002636 SetRemoteDescriptionWithoutError(offer.release());
2637
htaa2a49d92016-03-04 02:51:39 -08002638 cricket::MediaSessionOptions session_options;
2639 session_options.recv_audio = false;
2640 session_options.recv_video = false;
kwibergd1fe2812016-04-27 06:47:29 -07002641 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08002642 CreateAnswer(session_options));
2643
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002644 const cricket::ContentInfo* content =
2645 cricket::GetFirstAudioContent(answer->description());
2646 ASSERT_TRUE(content != NULL);
2647 EXPECT_TRUE(content->rejected);
2648
2649 content = cricket::GetFirstVideoContent(answer->description());
2650 ASSERT_TRUE(content != NULL);
2651 EXPECT_TRUE(content->rejected);
2652}
2653
2654// Test that an answer contains the correct media content descriptions when
2655// constraints have been set and streams are sent.
2656TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002657 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002658 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002659 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002660 SetRemoteDescriptionWithoutError(offer.release());
2661
htaa2a49d92016-03-04 02:51:39 -08002662 cricket::MediaSessionOptions options;
2663 options.recv_audio = false;
2664 options.recv_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002665
2666 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002667 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002668 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002669
2670 // TODO(perkj): Should the direction be set to SEND_ONLY?
2671 const cricket::ContentInfo* content =
2672 cricket::GetFirstAudioContent(answer->description());
2673 ASSERT_TRUE(content != NULL);
2674 EXPECT_FALSE(content->rejected);
2675
2676 // TODO(perkj): Should the direction be set to SEND_ONLY?
2677 content = cricket::GetFirstVideoContent(answer->description());
2678 ASSERT_TRUE(content != NULL);
2679 EXPECT_FALSE(content->rejected);
2680}
2681
2682TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2683 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002684 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002685 PeerConnectionInterface::RTCOfferAnswerOptions options;
2686 options.offer_to_receive_audio =
2687 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2688 options.voice_activity_detection = false;
2689
kwibergd1fe2812016-04-27 06:47:29 -07002690 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002691
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002692 const cricket::ContentInfo* content =
2693 cricket::GetFirstAudioContent(offer->description());
2694 EXPECT_TRUE(content != NULL);
2695 EXPECT_TRUE(VerifyNoCNCodecs(content));
2696}
2697
2698TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2699 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002700 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002701 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07002702 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002703 SetRemoteDescriptionWithoutError(offer.release());
2704
htaa2a49d92016-03-04 02:51:39 -08002705 cricket::MediaSessionOptions options;
2706 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07002707 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002708 const cricket::ContentInfo* content =
2709 cricket::GetFirstAudioContent(answer->description());
2710 ASSERT_TRUE(content != NULL);
2711 EXPECT_TRUE(VerifyNoCNCodecs(content));
2712}
2713
2714// This test verifies the call setup when remote answer with audio only and
2715// later updates with video.
2716TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002717 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002718 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2719 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2720
deadbeefab9b2d12015-10-14 11:33:11 -07002721 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002722 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002723
2724 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002725 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2726
2727 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2728 // and answer;
2729 SetLocalDescriptionWithoutError(offer);
2730 SetRemoteDescriptionWithoutError(answer);
2731
2732 video_channel_ = media_engine_->GetVideoChannel(0);
2733 voice_channel_ = media_engine_->GetVoiceChannel(0);
2734
2735 ASSERT_TRUE(video_channel_ == NULL);
2736
2737 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2738 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2739 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2740
2741 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002742 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002743 CreateAndSetRemoteOfferAndLocalAnswer();
2744
2745 video_channel_ = media_engine_->GetVideoChannel(0);
2746 voice_channel_ = media_engine_->GetVoiceChannel(0);
2747
2748 ASSERT_TRUE(video_channel_ != NULL);
2749 ASSERT_TRUE(voice_channel_ != NULL);
2750
2751 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2752 ASSERT_EQ(1u, video_channel_->send_streams().size());
2753 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2754 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2755 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2756 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2757 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2758 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2759
2760 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002761 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002762 CreateAndSetRemoteOfferAndLocalAnswer();
2763
2764 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2765 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2766 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2767 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2768 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2769}
2770
2771// This test verifies the call setup when remote answer with video only and
2772// later updates with audio.
2773TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002774 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002775 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2776 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002777 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002778 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002779
2780 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002781 options.recv_audio = false;
2782 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002783 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2784 offer, options, cricket::SEC_ENABLED);
2785
2786 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2787 // and answer.
2788 SetLocalDescriptionWithoutError(offer);
2789 SetRemoteDescriptionWithoutError(answer);
2790
2791 video_channel_ = media_engine_->GetVideoChannel(0);
2792 voice_channel_ = media_engine_->GetVoiceChannel(0);
2793
2794 ASSERT_TRUE(voice_channel_ == NULL);
2795 ASSERT_TRUE(video_channel_ != NULL);
2796
2797 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2798 ASSERT_EQ(1u, video_channel_->send_streams().size());
2799 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2800
2801 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002802 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002803 CreateAndSetRemoteOfferAndLocalAnswer();
2804
2805 voice_channel_ = media_engine_->GetVoiceChannel(0);
2806 ASSERT_TRUE(voice_channel_ != NULL);
2807
2808 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2809 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2810 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2811 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2812
2813 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002814 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002815 CreateAndSetRemoteOfferAndLocalAnswer();
2816
2817 video_channel_ = media_engine_->GetVideoChannel(0);
2818 voice_channel_ = media_engine_->GetVoiceChannel(0);
2819
2820 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2821 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2822 ASSERT_EQ(1u, video_channel_->send_streams().size());
2823 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2824}
2825
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002826TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002827 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002828 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002829 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002830 VerifyCryptoParams(offer->description());
2831 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07002832 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002833 VerifyCryptoParams(answer->description());
2834}
2835
jbauchcb560652016-08-04 05:20:32 -07002836TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDPGcm) {
2837 InitWithGcm();
2838 SendAudioVideoStream1();
2839 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
2840 VerifyCryptoParams(offer->description(), true);
2841 SetRemoteDescriptionWithoutError(offer.release());
2842 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
2843 VerifyCryptoParams(answer->description(), true);
2844}
2845
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002846TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002847 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002848 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002849 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002850 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002851 VerifyNoCryptoParams(offer->description(), false);
2852}
2853
2854TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002855 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002856 VerifyAnswerFromNonCryptoOffer();
2857}
2858
2859TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002860 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002861 VerifyAnswerFromCryptoOffer();
2862}
2863
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002864// This test verifies that setLocalDescription fails if
2865// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2866TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002867 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002868 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002869 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002870
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002871 std::string sdp;
2872 RemoveIceUfragPwdLines(offer.get(), &sdp);
2873 SessionDescriptionInterface* modified_offer =
2874 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002875 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002876}
2877
2878// This test verifies that setRemoteDescription fails if
2879// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2880TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002881 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002882 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002883 std::string sdp;
2884 RemoveIceUfragPwdLines(offer.get(), &sdp);
2885 SessionDescriptionInterface* modified_offer =
2886 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002887 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002888}
2889
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002890// This test verifies that setLocalDescription fails if local offer has
2891// too short ice ufrag and pwd strings.
2892TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002893 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002894 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07002895 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002896 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2897 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002898 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002899 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002900 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002901
2902 // Test with string greater than 256.
deadbeef0ed85b22016-02-23 17:24:52 -08002903 offer.reset(CreateOffer());
2904 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2905 EXPECT_FALSE(session_->SetLocalDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002906}
2907
2908// This test verifies that setRemoteDescription fails if remote offer has
2909// too short ice ufrag and pwd strings.
2910TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002911 Init();
kwibergd1fe2812016-04-27 06:47:29 -07002912 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002913 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2914 // recommended values of 4 and 22 bytes respectively.
deadbeef0ed85b22016-02-23 17:24:52 -08002915 SetIceUfragPwd(offer.get(), "ice", "icepwd");
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002916 std::string error;
deadbeef0ed85b22016-02-23 17:24:52 -08002917 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002918
deadbeef0ed85b22016-02-23 17:24:52 -08002919 offer.reset(CreateRemoteOffer());
2920 SetIceUfragPwd(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd);
2921 EXPECT_FALSE(session_->SetRemoteDescription(offer.release(), &error));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002922}
2923
Honghai Zhang04e91462015-12-11 14:26:22 -08002924// Test that if the remote offer indicates the peer requested ICE restart (via
2925// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2926TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002927 Init();
honghaiz503726c2015-07-31 12:37:38 -07002928
2929 // Create the first offer.
kwibergd1fe2812016-04-27 06:47:29 -07002930 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeef0ed85b22016-02-23 17:24:52 -08002931 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002932 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2933 0, "", "", "relay", 0, "");
2934 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2935 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002936 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2937 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002938 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2939
2940 // The second offer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002941 offer.reset(CreateRemoteOffer());
2942 SetIceUfragPwd(offer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002943 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2944 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2945 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002946 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2947 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002948 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2949
2950 // The third offer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002951 offer.reset(CreateRemoteOffer());
2952 SetIceUfragPwd(offer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
honghaiz503726c2015-07-31 12:37:38 -07002953 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2954 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2955 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002956 EXPECT_TRUE(offer->AddCandidate(&ice_candidate3));
2957 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002958 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2959
2960 // The fourth offer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08002961 offer.reset(CreateRemoteOffer());
2962 SetIceUfragPwd(offer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
2963 SetRemoteDescriptionWithoutError(offer.release());
honghaiz503726c2015-07-31 12:37:38 -07002964 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2965}
2966
Honghai Zhang04e91462015-12-11 14:26:22 -08002967// Test that if the remote answer indicates the peer requested ICE restart (via
2968// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2969TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2970 Init();
2971 SessionDescriptionInterface* offer = CreateOffer();
2972 SetLocalDescriptionWithoutError(offer);
Honghai Zhang04e91462015-12-11 14:26:22 -08002973
2974 // Create the first answer.
kwibergd1fe2812016-04-27 06:47:29 -07002975 std::unique_ptr<JsepSessionDescription> answer(CreateRemoteAnswer(offer));
deadbeef0ed85b22016-02-23 17:24:52 -08002976 answer->set_type(JsepSessionDescription::kPrAnswer);
2977 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002978 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2979 0, "", "", "relay", 0, "");
2980 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2981 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002982 EXPECT_TRUE(answer->AddCandidate(&ice_candidate1));
2983 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002984 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2985
2986 // The second answer has the same ufrag and pwd but different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002987 answer.reset(CreateRemoteAnswer(offer));
2988 answer->set_type(JsepSessionDescription::kPrAnswer);
2989 SetIceUfragPwd(answer.get(), "0123456789012345", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08002990 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2991 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2992 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08002993 EXPECT_TRUE(answer->AddCandidate(&ice_candidate2));
2994 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08002995 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2996
2997 // The third answer has a different ufrag and different address.
deadbeef0ed85b22016-02-23 17:24:52 -08002998 answer.reset(CreateRemoteAnswer(offer));
2999 answer->set_type(JsepSessionDescription::kPrAnswer);
3000 SetIceUfragPwd(answer.get(), "0123456789012333", "abcdefghijklmnopqrstuvwx");
Honghai Zhang04e91462015-12-11 14:26:22 -08003001 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
3002 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
3003 candidate1);
deadbeef0ed85b22016-02-23 17:24:52 -08003004 EXPECT_TRUE(answer->AddCandidate(&ice_candidate3));
3005 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003006 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
3007
3008 // The fourth answer has no candidate but a different ufrag/pwd.
deadbeef0ed85b22016-02-23 17:24:52 -08003009 answer.reset(CreateRemoteAnswer(offer));
3010 answer->set_type(JsepSessionDescription::kPrAnswer);
3011 SetIceUfragPwd(answer.get(), "0123456789012444", "abcdefghijklmnopqrstuvyz");
3012 SetRemoteDescriptionWithoutError(answer.release());
Honghai Zhang04e91462015-12-11 14:26:22 -08003013 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
3014}
3015
Donald Curtisd4f769d2015-05-28 09:48:21 -07003016// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07003017// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07003018TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
3019 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
3020
3021 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003022 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003023
3024 PeerConnectionInterface::RTCOfferAnswerOptions options;
3025 options.use_rtp_mux = true;
3026
3027 SessionDescriptionInterface* offer = CreateRemoteOffer();
3028 SetRemoteDescriptionWithoutError(offer);
3029
htaa2a49d92016-03-04 02:51:39 -08003030 SessionDescriptionInterface* answer = CreateAnswer();
Donald Curtisd4f769d2015-05-28 09:48:21 -07003031 SetLocalDescriptionWithoutError(answer);
3032
deadbeefcbecd352015-09-23 11:50:27 -07003033 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3034 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07003035
deadbeefcbecd352015-09-23 11:50:27 -07003036 cricket::BaseChannel* voice_channel = session_->voice_channel();
3037 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003038
3039 // Checks if one of the transport channels contains a connection using a given
3040 // port.
deadbeefcbecd352015-09-23 11:50:27 -07003041 auto connection_with_remote_port = [this, voice_channel](int port) {
hbosdf6075a2016-12-19 04:58:02 -08003042 std::unique_ptr<webrtc::SessionStats> stats = session_->GetStats_s();
3043 for (auto& kv : stats->transport_stats) {
deadbeefcbecd352015-09-23 11:50:27 -07003044 for (auto& chan_stat : kv.second.channel_stats) {
3045 for (auto& conn_info : chan_stat.connection_infos) {
3046 if (conn_info.remote_candidate.address().port() == port) {
3047 return true;
3048 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07003049 }
3050 }
3051 }
3052 return false;
3053 };
3054
3055 EXPECT_FALSE(connection_with_remote_port(5000));
3056 EXPECT_FALSE(connection_with_remote_port(5001));
3057 EXPECT_FALSE(connection_with_remote_port(6000));
3058
3059 // The way the *_WAIT checks work is they only wait if the condition fails,
3060 // which does not help in the case where state is not changing. This is
3061 // problematic in this test since we want to verify that adding a video
3062 // candidate does _not_ change state. So we interleave candidates and assume
3063 // that messages are executed in the order they were posted.
3064
3065 // First audio candidate.
3066 cricket::Candidate candidate0;
3067 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3068 candidate0.set_component(1);
3069 candidate0.set_protocol("udp");
3070 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3071 candidate0);
3072 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3073
3074 // Video candidate.
3075 cricket::Candidate candidate1;
3076 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3077 candidate1.set_component(1);
3078 candidate1.set_protocol("udp");
3079 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3080 candidate1);
3081 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3082
3083 // Second audio candidate.
3084 cricket::Candidate candidate2;
3085 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3086 candidate2.set_component(1);
3087 candidate2.set_protocol("udp");
3088 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3089 candidate2);
3090 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3091
3092 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3093 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3094
3095 // No need here for a _WAIT check since we are checking that state hasn't
3096 // changed: if this is false we would be doing waits for nothing and if this
3097 // is true then there will be no messages processed anyways.
3098 EXPECT_FALSE(connection_with_remote_port(6000));
3099}
3100
deadbeefcbecd352015-09-23 11:50:27 -07003101// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003102TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3103 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003104 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003105
3106 PeerConnectionInterface::RTCOfferAnswerOptions options;
3107 options.use_rtp_mux = true;
3108
3109 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003110 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003111
deadbeefcbecd352015-09-23 11:50:27 -07003112 EXPECT_NE(session_->voice_rtp_transport_channel(),
3113 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003114
deadbeefab9b2d12015-10-14 11:33:11 -07003115 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003116 SessionDescriptionInterface* answer =
3117 CreateRemoteAnswer(session_->local_description());
3118 SetRemoteDescriptionWithoutError(answer);
3119
deadbeefcbecd352015-09-23 11:50:27 -07003120 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3121 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003122}
3123
deadbeefcbecd352015-09-23 11:50:27 -07003124// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003125TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3126 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003127 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003128
Donald Curtis0e209b02015-03-24 09:29:54 -07003129 PeerConnectionInterface::RTCOfferAnswerOptions options;
3130 options.use_rtp_mux = true;
3131
3132 SessionDescriptionInterface* offer = CreateOffer(options);
3133 SetLocalDescriptionWithoutError(offer);
3134
deadbeefcbecd352015-09-23 11:50:27 -07003135 EXPECT_NE(session_->voice_rtp_transport_channel(),
3136 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003137
deadbeefab9b2d12015-10-14 11:33:11 -07003138 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003139
3140 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003141 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003142 CreateRemoteAnswer(session_->local_description()));
3143 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3144 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3145 JsepSessionDescription* modified_answer =
3146 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3147 modified_answer->Initialize(answer_copy, "1", "1");
3148 SetRemoteDescriptionWithoutError(modified_answer); //
3149
deadbeefcbecd352015-09-23 11:50:27 -07003150 EXPECT_NE(session_->voice_rtp_transport_channel(),
3151 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003152}
3153
3154// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3155TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3156 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003157 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003158
3159 PeerConnectionInterface::RTCOfferAnswerOptions options;
3160 options.use_rtp_mux = true;
3161
3162 SessionDescriptionInterface* offer = CreateOffer(options);
3163 SetLocalDescriptionWithoutError(offer);
3164
deadbeefcbecd352015-09-23 11:50:27 -07003165 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3166 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003167
deadbeefab9b2d12015-10-14 11:33:11 -07003168 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003169 SessionDescriptionInterface* answer =
3170 CreateRemoteAnswer(session_->local_description());
3171 SetRemoteDescriptionWithoutError(answer);
3172
deadbeefcbecd352015-09-23 11:50:27 -07003173 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3174 session_->video_rtp_transport_channel());
3175}
3176
3177// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3178// audio content in the answer.
3179TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3180 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003181 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003182
3183 PeerConnectionInterface::RTCOfferAnswerOptions options;
3184 options.use_rtp_mux = true;
3185
3186 SessionDescriptionInterface* offer = CreateOffer(options);
3187 SetLocalDescriptionWithoutError(offer);
3188
3189 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3190 session_->video_rtp_transport_channel());
3191
deadbeefab9b2d12015-10-14 11:33:11 -07003192 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003193 cricket::MediaSessionOptions recv_options;
3194 recv_options.recv_audio = false;
3195 recv_options.recv_video = true;
3196 SessionDescriptionInterface* answer =
3197 CreateRemoteAnswer(session_->local_description(), recv_options);
3198 SetRemoteDescriptionWithoutError(answer);
3199
deadbeefd59daf82015-10-14 15:02:44 -07003200 EXPECT_TRUE(nullptr == session_->voice_channel());
3201 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003202
deadbeefd59daf82015-10-14 15:02:44 -07003203 session_->Close();
3204 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3205 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3206 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3207 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003208}
3209
3210// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3211TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3212 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003213 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003214
Donald Curtis0e209b02015-03-24 09:29:54 -07003215 PeerConnectionInterface::RTCOfferAnswerOptions options;
3216 options.use_rtp_mux = true;
3217
3218 SessionDescriptionInterface* offer = CreateOffer(options);
3219 SetLocalDescriptionWithoutError(offer);
3220
deadbeefcbecd352015-09-23 11:50:27 -07003221 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3222 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003223
deadbeefab9b2d12015-10-14 11:33:11 -07003224 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003225
3226 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003227 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003228 CreateRemoteAnswer(session_->local_description()));
3229 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3230 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3231 JsepSessionDescription* modified_answer =
3232 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3233 modified_answer->Initialize(answer_copy, "1", "1");
3234 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003235
deadbeefcbecd352015-09-23 11:50:27 -07003236 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3237 session_->video_rtp_transport_channel());
3238}
3239
3240// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3241TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3242 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003243 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003244
3245 SessionDescriptionInterface* offer = CreateRemoteOffer();
3246 SetRemoteDescriptionWithoutError(offer);
3247
3248 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3249 session_->video_rtp_transport_channel());
3250
deadbeefab9b2d12015-10-14 11:33:11 -07003251 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003252 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003253 SetLocalDescriptionWithoutError(answer);
3254
3255 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3256 session_->video_rtp_transport_channel());
3257}
3258
3259// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3260TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3261 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003262 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003263
3264 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003265 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003266 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3267 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3268 JsepSessionDescription* modified_offer =
3269 new JsepSessionDescription(JsepSessionDescription::kOffer);
3270 modified_offer->Initialize(offer_copy, "1", "1");
3271
3272 // Expect an error when applying the remote description
3273 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3274 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003275}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003276
Peter Thatcher4eddf182015-04-30 10:55:59 -07003277// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003278TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3279 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003280 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003281
Donald Curtis0e209b02015-03-24 09:29:54 -07003282 PeerConnectionInterface::RTCOfferAnswerOptions options;
3283 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003284
Donald Curtis0e209b02015-03-24 09:29:54 -07003285 SessionDescriptionInterface* offer = CreateOffer(options);
3286 SetLocalDescriptionWithoutError(offer);
3287
deadbeefcbecd352015-09-23 11:50:27 -07003288 EXPECT_NE(session_->voice_rtp_transport_channel(),
3289 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003290
deadbeefab9b2d12015-10-14 11:33:11 -07003291 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003292 SessionDescriptionInterface* answer =
3293 CreateRemoteAnswer(session_->local_description());
3294 SetRemoteDescriptionWithoutError(answer);
3295
3296 // This should lead to an audio-only call but isn't implemented
3297 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003298 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3299 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003300}
3301
deadbeefcbecd352015-09-23 11:50:27 -07003302// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003303TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3304 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003305 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003306 PeerConnectionInterface::RTCOfferAnswerOptions options;
3307 options.use_rtp_mux = true;
3308
3309 SessionDescriptionInterface* offer = CreateOffer(options);
3310 SetLocalDescriptionWithoutError(offer);
3311
deadbeefcbecd352015-09-23 11:50:27 -07003312 EXPECT_NE(session_->voice_rtp_transport_channel(),
3313 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003314
deadbeefab9b2d12015-10-14 11:33:11 -07003315 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003316
3317 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003318 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003319 CreateRemoteAnswer(session_->local_description()));
3320 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3321 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3322 JsepSessionDescription* modified_answer =
3323 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3324 modified_answer->Initialize(answer_copy, "1", "1");
3325 SetRemoteDescriptionWithoutError(modified_answer); //
3326
deadbeefcbecd352015-09-23 11:50:27 -07003327 EXPECT_NE(session_->voice_rtp_transport_channel(),
3328 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003329}
3330
Peter Thatcher4eddf182015-04-30 10:55:59 -07003331// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3332TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3333 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003334 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003335
3336 PeerConnectionInterface::RTCOfferAnswerOptions options;
3337 options.use_rtp_mux = true;
3338
3339 SessionDescriptionInterface* offer = CreateOffer(options);
3340 SetRemoteDescriptionWithoutError(offer);
3341
deadbeefcbecd352015-09-23 11:50:27 -07003342 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3343 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003344}
3345
skvlad6c87a672016-05-17 17:49:52 -07003346// Adding a new channel to a BUNDLE which is already connected should directly
3347// assign the bundle transport to the channel, without first setting a
3348// disconnected non-bundle transport and then replacing it. The application
3349// should not receive any changes in the ICE state.
3350TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) {
3351 LoopbackNetworkConfiguration config;
3352 LoopbackNetworkManager loopback_network_manager(this, config);
3353 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain
3354 // connected. Disabling either of these two means that we need to wait for the
3355 // answer to find out if more transports are needed.
3356 configuration_.bundle_policy =
3357 PeerConnectionInterface::kBundlePolicyMaxBundle;
skvlad6c87a672016-05-17 17:49:52 -07003358 options_.disable_encryption = true;
zhihuang4dfb8ce2016-11-23 10:30:12 -08003359 Init(PeerConnectionInterface::kRtcpMuxPolicyRequire);
skvlad6c87a672016-05-17 17:49:52 -07003360
3361 // Negotiate an audio channel with MAX_BUNDLE enabled.
3362 SendAudioOnlyStream2();
3363 SessionDescriptionInterface* offer = CreateOffer();
3364 SetLocalDescriptionWithoutError(offer);
3365 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
3366 observer_.ice_gathering_state_, kIceCandidatesTimeout);
3367 std::string sdp;
3368 offer->ToString(&sdp);
3369 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription(
3370 JsepSessionDescription::kAnswer, sdp, nullptr);
3371 ASSERT_TRUE(answer != NULL);
3372 SetRemoteDescriptionWithoutError(answer);
3373
3374 // Wait for the ICE state to stabilize.
3375 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3376 observer_.ice_connection_state_, kIceCandidatesTimeout);
3377 observer_.ice_connection_state_history_.clear();
3378
3379 // Now add a video channel which should be using the same bundle transport.
3380 SendAudioVideoStream2();
3381 offer = CreateOffer();
3382 offer->ToString(&sdp);
3383 SetLocalDescriptionWithoutError(offer);
3384 answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer,
3385 sdp, nullptr);
3386 ASSERT_TRUE(answer != NULL);
3387 SetRemoteDescriptionWithoutError(answer);
3388
3389 // Wait for ICE state to stabilize
3390 rtc::Thread::Current()->ProcessMessages(0);
3391 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3392 observer_.ice_connection_state_, kIceCandidatesTimeout);
3393
3394 // No ICE state changes are expected to happen.
3395 EXPECT_EQ(0, observer_.ice_connection_state_history_.size());
3396}
3397
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003398TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3399 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003400 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003401
3402 PeerConnectionInterface::RTCOfferAnswerOptions options;
3403 SessionDescriptionInterface* offer = CreateOffer(options);
3404 SetLocalDescriptionWithoutError(offer);
3405
deadbeefcbecd352015-09-23 11:50:27 -07003406 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3407 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003408
deadbeefab9b2d12015-10-14 11:33:11 -07003409 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003410 SessionDescriptionInterface* answer =
3411 CreateRemoteAnswer(session_->local_description());
3412 SetRemoteDescriptionWithoutError(answer);
3413
deadbeefcbecd352015-09-23 11:50:27 -07003414 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3415 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003416}
3417
3418TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3419 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003420 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003421
3422 PeerConnectionInterface::RTCOfferAnswerOptions options;
3423 SessionDescriptionInterface* offer = CreateOffer(options);
3424 SetLocalDescriptionWithoutError(offer);
3425
deadbeefcbecd352015-09-23 11:50:27 -07003426 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3427 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003428
deadbeefab9b2d12015-10-14 11:33:11 -07003429 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003430 SessionDescriptionInterface* answer =
3431 CreateRemoteAnswer(session_->local_description());
3432 SetRemoteDescriptionWithoutError(answer);
3433
deadbeefcbecd352015-09-23 11:50:27 -07003434 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3435 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003436}
3437
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003438// This test verifies that SetLocalDescription and SetRemoteDescription fails
3439// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3440TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003441 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003442 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003443
3444 PeerConnectionInterface::RTCOfferAnswerOptions options;
3445 options.use_rtp_mux = true;
3446
3447 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003448 std::string offer_str;
3449 offer->ToString(&offer_str);
3450 // Disable rtcp-mux
3451 const std::string rtcp_mux = "rtcp-mux";
3452 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003453 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003454 xrtcp_mux.c_str(), xrtcp_mux.length(),
3455 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003456 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003457 new JsepSessionDescription(JsepSessionDescription::kOffer);
3458 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003459 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003460 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003461 new JsepSessionDescription(JsepSessionDescription::kOffer);
3462 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003463 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003464 // Trying unmodified SDP.
3465 SetLocalDescriptionWithoutError(offer);
3466}
3467
jbauchcb560652016-08-04 05:20:32 -07003468TEST_F(WebRtcSessionTest, SetSetupGcm) {
3469 InitWithGcm();
3470 SendAudioVideoStream1();
3471 CreateAndSetRemoteOfferAndLocalAnswer();
3472}
3473
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003474TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3475 TestCanInsertDtmf(false);
3476}
3477
3478TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3479 TestCanInsertDtmf(true);
3480}
3481
3482TEST_F(WebRtcSessionTest, InsertDtmf) {
3483 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003484 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003485 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003486 CreateAndSetRemoteOfferAndLocalAnswer();
3487 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3488 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3489
3490 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003491 const int expected_duration = 90;
3492 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3493 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3494 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3495
3496 // Verify
3497 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003498 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003499 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003500 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003501 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003502 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003503 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003504 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003505}
3506
deadbeefd59daf82015-10-14 15:02:44 -07003507// This test verifies the |initial_offerer| flag when session initiates the
3508// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003509TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003510 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003511 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003512 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003513 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3514 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003515 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003516 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003517 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003518}
3519
deadbeefd59daf82015-10-14 15:02:44 -07003520// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003521TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003522 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003523 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003524 SessionDescriptionInterface* offer = CreateRemoteOffer();
3525 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003526 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003527
deadbeefd59daf82015-10-14 15:02:44 -07003528 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003529 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003530 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003531}
3532
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003533// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3534TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003535 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003536 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003537 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003538 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003539 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003540 CreateRemoteAnswer(session_->local_description()));
3541
3542 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3543 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003544 JsepSessionDescription* modified_answer =
3545 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003546
3547 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3548 answer->session_id(),
3549 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003550 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003551
wu@webrtc.org4e393072014-04-07 17:04:35 +00003552 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003553 std::string sdp;
3554 EXPECT_TRUE(answer->ToString(&sdp));
3555 const std::string kAudioMid = "a=mid:audio";
3556 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003557 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003558 kAudioMidReplaceStr.c_str(),
3559 kAudioMidReplaceStr.length(),
3560 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003561 SessionDescriptionInterface* modified_answer1 =
3562 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003563 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003564
wu@webrtc.org4e393072014-04-07 17:04:35 +00003565 // Different media types.
3566 EXPECT_TRUE(answer->ToString(&sdp));
3567 const std::string kAudioMline = "m=audio";
3568 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003569 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003570 kAudioMlineReplaceStr.c_str(),
3571 kAudioMlineReplaceStr.length(),
3572 &sdp);
3573 SessionDescriptionInterface* modified_answer2 =
3574 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3575 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3576
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003577 SetRemoteDescriptionWithoutError(answer.release());
3578}
3579
3580// Verifying remote offer and local answer have matching m-lines as per
3581// RFC 3264.
3582TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003583 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003584 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003585 SessionDescriptionInterface* offer = CreateRemoteOffer();
3586 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003587 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003588
3589 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3590 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003591 JsepSessionDescription* modified_answer =
3592 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003593
3594 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3595 answer->session_id(),
3596 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003597 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003598 SetLocalDescriptionWithoutError(answer);
3599}
3600
3601// This test verifies that WebRtcSession does not start candidate allocation
3602// before SetLocalDescription is called.
3603TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003604 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003605 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003606 SessionDescriptionInterface* offer = CreateRemoteOffer();
3607 cricket::Candidate candidate;
3608 candidate.set_component(1);
3609 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3610 candidate);
3611 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3612 cricket::Candidate candidate1;
3613 candidate1.set_component(1);
3614 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3615 candidate1);
3616 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3617 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003618 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3619 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003620
3621 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003622 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003623 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3624 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3625
htaa2a49d92016-03-04 02:51:39 -08003626 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003627 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003628 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3629}
3630
3631// This test verifies that crypto parameter is updated in local session
3632// description as per security policy set in MediaSessionDescriptionFactory.
3633TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003634 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003635 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003636 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003637
3638 // Making sure SetLocalDescription correctly sets crypto value in
3639 // SessionDescription object after de-serialization of sdp string. The value
3640 // will be set as per MediaSessionDescriptionFactory.
3641 std::string offer_str;
3642 offer->ToString(&offer_str);
3643 SessionDescriptionInterface* jsep_offer_str =
3644 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3645 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003646 EXPECT_TRUE(session_->voice_channel()->srtp_required_for_testing());
3647 EXPECT_TRUE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003648}
3649
3650// This test verifies the crypto parameter when security is disabled.
3651TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003652 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003653 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003654 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003655 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003656
3657 // Making sure SetLocalDescription correctly sets crypto value in
3658 // SessionDescription object after de-serialization of sdp string. The value
3659 // will be set as per MediaSessionDescriptionFactory.
3660 std::string offer_str;
3661 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003662 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003663 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3664 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003665 EXPECT_FALSE(session_->voice_channel()->srtp_required_for_testing());
3666 EXPECT_FALSE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003667}
3668
3669// This test verifies that an answer contains new ufrag and password if an offer
3670// with new ufrag and password is received.
3671TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003672 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003673 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003674 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003675 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003676 SetRemoteDescriptionWithoutError(offer.release());
3677
deadbeefab9b2d12015-10-14 11:33:11 -07003678 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003679 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003680 SetLocalDescriptionWithoutError(answer.release());
3681
3682 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003683 for (const cricket::ContentInfo& content :
3684 session_->local_description()->description()->contents()) {
3685 options.transport_options[content.name].ice_restart = true;
3686 }
kwibergd1fe2812016-04-27 06:47:29 -07003687 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003688 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003689 SetRemoteDescriptionWithoutError(updated_offer1.release());
3690
kwibergd1fe2812016-04-27 06:47:29 -07003691 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003692
deadbeef0ed85b22016-02-23 17:24:52 -08003693 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3694 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003695
deadbeef0ed85b22016-02-23 17:24:52 -08003696 // Even a second answer (created before the description is set) should have
3697 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003698 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003699
3700 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3701 session_->local_description()->description()));
3702
3703 SetLocalDescriptionWithoutError(updated_answer2.release());
3704}
3705
3706// This test verifies that an answer contains new ufrag and password if an offer
3707// that changes either the ufrag or password (but not both) is received.
3708// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3709// a=ice-pwd attributes compared to the previous SDP from the peer, it
3710// indicates that ICE is restarting for this media stream."
3711TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3712 Init();
3713 cricket::MediaSessionOptions options;
3714 options.recv_audio = true;
3715 options.recv_video = true;
3716 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003717 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003718 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3719 SetRemoteDescriptionWithoutError(offer.release());
3720
3721 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003722 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003723 SetLocalDescriptionWithoutError(answer.release());
3724
3725 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003726 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003727 CreateRemoteOffer(options, session_->remote_description()));
3728 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3729 "original_password12345");
3730 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3731
kwibergd1fe2812016-04-27 06:47:29 -07003732 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003733 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3734 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003735 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003736
3737 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003738 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003739 CreateRemoteOffer(options, session_->remote_description()));
3740 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3741 "modified_password12345");
3742 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3743
kwibergd1fe2812016-04-27 06:47:29 -07003744 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003745 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3746 session_->local_description()->description()));
3747 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003748}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003749
wu@webrtc.org91053e72013-08-10 07:18:04 +00003750// This test verifies that an answer contains old ufrag and password if an offer
3751// with old ufrag and password is received.
3752TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003753 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003754 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003755 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003756 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003757 SetRemoteDescriptionWithoutError(offer.release());
3758
deadbeefab9b2d12015-10-14 11:33:11 -07003759 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003760 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003761 SetLocalDescriptionWithoutError(answer.release());
3762
3763 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003764 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003765 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003766 SetRemoteDescriptionWithoutError(updated_offer2.release());
3767
kwibergd1fe2812016-04-27 06:47:29 -07003768 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003769
deadbeef0ed85b22016-02-23 17:24:52 -08003770 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3771 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003772
3773 SetLocalDescriptionWithoutError(updated_answer2.release());
3774}
3775
deadbeef0ed85b22016-02-23 17:24:52 -08003776// This test verifies that if an offer does an ICE restart on some, but not all
3777// media sections, the answer will change the ufrag/password in the correct
3778// media sections.
3779TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3780 Init();
3781 cricket::MediaSessionOptions options;
3782 options.recv_video = true;
3783 options.recv_audio = true;
3784 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003785 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003786
3787 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3788 "aaaaaaaaaaaaaaaaaaaaaa");
3789 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3790 "bbbbbbbbbbbbbbbbbbbbbb");
3791 SetRemoteDescriptionWithoutError(offer.release());
3792
3793 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003794 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003795 SetLocalDescriptionWithoutError(answer.release());
3796
3797 // Receive an offer with new ufrag and password, but only for the video media
3798 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003799 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003800 CreateRemoteOffer(options, session_->remote_description()));
3801 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3802 "cccccccccccccccccccccc");
3803 SetRemoteDescriptionWithoutError(updated_offer.release());
3804
kwibergd1fe2812016-04-27 06:47:29 -07003805 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003806
3807 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3808 session_->local_description()->description(),
3809 cricket::MEDIA_TYPE_AUDIO));
3810
3811 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3812 session_->local_description()->description(),
3813 cricket::MEDIA_TYPE_VIDEO));
3814
3815 SetLocalDescriptionWithoutError(updated_answer.release());
3816}
3817
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003818TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003819 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003820 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003821 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003822 const std::string session_id_orig = offer->session_id();
3823 const std::string session_version_orig = offer->session_version();
3824 SetLocalDescriptionWithoutError(offer);
3825
3826 video_channel_ = media_engine_->GetVideoChannel(0);
3827 video_channel_->set_fail_set_send_codecs(true);
3828
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003829 SessionDescriptionInterface* answer =
3830 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003831 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003832
3833 // Test that after a content error, setting any description will
3834 // result in an error.
3835 video_channel_->set_fail_set_send_codecs(false);
3836 answer = CreateRemoteAnswer(session_->local_description());
3837 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3838 offer = CreateRemoteOffer();
3839 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003840}
3841
3842// Runs the loopback call test with BUNDLE and STUN disabled.
3843TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3844 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003845 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003846 cricket::PORTALLOCATOR_DISABLE_STUN |
3847 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003848 TestLoopbackCall();
3849}
3850
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003851TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003852 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003853 cricket::PORTALLOCATOR_DISABLE_STUN |
3854 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3855 cricket::PORTALLOCATOR_DISABLE_RELAY);
3856
3857 // best connection is IPv6 since it has higher network preference.
3858 LoopbackNetworkConfiguration config;
3859 config.test_ipv6_network_ = true;
3860 config.best_connection_after_initial_ice_converged_ =
3861 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3862
3863 TestLoopbackCall(config);
3864}
3865
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003866// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003867TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003868 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3869 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003870 TestLoopbackCall();
3871}
3872
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003873TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003874 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003875 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003876 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003877 ASSERT_TRUE(data_engine_);
deadbeefc0dad892017-01-04 20:28:21 -08003878 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003879}
3880
Henrik Boström87713d02015-08-25 09:53:21 +02003881TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003882 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003883
htaa2a49d92016-03-04 02:51:39 -08003884 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003885 options_.disable_sctp_data_channels = false;
3886
Henrik Boström87713d02015-08-25 09:53:21 +02003887 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003888
3889 SetLocalDescriptionWithDataChannel();
deadbeefc0dad892017-01-04 20:28:21 -08003890 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003891}
3892
Henrik Boström87713d02015-08-25 09:53:21 +02003893TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003894 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003895
Henrik Boström87713d02015-08-25 09:53:21 +02003896 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003897
kwibergd1fe2812016-04-27 06:47:29 -07003898 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003899 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003900 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3901}
3902
Henrik Boström87713d02015-08-25 09:53:21 +02003903TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003904 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003905 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003906 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003907
3908 // Create remote offer with SCTP.
3909 cricket::MediaSessionOptions options;
3910 options.data_channel_type = cricket::DCT_SCTP;
3911 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003912 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003913 SetRemoteDescriptionWithoutError(offer);
3914
3915 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07003916 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003917 EXPECT_TRUE(answer != NULL);
3918 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3919 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003920}
3921
Henrik Boström87713d02015-08-25 09:53:21 +02003922TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003923 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003924 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003925
3926 SetLocalDescriptionWithDataChannel();
deadbeefc0dad892017-01-04 20:28:21 -08003927 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003928}
3929
Henrik Boström87713d02015-08-25 09:53:21 +02003930TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003931 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003932
Henrik Boström87713d02015-08-25 09:53:21 +02003933 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003934
3935 SetLocalDescriptionWithDataChannel();
deadbeefc0dad892017-01-04 20:28:21 -08003936 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003937}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003938
Henrik Boström87713d02015-08-25 09:53:21 +02003939TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003940 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003941 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003942 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003943
3944 SetLocalDescriptionWithDataChannel();
deadbeefc0dad892017-01-04 20:28:21 -08003945 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003946}
3947
Henrik Boström87713d02015-08-25 09:53:21 +02003948TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003949 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003950 const int new_send_port = 9998;
3951 const int new_recv_port = 7775;
3952
Henrik Boström87713d02015-08-25 09:53:21 +02003953 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003954 SetFactoryDtlsSrtp();
3955
3956 // By default, don't actually add the codecs to desc_factory_; they don't
3957 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3958 // let the session description get parsed. That'll get the proper codecs
3959 // into the stream.
3960 cricket::MediaSessionOptions options;
3961 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3962 "stream1", new_send_port, options);
3963
3964 // SetRemoteDescription will take the ownership of the offer.
3965 SetRemoteDescriptionWithoutError(offer);
3966
htaa2a49d92016-03-04 02:51:39 -08003967 SessionDescriptionInterface* answer =
3968 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003969 ASSERT_TRUE(answer != NULL);
3970
3971 // Now set the local description, which'll take ownership of the answer.
3972 SetLocalDescriptionWithoutError(answer);
3973
3974 // TEST PLAN: Set the port number to something new, set it in the SDP,
3975 // and pass it all the way down.
deadbeefc0dad892017-01-04 20:28:21 -08003976 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003977 CreateDataChannel();
deadbeefc0dad892017-01-04 20:28:21 -08003978
3979 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3980 int portnum = -1;
3981 ASSERT_TRUE(ch != NULL);
3982 ASSERT_EQ(1UL, ch->send_codecs().size());
3983 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, ch->send_codecs()[0].id);
3984 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
3985 ch->send_codecs()[0].name.c_str()));
3986 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3987 &portnum));
3988 EXPECT_EQ(new_send_port, portnum);
3989
3990 ASSERT_EQ(1UL, ch->recv_codecs().size());
3991 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, ch->recv_codecs()[0].id);
3992 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
3993 ch->recv_codecs()[0].name.c_str()));
3994 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3995 &portnum));
3996 EXPECT_EQ(new_recv_port, portnum);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003997}
3998
deadbeefc0dad892017-01-04 20:28:21 -08003999// Verifies that when a session's DataChannel receives an OPEN message,
4000// WebRtcSession signals the DataChannel creation request with the expected
deadbeefab9b2d12015-10-14 11:33:11 -07004001// config.
4002TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
4003 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4004
4005 InitWithDtls(GetParam());
4006
4007 SetLocalDescriptionWithDataChannel();
deadbeefc0dad892017-01-04 20:28:21 -08004008 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07004009
4010 webrtc::DataChannelInit config;
4011 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07004012 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07004013 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4014 cricket::ReceiveDataParams params;
4015 params.ssrc = config.id;
4016 params.type = cricket::DMT_CONTROL;
4017
deadbeefc0dad892017-01-04 20:28:21 -08004018 cricket::DataChannel* data_channel = session_->data_channel();
4019 data_channel->SignalDataReceived(data_channel, params, payload);
4020
4021 EXPECT_EQ("a", last_data_channel_label_);
deadbeefab9b2d12015-10-14 11:33:11 -07004022 EXPECT_EQ(config.id, last_data_channel_config_.id);
4023 EXPECT_FALSE(last_data_channel_config_.negotiated);
4024 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4025 last_data_channel_config_.open_handshake_role);
4026}
4027
4028TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004029 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
Henrik Boströmd79599d2016-06-01 13:58:50 +02004030 FakeRTCCertificateGenerator::GenerateCertificate();
Henrik Boströmd8281982015-08-27 10:12:24 +02004031
htaa2a49d92016-03-04 02:51:39 -08004032 configuration_.certificates.push_back(certificate);
4033 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004034 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4035
4036 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4037}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004038
Henrik Boström87713d02015-08-25 09:53:21 +02004039// Verifies that CreateOffer succeeds when CreateOffer is called before async
4040// identity generation is finished (even if a certificate is provided this is
4041// an async op).
4042TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
4043 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4044 InitWithDtls(GetParam());
4045
Henrik Boströmd8281982015-08-27 10:12:24 +02004046 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004047 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07004048 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004049
wu@webrtc.org91053e72013-08-10 07:18:04 +00004050 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004051 VerifyNoCryptoParams(offer->description(), true);
4052 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004053}
4054
4055// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004056// identity generation is finished (even if a certificate is provided this is
4057// an async op).
4058TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004059 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004060 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004061 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004062
4063 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004064 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07004065 std::unique_ptr<JsepSessionDescription> offer(
4066 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004067 ASSERT_TRUE(offer.get() != NULL);
4068 SetRemoteDescriptionWithoutError(offer.release());
4069
kwibergd1fe2812016-04-27 06:47:29 -07004070 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004071 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004072 VerifyNoCryptoParams(answer->description(), true);
4073 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004074}
4075
4076// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004077// identity generation is finished (even if a certificate is provided this is
4078// an async op).
4079TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004080 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004081 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004082
Henrik Boströmd8281982015-08-27 10:12:24 +02004083 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004084
kwibergd1fe2812016-04-27 06:47:29 -07004085 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004086 EXPECT_TRUE(offer != NULL);
4087}
4088
4089// Verifies that CreateOffer fails when CreateOffer is called after async
4090// identity generation fails.
4091TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004092 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004093 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004094
Henrik Boströmd8281982015-08-27 10:12:24 +02004095 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004096
kwibergd1fe2812016-04-27 06:47:29 -07004097 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004098 EXPECT_TRUE(offer == NULL);
4099}
4100
4101// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4102// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004103TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004104 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004105 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004106 VerifyMultipleAsyncCreateDescription(GetParam(),
4107 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004108}
4109
4110// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4111// before async identity generation fails.
4112TEST_F(WebRtcSessionTest,
4113 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004114 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004115 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4116 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004117}
4118
4119// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4120// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004121TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004122 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004123 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004124 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004125 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004126}
4127
4128// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4129// before async identity generation fails.
4130TEST_F(WebRtcSessionTest,
4131 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004132 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004133 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4134 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004135}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004136
4137// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4138// offer has no SDES crypto but only DTLS fingerprint.
4139TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4140 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004141 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004142 // Create a remote offer with secured transport disabled.
4143 cricket::MediaSessionOptions options;
4144 JsepSessionDescription* offer(CreateRemoteOffer(
4145 options, cricket::SEC_DISABLED));
4146 // Adds a DTLS fingerprint to the remote offer.
4147 cricket::SessionDescription* sdp = offer->description();
4148 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4149 ASSERT_TRUE(audio != NULL);
4150 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4151 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004152 rtc::SSLFingerprint::CreateFromRfc4572(
4153 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004154 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004155 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004156}
4157
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004158TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004159 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004160 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004161 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004162 SessionDescriptionInterface* offer = CreateOffer();
4163
4164 SetLocalDescriptionWithoutError(offer);
4165
4166 voice_channel_ = media_engine_->GetVoiceChannel(0);
4167
4168 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004169 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004170 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004171}
4172
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004173// Tests that we can renegotiate new media content with ICE candidates in the
4174// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004175TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004176 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004177 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004178 SetFactoryDtlsSrtp();
4179
deadbeefab9b2d12015-10-14 11:33:11 -07004180 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004181 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004182 SetLocalDescriptionWithoutError(offer);
4183
4184 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4185 SetRemoteDescriptionWithoutError(answer);
4186
4187 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004188 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004189 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4190
4191 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004192 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004193 candidate1.set_component(1);
4194 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4195 candidate1);
4196 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4197 SetRemoteDescriptionWithoutError(offer);
4198
htaa2a49d92016-03-04 02:51:39 -08004199 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004200 SetLocalDescriptionWithoutError(answer);
4201}
4202
4203// Tests that we can renegotiate new media content with ICE candidates separated
4204// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004205TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004206 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004207 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004208 SetFactoryDtlsSrtp();
4209
deadbeefab9b2d12015-10-14 11:33:11 -07004210 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004211 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004212 SetLocalDescriptionWithoutError(offer);
4213
4214 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4215 SetRemoteDescriptionWithoutError(answer);
4216
4217 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004218 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004219 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4220 SetRemoteDescriptionWithoutError(offer);
4221
4222 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004223 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004224 candidate1.set_component(1);
4225 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4226 candidate1);
4227 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4228
htaa2a49d92016-03-04 02:51:39 -08004229 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004230 SetLocalDescriptionWithoutError(answer);
4231}
honghaiz7f777492016-02-02 21:54:01 -08004232
zhihuang9763d562016-08-05 11:14:50 -07004233#ifdef HAVE_QUIC
4234TEST_P(WebRtcSessionTest, TestNegotiateQuic) {
4235 configuration_.enable_quic = true;
4236 InitWithDtls(GetParam());
4237 EXPECT_TRUE(session_->data_channel_type() == cricket::DCT_QUIC);
4238 SessionDescriptionInterface* offer = CreateOffer();
4239 ASSERT_TRUE(offer);
4240 ASSERT_TRUE(offer->description());
4241 SetLocalDescriptionWithoutError(offer);
4242 cricket::MediaSessionOptions options;
4243 options.recv_audio = true;
4244 options.recv_video = true;
4245 SessionDescriptionInterface* answer =
4246 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
4247 ASSERT_TRUE(answer);
4248 ASSERT_TRUE(answer->description());
4249 SetRemoteDescriptionWithoutError(answer);
4250}
4251#endif // HAVE_QUIC
4252
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004253// Tests that RTX codec is removed from the answer when it isn't supported
4254// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004255TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004256 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004257 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004258 std::string offer_sdp(kSdpWithRtx);
4259
4260 SessionDescriptionInterface* offer =
4261 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4262 EXPECT_TRUE(offer->ToString(&offer_sdp));
4263
4264 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004265 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004266 SetRemoteDescriptionWithoutError(offer);
4267
htaa2a49d92016-03-04 02:51:39 -08004268 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004269 // Answer SDP does not contain the RTX codec.
4270 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004271 SetLocalDescriptionWithoutError(answer);
4272}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004273
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004274// This verifies that the voice channel after bundle has both options from video
4275// and voice channels.
4276TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4277 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004278 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004279
4280 PeerConnectionInterface::RTCOfferAnswerOptions options;
4281 options.use_rtp_mux = true;
4282
4283 SessionDescriptionInterface* offer = CreateOffer(options);
4284 SetLocalDescriptionWithoutError(offer);
4285
4286 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4287 rtc::Socket::Option::OPT_SNDBUF, 4000);
4288
4289 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4290 rtc::Socket::Option::OPT_RCVBUF, 8000);
4291
4292 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004293 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004294 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4295 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004296 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004297 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4298
deadbeefcbecd352015-09-23 11:50:27 -07004299 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004300 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4301 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004302 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004303 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4304
deadbeefcbecd352015-09-23 11:50:27 -07004305 EXPECT_NE(session_->voice_rtp_transport_channel(),
4306 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004307
deadbeefab9b2d12015-10-14 11:33:11 -07004308 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004309 SessionDescriptionInterface* answer =
4310 CreateRemoteAnswer(session_->local_description());
4311 SetRemoteDescriptionWithoutError(answer);
4312
deadbeefcbecd352015-09-23 11:50:27 -07004313 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004314 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4315 EXPECT_EQ(4000, option_val);
4316
deadbeefcbecd352015-09-23 11:50:27 -07004317 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004318 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4319 EXPECT_EQ(8000, option_val);
4320}
4321
tommi0f620f42015-07-09 03:25:02 -07004322// Test creating a session, request multiple offers, destroy the session
4323// and make sure we got success/failure callbacks for all of the requests.
4324// Background: crbug.com/507307
4325TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4326 Init();
4327
4328 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4329 PeerConnectionInterface::RTCOfferAnswerOptions options;
4330 options.offer_to_receive_audio =
4331 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004332 cricket::MediaSessionOptions session_options;
4333 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004334
4335 for (auto& o : observers) {
4336 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004337 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004338 }
4339
4340 session_.reset();
4341
tommi0f620f42015-07-09 03:25:02 -07004342 for (auto& o : observers) {
4343 // We expect to have received a notification now even if the session was
4344 // terminated. The offer creation may or may not have succeeded, but we
4345 // must have received a notification which, so the only invalid state
4346 // is kInit.
4347 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4348 }
4349}
4350
stefanc1aeaf02015-10-15 07:26:07 -07004351TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4352 TestPacketOptions();
4353}
4354
deadbeef057ecf02016-01-20 14:30:43 -08004355// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4356// is destroyed.
4357TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4358 Init();
4359 session_.reset();
4360 EXPECT_TRUE(session_destroyed_);
4361}
4362
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004363// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4364// currently fails because upon disconnection and reconnection OnIceComplete is
4365// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004366
deadbeefcbecd352015-09-23 11:50:27 -07004367INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4368 WebRtcSessionTest,
4369 testing::Values(ALREADY_GENERATED,
4370 DTLS_IDENTITY_STORE));