blob: fe3468820e9124c20cb297d47c14f2add24ac1d4 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
jbauch555604a2016-04-26 03:13:22 -070011#include <memory>
kwiberg0eb15ed2015-12-17 03:04:15 -080012#include <utility>
deadbeefcbecd352015-09-23 11:50:27 -070013#include <vector>
14
Henrik Kjellander15583c12016-02-10 10:53:12 +010015#include "webrtc/api/audiotrack.h"
16#include "webrtc/api/fakemediacontroller.h"
17#include "webrtc/api/fakemetricsobserver.h"
18#include "webrtc/api/jsepicecandidate.h"
19#include "webrtc/api/jsepsessiondescription.h"
20#include "webrtc/api/peerconnection.h"
21#include "webrtc/api/sctputils.h"
Henrik Boströmd79599d2016-06-01 13:58:50 +020022#include "webrtc/api/test/fakertccertificategenerator.h"
Henrik Kjellander15583c12016-02-10 10:53:12 +010023#include "webrtc/api/videotrack.h"
24#include "webrtc/api/webrtcsession.h"
25#include "webrtc/api/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000026#include "webrtc/base/fakenetwork.h"
27#include "webrtc/base/firewallsocketserver.h"
28#include "webrtc/base/gunit.h"
29#include "webrtc/base/logging.h"
30#include "webrtc/base/network.h"
31#include "webrtc/base/physicalsocketserver.h"
32#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020033#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000034#include "webrtc/base/sslstreamadapter.h"
35#include "webrtc/base/stringutils.h"
36#include "webrtc/base/thread.h"
37#include "webrtc/base/virtualsocketserver.h"
skvlad11a9cbf2016-10-07 11:53:05 -070038#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
kjellandera96e2d72016-02-04 23:52:28 -080039#include "webrtc/media/base/fakemediaengine.h"
40#include "webrtc/media/base/fakevideorenderer.h"
41#include "webrtc/media/base/mediachannel.h"
kjellander@webrtc.org5ad12972016-02-12 06:39:40 +010042#include "webrtc/media/engine/fakewebrtccall.h"
johan669d69b2016-11-08 14:14:08 -080043#include "webrtc/p2p/base/packettransportinterface.h"
kjellandera96e2d72016-02-04 23:52:28 -080044#include "webrtc/p2p/base/stunserver.h"
45#include "webrtc/p2p/base/teststunserver.h"
46#include "webrtc/p2p/base/testturnserver.h"
47#include "webrtc/p2p/base/transportchannel.h"
48#include "webrtc/p2p/client/basicportallocator.h"
kjellander@webrtc.org9b8df252016-02-12 06:47:59 +010049#include "webrtc/pc/channelmanager.h"
50#include "webrtc/pc/mediasession.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000051
52#define MAYBE_SKIP_TEST(feature) \
53 if (!(feature())) { \
54 LOG(LS_INFO) << "Feature disabled... skipping"; \
55 return; \
56 }
57
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000060using rtc::SocketAddress;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000061using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000063using webrtc::CreateSessionDescriptionObserver;
64using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070065using webrtc::DataChannel;
jbauchac8869e2015-07-03 01:36:14 -070066using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000067using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070068using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000069using webrtc::JsepIceCandidate;
70using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000071using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072using webrtc::PeerConnectionInterface;
73using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070074using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000076using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000077using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000078using webrtc::kCreateChannelFailed;
79using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000081using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000082using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000083using webrtc::kSdpWithoutDtlsFingerprint;
84using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000086using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000087using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +000089typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
90
wu@webrtc.org364f2042013-11-20 21:49:41 +000091static const int kClientAddrPort = 0;
92static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +000093static const char kClientIPv6AddrHost1[] =
94 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +000095static const char kClientAddrHost2[] = "22.22.22.22";
96static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +000097static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
98static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +000099static const char kTurnUsername[] = "test";
100static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101
102static const char kSessionVersion[] = "1";
103
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000104// Media index of candidates belonging to the first media content.
105static const int kMediaContentIndex0 = 0;
106static const char kMediaContentName0[] = "audio";
107
108// Media index of candidates belonging to the second media content.
109static const int kMediaContentIndex1 = 1;
110static const char kMediaContentName1[] = "video";
111
112static const int kIceCandidatesTimeout = 10000;
deadbeeff5f03e82016-06-06 11:16:06 -0700113// STUN timeout with all retransmissions is a total of 9500ms.
114static const int kStunTimeout = 9500;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000116static const char kFakeDtlsFingerprint[] =
117 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
118 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
119
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000120static const char kTooLongIceUfragPwd[] =
121 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
122 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
123 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
124 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
125
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000126static const char kSdpWithRtx[] =
127 "v=0\r\n"
128 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
129 "s=-\r\n"
130 "t=0 0\r\n"
131 "a=msid-semantic: WMS stream1\r\n"
132 "m=video 9 RTP/SAVPF 0 96\r\n"
133 "c=IN IP4 0.0.0.0\r\n"
134 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
135 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
136 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
137 "a=mid:video\r\n"
138 "a=sendrecv\r\n"
139 "a=rtcp-mux\r\n"
140 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
141 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
142 "a=rtpmap:0 fake_video_codec/90000\r\n"
143 "a=rtpmap:96 rtx/90000\r\n"
144 "a=fmtp:96 apt=0\r\n";
145
deadbeefab9b2d12015-10-14 11:33:11 -0700146static const char kStream1[] = "stream1";
147static const char kVideoTrack1[] = "video1";
148static const char kAudioTrack1[] = "audio1";
149
150static const char kStream2[] = "stream2";
151static const char kVideoTrack2[] = "video2";
152static const char kAudioTrack2[] = "audio2";
153
Henrik Boström87713d02015-08-25 09:53:21 +0200154enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
155
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000156class MockIceObserver : public webrtc::IceObserver {
157 public:
158 MockIceObserver()
159 : oncandidatesready_(false),
160 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
161 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
162 }
163
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200164 virtual ~MockIceObserver() = default;
165
perkjdfb769d2016-02-09 03:09:43 -0800166 void OnIceConnectionChange(
167 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000168 ice_connection_state_ = new_state;
skvlad6c87a672016-05-17 17:49:52 -0700169 ice_connection_state_history_.push_back(new_state);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000170 }
perkjdfb769d2016-02-09 03:09:43 -0800171 void OnIceGatheringChange(
172 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173 // We can never transition back to "new".
174 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
175 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800176 oncandidatesready_ =
177 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000178 }
179
180 // Found a new candidate.
perkjdfb769d2016-02-09 03:09:43 -0800181 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000182 switch (candidate->sdp_mline_index()) {
183 case kMediaContentIndex0:
184 mline_0_candidates_.push_back(candidate->candidate());
185 break;
186 case kMediaContentIndex1:
187 mline_1_candidates_.push_back(candidate->candidate());
188 break;
189 default:
190 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000191 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000192
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000193 // The ICE gathering state should always be Gathering when a candidate is
194 // received (or possibly Completed in the case of the final candidate).
195 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
196 }
197
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700198 // Some local candidates are removed.
199 void OnIceCandidatesRemoved(
nisseef8b61e2016-04-29 06:09:15 -0700200 const std::vector<cricket::Candidate>& candidates) override {
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700201 num_candidates_removed_ += candidates.size();
202 }
203
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000204 bool oncandidatesready_;
205 std::vector<cricket::Candidate> mline_0_candidates_;
206 std::vector<cricket::Candidate> mline_1_candidates_;
207 PeerConnectionInterface::IceConnectionState ice_connection_state_;
208 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
skvlad6c87a672016-05-17 17:49:52 -0700209 std::vector<PeerConnectionInterface::IceConnectionState>
210 ice_connection_state_history_;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700211 size_t num_candidates_removed_ = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212};
213
214class WebRtcSessionForTest : public webrtc::WebRtcSession {
215 public:
zhihuang29ff8442016-07-27 11:07:25 -0700216 WebRtcSessionForTest(
217 webrtc::MediaControllerInterface* media_controller,
218 rtc::Thread* network_thread,
219 rtc::Thread* worker_thread,
220 rtc::Thread* signaling_thread,
221 cricket::PortAllocator* port_allocator,
222 webrtc::IceObserver* ice_observer,
223 std::unique_ptr<cricket::TransportController> transport_controller)
stefanc1aeaf02015-10-15 07:26:07 -0700224 : WebRtcSession(media_controller,
danilchape9021a32016-05-17 01:52:02 -0700225 network_thread,
stefanc1aeaf02015-10-15 07:26:07 -0700226 worker_thread,
danilchape9021a32016-05-17 01:52:02 -0700227 signaling_thread,
zhihuang29ff8442016-07-27 11:07:25 -0700228 port_allocator,
229 std::move(transport_controller)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000230 RegisterIceObserver(ice_observer);
231 }
232 virtual ~WebRtcSessionForTest() {}
233
deadbeefcbecd352015-09-23 11:50:27 -0700234 // Note that these methods are only safe to use if the signaling thread
235 // is the same as the worker thread
johan669d69b2016-11-08 14:14:08 -0800236 rtc::PacketTransportInterface* voice_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700237 return rtp_transport_channel(voice_channel());
238 }
239
johan669d69b2016-11-08 14:14:08 -0800240 rtc::PacketTransportInterface* voice_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700241 return rtcp_transport_channel(voice_channel());
242 }
243
johan669d69b2016-11-08 14:14:08 -0800244 rtc::PacketTransportInterface* video_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700245 return rtp_transport_channel(video_channel());
246 }
247
johan669d69b2016-11-08 14:14:08 -0800248 rtc::PacketTransportInterface* video_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700249 return rtcp_transport_channel(video_channel());
250 }
251
johan669d69b2016-11-08 14:14:08 -0800252 rtc::PacketTransportInterface* data_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700253 return rtp_transport_channel(data_channel());
254 }
255
johan669d69b2016-11-08 14:14:08 -0800256 rtc::PacketTransportInterface* data_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700257 return rtcp_transport_channel(data_channel());
258 }
259
deadbeefcbecd352015-09-23 11:50:27 -0700260 private:
johan669d69b2016-11-08 14:14:08 -0800261 rtc::PacketTransportInterface* rtp_transport_channel(
262 cricket::BaseChannel* ch) {
deadbeefcbecd352015-09-23 11:50:27 -0700263 if (!ch) {
264 return nullptr;
265 }
266 return ch->transport_channel();
267 }
268
johan669d69b2016-11-08 14:14:08 -0800269 rtc::PacketTransportInterface* rtcp_transport_channel(
270 cricket::BaseChannel* ch) {
deadbeefcbecd352015-09-23 11:50:27 -0700271 if (!ch) {
272 return nullptr;
273 }
274 return ch->rtcp_transport_channel();
275 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000276};
277
wu@webrtc.org91053e72013-08-10 07:18:04 +0000278class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000279 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000280 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000281 enum State {
282 kInit,
283 kFailed,
284 kSucceeded,
285 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000286 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000287
288 // CreateSessionDescriptionObserver implementation.
289 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000290 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000291 state_ = kSucceeded;
292 }
293 virtual void OnFailure(const std::string& error) {
294 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295 }
296
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000297 SessionDescriptionInterface* description() { return description_.get(); }
298
299 SessionDescriptionInterface* ReleaseDescription() {
300 return description_.release();
301 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000302
wu@webrtc.org91053e72013-08-10 07:18:04 +0000303 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304
wu@webrtc.org91053e72013-08-10 07:18:04 +0000305 protected:
306 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000307
308 private:
kwibergd1fe2812016-04-27 06:47:29 -0700309 std::unique_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000310 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311};
312
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800313class FakeAudioSource : public cricket::AudioSource {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000314 public:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800315 FakeAudioSource() : sink_(NULL) {}
316 virtual ~FakeAudioSource() {
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000317 if (sink_)
318 sink_->OnClose();
319 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000320
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000321 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000322
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800323 const cricket::AudioSource::Sink* sink() const { return sink_; }
324
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000325 private:
Taylor Brandstetter1a018dc2016-03-08 12:37:39 -0800326 cricket::AudioSource::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000327};
328
Henrik Boström87713d02015-08-25 09:53:21 +0200329class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700330 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
331 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000332 protected:
333 // TODO Investigate why ChannelManager crashes, if it's created
334 // after stun_server.
335 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700336 : media_engine_(new cricket::FakeMediaEngine()),
337 data_engine_(new cricket::FakeDataEngine()),
skvlad11a9cbf2016-10-07 11:53:05 -0700338 channel_manager_(new cricket::ChannelManager(media_engine_,
339 data_engine_,
340 rtc::Thread::Current())),
341 fake_call_(webrtc::Call::Config(&event_log_)),
stefanc1aeaf02015-10-15 07:26:07 -0700342 media_controller_(
nisse51542be2016-02-12 02:27:06 -0800343 webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
344 rtc::Thread::Current(),
skvlad11a9cbf2016-10-07 11:53:05 -0700345 channel_manager_.get(),
346 &event_log_)),
stefanc1aeaf02015-10-15 07:26:07 -0700347 tdesc_factory_(new cricket::TransportDescriptionFactory()),
348 desc_factory_(
349 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
350 tdesc_factory_.get())),
351 pss_(new rtc::PhysicalSocketServer),
352 vss_(new rtc::VirtualSocketServer(pss_.get())),
353 fss_(new rtc::FirewallSocketServer(vss_.get())),
354 ss_scope_(fss_.get()),
355 stun_socket_addr_(
356 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
357 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
358 stun_socket_addr_)),
359 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
360 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000361 cricket::ServerAddresses stun_servers;
362 stun_servers.insert(stun_socket_addr_);
363 allocator_.reset(new cricket::BasicPortAllocator(
364 &network_manager_,
365 stun_servers,
366 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000367 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700368 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369 EXPECT_TRUE(channel_manager_->Init());
370 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000371 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000372 }
373
374 void AddInterface(const SocketAddress& addr) {
375 network_manager_.AddInterface(addr);
376 }
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700377 void RemoveInterface(const SocketAddress& addr) {
378 network_manager_.RemoveInterface(addr);
379 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000380
Henrik Boströmd79599d2016-06-01 13:58:50 +0200381 // If |cert_generator| != null or |rtc_configuration| contains |certificates|
382 // then DTLS will be enabled unless explicitly disabled by |rtc_configuration|
383 // options. When DTLS is enabled a certificate will be used if provided,
384 // otherwise one will be generated using the |cert_generator|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000385 void Init(
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(),
395 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) {
deadbeefd59daf82015-10-14 15:02:44 -07003042 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07003043 session_->GetChannelTransportStats(voice_channel, &stats);
3044 for (auto& kv : stats.transport_stats) {
3045 for (auto& chan_stat : kv.second.channel_stats) {
3046 for (auto& conn_info : chan_stat.connection_infos) {
3047 if (conn_info.remote_candidate.address().port() == port) {
3048 return true;
3049 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07003050 }
3051 }
3052 }
3053 return false;
3054 };
3055
3056 EXPECT_FALSE(connection_with_remote_port(5000));
3057 EXPECT_FALSE(connection_with_remote_port(5001));
3058 EXPECT_FALSE(connection_with_remote_port(6000));
3059
3060 // The way the *_WAIT checks work is they only wait if the condition fails,
3061 // which does not help in the case where state is not changing. This is
3062 // problematic in this test since we want to verify that adding a video
3063 // candidate does _not_ change state. So we interleave candidates and assume
3064 // that messages are executed in the order they were posted.
3065
3066 // First audio candidate.
3067 cricket::Candidate candidate0;
3068 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
3069 candidate0.set_component(1);
3070 candidate0.set_protocol("udp");
3071 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
3072 candidate0);
3073 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
3074
3075 // Video candidate.
3076 cricket::Candidate candidate1;
3077 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
3078 candidate1.set_component(1);
3079 candidate1.set_protocol("udp");
3080 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3081 candidate1);
3082 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
3083
3084 // Second audio candidate.
3085 cricket::Candidate candidate2;
3086 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
3087 candidate2.set_component(1);
3088 candidate2.set_protocol("udp");
3089 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
3090 candidate2);
3091 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3092
3093 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3094 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3095
3096 // No need here for a _WAIT check since we are checking that state hasn't
3097 // changed: if this is false we would be doing waits for nothing and if this
3098 // is true then there will be no messages processed anyways.
3099 EXPECT_FALSE(connection_with_remote_port(6000));
3100}
3101
deadbeefcbecd352015-09-23 11:50:27 -07003102// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003103TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3104 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003105 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003106
3107 PeerConnectionInterface::RTCOfferAnswerOptions options;
3108 options.use_rtp_mux = true;
3109
3110 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003111 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003112
deadbeefcbecd352015-09-23 11:50:27 -07003113 EXPECT_NE(session_->voice_rtp_transport_channel(),
3114 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003115
deadbeefab9b2d12015-10-14 11:33:11 -07003116 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003117 SessionDescriptionInterface* answer =
3118 CreateRemoteAnswer(session_->local_description());
3119 SetRemoteDescriptionWithoutError(answer);
3120
deadbeefcbecd352015-09-23 11:50:27 -07003121 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3122 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003123}
3124
deadbeefcbecd352015-09-23 11:50:27 -07003125// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003126TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3127 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003128 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003129
Donald Curtis0e209b02015-03-24 09:29:54 -07003130 PeerConnectionInterface::RTCOfferAnswerOptions options;
3131 options.use_rtp_mux = true;
3132
3133 SessionDescriptionInterface* offer = CreateOffer(options);
3134 SetLocalDescriptionWithoutError(offer);
3135
deadbeefcbecd352015-09-23 11:50:27 -07003136 EXPECT_NE(session_->voice_rtp_transport_channel(),
3137 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003138
deadbeefab9b2d12015-10-14 11:33:11 -07003139 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003140
3141 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003142 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003143 CreateRemoteAnswer(session_->local_description()));
3144 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3145 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3146 JsepSessionDescription* modified_answer =
3147 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3148 modified_answer->Initialize(answer_copy, "1", "1");
3149 SetRemoteDescriptionWithoutError(modified_answer); //
3150
deadbeefcbecd352015-09-23 11:50:27 -07003151 EXPECT_NE(session_->voice_rtp_transport_channel(),
3152 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003153}
3154
3155// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3156TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3157 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003158 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003159
3160 PeerConnectionInterface::RTCOfferAnswerOptions options;
3161 options.use_rtp_mux = true;
3162
3163 SessionDescriptionInterface* offer = CreateOffer(options);
3164 SetLocalDescriptionWithoutError(offer);
3165
deadbeefcbecd352015-09-23 11:50:27 -07003166 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3167 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003168
deadbeefab9b2d12015-10-14 11:33:11 -07003169 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003170 SessionDescriptionInterface* answer =
3171 CreateRemoteAnswer(session_->local_description());
3172 SetRemoteDescriptionWithoutError(answer);
3173
deadbeefcbecd352015-09-23 11:50:27 -07003174 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3175 session_->video_rtp_transport_channel());
3176}
3177
3178// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3179// audio content in the answer.
3180TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3181 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003182 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003183
3184 PeerConnectionInterface::RTCOfferAnswerOptions options;
3185 options.use_rtp_mux = true;
3186
3187 SessionDescriptionInterface* offer = CreateOffer(options);
3188 SetLocalDescriptionWithoutError(offer);
3189
3190 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3191 session_->video_rtp_transport_channel());
3192
deadbeefab9b2d12015-10-14 11:33:11 -07003193 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003194 cricket::MediaSessionOptions recv_options;
3195 recv_options.recv_audio = false;
3196 recv_options.recv_video = true;
3197 SessionDescriptionInterface* answer =
3198 CreateRemoteAnswer(session_->local_description(), recv_options);
3199 SetRemoteDescriptionWithoutError(answer);
3200
deadbeefd59daf82015-10-14 15:02:44 -07003201 EXPECT_TRUE(nullptr == session_->voice_channel());
3202 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003203
deadbeefd59daf82015-10-14 15:02:44 -07003204 session_->Close();
3205 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3206 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3207 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3208 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003209}
3210
3211// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3212TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3213 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003214 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003215
Donald Curtis0e209b02015-03-24 09:29:54 -07003216 PeerConnectionInterface::RTCOfferAnswerOptions options;
3217 options.use_rtp_mux = true;
3218
3219 SessionDescriptionInterface* offer = CreateOffer(options);
3220 SetLocalDescriptionWithoutError(offer);
3221
deadbeefcbecd352015-09-23 11:50:27 -07003222 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3223 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003224
deadbeefab9b2d12015-10-14 11:33:11 -07003225 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003226
3227 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003228 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003229 CreateRemoteAnswer(session_->local_description()));
3230 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3231 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3232 JsepSessionDescription* modified_answer =
3233 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3234 modified_answer->Initialize(answer_copy, "1", "1");
3235 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003236
deadbeefcbecd352015-09-23 11:50:27 -07003237 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3238 session_->video_rtp_transport_channel());
3239}
3240
3241// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3242TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3243 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003244 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003245
3246 SessionDescriptionInterface* offer = CreateRemoteOffer();
3247 SetRemoteDescriptionWithoutError(offer);
3248
3249 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3250 session_->video_rtp_transport_channel());
3251
deadbeefab9b2d12015-10-14 11:33:11 -07003252 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08003253 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07003254 SetLocalDescriptionWithoutError(answer);
3255
3256 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3257 session_->video_rtp_transport_channel());
3258}
3259
3260// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3261TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3262 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003263 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003264
3265 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07003266 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07003267 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3268 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3269 JsepSessionDescription* modified_offer =
3270 new JsepSessionDescription(JsepSessionDescription::kOffer);
3271 modified_offer->Initialize(offer_copy, "1", "1");
3272
3273 // Expect an error when applying the remote description
3274 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3275 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003276}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003277
Peter Thatcher4eddf182015-04-30 10:55:59 -07003278// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003279TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3280 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003281 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003282
Donald Curtis0e209b02015-03-24 09:29:54 -07003283 PeerConnectionInterface::RTCOfferAnswerOptions options;
3284 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003285
Donald Curtis0e209b02015-03-24 09:29:54 -07003286 SessionDescriptionInterface* offer = CreateOffer(options);
3287 SetLocalDescriptionWithoutError(offer);
3288
deadbeefcbecd352015-09-23 11:50:27 -07003289 EXPECT_NE(session_->voice_rtp_transport_channel(),
3290 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003291
deadbeefab9b2d12015-10-14 11:33:11 -07003292 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003293 SessionDescriptionInterface* answer =
3294 CreateRemoteAnswer(session_->local_description());
3295 SetRemoteDescriptionWithoutError(answer);
3296
3297 // This should lead to an audio-only call but isn't implemented
3298 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003299 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3300 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003301}
3302
deadbeefcbecd352015-09-23 11:50:27 -07003303// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003304TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3305 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003306 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003307 PeerConnectionInterface::RTCOfferAnswerOptions options;
3308 options.use_rtp_mux = true;
3309
3310 SessionDescriptionInterface* offer = CreateOffer(options);
3311 SetLocalDescriptionWithoutError(offer);
3312
deadbeefcbecd352015-09-23 11:50:27 -07003313 EXPECT_NE(session_->voice_rtp_transport_channel(),
3314 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003315
deadbeefab9b2d12015-10-14 11:33:11 -07003316 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003317
3318 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07003319 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07003320 CreateRemoteAnswer(session_->local_description()));
3321 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3322 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3323 JsepSessionDescription* modified_answer =
3324 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3325 modified_answer->Initialize(answer_copy, "1", "1");
3326 SetRemoteDescriptionWithoutError(modified_answer); //
3327
deadbeefcbecd352015-09-23 11:50:27 -07003328 EXPECT_NE(session_->voice_rtp_transport_channel(),
3329 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003330}
3331
Peter Thatcher4eddf182015-04-30 10:55:59 -07003332// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3333TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3334 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003335 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003336
3337 PeerConnectionInterface::RTCOfferAnswerOptions options;
3338 options.use_rtp_mux = true;
3339
3340 SessionDescriptionInterface* offer = CreateOffer(options);
3341 SetRemoteDescriptionWithoutError(offer);
3342
deadbeefcbecd352015-09-23 11:50:27 -07003343 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3344 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003345}
3346
skvlad6c87a672016-05-17 17:49:52 -07003347// Adding a new channel to a BUNDLE which is already connected should directly
3348// assign the bundle transport to the channel, without first setting a
3349// disconnected non-bundle transport and then replacing it. The application
3350// should not receive any changes in the ICE state.
3351TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) {
3352 LoopbackNetworkConfiguration config;
3353 LoopbackNetworkManager loopback_network_manager(this, config);
3354 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain
3355 // connected. Disabling either of these two means that we need to wait for the
3356 // answer to find out if more transports are needed.
3357 configuration_.bundle_policy =
3358 PeerConnectionInterface::kBundlePolicyMaxBundle;
skvlad6c87a672016-05-17 17:49:52 -07003359 options_.disable_encryption = true;
zhihuang4dfb8ce2016-11-23 10:30:12 -08003360 Init(PeerConnectionInterface::kRtcpMuxPolicyRequire);
skvlad6c87a672016-05-17 17:49:52 -07003361
3362 // Negotiate an audio channel with MAX_BUNDLE enabled.
3363 SendAudioOnlyStream2();
3364 SessionDescriptionInterface* offer = CreateOffer();
3365 SetLocalDescriptionWithoutError(offer);
3366 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
3367 observer_.ice_gathering_state_, kIceCandidatesTimeout);
3368 std::string sdp;
3369 offer->ToString(&sdp);
3370 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription(
3371 JsepSessionDescription::kAnswer, sdp, nullptr);
3372 ASSERT_TRUE(answer != NULL);
3373 SetRemoteDescriptionWithoutError(answer);
3374
3375 // Wait for the ICE state to stabilize.
3376 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3377 observer_.ice_connection_state_, kIceCandidatesTimeout);
3378 observer_.ice_connection_state_history_.clear();
3379
3380 // Now add a video channel which should be using the same bundle transport.
3381 SendAudioVideoStream2();
3382 offer = CreateOffer();
3383 offer->ToString(&sdp);
3384 SetLocalDescriptionWithoutError(offer);
3385 answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer,
3386 sdp, nullptr);
3387 ASSERT_TRUE(answer != NULL);
3388 SetRemoteDescriptionWithoutError(answer);
3389
3390 // Wait for ICE state to stabilize
3391 rtc::Thread::Current()->ProcessMessages(0);
3392 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3393 observer_.ice_connection_state_, kIceCandidatesTimeout);
3394
3395 // No ICE state changes are expected to happen.
3396 EXPECT_EQ(0, observer_.ice_connection_state_history_.size());
3397}
3398
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003399TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3400 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003401 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003402
3403 PeerConnectionInterface::RTCOfferAnswerOptions options;
3404 SessionDescriptionInterface* offer = CreateOffer(options);
3405 SetLocalDescriptionWithoutError(offer);
3406
deadbeefcbecd352015-09-23 11:50:27 -07003407 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3408 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003409
deadbeefab9b2d12015-10-14 11:33:11 -07003410 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003411 SessionDescriptionInterface* answer =
3412 CreateRemoteAnswer(session_->local_description());
3413 SetRemoteDescriptionWithoutError(answer);
3414
deadbeefcbecd352015-09-23 11:50:27 -07003415 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3416 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003417}
3418
3419TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3420 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003421 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003422
3423 PeerConnectionInterface::RTCOfferAnswerOptions options;
3424 SessionDescriptionInterface* offer = CreateOffer(options);
3425 SetLocalDescriptionWithoutError(offer);
3426
deadbeefcbecd352015-09-23 11:50:27 -07003427 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3428 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003429
deadbeefab9b2d12015-10-14 11:33:11 -07003430 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003431 SessionDescriptionInterface* answer =
3432 CreateRemoteAnswer(session_->local_description());
3433 SetRemoteDescriptionWithoutError(answer);
3434
deadbeefcbecd352015-09-23 11:50:27 -07003435 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3436 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003437}
3438
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003439// This test verifies that SetLocalDescription and SetRemoteDescription fails
3440// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3441TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003442 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003443 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003444
3445 PeerConnectionInterface::RTCOfferAnswerOptions options;
3446 options.use_rtp_mux = true;
3447
3448 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003449 std::string offer_str;
3450 offer->ToString(&offer_str);
3451 // Disable rtcp-mux
3452 const std::string rtcp_mux = "rtcp-mux";
3453 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003454 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003455 xrtcp_mux.c_str(), xrtcp_mux.length(),
3456 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003457 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003458 new JsepSessionDescription(JsepSessionDescription::kOffer);
3459 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003460 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003461 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003462 new JsepSessionDescription(JsepSessionDescription::kOffer);
3463 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003464 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003465 // Trying unmodified SDP.
3466 SetLocalDescriptionWithoutError(offer);
3467}
3468
jbauchcb560652016-08-04 05:20:32 -07003469TEST_F(WebRtcSessionTest, SetSetupGcm) {
3470 InitWithGcm();
3471 SendAudioVideoStream1();
3472 CreateAndSetRemoteOfferAndLocalAnswer();
3473}
3474
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003475TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3476 TestCanInsertDtmf(false);
3477}
3478
3479TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3480 TestCanInsertDtmf(true);
3481}
3482
3483TEST_F(WebRtcSessionTest, InsertDtmf) {
3484 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003485 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003486 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003487 CreateAndSetRemoteOfferAndLocalAnswer();
3488 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3489 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3490
3491 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003492 const int expected_duration = 90;
3493 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3494 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3495 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3496
3497 // Verify
3498 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003499 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003500 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003501 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003502 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003503 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003504 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003505 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003506}
3507
deadbeefd59daf82015-10-14 15:02:44 -07003508// This test verifies the |initial_offerer| flag when session initiates the
3509// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003510TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003511 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003512 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003513 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003514 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3515 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003516 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003517 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003518 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003519}
3520
deadbeefd59daf82015-10-14 15:02:44 -07003521// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003522TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003523 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003524 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003525 SessionDescriptionInterface* offer = CreateRemoteOffer();
3526 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003527 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003528
deadbeefd59daf82015-10-14 15:02:44 -07003529 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003530 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003531 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003532}
3533
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003534// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3535TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003536 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003537 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003538 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003539 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07003540 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003541 CreateRemoteAnswer(session_->local_description()));
3542
3543 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3544 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003545 JsepSessionDescription* modified_answer =
3546 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003547
3548 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3549 answer->session_id(),
3550 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003551 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003552
wu@webrtc.org4e393072014-04-07 17:04:35 +00003553 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003554 std::string sdp;
3555 EXPECT_TRUE(answer->ToString(&sdp));
3556 const std::string kAudioMid = "a=mid:audio";
3557 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003558 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003559 kAudioMidReplaceStr.c_str(),
3560 kAudioMidReplaceStr.length(),
3561 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003562 SessionDescriptionInterface* modified_answer1 =
3563 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003564 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003565
wu@webrtc.org4e393072014-04-07 17:04:35 +00003566 // Different media types.
3567 EXPECT_TRUE(answer->ToString(&sdp));
3568 const std::string kAudioMline = "m=audio";
3569 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003570 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003571 kAudioMlineReplaceStr.c_str(),
3572 kAudioMlineReplaceStr.length(),
3573 &sdp);
3574 SessionDescriptionInterface* modified_answer2 =
3575 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3576 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3577
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003578 SetRemoteDescriptionWithoutError(answer.release());
3579}
3580
3581// Verifying remote offer and local answer have matching m-lines as per
3582// RFC 3264.
3583TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003584 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003585 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003586 SessionDescriptionInterface* offer = CreateRemoteOffer();
3587 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08003588 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003589
3590 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3591 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003592 JsepSessionDescription* modified_answer =
3593 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003594
3595 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3596 answer->session_id(),
3597 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003598 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003599 SetLocalDescriptionWithoutError(answer);
3600}
3601
3602// This test verifies that WebRtcSession does not start candidate allocation
3603// before SetLocalDescription is called.
3604TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003605 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003606 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003607 SessionDescriptionInterface* offer = CreateRemoteOffer();
3608 cricket::Candidate candidate;
3609 candidate.set_component(1);
3610 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3611 candidate);
3612 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3613 cricket::Candidate candidate1;
3614 candidate1.set_component(1);
3615 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3616 candidate1);
3617 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3618 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003619 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3620 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003621
3622 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003623 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003624 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3625 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3626
htaa2a49d92016-03-04 02:51:39 -08003627 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003628 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003629 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3630}
3631
3632// This test verifies that crypto parameter is updated in local session
3633// description as per security policy set in MediaSessionDescriptionFactory.
3634TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003635 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003636 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003637 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003638
3639 // Making sure SetLocalDescription correctly sets crypto value in
3640 // SessionDescription object after de-serialization of sdp string. The value
3641 // will be set as per MediaSessionDescriptionFactory.
3642 std::string offer_str;
3643 offer->ToString(&offer_str);
3644 SessionDescriptionInterface* jsep_offer_str =
3645 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3646 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003647 EXPECT_TRUE(session_->voice_channel()->srtp_required_for_testing());
3648 EXPECT_TRUE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003649}
3650
3651// This test verifies the crypto parameter when security is disabled.
3652TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003653 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003654 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003655 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003656 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003657
3658 // Making sure SetLocalDescription correctly sets crypto value in
3659 // SessionDescription object after de-serialization of sdp string. The value
3660 // will be set as per MediaSessionDescriptionFactory.
3661 std::string offer_str;
3662 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003663 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003664 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3665 SetLocalDescriptionWithoutError(jsep_offer_str);
deadbeef7af91dd2016-12-13 11:29:11 -08003666 EXPECT_FALSE(session_->voice_channel()->srtp_required_for_testing());
3667 EXPECT_FALSE(session_->video_channel()->srtp_required_for_testing());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003668}
3669
3670// This test verifies that an answer contains new ufrag and password if an offer
3671// with new ufrag and password is received.
3672TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003673 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003674 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003675 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003676 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003677 SetRemoteDescriptionWithoutError(offer.release());
3678
deadbeefab9b2d12015-10-14 11:33:11 -07003679 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003680 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003681 SetLocalDescriptionWithoutError(answer.release());
3682
3683 // Receive an offer with new ufrag and password.
deadbeef0ed85b22016-02-23 17:24:52 -08003684 for (const cricket::ContentInfo& content :
3685 session_->local_description()->description()->contents()) {
3686 options.transport_options[content.name].ice_restart = true;
3687 }
kwibergd1fe2812016-04-27 06:47:29 -07003688 std::unique_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003689 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003690 SetRemoteDescriptionWithoutError(updated_offer1.release());
3691
kwibergd1fe2812016-04-27 06:47:29 -07003692 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003693
deadbeef0ed85b22016-02-23 17:24:52 -08003694 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3695 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003696
deadbeef0ed85b22016-02-23 17:24:52 -08003697 // Even a second answer (created before the description is set) should have
3698 // a new ufrag/password.
kwibergd1fe2812016-04-27 06:47:29 -07003699 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003700
3701 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3702 session_->local_description()->description()));
3703
3704 SetLocalDescriptionWithoutError(updated_answer2.release());
3705}
3706
3707// This test verifies that an answer contains new ufrag and password if an offer
3708// that changes either the ufrag or password (but not both) is received.
3709// RFC 5245 says: "If the offer contained a change in the a=ice-ufrag or
3710// a=ice-pwd attributes compared to the previous SDP from the peer, it
3711// indicates that ICE is restarting for this media stream."
3712TEST_F(WebRtcSessionTest, TestOfferChangingOnlyUfragOrPassword) {
3713 Init();
3714 cricket::MediaSessionOptions options;
3715 options.recv_audio = true;
3716 options.recv_video = true;
3717 // Create an offer with audio and video.
kwibergd1fe2812016-04-27 06:47:29 -07003718 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003719 SetIceUfragPwd(offer.get(), "original_ufrag", "original_password12345");
3720 SetRemoteDescriptionWithoutError(offer.release());
3721
3722 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003723 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003724 SetLocalDescriptionWithoutError(answer.release());
3725
3726 // Receive an offer with a new ufrag but stale password.
kwibergd1fe2812016-04-27 06:47:29 -07003727 std::unique_ptr<JsepSessionDescription> ufrag_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003728 CreateRemoteOffer(options, session_->remote_description()));
3729 SetIceUfragPwd(ufrag_changed_offer.get(), "modified_ufrag",
3730 "original_password12345");
3731 SetRemoteDescriptionWithoutError(ufrag_changed_offer.release());
3732
kwibergd1fe2812016-04-27 06:47:29 -07003733 std::unique_ptr<SessionDescriptionInterface> updated_answer1(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003734 EXPECT_FALSE(IceUfragPwdEqual(updated_answer1->description(),
3735 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003736 SetLocalDescriptionWithoutError(updated_answer1.release());
deadbeef0ed85b22016-02-23 17:24:52 -08003737
3738 // Receive an offer with a new password but stale ufrag.
kwibergd1fe2812016-04-27 06:47:29 -07003739 std::unique_ptr<JsepSessionDescription> password_changed_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003740 CreateRemoteOffer(options, session_->remote_description()));
3741 SetIceUfragPwd(password_changed_offer.get(), "modified_ufrag",
3742 "modified_password12345");
3743 SetRemoteDescriptionWithoutError(password_changed_offer.release());
3744
kwibergd1fe2812016-04-27 06:47:29 -07003745 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003746 EXPECT_FALSE(IceUfragPwdEqual(updated_answer2->description(),
3747 session_->local_description()->description()));
3748 SetLocalDescriptionWithoutError(updated_answer2.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003749}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003750
wu@webrtc.org91053e72013-08-10 07:18:04 +00003751// This test verifies that an answer contains old ufrag and password if an offer
3752// with old ufrag and password is received.
3753TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003754 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003755 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003756 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07003757 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003758 SetRemoteDescriptionWithoutError(offer.release());
3759
deadbeefab9b2d12015-10-14 11:33:11 -07003760 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003761 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003762 SetLocalDescriptionWithoutError(answer.release());
3763
3764 // Receive an offer without changed ufrag or password.
kwibergd1fe2812016-04-27 06:47:29 -07003765 std::unique_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003766 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003767 SetRemoteDescriptionWithoutError(updated_offer2.release());
3768
kwibergd1fe2812016-04-27 06:47:29 -07003769 std::unique_ptr<SessionDescriptionInterface> updated_answer2(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003770
deadbeef0ed85b22016-02-23 17:24:52 -08003771 EXPECT_TRUE(IceUfragPwdEqual(updated_answer2->description(),
3772 session_->local_description()->description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003773
3774 SetLocalDescriptionWithoutError(updated_answer2.release());
3775}
3776
deadbeef0ed85b22016-02-23 17:24:52 -08003777// This test verifies that if an offer does an ICE restart on some, but not all
3778// media sections, the answer will change the ufrag/password in the correct
3779// media sections.
3780TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewAndOldUfragAndPassword) {
3781 Init();
3782 cricket::MediaSessionOptions options;
3783 options.recv_video = true;
3784 options.recv_audio = true;
3785 options.bundle_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07003786 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
deadbeef0ed85b22016-02-23 17:24:52 -08003787
3788 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_AUDIO, "aaaa",
3789 "aaaaaaaaaaaaaaaaaaaaaa");
3790 SetIceUfragPwd(offer.get(), cricket::MEDIA_TYPE_VIDEO, "bbbb",
3791 "bbbbbbbbbbbbbbbbbbbbbb");
3792 SetRemoteDescriptionWithoutError(offer.release());
3793
3794 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07003795 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003796 SetLocalDescriptionWithoutError(answer.release());
3797
3798 // Receive an offer with new ufrag and password, but only for the video media
3799 // section.
kwibergd1fe2812016-04-27 06:47:29 -07003800 std::unique_ptr<JsepSessionDescription> updated_offer(
deadbeef0ed85b22016-02-23 17:24:52 -08003801 CreateRemoteOffer(options, session_->remote_description()));
3802 SetIceUfragPwd(updated_offer.get(), cricket::MEDIA_TYPE_VIDEO, "cccc",
3803 "cccccccccccccccccccccc");
3804 SetRemoteDescriptionWithoutError(updated_offer.release());
3805
kwibergd1fe2812016-04-27 06:47:29 -07003806 std::unique_ptr<SessionDescriptionInterface> updated_answer(CreateAnswer());
deadbeef0ed85b22016-02-23 17:24:52 -08003807
3808 EXPECT_TRUE(IceUfragPwdEqual(updated_answer->description(),
3809 session_->local_description()->description(),
3810 cricket::MEDIA_TYPE_AUDIO));
3811
3812 EXPECT_FALSE(IceUfragPwdEqual(updated_answer->description(),
3813 session_->local_description()->description(),
3814 cricket::MEDIA_TYPE_VIDEO));
3815
3816 SetLocalDescriptionWithoutError(updated_answer.release());
3817}
3818
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003819TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003820 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003821 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003822 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003823 const std::string session_id_orig = offer->session_id();
3824 const std::string session_version_orig = offer->session_version();
3825 SetLocalDescriptionWithoutError(offer);
3826
3827 video_channel_ = media_engine_->GetVideoChannel(0);
3828 video_channel_->set_fail_set_send_codecs(true);
3829
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003830 SessionDescriptionInterface* answer =
3831 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003832 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003833
3834 // Test that after a content error, setting any description will
3835 // result in an error.
3836 video_channel_->set_fail_set_send_codecs(false);
3837 answer = CreateRemoteAnswer(session_->local_description());
3838 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3839 offer = CreateRemoteOffer();
3840 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003841}
3842
3843// Runs the loopback call test with BUNDLE and STUN disabled.
3844TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3845 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003846 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003847 cricket::PORTALLOCATOR_DISABLE_STUN |
3848 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003849 TestLoopbackCall();
3850}
3851
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003852TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003853 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003854 cricket::PORTALLOCATOR_DISABLE_STUN |
3855 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3856 cricket::PORTALLOCATOR_DISABLE_RELAY);
3857
3858 // best connection is IPv6 since it has higher network preference.
3859 LoopbackNetworkConfiguration config;
3860 config.test_ipv6_network_ = true;
3861 config.best_connection_after_initial_ice_converged_ =
3862 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3863
3864 TestLoopbackCall(config);
3865}
3866
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003867// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003868TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003869 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3870 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003871 TestLoopbackCall();
3872}
3873
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003874TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08003875 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003876 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003877 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08003878 ASSERT_TRUE(data_engine_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003879 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3880}
3881
Henrik Boström87713d02015-08-25 09:53:21 +02003882TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003883 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003884
htaa2a49d92016-03-04 02:51:39 -08003885 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00003886 options_.disable_sctp_data_channels = false;
3887
Henrik Boström87713d02015-08-25 09:53:21 +02003888 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003889
3890 SetLocalDescriptionWithDataChannel();
3891 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3892}
3893
Henrik Boström87713d02015-08-25 09:53:21 +02003894TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003895 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003896
Henrik Boström87713d02015-08-25 09:53:21 +02003897 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003898
kwibergd1fe2812016-04-27 06:47:29 -07003899 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003900 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003901 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3902}
3903
Henrik Boström87713d02015-08-25 09:53:21 +02003904TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003905 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003906 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003907 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003908
3909 // Create remote offer with SCTP.
3910 cricket::MediaSessionOptions options;
3911 options.data_channel_type = cricket::DCT_SCTP;
3912 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003913 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003914 SetRemoteDescriptionWithoutError(offer);
3915
3916 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07003917 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003918 EXPECT_TRUE(answer != NULL);
3919 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3920 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003921}
3922
Henrik Boström87713d02015-08-25 09:53:21 +02003923TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08003924 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02003925 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003926
3927 SetLocalDescriptionWithDataChannel();
3928 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3929}
3930
Henrik Boström87713d02015-08-25 09:53:21 +02003931TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003932 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003933
Henrik Boström87713d02015-08-25 09:53:21 +02003934 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003935
3936 SetLocalDescriptionWithDataChannel();
3937 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3938}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003939
Henrik Boström87713d02015-08-25 09:53:21 +02003940TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003941 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003942 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003943 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003944
3945 SetLocalDescriptionWithDataChannel();
3946 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3947}
3948
Henrik Boström87713d02015-08-25 09:53:21 +02003949TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003950 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003951 const int new_send_port = 9998;
3952 const int new_recv_port = 7775;
3953
Henrik Boström87713d02015-08-25 09:53:21 +02003954 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003955 SetFactoryDtlsSrtp();
3956
3957 // By default, don't actually add the codecs to desc_factory_; they don't
3958 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3959 // let the session description get parsed. That'll get the proper codecs
3960 // into the stream.
3961 cricket::MediaSessionOptions options;
3962 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3963 "stream1", new_send_port, options);
3964
3965 // SetRemoteDescription will take the ownership of the offer.
3966 SetRemoteDescriptionWithoutError(offer);
3967
htaa2a49d92016-03-04 02:51:39 -08003968 SessionDescriptionInterface* answer =
3969 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003970 ASSERT_TRUE(answer != NULL);
3971
3972 // Now set the local description, which'll take ownership of the answer.
3973 SetLocalDescriptionWithoutError(answer);
3974
3975 // TEST PLAN: Set the port number to something new, set it in the SDP,
3976 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003977 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003978 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003979
3980 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3981 int portnum = -1;
3982 ASSERT_TRUE(ch != NULL);
3983 ASSERT_EQ(1UL, ch->send_codecs().size());
solenberg9fa49752016-10-08 13:02:44 -07003984 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003985 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003986 ch->send_codecs()[0].name.c_str()));
3987 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3988 &portnum));
3989 EXPECT_EQ(new_send_port, portnum);
3990
3991 ASSERT_EQ(1UL, ch->recv_codecs().size());
solenberg9fa49752016-10-08 13:02:44 -07003992 EXPECT_EQ(cricket::kGoogleSctpDataCodecPlType, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003993 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003994 ch->recv_codecs()[0].name.c_str()));
3995 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3996 &portnum));
3997 EXPECT_EQ(new_recv_port, portnum);
3998}
3999
deadbeefab9b2d12015-10-14 11:33:11 -07004000// Verifies that when a session's DataChannel receives an OPEN message,
4001// WebRtcSession signals the DataChannel creation request with the expected
4002// config.
4003TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
4004 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4005
4006 InitWithDtls(GetParam());
4007
4008 SetLocalDescriptionWithDataChannel();
4009 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
4010
4011 webrtc::DataChannelInit config;
4012 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07004013 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07004014 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
4015 cricket::ReceiveDataParams params;
4016 params.ssrc = config.id;
4017 params.type = cricket::DMT_CONTROL;
4018
4019 cricket::DataChannel* data_channel = session_->data_channel();
4020 data_channel->SignalDataReceived(data_channel, params, payload);
4021
4022 EXPECT_EQ("a", last_data_channel_label_);
4023 EXPECT_EQ(config.id, last_data_channel_config_.id);
4024 EXPECT_FALSE(last_data_channel_config_.negotiated);
4025 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
4026 last_data_channel_config_.open_handshake_role);
4027}
4028
4029TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02004030 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
Henrik Boströmd79599d2016-06-01 13:58:50 +02004031 FakeRTCCertificateGenerator::GenerateCertificate();
Henrik Boströmd8281982015-08-27 10:12:24 +02004032
htaa2a49d92016-03-04 02:51:39 -08004033 configuration_.certificates.push_back(certificate);
4034 Init();
Henrik Boströmd8281982015-08-27 10:12:24 +02004035 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
4036
4037 EXPECT_EQ(session_->certificate_for_testing(), certificate);
4038}
wu@webrtc.org91053e72013-08-10 07:18:04 +00004039
Henrik Boström87713d02015-08-25 09:53:21 +02004040// Verifies that CreateOffer succeeds when CreateOffer is called before async
4041// identity generation is finished (even if a certificate is provided this is
4042// an async op).
4043TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
4044 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
4045 InitWithDtls(GetParam());
4046
Henrik Boströmd8281982015-08-27 10:12:24 +02004047 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07004048 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07004049 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004050
wu@webrtc.org91053e72013-08-10 07:18:04 +00004051 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004052 VerifyNoCryptoParams(offer->description(), true);
4053 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004054}
4055
4056// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02004057// identity generation is finished (even if a certificate is provided this is
4058// an async op).
4059TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004060 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004061 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004062 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004063
4064 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004065 options.recv_video = true;
kwibergd1fe2812016-04-27 06:47:29 -07004066 std::unique_ptr<JsepSessionDescription> offer(
4067 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00004068 ASSERT_TRUE(offer.get() != NULL);
4069 SetRemoteDescriptionWithoutError(offer.release());
4070
kwibergd1fe2812016-04-27 06:47:29 -07004071 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004072 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004073 VerifyNoCryptoParams(answer->description(), true);
4074 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004075}
4076
4077// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02004078// identity generation is finished (even if a certificate is provided this is
4079// an async op).
4080TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004081 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004082 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004083
Henrik Boströmd8281982015-08-27 10:12:24 +02004084 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004085
kwibergd1fe2812016-04-27 06:47:29 -07004086 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004087 EXPECT_TRUE(offer != NULL);
4088}
4089
4090// Verifies that CreateOffer fails when CreateOffer is called after async
4091// identity generation fails.
4092TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004093 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004094 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00004095
Henrik Boströmd8281982015-08-27 10:12:24 +02004096 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004097
kwibergd1fe2812016-04-27 06:47:29 -07004098 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00004099 EXPECT_TRUE(offer == NULL);
4100}
4101
4102// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
4103// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004104TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004105 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004106 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07004107 VerifyMultipleAsyncCreateDescription(GetParam(),
4108 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004109}
4110
4111// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
4112// before async identity generation fails.
4113TEST_F(WebRtcSessionTest,
4114 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004115 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004116 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4117 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004118}
4119
4120// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
4121// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02004122TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00004123 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004124 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004125 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02004126 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004127}
4128
4129// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4130// before async identity generation fails.
4131TEST_F(WebRtcSessionTest,
4132 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004133 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004134 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4135 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004136}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004137
4138// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4139// offer has no SDES crypto but only DTLS fingerprint.
4140TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4141 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004142 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004143 // Create a remote offer with secured transport disabled.
4144 cricket::MediaSessionOptions options;
4145 JsepSessionDescription* offer(CreateRemoteOffer(
4146 options, cricket::SEC_DISABLED));
4147 // Adds a DTLS fingerprint to the remote offer.
4148 cricket::SessionDescription* sdp = offer->description();
4149 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4150 ASSERT_TRUE(audio != NULL);
4151 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4152 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004153 rtc::SSLFingerprint::CreateFromRfc4572(
4154 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004155 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004156 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004157}
4158
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004159TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08004160 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004161 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004162 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004163 SessionDescriptionInterface* offer = CreateOffer();
4164
4165 SetLocalDescriptionWithoutError(offer);
4166
4167 voice_channel_ = media_engine_->GetVoiceChannel(0);
4168
4169 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004170 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004171 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004172}
4173
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004174// Tests that we can renegotiate new media content with ICE candidates in the
4175// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004176TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004177 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004178 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004179 SetFactoryDtlsSrtp();
4180
deadbeefab9b2d12015-10-14 11:33:11 -07004181 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004182 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004183 SetLocalDescriptionWithoutError(offer);
4184
4185 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4186 SetRemoteDescriptionWithoutError(answer);
4187
4188 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004189 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004190 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4191
4192 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004193 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004194 candidate1.set_component(1);
4195 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4196 candidate1);
4197 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4198 SetRemoteDescriptionWithoutError(offer);
4199
htaa2a49d92016-03-04 02:51:39 -08004200 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004201 SetLocalDescriptionWithoutError(answer);
4202}
4203
4204// Tests that we can renegotiate new media content with ICE candidates separated
4205// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004206TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004207 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004208 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004209 SetFactoryDtlsSrtp();
4210
deadbeefab9b2d12015-10-14 11:33:11 -07004211 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004212 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004213 SetLocalDescriptionWithoutError(offer);
4214
4215 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4216 SetRemoteDescriptionWithoutError(answer);
4217
4218 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004219 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004220 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4221 SetRemoteDescriptionWithoutError(offer);
4222
4223 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004224 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004225 candidate1.set_component(1);
4226 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4227 candidate1);
4228 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4229
htaa2a49d92016-03-04 02:51:39 -08004230 answer = CreateAnswer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004231 SetLocalDescriptionWithoutError(answer);
4232}
honghaiz7f777492016-02-02 21:54:01 -08004233
zhihuang9763d562016-08-05 11:14:50 -07004234#ifdef HAVE_QUIC
4235TEST_P(WebRtcSessionTest, TestNegotiateQuic) {
4236 configuration_.enable_quic = true;
4237 InitWithDtls(GetParam());
4238 EXPECT_TRUE(session_->data_channel_type() == cricket::DCT_QUIC);
4239 SessionDescriptionInterface* offer = CreateOffer();
4240 ASSERT_TRUE(offer);
4241 ASSERT_TRUE(offer->description());
4242 SetLocalDescriptionWithoutError(offer);
4243 cricket::MediaSessionOptions options;
4244 options.recv_audio = true;
4245 options.recv_video = true;
4246 SessionDescriptionInterface* answer =
4247 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
4248 ASSERT_TRUE(answer);
4249 ASSERT_TRUE(answer->description());
4250 SetRemoteDescriptionWithoutError(answer);
4251}
4252#endif // HAVE_QUIC
4253
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004254// Tests that RTX codec is removed from the answer when it isn't supported
4255// by local side.
zhihuang3a334652016-05-05 18:37:49 -07004256TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004257 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004258 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004259 std::string offer_sdp(kSdpWithRtx);
4260
4261 SessionDescriptionInterface* offer =
4262 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4263 EXPECT_TRUE(offer->ToString(&offer_sdp));
4264
4265 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07004266 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004267 SetRemoteDescriptionWithoutError(offer);
4268
htaa2a49d92016-03-04 02:51:39 -08004269 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07004270 // Answer SDP does not contain the RTX codec.
4271 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004272 SetLocalDescriptionWithoutError(answer);
4273}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004274
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004275// This verifies that the voice channel after bundle has both options from video
4276// and voice channels.
4277TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4278 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004279 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004280
4281 PeerConnectionInterface::RTCOfferAnswerOptions options;
4282 options.use_rtp_mux = true;
4283
4284 SessionDescriptionInterface* offer = CreateOffer(options);
4285 SetLocalDescriptionWithoutError(offer);
4286
4287 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4288 rtc::Socket::Option::OPT_SNDBUF, 4000);
4289
4290 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4291 rtc::Socket::Option::OPT_RCVBUF, 8000);
4292
4293 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004294 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004295 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4296 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004297 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004298 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4299
deadbeefcbecd352015-09-23 11:50:27 -07004300 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004301 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4302 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004303 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004304 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4305
deadbeefcbecd352015-09-23 11:50:27 -07004306 EXPECT_NE(session_->voice_rtp_transport_channel(),
4307 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004308
deadbeefab9b2d12015-10-14 11:33:11 -07004309 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004310 SessionDescriptionInterface* answer =
4311 CreateRemoteAnswer(session_->local_description());
4312 SetRemoteDescriptionWithoutError(answer);
4313
deadbeefcbecd352015-09-23 11:50:27 -07004314 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004315 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4316 EXPECT_EQ(4000, option_val);
4317
deadbeefcbecd352015-09-23 11:50:27 -07004318 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004319 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4320 EXPECT_EQ(8000, option_val);
4321}
4322
tommi0f620f42015-07-09 03:25:02 -07004323// Test creating a session, request multiple offers, destroy the session
4324// and make sure we got success/failure callbacks for all of the requests.
4325// Background: crbug.com/507307
4326TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4327 Init();
4328
4329 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4330 PeerConnectionInterface::RTCOfferAnswerOptions options;
4331 options.offer_to_receive_audio =
4332 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004333 cricket::MediaSessionOptions session_options;
4334 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004335
4336 for (auto& o : observers) {
4337 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004338 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004339 }
4340
4341 session_.reset();
4342
tommi0f620f42015-07-09 03:25:02 -07004343 for (auto& o : observers) {
4344 // We expect to have received a notification now even if the session was
4345 // terminated. The offer creation may or may not have succeeded, but we
4346 // must have received a notification which, so the only invalid state
4347 // is kInit.
4348 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4349 }
4350}
4351
stefanc1aeaf02015-10-15 07:26:07 -07004352TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4353 TestPacketOptions();
4354}
4355
deadbeef057ecf02016-01-20 14:30:43 -08004356// Make sure the signal from "GetOnDestroyedSignal()" fires when the session
4357// is destroyed.
4358TEST_F(WebRtcSessionTest, TestOnDestroyedSignal) {
4359 Init();
4360 session_.reset();
4361 EXPECT_TRUE(session_destroyed_);
4362}
4363
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004364// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4365// currently fails because upon disconnection and reconnection OnIceComplete is
4366// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004367
deadbeefcbecd352015-09-23 11:50:27 -07004368INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4369 WebRtcSessionTest,
4370 testing::Values(ALREADY_GENERATED,
4371 DTLS_IDENTITY_STORE));