blob: 6dc0fc71cd753b3ad894e30e1463d7df35f6b77e [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2012 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
deadbeefcbecd352015-09-23 11:50:27 -070028#include <vector>
29
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030#include "talk/app/webrtc/audiotrack.h"
jbauchac8869e2015-07-03 01:36:14 -070031#include "talk/app/webrtc/fakemetricsobserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000032#include "talk/app/webrtc/jsepicecandidate.h"
33#include "talk/app/webrtc/jsepsessiondescription.h"
34#include "talk/app/webrtc/mediastreamsignaling.h"
35#include "talk/app/webrtc/streamcollection.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000036#include "talk/app/webrtc/test/fakeconstraints.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020037#include "talk/app/webrtc/test/fakedtlsidentitystore.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000038#include "talk/app/webrtc/test/fakemediastreamsignaling.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000039#include "talk/app/webrtc/videotrack.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040#include "talk/app/webrtc/webrtcsession.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000041#include "talk/app/webrtc/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000042#include "talk/media/base/fakemediaengine.h"
43#include "talk/media/base/fakevideorenderer.h"
44#include "talk/media/base/mediachannel.h"
45#include "talk/media/devices/fakedevicemanager.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000046#include "webrtc/p2p/base/stunserver.h"
47#include "webrtc/p2p/base/teststunserver.h"
48#include "webrtc/p2p/base/testturnserver.h"
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +000049#include "webrtc/p2p/base/transportchannel.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000050#include "webrtc/p2p/client/basicportallocator.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000051#include "talk/session/media/channelmanager.h"
52#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000053#include "webrtc/base/fakenetwork.h"
54#include "webrtc/base/firewallsocketserver.h"
55#include "webrtc/base/gunit.h"
56#include "webrtc/base/logging.h"
57#include "webrtc/base/network.h"
58#include "webrtc/base/physicalsocketserver.h"
59#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020060#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000061#include "webrtc/base/sslstreamadapter.h"
62#include "webrtc/base/stringutils.h"
63#include "webrtc/base/thread.h"
64#include "webrtc/base/virtualsocketserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065
66#define MAYBE_SKIP_TEST(feature) \
67 if (!(feature())) { \
68 LOG(LS_INFO) << "Feature disabled... skipping"; \
69 return; \
70 }
71
72using cricket::BaseSession;
73using cricket::DF_PLAY;
74using cricket::DF_SEND;
75using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000077using rtc::SocketAddress;
78using rtc::scoped_ptr;
79using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000081using webrtc::CreateSessionDescriptionObserver;
82using webrtc::CreateSessionDescriptionRequest;
Henrik Boström5e56c592015-08-11 10:33:13 +020083using webrtc::DtlsIdentityStoreInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084using webrtc::FakeConstraints;
jbauchac8869e2015-07-03 01:36:14 -070085using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086using webrtc::IceCandidateCollection;
87using webrtc::JsepIceCandidate;
88using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000089using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090using webrtc::PeerConnectionInterface;
91using webrtc::SessionDescriptionInterface;
92using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000093using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000094using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000095using webrtc::kCreateChannelFailed;
96using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000098using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000099using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000100using webrtc::kSdpWithoutDtlsFingerprint;
101using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000103using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000104using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000106typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
107
wu@webrtc.org364f2042013-11-20 21:49:41 +0000108static const int kClientAddrPort = 0;
109static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000110static const char kClientIPv6AddrHost1[] =
111 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +0000112static const char kClientAddrHost2[] = "22.22.22.22";
113static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000114static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
115static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000116static const char kTurnUsername[] = "test";
117static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118
119static const char kSessionVersion[] = "1";
120
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121// Media index of candidates belonging to the first media content.
122static const int kMediaContentIndex0 = 0;
123static const char kMediaContentName0[] = "audio";
124
125// Media index of candidates belonging to the second media content.
126static const int kMediaContentIndex1 = 1;
127static const char kMediaContentName1[] = "video";
128
129static const int kIceCandidatesTimeout = 10000;
130
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000131static const char kFakeDtlsFingerprint[] =
132 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
133 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
134
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000135static const char kTooLongIceUfragPwd[] =
136 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
137 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
138 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
139 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
140
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000141static const char kSdpWithRtx[] =
142 "v=0\r\n"
143 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
144 "s=-\r\n"
145 "t=0 0\r\n"
146 "a=msid-semantic: WMS stream1\r\n"
147 "m=video 9 RTP/SAVPF 0 96\r\n"
148 "c=IN IP4 0.0.0.0\r\n"
149 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
150 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
151 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
152 "a=mid:video\r\n"
153 "a=sendrecv\r\n"
154 "a=rtcp-mux\r\n"
155 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
156 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
157 "a=rtpmap:0 fake_video_codec/90000\r\n"
158 "a=rtpmap:96 rtx/90000\r\n"
159 "a=fmtp:96 apt=0\r\n";
160
Henrik Boström87713d02015-08-25 09:53:21 +0200161enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
162
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000163// Add some extra |newlines| to the |message| after |line|.
164static void InjectAfter(const std::string& line,
165 const std::string& newlines,
166 std::string* message) {
167 const std::string tmp = line + newlines;
deadbeefcbecd352015-09-23 11:50:27 -0700168 rtc::replace_substrs(line.c_str(), line.length(), tmp.c_str(), tmp.length(),
169 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000170}
171
172class MockIceObserver : public webrtc::IceObserver {
173 public:
174 MockIceObserver()
175 : oncandidatesready_(false),
176 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
177 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
178 }
179
180 virtual void OnIceConnectionChange(
181 PeerConnectionInterface::IceConnectionState new_state) {
182 ice_connection_state_ = new_state;
183 }
184 virtual void OnIceGatheringChange(
185 PeerConnectionInterface::IceGatheringState new_state) {
186 // We can never transition back to "new".
187 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
188 ice_gathering_state_ = new_state;
189
190 // oncandidatesready_ really means "ICE gathering is complete".
191 // This if statement ensures that this value remains correct when we
192 // transition from kIceGatheringComplete to kIceGatheringGathering.
193 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
194 oncandidatesready_ = false;
195 }
196 }
197
198 // Found a new candidate.
199 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000200 switch (candidate->sdp_mline_index()) {
201 case kMediaContentIndex0:
202 mline_0_candidates_.push_back(candidate->candidate());
203 break;
204 case kMediaContentIndex1:
205 mline_1_candidates_.push_back(candidate->candidate());
206 break;
207 default:
208 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000210
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 // The ICE gathering state should always be Gathering when a candidate is
212 // received (or possibly Completed in the case of the final candidate).
213 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
214 }
215
216 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
217 virtual void OnIceComplete() {
218 EXPECT_FALSE(oncandidatesready_);
219 oncandidatesready_ = true;
220
221 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
222 // be called approximately simultaneously. For ease of testing, this
223 // check additionally requires that they be called in the above order.
224 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
225 ice_gathering_state_);
226 }
227
228 bool oncandidatesready_;
229 std::vector<cricket::Candidate> mline_0_candidates_;
230 std::vector<cricket::Candidate> mline_1_candidates_;
231 PeerConnectionInterface::IceConnectionState ice_connection_state_;
232 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
233};
234
235class WebRtcSessionForTest : public webrtc::WebRtcSession {
236 public:
237 WebRtcSessionForTest(cricket::ChannelManager* cmgr,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000238 rtc::Thread* signaling_thread,
239 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000240 cricket::PortAllocator* port_allocator,
241 webrtc::IceObserver* ice_observer,
242 webrtc::MediaStreamSignaling* mediastream_signaling)
243 : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator,
244 mediastream_signaling) {
245 RegisterIceObserver(ice_observer);
246 }
247 virtual ~WebRtcSessionForTest() {}
248
deadbeefcbecd352015-09-23 11:50:27 -0700249 // Note that these methods are only safe to use if the signaling thread
250 // is the same as the worker thread
251 cricket::TransportChannel* voice_rtp_transport_channel() {
252 return rtp_transport_channel(voice_channel());
253 }
254
255 cricket::TransportChannel* voice_rtcp_transport_channel() {
256 return rtcp_transport_channel(voice_channel());
257 }
258
259 cricket::TransportChannel* video_rtp_transport_channel() {
260 return rtp_transport_channel(video_channel());
261 }
262
263 cricket::TransportChannel* video_rtcp_transport_channel() {
264 return rtcp_transport_channel(video_channel());
265 }
266
267 cricket::TransportChannel* data_rtp_transport_channel() {
268 return rtp_transport_channel(data_channel());
269 }
270
271 cricket::TransportChannel* data_rtcp_transport_channel() {
272 return rtcp_transport_channel(data_channel());
273 }
274
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000275 using webrtc::WebRtcSession::SetAudioPlayout;
276 using webrtc::WebRtcSession::SetAudioSend;
277 using webrtc::WebRtcSession::SetCaptureDevice;
278 using webrtc::WebRtcSession::SetVideoPlayout;
279 using webrtc::WebRtcSession::SetVideoSend;
deadbeefcbecd352015-09-23 11:50:27 -0700280
281 private:
282 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
283 if (!ch) {
284 return nullptr;
285 }
286 return ch->transport_channel();
287 }
288
289 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
290 if (!ch) {
291 return nullptr;
292 }
293 return ch->rtcp_transport_channel();
294 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000295};
296
wu@webrtc.org91053e72013-08-10 07:18:04 +0000297class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000298 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000299 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000300 enum State {
301 kInit,
302 kFailed,
303 kSucceeded,
304 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000305 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000306
307 // CreateSessionDescriptionObserver implementation.
308 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000309 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000310 state_ = kSucceeded;
311 }
312 virtual void OnFailure(const std::string& error) {
313 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000314 }
315
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000316 SessionDescriptionInterface* description() { return description_.get(); }
317
318 SessionDescriptionInterface* ReleaseDescription() {
319 return description_.release();
320 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000321
wu@webrtc.org91053e72013-08-10 07:18:04 +0000322 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323
wu@webrtc.org91053e72013-08-10 07:18:04 +0000324 protected:
325 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326
327 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000328 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000329 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330};
331
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000332class FakeAudioRenderer : public cricket::AudioRenderer {
333 public:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000334 FakeAudioRenderer() : channel_id_(-1), sink_(NULL) {}
335 virtual ~FakeAudioRenderer() {
336 if (sink_)
337 sink_->OnClose();
338 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000339
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000340 void AddChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000341 ASSERT(channel_id_ == -1);
342 channel_id_ = channel_id;
343 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000344 void RemoveChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000345 ASSERT(channel_id == channel_id_);
346 channel_id_ = -1;
347 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000348 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000349
350 int channel_id() const { return channel_id_; }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000351 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000352 private:
353 int channel_id_;
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000354 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000355};
356
Henrik Boström87713d02015-08-25 09:53:21 +0200357class WebRtcSessionTest
358 : public testing::TestWithParam<RTCCertificateGenerationMethod> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000359 protected:
360 // TODO Investigate why ChannelManager crashes, if it's created
361 // after stun_server.
362 WebRtcSessionTest()
363 : media_engine_(new cricket::FakeMediaEngine()),
364 data_engine_(new cricket::FakeDataEngine()),
365 device_manager_(new cricket::FakeDeviceManager()),
366 channel_manager_(new cricket::ChannelManager(
367 media_engine_, data_engine_, device_manager_,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000368 new cricket::CaptureManager(), rtc::Thread::Current())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369 tdesc_factory_(new cricket::TransportDescriptionFactory()),
370 desc_factory_(new cricket::MediaSessionDescriptionFactory(
371 channel_manager_.get(), tdesc_factory_.get())),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000372 pss_(new rtc::PhysicalSocketServer),
373 vss_(new rtc::VirtualSocketServer(pss_.get())),
374 fss_(new rtc::FirewallSocketServer(vss_.get())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000375 ss_scope_(fss_.get()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000376 stun_socket_addr_(rtc::SocketAddress(kStunAddrHost,
wu@webrtc.org364f2042013-11-20 21:49:41 +0000377 cricket::STUN_SERVER_PORT)),
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +0000378 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
379 stun_socket_addr_)),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000380 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
jbauchac8869e2015-07-03 01:36:14 -0700381 mediastream_signaling_(channel_manager_.get()),
382 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000383 cricket::ServerAddresses stun_servers;
384 stun_servers.insert(stun_socket_addr_);
385 allocator_.reset(new cricket::BasicPortAllocator(
386 &network_manager_,
387 stun_servers,
388 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000389 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700390 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000391 EXPECT_TRUE(channel_manager_->Init());
392 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000393 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000394 }
395
396 void AddInterface(const SocketAddress& addr) {
397 network_manager_.AddInterface(addr);
398 }
399
Henrik Boström87713d02015-08-25 09:53:21 +0200400 // If |dtls_identity_store| != null or |rtc_configuration| contains
401 // |certificates| then DTLS will be enabled unless explicitly disabled by
402 // |rtc_configuration| options. When DTLS is enabled a certificate will be
403 // used if provided, otherwise one will be generated using the
404 // |dtls_identity_store|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000405 void Init(
Henrik Boström5e56c592015-08-11 10:33:13 +0200406 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store,
Henrik Lundin64dad832015-05-11 12:44:23 +0200407 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000408 ASSERT_TRUE(session_.get() == NULL);
409 session_.reset(new WebRtcSessionForTest(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000410 channel_manager_.get(), rtc::Thread::Current(),
411 rtc::Thread::Current(), allocator_.get(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000412 &observer_,
413 &mediastream_signaling_));
414
415 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
416 observer_.ice_connection_state_);
417 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
418 observer_.ice_gathering_state_);
419
deadbeefcbecd352015-09-23 11:50:27 -0700420 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
421 dtls_identity_store.Pass(),
422 rtc_configuration));
jbauchac8869e2015-07-03 01:36:14 -0700423 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000424 }
425
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000426 void Init() {
Henrik Lundin64dad832015-05-11 12:44:23 +0200427 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200428 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000429 }
430
431 void InitWithIceTransport(
432 PeerConnectionInterface::IceTransportsType ice_transport_type) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200433 PeerConnectionInterface::RTCConfiguration configuration;
434 configuration.type = ice_transport_type;
Henrik Boström5e56c592015-08-11 10:33:13 +0200435 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000436 }
437
438 void InitWithBundlePolicy(
439 PeerConnectionInterface::BundlePolicy bundle_policy) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200440 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Lundin64dad832015-05-11 12:44:23 +0200441 configuration.bundle_policy = bundle_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200442 Init(nullptr, configuration);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700443 }
444
445 void InitWithRtcpMuxPolicy(
446 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
447 PeerConnectionInterface::RTCConfiguration configuration;
448 configuration.rtcp_mux_policy = rtcp_mux_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200449 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000450 }
451
Henrik Boström87713d02015-08-25 09:53:21 +0200452 // Successfully init with DTLS; with a certificate generated and supplied or
453 // with a store that generates it for us.
454 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
455 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store;
456 PeerConnectionInterface::RTCConfiguration configuration;
457 if (cert_gen_method == ALREADY_GENERATED) {
458 configuration.certificates.push_back(
459 FakeDtlsIdentityStore::GenerateCertificate());
460 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
461 dtls_identity_store.reset(new FakeDtlsIdentityStore());
462 dtls_identity_store->set_should_fail(false);
463 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700464 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200465 }
466 Init(dtls_identity_store.Pass(), configuration);
467 }
468
469 // Init with DTLS with a store that will fail to generate a certificate.
470 void InitWithDtlsIdentityGenFail() {
Henrik Boström5e56c592015-08-11 10:33:13 +0200471 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
472 new FakeDtlsIdentityStore());
Henrik Boström87713d02015-08-25 09:53:21 +0200473 dtls_identity_store->set_should_fail(true);
Henrik Lundin64dad832015-05-11 12:44:23 +0200474 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200475 Init(dtls_identity_store.Pass(), configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000476 }
477
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000478 void InitWithDtmfCodec() {
479 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000480 const cricket::AudioCodec kTelephoneEventCodec(
481 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000482 std::vector<cricket::AudioCodec> codecs;
483 codecs.push_back(kTelephoneEventCodec);
484 media_engine_->SetAudioCodecs(codecs);
485 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000486 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000487 }
488
489 // Creates a local offer and applies it. Starts ice.
490 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
491 // to decide which streams to create.
492 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000493 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000494 SetLocalDescriptionWithoutError(offer);
495 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
496 observer_.ice_gathering_state_,
497 kIceCandidatesTimeout);
498 }
499
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000500 SessionDescriptionInterface* CreateOffer() {
501 PeerConnectionInterface::RTCOfferAnswerOptions options;
502 options.offer_to_receive_audio =
503 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
504
505 return CreateOffer(options);
506 }
507
wu@webrtc.org91053e72013-08-10 07:18:04 +0000508 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000509 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000510 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000511 observer = new WebRtcSessionCreateSDPObserverForTest();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000512 session_->CreateOffer(observer, options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000513 EXPECT_TRUE_WAIT(
514 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000515 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000516 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000517 }
518
519 SessionDescriptionInterface* CreateAnswer(
520 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000521 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000522 = new WebRtcSessionCreateSDPObserverForTest();
523 session_->CreateAnswer(observer, constraints);
524 EXPECT_TRUE_WAIT(
525 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000526 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000527 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000528 }
529
wu@webrtc.org364f2042013-11-20 21:49:41 +0000530 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000531 return (session_->voice_channel() != NULL &&
532 session_->video_channel() != NULL);
533 }
534
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000535 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
536 ASSERT_TRUE(session_.get() != NULL);
537 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
538 ASSERT_TRUE(content != NULL);
539 const cricket::AudioContentDescription* audio_content =
540 static_cast<const cricket::AudioContentDescription*>(
541 content->description);
542 ASSERT_TRUE(audio_content != NULL);
543 ASSERT_EQ(1U, audio_content->cryptos().size());
544 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
545 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
546 audio_content->cryptos()[0].cipher_suite);
547 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
548 audio_content->protocol());
549
550 content = cricket::GetFirstVideoContent(sdp);
551 ASSERT_TRUE(content != NULL);
552 const cricket::VideoContentDescription* video_content =
553 static_cast<const cricket::VideoContentDescription*>(
554 content->description);
555 ASSERT_TRUE(video_content != NULL);
556 ASSERT_EQ(1U, video_content->cryptos().size());
557 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
558 video_content->cryptos()[0].cipher_suite);
559 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
560 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
561 video_content->protocol());
562 }
563
564 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
565 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
566 ASSERT_TRUE(content != NULL);
567 const cricket::AudioContentDescription* audio_content =
568 static_cast<const cricket::AudioContentDescription*>(
569 content->description);
570 ASSERT_TRUE(audio_content != NULL);
571 ASSERT_EQ(0U, audio_content->cryptos().size());
572
573 content = cricket::GetFirstVideoContent(sdp);
574 ASSERT_TRUE(content != NULL);
575 const cricket::VideoContentDescription* video_content =
576 static_cast<const cricket::VideoContentDescription*>(
577 content->description);
578 ASSERT_TRUE(video_content != NULL);
579 ASSERT_EQ(0U, video_content->cryptos().size());
580
581 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700582 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000583 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700584 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000585 video_content->protocol());
586 } else {
587 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
588 audio_content->protocol());
589 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
590 video_content->protocol());
591 }
592 }
593
594 // Set the internal fake description factories to do DTLS-SRTP.
595 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000596 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000597 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000598 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200599 // Confirmed to work with KT_RSA and KT_ECDSA.
Henrik Boström3a14bf32015-08-31 09:27:58 +0200600 tdesc_factory_->set_certificate(rtc::RTCCertificate::Create(
601 rtc::scoped_ptr<rtc::SSLIdentity>(rtc::SSLIdentity::Generate(
602 identity_name, rtc::KT_DEFAULT)).Pass()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000603 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
604 }
605
606 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
607 bool expected) {
608 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
609 ASSERT_TRUE(audio != NULL);
610 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000611 const TransportInfo* video = sdp->GetTransportInfoByName("video");
612 ASSERT_TRUE(video != NULL);
613 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000614 }
615
616 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000617 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000618 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000619 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000620 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000621 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000622 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000623 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000624 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
625 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000626 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000627 // Answer should be NULL as no crypto params in offer.
628 ASSERT_TRUE(answer == NULL);
629 }
630
631 void VerifyAnswerFromCryptoOffer() {
632 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000633 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000634 options.bundle_enabled = true;
635 scoped_ptr<JsepSessionDescription> offer(
636 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
637 ASSERT_TRUE(offer.get() != NULL);
638 VerifyCryptoParams(offer->description());
639 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000640 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000641 ASSERT_TRUE(answer.get() != NULL);
642 VerifyCryptoParams(answer->description());
643 }
644
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000645 void SetAndVerifyNumUnsignalledRecvStreams(
646 int value_set, int value_expected) {
647 constraints_.reset(new FakeConstraints());
648 constraints_->AddOptional(
649 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
650 value_set);
651 session_.reset();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000652 Init();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000653 mediastream_signaling_.SendAudioVideoStream1();
654 SessionDescriptionInterface* offer = CreateOffer();
655
656 SetLocalDescriptionWithoutError(offer);
657
658 video_channel_ = media_engine_->GetVideoChannel(0);
659
660 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -0700661 const cricket::VideoOptions& video_options = video_channel_->options();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000662 EXPECT_EQ(value_expected,
663 video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1));
664 }
665
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000666 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
667 const cricket::SessionDescription* desc2,
668 bool expect_equal) {
669 if (desc1->contents().size() != desc2->contents().size()) {
670 EXPECT_FALSE(expect_equal);
671 return;
672 }
673
674 const cricket::ContentInfos& contents = desc1->contents();
675 cricket::ContentInfos::const_iterator it = contents.begin();
676
677 for (; it != contents.end(); ++it) {
678 const cricket::TransportDescription* transport_desc1 =
679 desc1->GetTransportDescriptionByName(it->name);
680 const cricket::TransportDescription* transport_desc2 =
681 desc2->GetTransportDescriptionByName(it->name);
682 if (!transport_desc1 || !transport_desc2) {
683 EXPECT_FALSE(expect_equal);
684 return;
685 }
686 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
687 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
688 EXPECT_FALSE(expect_equal);
689 return;
690 }
691 }
692 EXPECT_TRUE(expect_equal);
693 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000694
695 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
696 std::string *sdp) {
697 const cricket::SessionDescription* desc = current_desc->description();
698 EXPECT_TRUE(current_desc->ToString(sdp));
699
700 const cricket::ContentInfos& contents = desc->contents();
701 cricket::ContentInfos::const_iterator it = contents.begin();
702 // Replace ufrag and pwd lines with empty strings.
703 for (; it != contents.end(); ++it) {
704 const cricket::TransportDescription* transport_desc =
705 desc->GetTransportDescriptionByName(it->name);
706 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
707 + "\r\n";
708 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
709 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000710 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000711 "", 0,
712 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000713 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000714 "", 0,
715 sdp);
716 }
717 }
718
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000719 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
720 const std::string& modified_ice_ufrag,
721 const std::string& modified_ice_pwd,
722 std::string* sdp) {
723 const cricket::SessionDescription* desc = current_desc->description();
724 EXPECT_TRUE(current_desc->ToString(sdp));
725
726 const cricket::ContentInfos& contents = desc->contents();
727 cricket::ContentInfos::const_iterator it = contents.begin();
728 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
729 // |modified_ice_pwd| strings.
730 for (; it != contents.end(); ++it) {
731 const cricket::TransportDescription* transport_desc =
732 desc->GetTransportDescriptionByName(it->name);
733 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
734 + "\r\n";
735 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
736 + "\r\n";
737 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
738 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000739 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000740 mod_ufrag.c_str(), mod_ufrag.length(),
741 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000742 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000743 mod_pwd.c_str(), mod_pwd.length(),
744 sdp);
745 }
746 }
747
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000748 // Creates a remote offer and and applies it as a remote description,
749 // creates a local answer and applies is as a local description.
750 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
751 // to decide which local and remote streams to create.
752 void CreateAndSetRemoteOfferAndLocalAnswer() {
753 SessionDescriptionInterface* offer = CreateRemoteOffer();
754 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000755 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756 SetLocalDescriptionWithoutError(answer);
757 }
758 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
759 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700760 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000761 }
762 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
763 BaseSession::State expected_state) {
764 SetLocalDescriptionWithoutError(desc);
765 EXPECT_EQ(expected_state, session_->state());
766 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000767 void SetLocalDescriptionExpectError(const std::string& action,
768 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000769 SessionDescriptionInterface* desc) {
770 std::string error;
771 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000772 std::string sdp_type = "local ";
773 sdp_type.append(action);
774 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000775 EXPECT_NE(std::string::npos, error.find(expected_error));
776 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000777 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
778 SessionDescriptionInterface* desc) {
779 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
780 expected_error, desc);
781 }
782 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
783 SessionDescriptionInterface* desc) {
784 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
785 expected_error, desc);
786 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
788 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
789 }
790 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
791 BaseSession::State expected_state) {
792 SetRemoteDescriptionWithoutError(desc);
793 EXPECT_EQ(expected_state, session_->state());
794 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000795 void SetRemoteDescriptionExpectError(const std::string& action,
796 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797 SessionDescriptionInterface* desc) {
798 std::string error;
799 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000800 std::string sdp_type = "remote ";
801 sdp_type.append(action);
802 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000803 EXPECT_NE(std::string::npos, error.find(expected_error));
804 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000805 void SetRemoteDescriptionOfferExpectError(
806 const std::string& expected_error, SessionDescriptionInterface* desc) {
807 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
808 expected_error, desc);
809 }
810 void SetRemoteDescriptionPranswerExpectError(
811 const std::string& expected_error, SessionDescriptionInterface* desc) {
812 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
813 expected_error, desc);
814 }
815 void SetRemoteDescriptionAnswerExpectError(
816 const std::string& expected_error, SessionDescriptionInterface* desc) {
817 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
818 expected_error, desc);
819 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000820
821 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
822 SessionDescriptionInterface** nocrypto_answer) {
823 // Create a SDP without Crypto.
824 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000825 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000826 options.bundle_enabled = true;
827 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
828 ASSERT_TRUE(*offer != NULL);
829 VerifyCryptoParams((*offer)->description());
830
831 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
832 cricket::SEC_DISABLED);
833 EXPECT_TRUE(*nocrypto_answer != NULL);
834 }
835
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000836 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
837 SessionDescriptionInterface** nodtls_answer) {
838 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000839 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000840 options.bundle_enabled = true;
841
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000842 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000843 CreateRemoteOffer(options, cricket::SEC_ENABLED));
844
845 *nodtls_answer =
846 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
847 EXPECT_TRUE(*nodtls_answer != NULL);
848 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
849 VerifyCryptoParams((*nodtls_answer)->description());
850
851 SetFactoryDtlsSrtp();
852 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
853 ASSERT_TRUE(*offer != NULL);
854 VerifyFingerprintStatus((*offer)->description(), true);
855 VerifyCryptoParams((*offer)->description());
856 }
857
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858 JsepSessionDescription* CreateRemoteOfferWithVersion(
859 cricket::MediaSessionOptions options,
860 cricket::SecurePolicy secure_policy,
861 const std::string& session_version,
862 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000863 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000864 const cricket::SessionDescription* cricket_desc = NULL;
865 if (current_desc) {
866 cricket_desc = current_desc->description();
867 session_id = current_desc->session_id();
868 }
869
870 desc_factory_->set_secure(secure_policy);
871 JsepSessionDescription* offer(
872 new JsepSessionDescription(JsepSessionDescription::kOffer));
873 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
874 session_id, session_version)) {
875 delete offer;
876 offer = NULL;
877 }
878 return offer;
879 }
880 JsepSessionDescription* CreateRemoteOffer(
881 cricket::MediaSessionOptions options) {
882 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
883 kSessionVersion, NULL);
884 }
885 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000886 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
887 return CreateRemoteOfferWithVersion(
888 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889 }
890 JsepSessionDescription* CreateRemoteOffer(
891 cricket::MediaSessionOptions options,
892 const SessionDescriptionInterface* current_desc) {
893 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
894 kSessionVersion, current_desc);
895 }
896
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000897 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
898 const char* sctp_stream_name, int new_port,
899 cricket::MediaSessionOptions options) {
900 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000901 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
902 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000903 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
904 }
905
906 // Takes ownership of offer_basis (and deletes it).
907 JsepSessionDescription* ChangeSDPSctpPort(
908 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
909 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
910 // SessionDescription from the mutated string.
911 const char* default_port_str = "5000";
912 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000913 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000914 std::string offer_str;
915 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000916 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000917 new_port_str, strlen(new_port_str),
918 &offer_str);
919 JsepSessionDescription* offer = new JsepSessionDescription(
920 offer_basis->type());
921 delete offer_basis;
922 offer->Initialize(offer_str, NULL);
923 return offer;
924 }
925
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
927 // before this function to decide which streams to create.
928 JsepSessionDescription* CreateRemoteOffer() {
929 cricket::MediaSessionOptions options;
930 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
931 return CreateRemoteOffer(options, session_->remote_description());
932 }
933
934 JsepSessionDescription* CreateRemoteAnswer(
935 const SessionDescriptionInterface* offer,
936 cricket::MediaSessionOptions options,
937 cricket::SecurePolicy policy) {
938 desc_factory_->set_secure(policy);
939 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000940 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941 JsepSessionDescription* answer(
942 new JsepSessionDescription(JsepSessionDescription::kAnswer));
943 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
944 options, NULL),
945 session_id, kSessionVersion)) {
946 delete answer;
947 answer = NULL;
948 }
949 return answer;
950 }
951
952 JsepSessionDescription* CreateRemoteAnswer(
953 const SessionDescriptionInterface* offer,
954 cricket::MediaSessionOptions options) {
955 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
956 }
957
958 // Creates an answer session description with streams based on
959 // |mediastream_signaling_|. Call
960 // mediastream_signaling_.UseOptionsWithStreamX() before this function
961 // to decide which streams to create.
962 JsepSessionDescription* CreateRemoteAnswer(
963 const SessionDescriptionInterface* offer) {
964 cricket::MediaSessionOptions options;
965 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
966 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
967 }
968
969 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000970 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000971 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000972 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000973
974 PeerConnectionInterface::RTCOfferAnswerOptions options;
975 options.use_rtp_mux = bundle;
976
977 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000978 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
979 // and answer.
980 SetLocalDescriptionWithoutError(offer);
981
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000982 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000983 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000984 std::string sdp;
985 EXPECT_TRUE(answer->ToString(&sdp));
986
987 size_t expected_candidate_num = 2;
988 if (!rtcp_mux) {
989 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
990 // for rtp and rtcp.
991 expected_candidate_num = 4;
992 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000993 const std::string kRtcpMux = "a=rtcp-mux";
994 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000995 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000996 kXRtcpMux.c_str(), kXRtcpMux.length(),
997 &sdp);
998 }
999
1000 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1001 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001002
1003 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001004 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001005 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1006 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001007 if (bundle) {
1008 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1009 } else {
1010 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001011 }
1012 }
1013 // Tests that we can only send DTMF when the dtmf codec is supported.
1014 void TestCanInsertDtmf(bool can) {
1015 if (can) {
1016 InitWithDtmfCodec();
1017 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001018 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001019 }
1020 mediastream_signaling_.SendAudioVideoStream1();
1021 CreateAndSetRemoteOfferAndLocalAnswer();
1022 EXPECT_FALSE(session_->CanInsertDtmf(""));
1023 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1024 }
1025
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001026 // Helper class to configure loopback network and verify Best
1027 // Connection using right IP protocol for TestLoopbackCall
1028 // method. LoopbackNetworkManager applies firewall rules to block
1029 // all ping traffic once ICE completed, and remove them to observe
1030 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1031 // verifies the best connection is using the right IP protocol after
1032 // initial ICE convergences.
1033
1034 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001035 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001036 LoopbackNetworkConfiguration()
1037 : test_ipv6_network_(false),
1038 test_extra_ipv4_network_(false),
1039 best_connection_after_initial_ice_converged_(1, 0) {}
1040
1041 // Used to track the expected best connection count in each IP protocol.
1042 struct ExpectedBestConnection {
1043 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1044 : ipv4_count_(ipv4_count),
1045 ipv6_count_(ipv6_count) {}
1046
1047 int ipv4_count_;
1048 int ipv6_count_;
1049 };
1050
1051 bool test_ipv6_network_;
1052 bool test_extra_ipv4_network_;
1053 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1054
1055 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001056 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001057 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1058 }
1059
1060 private:
jbauchac8869e2015-07-03 01:36:14 -07001061 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001062 const ExpectedBestConnection& expected) const {
1063 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001064 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1065 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001066 expected.ipv4_count_);
1067 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001068 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1069 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001070 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001071 // This is used in the loopback call so there is only single host to host
1072 // candidate pair.
1073 EXPECT_EQ(metrics_observer->GetEnumCounter(
1074 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1075 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001076 0);
1077 EXPECT_EQ(metrics_observer->GetEnumCounter(
1078 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1079 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001080 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001081 }
1082 };
1083
1084 class LoopbackNetworkManager {
1085 public:
1086 LoopbackNetworkManager(WebRtcSessionTest* session,
1087 const LoopbackNetworkConfiguration& config)
1088 : config_(config) {
1089 session->AddInterface(
1090 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1091 if (config_.test_extra_ipv4_network_) {
1092 session->AddInterface(
1093 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1094 }
1095 if (config_.test_ipv6_network_) {
1096 session->AddInterface(
1097 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1098 }
1099 }
1100
1101 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1102 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1103 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1104 if (config_.test_extra_ipv4_network_) {
1105 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1106 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1107 }
1108 if (config_.test_ipv6_network_) {
1109 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1110 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1111 }
1112 }
1113
1114 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1115
1116 private:
1117 LoopbackNetworkConfiguration config_;
1118 };
1119
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001120 // The method sets up a call from the session to itself, in a loopback
1121 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001122 // disconnection, and then a permanent disconnection.
1123 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001124 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1125 // While running the call, this method also checks if the session goes through
1126 // the correct sequence of ICE states when a connection is established,
1127 // broken, and re-established.
1128 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001129 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1130 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001131 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001132
1133 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1134 LoopbackNetworkManager loopback_network_manager(this, config);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001135 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001136 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001137 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001138
1139 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1140 observer_.ice_gathering_state_);
1141 SetLocalDescriptionWithoutError(offer);
1142 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1143 observer_.ice_connection_state_);
1144 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
1145 observer_.ice_gathering_state_,
1146 kIceCandidatesTimeout);
1147 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1148 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
1149 observer_.ice_gathering_state_,
1150 kIceCandidatesTimeout);
1151
1152 std::string sdp;
1153 offer->ToString(&sdp);
1154 SessionDescriptionInterface* desc =
jbauchfabe2c92015-07-16 13:43:14 -07001155 webrtc::CreateSessionDescription(
1156 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001157 ASSERT_TRUE(desc != NULL);
1158 SetRemoteDescriptionWithoutError(desc);
1159
1160 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
1161 observer_.ice_connection_state_,
1162 kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001163
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001164 // The ice connection state is "Connected" too briefly to catch in a test.
1165 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001166 observer_.ice_connection_state_,
1167 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001168
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001169 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001170 // Adding firewall rule to block ping requests, which should cause
1171 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001172
1173 loopback_network_manager.ApplyFirewallRules(fss_.get());
1174
1175 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001176 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1177 observer_.ice_connection_state_,
1178 kIceCandidatesTimeout);
1179
jbauchac8869e2015-07-03 01:36:14 -07001180 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001181
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001182 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001183 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001184
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001185 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001186 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001187 observer_.ice_connection_state_,
1188 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001189
1190 // Now we block ping requests and wait until the ICE connection transitions
1191 // to the Failed state. This will take at least 30 seconds because it must
1192 // wait for the Port to timeout.
1193 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001194
1195 loopback_network_manager.ApplyFirewallRules(fss_.get());
1196 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001197 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001198 observer_.ice_connection_state_,
1199 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001200 }
1201
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001202 void TestLoopbackCall() {
1203 LoopbackNetworkConfiguration config;
1204 TestLoopbackCall(config);
1205 }
1206
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001207 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1208 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001209 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1210 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1211
1212 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001213 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1214 codecs.push_back(kCNCodec1);
1215 codecs.push_back(kCNCodec2);
1216 media_engine_->SetAudioCodecs(codecs);
1217 desc_factory_->set_audio_codecs(codecs);
1218 }
1219
1220 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1221 const cricket::ContentDescription* description = content->description;
1222 ASSERT(description != NULL);
1223 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001224 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001225 ASSERT(audio_content_desc != NULL);
1226 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1227 if (audio_content_desc->codecs()[i].name == "CN")
1228 return false;
1229 }
1230 return true;
1231 }
1232
1233 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001234 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001235 dci.reliable = false;
1236 session_->CreateDataChannel("datachannel", &dci);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001237 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001238 SetLocalDescriptionWithoutError(offer);
1239 }
1240
wu@webrtc.org91053e72013-08-10 07:18:04 +00001241 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001242 RTCCertificateGenerationMethod cert_gen_method,
1243 CreateSessionDescriptionRequest::Type type) {
1244 InitWithDtls(cert_gen_method);
1245 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1246 }
1247
1248 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1249 CreateSessionDescriptionRequest::Type type) {
1250 InitWithDtlsIdentityGenFail();
1251 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1252 }
1253
1254 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001255 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001256 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001257 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001258 if (type == CreateSessionDescriptionRequest::kAnswer) {
1259 cricket::MediaSessionOptions options;
1260 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001261 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001262 ASSERT_TRUE(offer.get() != NULL);
1263 SetRemoteDescriptionWithoutError(offer.release());
1264 }
1265
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001266 PeerConnectionInterface::RTCOfferAnswerOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001267 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001268 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001269 observers[kNumber];
1270 for (int i = 0; i < kNumber; ++i) {
1271 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1272 if (type == CreateSessionDescriptionRequest::kOffer) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001273 session_->CreateOffer(observers[i], options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001274 } else {
1275 session_->CreateAnswer(observers[i], NULL);
1276 }
1277 }
1278
1279 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1280 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1281 WebRtcSessionCreateSDPObserverForTest::kFailed;
1282
1283 for (int i = 0; i < kNumber; ++i) {
1284 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1285 if (success) {
1286 EXPECT_TRUE(observers[i]->description() != NULL);
1287 } else {
1288 EXPECT_TRUE(observers[i]->description() == NULL);
1289 }
1290 }
1291 }
1292
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001293 void ConfigureAllocatorWithTurn() {
1294 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1295 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
1296 relay_server.credentials = credentials;
1297 relay_server.ports.push_back(cricket::ProtocolAddress(
1298 kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1299 allocator_->AddRelay(relay_server);
1300 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001301 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001302 }
1303
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001304 cricket::FakeMediaEngine* media_engine_;
1305 cricket::FakeDataEngine* data_engine_;
1306 cricket::FakeDeviceManager* device_manager_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001307 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
1308 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001309 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1310 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1311 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1312 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1313 rtc::SocketServerScope ss_scope_;
1314 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001315 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001316 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001317 rtc::FakeNetworkManager network_manager_;
1318 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001319 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001320 rtc::scoped_ptr<FakeConstraints> constraints_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001321 FakeMediaStreamSignaling mediastream_signaling_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001322 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001323 MockIceObserver observer_;
1324 cricket::FakeVideoMediaChannel* video_channel_;
1325 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001326 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001327};
1328
Henrik Boström87713d02015-08-25 09:53:21 +02001329TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1330 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001331 // SDES is disabled when DTLS is on.
1332 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001333}
1334
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001335TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001336 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001337 // SDES is required if DTLS is off.
1338 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001339}
1340
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001341TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1342 TestSessionCandidatesWithBundleRtcpMux(false, false);
1343}
1344
1345// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1346// with rtcp-mux and/or bundle.
1347TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1348 TestSessionCandidatesWithBundleRtcpMux(false, true);
1349}
1350
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001351TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1352 TestSessionCandidatesWithBundleRtcpMux(true, true);
1353}
1354
1355TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001356 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1357 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001358 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001359 mediastream_signaling_.SendAudioVideoStream1();
1360 InitiateCall();
1361 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1362 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1363 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1364}
1365
1366TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001367 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1368 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001369 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001370 rtc::FP_UDP,
1371 rtc::FD_ANY,
1372 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001373 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001374 mediastream_signaling_.SendAudioVideoStream1();
1375 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001376 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001377 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1378 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1379 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1380}
1381
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001382// Test session delivers no candidates gathered when constraint set to "none".
1383TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1384 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001385 InitWithIceTransport(PeerConnectionInterface::kNone);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001386 mediastream_signaling_.SendAudioVideoStream1();
1387 InitiateCall();
1388 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1389 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1390 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1391}
1392
1393// Test session delivers only relay candidates gathered when constaint set to
1394// "relay".
1395TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1396 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1397 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001398 InitWithIceTransport(PeerConnectionInterface::kRelay);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001399 mediastream_signaling_.SendAudioVideoStream1();
1400 InitiateCall();
1401 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1402 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1403 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1404 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1405 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1406 observer_.mline_0_candidates_[i].type());
1407 }
1408 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1409 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1410 observer_.mline_1_candidates_[i].type());
1411 }
1412}
1413
1414// Test session delivers all candidates gathered when constaint set to "all".
1415TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1416 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001417 InitWithIceTransport(PeerConnectionInterface::kAll);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001418 mediastream_signaling_.SendAudioVideoStream1();
1419 InitiateCall();
1420 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1421 // Host + STUN. By default allocator is disabled to gather relay candidates.
1422 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1423 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1424}
1425
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001426TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001427 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001428 SessionDescriptionInterface* offer = NULL;
1429 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1430 std::string unknown_action;
1431 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1432 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1433}
1434
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001435// Test creating offers and receive answers and make sure the
1436// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001437TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001438 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001439 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001440 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001441 const std::string session_id_orig = offer->session_id();
1442 const std::string session_version_orig = offer->session_version();
1443 SetLocalDescriptionWithoutError(offer);
1444
1445 mediastream_signaling_.SendAudioVideoStream2();
1446 SessionDescriptionInterface* answer =
1447 CreateRemoteAnswer(session_->local_description());
1448 SetRemoteDescriptionWithoutError(answer);
1449
1450 video_channel_ = media_engine_->GetVideoChannel(0);
1451 voice_channel_ = media_engine_->GetVoiceChannel(0);
1452
1453 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1454 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1455
1456 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1457 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1458
1459 ASSERT_EQ(1u, video_channel_->send_streams().size());
1460 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1461 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1462 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1463
1464 // Create new offer without send streams.
1465 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001466 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001467
1468 // Verify the session id is the same and the session version is
1469 // increased.
1470 EXPECT_EQ(session_id_orig, offer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001471 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1472 rtc::FromString<uint64>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001473
1474 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001475 EXPECT_EQ(0u, video_channel_->send_streams().size());
1476 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001477
1478 mediastream_signaling_.SendAudioVideoStream2();
1479 answer = CreateRemoteAnswer(session_->local_description());
1480 SetRemoteDescriptionWithoutError(answer);
1481
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001482 // Make sure the receive streams have not changed.
1483 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1484 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1485 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1486 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1487}
1488
1489// Test receiving offers and creating answers and make sure the
1490// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001491TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001492 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001493 mediastream_signaling_.SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001494 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001495 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001496 SetRemoteDescriptionWithoutError(offer);
1497
1498 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001499 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001500 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001501 SetLocalDescriptionWithoutError(answer);
1502
1503 const std::string session_id_orig = answer->session_id();
1504 const std::string session_version_orig = answer->session_version();
1505
1506 video_channel_ = media_engine_->GetVideoChannel(0);
1507 voice_channel_ = media_engine_->GetVoiceChannel(0);
1508
1509 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1510 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1511
1512 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1513 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1514
1515 ASSERT_EQ(1u, video_channel_->send_streams().size());
1516 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1517 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1518 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1519
1520 mediastream_signaling_.SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001521 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001522 SetRemoteDescriptionWithoutError(offer);
1523
1524 // Answer by turning off all send streams.
1525 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001526 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001527
1528 // Verify the session id is the same and the session version is
1529 // increased.
1530 EXPECT_EQ(session_id_orig, answer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001531 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1532 rtc::FromString<uint64>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001533 SetLocalDescriptionWithoutError(answer);
1534
1535 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1536 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1537 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1538 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1539 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1540 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1541
1542 // Make sure we have no send streams.
1543 EXPECT_EQ(0u, video_channel_->send_streams().size());
1544 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1545}
1546
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001547TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001548 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001549 media_engine_->set_fail_create_channel(true);
1550
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001551 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001552 ASSERT_TRUE(offer != NULL);
1553 // SetRemoteDescription and SetLocalDescription will take the ownership of
1554 // the offer.
1555 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001556 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001557 ASSERT_TRUE(offer != NULL);
1558 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1559}
1560
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001561//
1562// Tests for creating/setting SDP under different SDES/DTLS polices:
1563//
1564// --DTLS off and SDES on
1565// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1566// set local/remote offer/answer with crypto --> success
1567// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1568// failure
1569// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1570// failure
1571// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1572// failure
1573//
1574// --DTLS on and SDES off
1575// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1576// set local/remote offer/answer with DTLS fingerprint --> success
1577// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1578// fingerprint --> failure
1579// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1580// --> failure
1581// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1582// --> failure
1583//
1584// --Encryption disabled: DTLS off and SDES off
1585// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1586// answer without SDES or DTLS --> success
1587// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1588// answer without SDES or DTLS --> success
1589//
1590
1591// Test that we return a failure when applying a remote/local offer that doesn't
1592// have cryptos enabled when DTLS is off.
1593TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001594 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001595 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001596 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001597 JsepSessionDescription* offer = CreateRemoteOffer(
1598 options, cricket::SEC_DISABLED);
1599 ASSERT_TRUE(offer != NULL);
1600 VerifyNoCryptoParams(offer->description(), false);
1601 // SetRemoteDescription and SetLocalDescription will take the ownership of
1602 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001603 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1605 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001606 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607}
1608
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001609// Test that we return a failure when applying a local answer that doesn't have
1610// cryptos enabled when DTLS is off.
1611TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001612 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001613 SessionDescriptionInterface* offer = NULL;
1614 SessionDescriptionInterface* answer = NULL;
1615 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1616 // SetRemoteDescription and SetLocalDescription will take the ownership of
1617 // the offer.
1618 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001619 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001620}
1621
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001622// Test we will return fail when apply an remote answer that doesn't have
1623// crypto enabled when DTLS is off.
1624TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001625 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626 SessionDescriptionInterface* offer = NULL;
1627 SessionDescriptionInterface* answer = NULL;
1628 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1629 // SetRemoteDescription and SetLocalDescription will take the ownership of
1630 // the offer.
1631 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001632 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001633}
1634
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001635// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1636// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001637TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001638 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001639 mediastream_signaling_.SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001640 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001641 SetFactoryDtlsSrtp();
1642 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001643 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001644 JsepSessionDescription* offer =
1645 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001646 ASSERT_TRUE(offer != NULL);
1647 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001648 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001649
1650 // SetRemoteDescription will take the ownership of the offer.
1651 SetRemoteDescriptionWithoutError(offer);
1652
1653 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001654 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001655 ASSERT_TRUE(answer != NULL);
1656 VerifyFingerprintStatus(answer->description(), true);
1657 // Check that we don't have an a=crypto line in the answer.
1658 VerifyNoCryptoParams(answer->description(), true);
1659
1660 // Now set the local description, which should work, even without a=crypto.
1661 SetLocalDescriptionWithoutError(answer);
1662}
1663
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001664// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1665// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001666TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001667 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001668 mediastream_signaling_.SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001669 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001670 SetFactoryDtlsSrtp();
1671
1672 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001673 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001674 ASSERT_TRUE(offer != NULL);
1675 VerifyFingerprintStatus(offer->description(), true);
1676 // Check that we don't have an a=crypto line in the offer.
1677 VerifyNoCryptoParams(offer->description(), true);
1678
1679 // Now set the local description, which should work, even without a=crypto.
1680 SetLocalDescriptionWithoutError(offer);
1681
1682 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001683 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001684 JsepSessionDescription* answer =
1685 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1686 ASSERT_TRUE(answer != NULL);
1687 VerifyFingerprintStatus(answer->description(), true);
1688 VerifyNoCryptoParams(answer->description(), true);
1689
1690 // SetRemoteDescription will take the ownership of the answer.
1691 SetRemoteDescriptionWithoutError(answer);
1692}
1693
1694// Test that if we support DTLS and the other side didn't offer a fingerprint,
1695// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001696TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001697 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001698 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001699 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001700 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001701 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001702 JsepSessionDescription* offer = CreateRemoteOffer(
1703 options, cricket::SEC_REQUIRED);
1704 ASSERT_TRUE(offer != NULL);
1705 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001706 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001707
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001708 // SetRemoteDescription will take the ownership of the offer.
1709 SetRemoteDescriptionOfferExpectError(
1710 kSdpWithoutDtlsFingerprint, offer);
1711
1712 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1713 // SetLocalDescription will take the ownership of the offer.
1714 SetLocalDescriptionOfferExpectError(
1715 kSdpWithoutDtlsFingerprint, offer);
1716}
1717
1718// Test that we return a failure when applying a local answer that doesn't have
1719// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001720TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001721 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001722 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001723 SessionDescriptionInterface* offer = NULL;
1724 SessionDescriptionInterface* answer = NULL;
1725 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1726
1727 // SetRemoteDescription and SetLocalDescription will take the ownership of
1728 // the offer and answer.
1729 SetRemoteDescriptionWithoutError(offer);
1730 SetLocalDescriptionAnswerExpectError(
1731 kSdpWithoutDtlsFingerprint, answer);
1732}
1733
1734// Test that we return a failure when applying a remote answer that doesn't have
1735// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001736TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001737 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001738 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001739 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001740 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001741 options.recv_video = true;
deadbeefcbecd352015-09-23 11:50:27 -07001742 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
1743 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001744 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001745 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001746
1747 // SetRemoteDescription and SetLocalDescription will take the ownership of
1748 // the offer and answer.
1749 SetLocalDescriptionWithoutError(offer);
1750 SetRemoteDescriptionAnswerExpectError(
1751 kSdpWithoutDtlsFingerprint, answer);
1752}
1753
1754// Test that we create a local offer without SDES or DTLS and accept a remote
1755// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001756TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001757 mediastream_signaling_.SendAudioVideoStream1();
1758 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001759 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001760
1761 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001762 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001763 ASSERT_TRUE(offer != NULL);
1764 VerifyFingerprintStatus(offer->description(), false);
1765 // Check that we don't have an a=crypto line in the offer.
1766 VerifyNoCryptoParams(offer->description(), false);
1767
1768 // Now set the local description, which should work, even without a=crypto.
1769 SetLocalDescriptionWithoutError(offer);
1770
1771 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001772 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001773 JsepSessionDescription* answer =
1774 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1775 ASSERT_TRUE(answer != NULL);
1776 VerifyFingerprintStatus(answer->description(), false);
1777 VerifyNoCryptoParams(answer->description(), false);
1778
1779 // SetRemoteDescription will take the ownership of the answer.
1780 SetRemoteDescriptionWithoutError(answer);
1781}
1782
1783// Test that we create a local answer without SDES or DTLS and accept a remote
1784// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001785TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001786 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001787 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001788
1789 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001790 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001791 JsepSessionDescription* offer =
1792 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1793 ASSERT_TRUE(offer != NULL);
1794 VerifyFingerprintStatus(offer->description(), false);
1795 VerifyNoCryptoParams(offer->description(), false);
1796
1797 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798 SetRemoteDescriptionWithoutError(offer);
1799
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001800 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001801 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001802 ASSERT_TRUE(answer != NULL);
1803 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001804 // Check that we don't have an a=crypto line in the answer.
1805 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001806
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001807 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001808 SetLocalDescriptionWithoutError(answer);
1809}
1810
1811TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001812 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001813 mediastream_signaling_.SendNothing();
1814 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001815 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001816 SetLocalDescriptionWithoutError(offer);
1817
1818 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001819 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001820 SetLocalDescriptionWithoutError(offer2);
1821}
1822
1823TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001824 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001825 mediastream_signaling_.SendNothing();
1826 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001827 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001828 SetRemoteDescriptionWithoutError(offer);
1829
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001830 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001831 SetRemoteDescriptionWithoutError(offer2);
1832}
1833
1834TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001835 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001836 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001837 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001838 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001839 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001840 SetRemoteDescriptionOfferExpectError(
1841 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001842}
1843
1844TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001845 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001846 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001847 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001848 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001849 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001850 SetLocalDescriptionOfferExpectError(
1851 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001852}
1853
1854TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001855 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001856 mediastream_signaling_.SendNothing();
1857 SessionDescriptionInterface* offer = CreateRemoteOffer();
1858 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1859
1860 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001861 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001862 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1863 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1864
1865 mediastream_signaling_.SendAudioVideoStream1();
1866 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001867 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001868 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1869
1870 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1871
1872 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001873 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001874 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1875}
1876
1877TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001878 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001879 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001880 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001881 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1882
1883 JsepSessionDescription* pranswer =
1884 CreateRemoteAnswer(session_->local_description());
1885 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1886
1887 SetRemoteDescriptionExpectState(pranswer,
1888 BaseSession::STATE_RECEIVEDPRACCEPT);
1889
1890 mediastream_signaling_.SendAudioVideoStream1();
1891 JsepSessionDescription* pranswer2 =
1892 CreateRemoteAnswer(session_->local_description());
1893 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1894
1895 SetRemoteDescriptionExpectState(pranswer2,
1896 BaseSession::STATE_RECEIVEDPRACCEPT);
1897
1898 mediastream_signaling_.SendAudioVideoStream2();
1899 SessionDescriptionInterface* answer =
1900 CreateRemoteAnswer(session_->local_description());
1901 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1902}
1903
1904TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001905 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001906 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001907 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1908
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001909 SessionDescriptionInterface* answer =
1910 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001911 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1912 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001913}
1914
1915TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001916 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001917 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001918 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1919
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001920 SessionDescriptionInterface* answer =
1921 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001922 SetRemoteDescriptionAnswerExpectError(
1923 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001924}
1925
1926TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001927 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001928 mediastream_signaling_.SendAudioVideoStream1();
1929
1930 cricket::Candidate candidate;
1931 candidate.set_component(1);
1932 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1933
1934 // Fail since we have not set a offer description.
1935 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1936
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001937 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001938 SetLocalDescriptionWithoutError(offer);
1939 // Candidate should be allowed to add before remote description.
1940 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1941 candidate.set_component(2);
1942 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1943 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1944
1945 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1946 session_->local_description());
1947 SetRemoteDescriptionWithoutError(answer);
1948
1949 // Verifying the candidates are copied properly from internal vector.
1950 const SessionDescriptionInterface* remote_desc =
1951 session_->remote_description();
1952 ASSERT_TRUE(remote_desc != NULL);
1953 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1954 const IceCandidateCollection* candidates =
1955 remote_desc->candidates(kMediaContentIndex0);
1956 ASSERT_EQ(2u, candidates->count());
1957 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1958 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1959 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1960 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1961
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001962 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1963 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001964 candidate.set_component(2);
1965 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1966 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001967 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001968
1969 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1970 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1971}
1972
1973// Test that a remote candidate is added to the remote session description and
1974// that it is retained if the remote session description is changed.
1975TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001976 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001977 cricket::Candidate candidate1;
1978 candidate1.set_component(1);
1979 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1980 candidate1);
1981 mediastream_signaling_.SendAudioVideoStream1();
1982 CreateAndSetRemoteOfferAndLocalAnswer();
1983
1984 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1985 const SessionDescriptionInterface* remote_desc =
1986 session_->remote_description();
1987 ASSERT_TRUE(remote_desc != NULL);
1988 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1989 const IceCandidateCollection* candidates =
1990 remote_desc->candidates(kMediaContentIndex0);
1991 ASSERT_EQ(1u, candidates->count());
1992 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1993
1994 // Update the RemoteSessionDescription with a new session description and
1995 // a candidate and check that the new remote session description contains both
1996 // candidates.
1997 SessionDescriptionInterface* offer = CreateRemoteOffer();
1998 cricket::Candidate candidate2;
1999 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2000 candidate2);
2001 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2002 SetRemoteDescriptionWithoutError(offer);
2003
2004 remote_desc = session_->remote_description();
2005 ASSERT_TRUE(remote_desc != NULL);
2006 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2007 candidates = remote_desc->candidates(kMediaContentIndex0);
2008 ASSERT_EQ(2u, candidates->count());
2009 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2010 // Username and password have be updated with the TransportInfo of the
2011 // SessionDescription, won't be equal to the original one.
2012 candidate2.set_username(candidates->at(0)->candidate().username());
2013 candidate2.set_password(candidates->at(0)->candidate().password());
2014 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2015 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2016 // No need to verify the username and password.
2017 candidate1.set_username(candidates->at(1)->candidate().username());
2018 candidate1.set_password(candidates->at(1)->candidate().password());
2019 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2020
2021 // Test that the candidate is ignored if we can add the same candidate again.
2022 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2023}
2024
2025// Test that local candidates are added to the local session description and
2026// that they are retained if the local session description is changed.
2027TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002028 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002029 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002030 mediastream_signaling_.SendAudioVideoStream1();
2031 CreateAndSetRemoteOfferAndLocalAnswer();
2032
2033 const SessionDescriptionInterface* local_desc = session_->local_description();
2034 const IceCandidateCollection* candidates =
2035 local_desc->candidates(kMediaContentIndex0);
2036 ASSERT_TRUE(candidates != NULL);
2037 EXPECT_EQ(0u, candidates->count());
2038
2039 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2040
2041 local_desc = session_->local_description();
2042 candidates = local_desc->candidates(kMediaContentIndex0);
2043 ASSERT_TRUE(candidates != NULL);
2044 EXPECT_LT(0u, candidates->count());
2045 candidates = local_desc->candidates(1);
2046 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002047 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002048
2049 // Update the session descriptions.
2050 mediastream_signaling_.SendAudioVideoStream1();
2051 CreateAndSetRemoteOfferAndLocalAnswer();
2052
2053 local_desc = session_->local_description();
2054 candidates = local_desc->candidates(kMediaContentIndex0);
2055 ASSERT_TRUE(candidates != NULL);
2056 EXPECT_LT(0u, candidates->count());
2057 candidates = local_desc->candidates(1);
2058 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002059 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002060}
2061
2062// Test that we can set a remote session description with remote candidates.
2063TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002064 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002065
2066 cricket::Candidate candidate1;
2067 candidate1.set_component(1);
2068 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2069 candidate1);
2070 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002071 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072
2073 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2074 SetRemoteDescriptionWithoutError(offer);
2075
2076 const SessionDescriptionInterface* remote_desc =
2077 session_->remote_description();
2078 ASSERT_TRUE(remote_desc != NULL);
2079 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2080 const IceCandidateCollection* candidates =
2081 remote_desc->candidates(kMediaContentIndex0);
2082 ASSERT_EQ(1u, candidates->count());
2083 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2084
wu@webrtc.org91053e72013-08-10 07:18:04 +00002085 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002086 SetLocalDescriptionWithoutError(answer);
2087}
2088
2089// Test that offers and answers contains ice candidates when Ice candidates have
2090// been gathered.
2091TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002092 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002093 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002094 mediastream_signaling_.SendAudioVideoStream1();
2095 // Ice is started but candidates are not provided until SetLocalDescription
2096 // is called.
2097 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2098 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2099 CreateAndSetRemoteOfferAndLocalAnswer();
2100 // Wait until at least one local candidate has been collected.
2101 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2102 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002104 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2105
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002106 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2107 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108
2109 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2110 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002111 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002112 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2113 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002114 SetLocalDescriptionWithoutError(answer);
2115}
2116
2117// Verifies TransportProxy and media channels are created with content names
2118// present in the SessionDescription.
2119TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002120 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002121 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002122 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002123
2124 // CreateOffer creates session description with the content names "audio" and
2125 // "video". Goal is to modify these content names and verify transport channel
2126 // proxy in the BaseSession, as proxies are created with the content names
2127 // present in SDP.
2128 std::string sdp;
2129 EXPECT_TRUE(offer->ToString(&sdp));
2130 const std::string kAudioMid = "a=mid:audio";
2131 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2132 const std::string kVideoMid = "a=mid:video";
2133 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2134
2135 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002136 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137 kAudioMidReplaceStr.c_str(),
2138 kAudioMidReplaceStr.length(),
2139 &sdp);
2140 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002141 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002142 kVideoMidReplaceStr.c_str(),
2143 kVideoMidReplaceStr.length(),
2144 &sdp);
2145
2146 SessionDescriptionInterface* modified_offer =
2147 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2148
2149 SetRemoteDescriptionWithoutError(modified_offer);
2150
2151 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002152 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002153 SetLocalDescriptionWithoutError(answer);
2154
deadbeefcbecd352015-09-23 11:50:27 -07002155 cricket::TransportChannel* voice_transport_channel =
2156 session_->voice_rtp_transport_channel();
2157 EXPECT_TRUE(voice_transport_channel != NULL);
2158 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2159 cricket::TransportChannel* video_transport_channel =
2160 session_->video_rtp_transport_channel();
2161 EXPECT_TRUE(video_transport_channel != NULL);
2162 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2164 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2165}
2166
2167// Test that an offer contains the correct media content descriptions based on
2168// the send streams when no constraints have been set.
2169TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002170 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002171 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2172
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002173 ASSERT_TRUE(offer != NULL);
2174 const cricket::ContentInfo* content =
2175 cricket::GetFirstAudioContent(offer->description());
2176 EXPECT_TRUE(content != NULL);
2177 content = cricket::GetFirstVideoContent(offer->description());
2178 EXPECT_TRUE(content == NULL);
2179}
2180
2181// Test that an offer contains the correct media content descriptions based on
2182// the send streams when no constraints have been set.
2183TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002184 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002185 // Test Audio only offer.
2186 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002187 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2188
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002189 const cricket::ContentInfo* content =
2190 cricket::GetFirstAudioContent(offer->description());
2191 EXPECT_TRUE(content != NULL);
2192 content = cricket::GetFirstVideoContent(offer->description());
2193 EXPECT_TRUE(content == NULL);
2194
2195 // Test Audio / Video offer.
2196 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002197 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002198 content = cricket::GetFirstAudioContent(offer->description());
2199 EXPECT_TRUE(content != NULL);
2200 content = cricket::GetFirstVideoContent(offer->description());
2201 EXPECT_TRUE(content != NULL);
2202}
2203
2204// Test that an offer contains no media content descriptions if
2205// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2206TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002207 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002208 PeerConnectionInterface::RTCOfferAnswerOptions options;
2209 options.offer_to_receive_audio = 0;
2210 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002211
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002212 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002213 CreateOffer(options));
2214
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002215 ASSERT_TRUE(offer != NULL);
2216 const cricket::ContentInfo* content =
2217 cricket::GetFirstAudioContent(offer->description());
2218 EXPECT_TRUE(content == NULL);
2219 content = cricket::GetFirstVideoContent(offer->description());
2220 EXPECT_TRUE(content == NULL);
2221}
2222
2223// Test that an offer contains only audio media content descriptions if
2224// kOfferToReceiveAudio constraints are set to true.
2225TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002226 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002227 PeerConnectionInterface::RTCOfferAnswerOptions options;
2228 options.offer_to_receive_audio =
2229 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2230
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002231 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002232 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002233
2234 const cricket::ContentInfo* content =
2235 cricket::GetFirstAudioContent(offer->description());
2236 EXPECT_TRUE(content != NULL);
2237 content = cricket::GetFirstVideoContent(offer->description());
2238 EXPECT_TRUE(content == NULL);
2239}
2240
2241// Test that an offer contains audio and video media content descriptions if
2242// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2243TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002244 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002245 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002246 PeerConnectionInterface::RTCOfferAnswerOptions options;
2247 options.offer_to_receive_audio =
2248 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2249 options.offer_to_receive_video =
2250 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2251
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002252 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002253 CreateOffer(options));
2254
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002255 const cricket::ContentInfo* content =
2256 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002257 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002258
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002259 content = cricket::GetFirstVideoContent(offer->description());
2260 EXPECT_TRUE(content != NULL);
2261
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002262 // Sets constraints to false and verifies that audio/video contents are
2263 // removed.
2264 options.offer_to_receive_audio = 0;
2265 options.offer_to_receive_video = 0;
2266 offer.reset(CreateOffer(options));
2267
2268 content = cricket::GetFirstAudioContent(offer->description());
2269 EXPECT_TRUE(content == NULL);
2270 content = cricket::GetFirstVideoContent(offer->description());
2271 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002272}
2273
2274// Test that an answer can not be created if the last remote description is not
2275// an offer.
2276TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002277 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002278 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002279 SetLocalDescriptionWithoutError(offer);
2280 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2281 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002282 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002283}
2284
2285// Test that an answer contains the correct media content descriptions when no
2286// constraints have been set.
2287TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002288 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002289 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002290 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002291 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002292 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002293 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002294 const cricket::ContentInfo* content =
2295 cricket::GetFirstAudioContent(answer->description());
2296 ASSERT_TRUE(content != NULL);
2297 EXPECT_FALSE(content->rejected);
2298
2299 content = cricket::GetFirstVideoContent(answer->description());
2300 ASSERT_TRUE(content != NULL);
2301 EXPECT_FALSE(content->rejected);
2302}
2303
2304// Test that an answer contains the correct media content descriptions when no
2305// constraints have been set and the offer only contain audio.
2306TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002307 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002308 // Create a remote offer with audio only.
2309 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002310
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002311 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002312 CreateRemoteOffer(options));
2313 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2314 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2315
2316 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002317 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002318 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002319 const cricket::ContentInfo* content =
2320 cricket::GetFirstAudioContent(answer->description());
2321 ASSERT_TRUE(content != NULL);
2322 EXPECT_FALSE(content->rejected);
2323
2324 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2325}
2326
2327// Test that an answer contains the correct media content descriptions when no
2328// constraints have been set.
2329TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002330 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002331 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002332 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002333 SetRemoteDescriptionWithoutError(offer.release());
2334 // Test with a stream with tracks.
2335 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002336 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002337 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002338 const cricket::ContentInfo* content =
2339 cricket::GetFirstAudioContent(answer->description());
2340 ASSERT_TRUE(content != NULL);
2341 EXPECT_FALSE(content->rejected);
2342
2343 content = cricket::GetFirstVideoContent(answer->description());
2344 ASSERT_TRUE(content != NULL);
2345 EXPECT_FALSE(content->rejected);
2346}
2347
2348// Test that an answer contains the correct media content descriptions when
2349// constraints have been set but no stream is sent.
2350TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002351 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002352 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002353 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002354 SetRemoteDescriptionWithoutError(offer.release());
2355
2356 webrtc::FakeConstraints constraints_no_receive;
2357 constraints_no_receive.SetMandatoryReceiveAudio(false);
2358 constraints_no_receive.SetMandatoryReceiveVideo(false);
2359
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002360 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002361 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002362 const cricket::ContentInfo* content =
2363 cricket::GetFirstAudioContent(answer->description());
2364 ASSERT_TRUE(content != NULL);
2365 EXPECT_TRUE(content->rejected);
2366
2367 content = cricket::GetFirstVideoContent(answer->description());
2368 ASSERT_TRUE(content != NULL);
2369 EXPECT_TRUE(content->rejected);
2370}
2371
2372// Test that an answer contains the correct media content descriptions when
2373// constraints have been set and streams are sent.
2374TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002375 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002376 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002377 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002378 SetRemoteDescriptionWithoutError(offer.release());
2379
2380 webrtc::FakeConstraints constraints_no_receive;
2381 constraints_no_receive.SetMandatoryReceiveAudio(false);
2382 constraints_no_receive.SetMandatoryReceiveVideo(false);
2383
2384 // Test with a stream with tracks.
2385 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002386 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002387 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002388
2389 // TODO(perkj): Should the direction be set to SEND_ONLY?
2390 const cricket::ContentInfo* content =
2391 cricket::GetFirstAudioContent(answer->description());
2392 ASSERT_TRUE(content != NULL);
2393 EXPECT_FALSE(content->rejected);
2394
2395 // TODO(perkj): Should the direction be set to SEND_ONLY?
2396 content = cricket::GetFirstVideoContent(answer->description());
2397 ASSERT_TRUE(content != NULL);
2398 EXPECT_FALSE(content->rejected);
2399}
2400
2401TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2402 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002403 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002404 PeerConnectionInterface::RTCOfferAnswerOptions options;
2405 options.offer_to_receive_audio =
2406 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2407 options.voice_activity_detection = false;
2408
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002409 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002410 CreateOffer(options));
2411
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002412 const cricket::ContentInfo* content =
2413 cricket::GetFirstAudioContent(offer->description());
2414 EXPECT_TRUE(content != NULL);
2415 EXPECT_TRUE(VerifyNoCNCodecs(content));
2416}
2417
2418TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2419 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002420 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002421 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002422 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002423 SetRemoteDescriptionWithoutError(offer.release());
2424
2425 webrtc::FakeConstraints constraints;
2426 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002427 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002428 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002429 const cricket::ContentInfo* content =
2430 cricket::GetFirstAudioContent(answer->description());
2431 ASSERT_TRUE(content != NULL);
2432 EXPECT_TRUE(VerifyNoCNCodecs(content));
2433}
2434
2435// This test verifies the call setup when remote answer with audio only and
2436// later updates with video.
2437TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002438 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002439 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2440 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2441
2442 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002443 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002444
2445 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002446 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2447
2448 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2449 // and answer;
2450 SetLocalDescriptionWithoutError(offer);
2451 SetRemoteDescriptionWithoutError(answer);
2452
2453 video_channel_ = media_engine_->GetVideoChannel(0);
2454 voice_channel_ = media_engine_->GetVoiceChannel(0);
2455
2456 ASSERT_TRUE(video_channel_ == NULL);
2457
2458 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2459 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2460 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2461
2462 // Let the remote end update the session descriptions, with Audio and Video.
2463 mediastream_signaling_.SendAudioVideoStream2();
2464 CreateAndSetRemoteOfferAndLocalAnswer();
2465
2466 video_channel_ = media_engine_->GetVideoChannel(0);
2467 voice_channel_ = media_engine_->GetVoiceChannel(0);
2468
2469 ASSERT_TRUE(video_channel_ != NULL);
2470 ASSERT_TRUE(voice_channel_ != NULL);
2471
2472 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2473 ASSERT_EQ(1u, video_channel_->send_streams().size());
2474 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2475 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2476 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2477 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2478 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2479 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2480
2481 // Change session back to audio only.
2482 mediastream_signaling_.UseOptionsAudioOnly();
2483 CreateAndSetRemoteOfferAndLocalAnswer();
2484
2485 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2486 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2487 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2488 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2489 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2490}
2491
2492// This test verifies the call setup when remote answer with video only and
2493// later updates with audio.
2494TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002495 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002496 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2497 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2498 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002499 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002500
2501 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002502 options.recv_audio = false;
2503 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002504 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2505 offer, options, cricket::SEC_ENABLED);
2506
2507 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2508 // and answer.
2509 SetLocalDescriptionWithoutError(offer);
2510 SetRemoteDescriptionWithoutError(answer);
2511
2512 video_channel_ = media_engine_->GetVideoChannel(0);
2513 voice_channel_ = media_engine_->GetVoiceChannel(0);
2514
2515 ASSERT_TRUE(voice_channel_ == NULL);
2516 ASSERT_TRUE(video_channel_ != NULL);
2517
2518 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2519 ASSERT_EQ(1u, video_channel_->send_streams().size());
2520 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2521
2522 // Update the session descriptions, with Audio and Video.
2523 mediastream_signaling_.SendAudioVideoStream2();
2524 CreateAndSetRemoteOfferAndLocalAnswer();
2525
2526 voice_channel_ = media_engine_->GetVoiceChannel(0);
2527 ASSERT_TRUE(voice_channel_ != NULL);
2528
2529 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2530 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2531 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2532 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2533
2534 // Change session back to video only.
2535 mediastream_signaling_.UseOptionsVideoOnly();
2536 CreateAndSetRemoteOfferAndLocalAnswer();
2537
2538 video_channel_ = media_engine_->GetVideoChannel(0);
2539 voice_channel_ = media_engine_->GetVoiceChannel(0);
2540
2541 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2542 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2543 ASSERT_EQ(1u, video_channel_->send_streams().size());
2544 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2545}
2546
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002547TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002548 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002549 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002550 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002551 VerifyCryptoParams(offer->description());
2552 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002553 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002554 VerifyCryptoParams(answer->description());
2555}
2556
2557TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002558 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002559 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002560 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002561 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002562 VerifyNoCryptoParams(offer->description(), false);
2563}
2564
2565TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002566 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002567 VerifyAnswerFromNonCryptoOffer();
2568}
2569
2570TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002571 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002572 VerifyAnswerFromCryptoOffer();
2573}
2574
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002575// This test verifies that setLocalDescription fails if
2576// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2577TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002578 Init();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002579 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002580 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2581
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002582 std::string sdp;
2583 RemoveIceUfragPwdLines(offer.get(), &sdp);
2584 SessionDescriptionInterface* modified_offer =
2585 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002586 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002587}
2588
2589// This test verifies that setRemoteDescription fails if
2590// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2591TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002592 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002593 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002594 std::string sdp;
2595 RemoveIceUfragPwdLines(offer.get(), &sdp);
2596 SessionDescriptionInterface* modified_offer =
2597 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002598 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002599}
2600
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002601// This test verifies that setLocalDescription fails if local offer has
2602// too short ice ufrag and pwd strings.
2603TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002604 Init();
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002605 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002606 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2607
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002608 std::string sdp;
2609 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2610 // recommended values of 4 and 22 bytes respectively.
2611 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2612 SessionDescriptionInterface* modified_offer =
2613 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2614 std::string error;
2615 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2616
2617 // Test with string greater than 256.
2618 sdp.clear();
2619 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2620 &sdp);
2621 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2622 NULL);
2623 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2624}
2625
2626// This test verifies that setRemoteDescription fails if remote offer has
2627// too short ice ufrag and pwd strings.
2628TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002629 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002630 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002631 std::string sdp;
2632 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2633 // recommended values of 4 and 22 bytes respectively.
2634 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2635 SessionDescriptionInterface* modified_offer =
2636 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2637 std::string error;
2638 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2639
2640 sdp.clear();
2641 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2642 &sdp);
2643 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2644 NULL);
2645 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2646}
2647
honghaiz503726c2015-07-31 12:37:38 -07002648// Test that if the remote description indicates the peer requested ICE restart
2649// (via a new ufrag or pwd), the old ICE candidates are not copied,
2650// and vice versa.
2651TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithIceRestart) {
2652 Init();
2653 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2654
2655 // Create the first offer.
2656 std::string sdp;
2657 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2658 "abcdefghijklmnopqrstuvwx", &sdp);
2659 SessionDescriptionInterface* offer1 =
2660 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2661 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2662 0, "", "", "relay", 0, "");
2663 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2664 candidate1);
2665 EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1));
2666 SetRemoteDescriptionWithoutError(offer1);
2667 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2668
2669 // The second offer has the same ufrag and pwd but different address.
2670 sdp.clear();
2671 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2672 "abcdefghijklmnopqrstuvwx", &sdp);
2673 SessionDescriptionInterface* offer2 =
2674 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2675 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2676 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2677 candidate1);
2678 EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2));
2679 SetRemoteDescriptionWithoutError(offer2);
2680 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2681
2682 // The third offer has a different ufrag and different address.
2683 sdp.clear();
2684 ModifyIceUfragPwdLines(offer.get(), "0123456789012333",
2685 "abcdefghijklmnopqrstuvwx", &sdp);
2686 SessionDescriptionInterface* offer3 =
2687 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2688 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2689 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2690 candidate1);
2691 EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3));
2692 SetRemoteDescriptionWithoutError(offer3);
2693 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2694
2695 // The fourth offer has no candidate but a different ufrag/pwd.
2696 sdp.clear();
2697 ModifyIceUfragPwdLines(offer.get(), "0123456789012444",
2698 "abcdefghijklmnopqrstuvyz", &sdp);
2699 SessionDescriptionInterface* offer4 =
2700 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2701 SetRemoteDescriptionWithoutError(offer4);
2702 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2703}
2704
Donald Curtisd4f769d2015-05-28 09:48:21 -07002705// Test that candidates sent to the "video" transport do not get pushed down to
2706// the "audio" transport channel when bundling using TransportProxy.
2707TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2708 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2709
2710 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2711 mediastream_signaling_.SendAudioVideoStream1();
2712
2713 PeerConnectionInterface::RTCOfferAnswerOptions options;
2714 options.use_rtp_mux = true;
2715
2716 SessionDescriptionInterface* offer = CreateRemoteOffer();
2717 SetRemoteDescriptionWithoutError(offer);
2718
2719 SessionDescriptionInterface* answer = CreateAnswer(NULL);
2720 SetLocalDescriptionWithoutError(answer);
2721
deadbeefcbecd352015-09-23 11:50:27 -07002722 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2723 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002724
deadbeefcbecd352015-09-23 11:50:27 -07002725 cricket::BaseChannel* voice_channel = session_->voice_channel();
2726 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002727
2728 // Checks if one of the transport channels contains a connection using a given
2729 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002730 auto connection_with_remote_port = [this, voice_channel](int port) {
2731 cricket::SessionStats stats;
2732 session_->GetChannelTransportStats(voice_channel, &stats);
2733 for (auto& kv : stats.transport_stats) {
2734 for (auto& chan_stat : kv.second.channel_stats) {
2735 for (auto& conn_info : chan_stat.connection_infos) {
2736 if (conn_info.remote_candidate.address().port() == port) {
2737 return true;
2738 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002739 }
2740 }
2741 }
2742 return false;
2743 };
2744
2745 EXPECT_FALSE(connection_with_remote_port(5000));
2746 EXPECT_FALSE(connection_with_remote_port(5001));
2747 EXPECT_FALSE(connection_with_remote_port(6000));
2748
2749 // The way the *_WAIT checks work is they only wait if the condition fails,
2750 // which does not help in the case where state is not changing. This is
2751 // problematic in this test since we want to verify that adding a video
2752 // candidate does _not_ change state. So we interleave candidates and assume
2753 // that messages are executed in the order they were posted.
2754
2755 // First audio candidate.
2756 cricket::Candidate candidate0;
2757 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2758 candidate0.set_component(1);
2759 candidate0.set_protocol("udp");
2760 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2761 candidate0);
2762 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2763
2764 // Video candidate.
2765 cricket::Candidate candidate1;
2766 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2767 candidate1.set_component(1);
2768 candidate1.set_protocol("udp");
2769 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2770 candidate1);
2771 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2772
2773 // Second audio candidate.
2774 cricket::Candidate candidate2;
2775 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
2776 candidate2.set_component(1);
2777 candidate2.set_protocol("udp");
2778 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2779 candidate2);
2780 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2781
2782 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
2783 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
2784
2785 // No need here for a _WAIT check since we are checking that state hasn't
2786 // changed: if this is false we would be doing waits for nothing and if this
2787 // is true then there will be no messages processed anyways.
2788 EXPECT_FALSE(connection_with_remote_port(6000));
2789}
2790
deadbeefcbecd352015-09-23 11:50:27 -07002791// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002792TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
2793 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002794 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002795
2796 PeerConnectionInterface::RTCOfferAnswerOptions options;
2797 options.use_rtp_mux = true;
2798
2799 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002800 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07002801
deadbeefcbecd352015-09-23 11:50:27 -07002802 EXPECT_NE(session_->voice_rtp_transport_channel(),
2803 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002804
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002805 mediastream_signaling_.SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002806 SessionDescriptionInterface* answer =
2807 CreateRemoteAnswer(session_->local_description());
2808 SetRemoteDescriptionWithoutError(answer);
2809
deadbeefcbecd352015-09-23 11:50:27 -07002810 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2811 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002812}
2813
deadbeefcbecd352015-09-23 11:50:27 -07002814// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07002815TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
2816 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2817 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002818
Donald Curtis0e209b02015-03-24 09:29:54 -07002819 PeerConnectionInterface::RTCOfferAnswerOptions options;
2820 options.use_rtp_mux = true;
2821
2822 SessionDescriptionInterface* offer = CreateOffer(options);
2823 SetLocalDescriptionWithoutError(offer);
2824
deadbeefcbecd352015-09-23 11:50:27 -07002825 EXPECT_NE(session_->voice_rtp_transport_channel(),
2826 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002827
2828 mediastream_signaling_.SendAudioVideoStream2();
2829
2830 // Remove BUNDLE from the answer.
2831 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2832 CreateRemoteAnswer(session_->local_description()));
2833 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2834 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2835 JsepSessionDescription* modified_answer =
2836 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2837 modified_answer->Initialize(answer_copy, "1", "1");
2838 SetRemoteDescriptionWithoutError(modified_answer); //
2839
deadbeefcbecd352015-09-23 11:50:27 -07002840 EXPECT_NE(session_->voice_rtp_transport_channel(),
2841 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002842}
2843
2844// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
2845TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
2846 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2847 mediastream_signaling_.SendAudioVideoStream1();
2848
2849 PeerConnectionInterface::RTCOfferAnswerOptions options;
2850 options.use_rtp_mux = true;
2851
2852 SessionDescriptionInterface* offer = CreateOffer(options);
2853 SetLocalDescriptionWithoutError(offer);
2854
deadbeefcbecd352015-09-23 11:50:27 -07002855 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2856 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002857
2858 mediastream_signaling_.SendAudioVideoStream2();
2859 SessionDescriptionInterface* answer =
2860 CreateRemoteAnswer(session_->local_description());
2861 SetRemoteDescriptionWithoutError(answer);
2862
deadbeefcbecd352015-09-23 11:50:27 -07002863 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2864 session_->video_rtp_transport_channel());
2865}
2866
2867// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
2868// audio content in the answer.
2869TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
2870 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2871 mediastream_signaling_.SendAudioVideoStream1();
2872
2873 PeerConnectionInterface::RTCOfferAnswerOptions options;
2874 options.use_rtp_mux = true;
2875
2876 SessionDescriptionInterface* offer = CreateOffer(options);
2877 SetLocalDescriptionWithoutError(offer);
2878
2879 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2880 session_->video_rtp_transport_channel());
2881
2882 mediastream_signaling_.SendAudioVideoStream2();
2883 cricket::MediaSessionOptions recv_options;
2884 recv_options.recv_audio = false;
2885 recv_options.recv_video = true;
2886 SessionDescriptionInterface* answer =
2887 CreateRemoteAnswer(session_->local_description(), recv_options);
2888 SetRemoteDescriptionWithoutError(answer);
2889
2890 EXPECT_TRUE(NULL == session_->voice_channel());
2891 EXPECT_TRUE(NULL != session_->video_rtp_transport_channel());
2892
2893 session_->Terminate();
2894 EXPECT_TRUE(NULL == session_->voice_rtp_transport_channel());
2895 EXPECT_TRUE(NULL == session_->voice_rtcp_transport_channel());
2896 EXPECT_TRUE(NULL == session_->video_rtp_transport_channel());
2897 EXPECT_TRUE(NULL == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002898}
2899
2900// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
2901TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
2902 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2903 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002904
Donald Curtis0e209b02015-03-24 09:29:54 -07002905 PeerConnectionInterface::RTCOfferAnswerOptions options;
2906 options.use_rtp_mux = true;
2907
2908 SessionDescriptionInterface* offer = CreateOffer(options);
2909 SetLocalDescriptionWithoutError(offer);
2910
deadbeefcbecd352015-09-23 11:50:27 -07002911 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2912 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002913
2914 mediastream_signaling_.SendAudioVideoStream2();
2915
2916 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002917 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002918 CreateRemoteAnswer(session_->local_description()));
2919 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2920 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2921 JsepSessionDescription* modified_answer =
2922 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2923 modified_answer->Initialize(answer_copy, "1", "1");
2924 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002925
deadbeefcbecd352015-09-23 11:50:27 -07002926 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2927 session_->video_rtp_transport_channel());
2928}
2929
2930// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
2931TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
2932 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2933 mediastream_signaling_.SendAudioVideoStream1();
2934
2935 SessionDescriptionInterface* offer = CreateRemoteOffer();
2936 SetRemoteDescriptionWithoutError(offer);
2937
2938 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2939 session_->video_rtp_transport_channel());
2940
2941 mediastream_signaling_.SendAudioVideoStream2();
2942 SessionDescriptionInterface* answer = CreateAnswer(nullptr);
2943 SetLocalDescriptionWithoutError(answer);
2944
2945 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2946 session_->video_rtp_transport_channel());
2947}
2948
2949// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
2950TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
2951 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2952 mediastream_signaling_.SendAudioVideoStream1();
2953
2954 // Remove BUNDLE from the offer.
2955 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2956 cricket::SessionDescription* offer_copy = offer->description()->Copy();
2957 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2958 JsepSessionDescription* modified_offer =
2959 new JsepSessionDescription(JsepSessionDescription::kOffer);
2960 modified_offer->Initialize(offer_copy, "1", "1");
2961
2962 // Expect an error when applying the remote description
2963 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
2964 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07002965}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002966
Peter Thatcher4eddf182015-04-30 10:55:59 -07002967// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002968TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
2969 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2970 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002971
Donald Curtis0e209b02015-03-24 09:29:54 -07002972 PeerConnectionInterface::RTCOfferAnswerOptions options;
2973 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002974
Donald Curtis0e209b02015-03-24 09:29:54 -07002975 SessionDescriptionInterface* offer = CreateOffer(options);
2976 SetLocalDescriptionWithoutError(offer);
2977
deadbeefcbecd352015-09-23 11:50:27 -07002978 EXPECT_NE(session_->voice_rtp_transport_channel(),
2979 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002980
2981 mediastream_signaling_.SendAudioVideoStream2();
2982 SessionDescriptionInterface* answer =
2983 CreateRemoteAnswer(session_->local_description());
2984 SetRemoteDescriptionWithoutError(answer);
2985
2986 // This should lead to an audio-only call but isn't implemented
2987 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07002988 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2989 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002990}
2991
deadbeefcbecd352015-09-23 11:50:27 -07002992// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07002993TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
2994 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2995 mediastream_signaling_.SendAudioVideoStream1();
2996 PeerConnectionInterface::RTCOfferAnswerOptions options;
2997 options.use_rtp_mux = true;
2998
2999 SessionDescriptionInterface* offer = CreateOffer(options);
3000 SetLocalDescriptionWithoutError(offer);
3001
deadbeefcbecd352015-09-23 11:50:27 -07003002 EXPECT_NE(session_->voice_rtp_transport_channel(),
3003 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003004
3005 mediastream_signaling_.SendAudioVideoStream2();
3006
3007 // Remove BUNDLE from the answer.
3008 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3009 CreateRemoteAnswer(session_->local_description()));
3010 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3011 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3012 JsepSessionDescription* modified_answer =
3013 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3014 modified_answer->Initialize(answer_copy, "1", "1");
3015 SetRemoteDescriptionWithoutError(modified_answer); //
3016
deadbeefcbecd352015-09-23 11:50:27 -07003017 EXPECT_NE(session_->voice_rtp_transport_channel(),
3018 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003019}
3020
Peter Thatcher4eddf182015-04-30 10:55:59 -07003021// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3022TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3023 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
3024 mediastream_signaling_.SendAudioVideoStream1();
3025
3026 PeerConnectionInterface::RTCOfferAnswerOptions options;
3027 options.use_rtp_mux = true;
3028
3029 SessionDescriptionInterface* offer = CreateOffer(options);
3030 SetRemoteDescriptionWithoutError(offer);
3031
deadbeefcbecd352015-09-23 11:50:27 -07003032 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3033 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003034}
3035
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003036TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3037 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
3038 mediastream_signaling_.SendAudioVideoStream1();
3039
3040 PeerConnectionInterface::RTCOfferAnswerOptions options;
3041 SessionDescriptionInterface* offer = CreateOffer(options);
3042 SetLocalDescriptionWithoutError(offer);
3043
deadbeefcbecd352015-09-23 11:50:27 -07003044 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3045 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003046
3047 mediastream_signaling_.SendAudioVideoStream2();
3048 SessionDescriptionInterface* answer =
3049 CreateRemoteAnswer(session_->local_description());
3050 SetRemoteDescriptionWithoutError(answer);
3051
deadbeefcbecd352015-09-23 11:50:27 -07003052 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3053 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003054}
3055
3056TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3057 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
3058 mediastream_signaling_.SendAudioVideoStream1();
3059
3060 PeerConnectionInterface::RTCOfferAnswerOptions options;
3061 SessionDescriptionInterface* offer = CreateOffer(options);
3062 SetLocalDescriptionWithoutError(offer);
3063
deadbeefcbecd352015-09-23 11:50:27 -07003064 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3065 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003066
3067 mediastream_signaling_.SendAudioVideoStream2();
3068 SessionDescriptionInterface* answer =
3069 CreateRemoteAnswer(session_->local_description());
3070 SetRemoteDescriptionWithoutError(answer);
3071
deadbeefcbecd352015-09-23 11:50:27 -07003072 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3073 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003074}
3075
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003076// This test verifies that SetLocalDescription and SetRemoteDescription fails
3077// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3078TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003079 Init();
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003080 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003081
3082 PeerConnectionInterface::RTCOfferAnswerOptions options;
3083 options.use_rtp_mux = true;
3084
3085 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003086 std::string offer_str;
3087 offer->ToString(&offer_str);
3088 // Disable rtcp-mux
3089 const std::string rtcp_mux = "rtcp-mux";
3090 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003091 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003092 xrtcp_mux.c_str(), xrtcp_mux.length(),
3093 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003094 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003095 new JsepSessionDescription(JsepSessionDescription::kOffer);
3096 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003097 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003098 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003099 new JsepSessionDescription(JsepSessionDescription::kOffer);
3100 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003101 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003102 // Trying unmodified SDP.
3103 SetLocalDescriptionWithoutError(offer);
3104}
3105
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003106TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003107 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003108 mediastream_signaling_.SendAudioVideoStream1();
3109 CreateAndSetRemoteOfferAndLocalAnswer();
3110 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3111 ASSERT_TRUE(channel != NULL);
3112 ASSERT_EQ(1u, channel->recv_streams().size());
3113 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
3114 double left_vol, right_vol;
3115 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
3116 EXPECT_EQ(1, left_vol);
3117 EXPECT_EQ(1, right_vol);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003118 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003119 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003120 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
3121 EXPECT_EQ(0, left_vol);
3122 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003123 EXPECT_EQ(0, renderer->channel_id());
3124 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003125 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
3126 EXPECT_EQ(1, left_vol);
3127 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003128 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003129}
3130
3131TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003132 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003133 mediastream_signaling_.SendAudioVideoStream1();
3134 CreateAndSetRemoteOfferAndLocalAnswer();
3135 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3136 ASSERT_TRUE(channel != NULL);
3137 ASSERT_EQ(1u, channel->send_streams().size());
3138 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3139 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3140
3141 cricket::AudioOptions options;
3142 options.echo_cancellation.Set(true);
3143
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003144 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003145 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003146 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3147 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003148 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003149 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003150
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003151 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003152 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003153 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3154 bool value;
3155 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
3156 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003157 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003158 EXPECT_TRUE(renderer->sink() == NULL);
3159}
3160
3161TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003162 Init();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003163 mediastream_signaling_.SendAudioVideoStream1();
3164 CreateAndSetRemoteOfferAndLocalAnswer();
3165 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3166 ASSERT_TRUE(channel != NULL);
3167 ASSERT_EQ(1u, channel->send_streams().size());
3168 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3169
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003170 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003171 cricket::AudioOptions options;
3172 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3173 EXPECT_TRUE(renderer->sink() != NULL);
3174
3175 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3176 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3177 // SetSink(NULL) callback afterwards.
3178 renderer.reset();
3179
3180 // This will trigger SetSink(NULL) if no OnClose() callback.
3181 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003182}
3183
3184TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003185 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003186 mediastream_signaling_.SendAudioVideoStream1();
3187 CreateAndSetRemoteOfferAndLocalAnswer();
3188 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3189 ASSERT_TRUE(channel != NULL);
3190 ASSERT_LT(0u, channel->renderers().size());
3191 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3192 ASSERT_EQ(1u, channel->recv_streams().size());
3193 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
3194 cricket::FakeVideoRenderer renderer;
3195 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
3196 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
3197 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
3198 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3199}
3200
3201TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003202 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003203 mediastream_signaling_.SendAudioVideoStream1();
3204 CreateAndSetRemoteOfferAndLocalAnswer();
3205 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3206 ASSERT_TRUE(channel != NULL);
3207 ASSERT_EQ(1u, channel->send_streams().size());
3208 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3209 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3210 cricket::VideoOptions* options = NULL;
3211 session_->SetVideoSend(send_ssrc, false, options);
3212 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3213 session_->SetVideoSend(send_ssrc, true, options);
3214 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3215}
3216
3217TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3218 TestCanInsertDtmf(false);
3219}
3220
3221TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3222 TestCanInsertDtmf(true);
3223}
3224
3225TEST_F(WebRtcSessionTest, InsertDtmf) {
3226 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003227 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003228 mediastream_signaling_.SendAudioVideoStream1();
3229 CreateAndSetRemoteOfferAndLocalAnswer();
3230 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3231 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3232
3233 // Insert DTMF
3234 const int expected_flags = DF_SEND;
3235 const int expected_duration = 90;
3236 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3237 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3238 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3239
3240 // Verify
3241 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
3242 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3243 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
3244 expected_duration, expected_flags));
3245 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
3246 expected_duration, expected_flags));
3247 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
3248 expected_duration, expected_flags));
3249}
3250
3251// This test verifies the |initiator| flag when session initiates the call.
3252TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003253 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003254 EXPECT_FALSE(session_->initiator());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003255 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003256 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3257 SetLocalDescriptionWithoutError(offer);
3258 EXPECT_TRUE(session_->initiator());
3259 SetRemoteDescriptionWithoutError(answer);
3260 EXPECT_TRUE(session_->initiator());
3261}
3262
3263// This test verifies the |initiator| flag when session receives the call.
3264TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003265 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003266 EXPECT_FALSE(session_->initiator());
3267 SessionDescriptionInterface* offer = CreateRemoteOffer();
3268 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003269 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003270
3271 EXPECT_FALSE(session_->initiator());
3272 SetLocalDescriptionWithoutError(answer);
3273 EXPECT_FALSE(session_->initiator());
3274}
3275
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003276// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3277TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003278 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003279 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003280 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003281 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003282 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003283 CreateRemoteAnswer(session_->local_description()));
3284
3285 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3286 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003287 JsepSessionDescription* modified_answer =
3288 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003289
3290 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3291 answer->session_id(),
3292 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003293 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003294
wu@webrtc.org4e393072014-04-07 17:04:35 +00003295 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003296 std::string sdp;
3297 EXPECT_TRUE(answer->ToString(&sdp));
3298 const std::string kAudioMid = "a=mid:audio";
3299 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003300 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003301 kAudioMidReplaceStr.c_str(),
3302 kAudioMidReplaceStr.length(),
3303 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003304 SessionDescriptionInterface* modified_answer1 =
3305 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003306 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003307
wu@webrtc.org4e393072014-04-07 17:04:35 +00003308 // Different media types.
3309 EXPECT_TRUE(answer->ToString(&sdp));
3310 const std::string kAudioMline = "m=audio";
3311 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003312 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003313 kAudioMlineReplaceStr.c_str(),
3314 kAudioMlineReplaceStr.length(),
3315 &sdp);
3316 SessionDescriptionInterface* modified_answer2 =
3317 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3318 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3319
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003320 SetRemoteDescriptionWithoutError(answer.release());
3321}
3322
3323// Verifying remote offer and local answer have matching m-lines as per
3324// RFC 3264.
3325TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003326 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003327 mediastream_signaling_.SendAudioVideoStream1();
3328 SessionDescriptionInterface* offer = CreateRemoteOffer();
3329 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003330 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003331
3332 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3333 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003334 JsepSessionDescription* modified_answer =
3335 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003336
3337 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3338 answer->session_id(),
3339 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003340 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003341 SetLocalDescriptionWithoutError(answer);
3342}
3343
3344// This test verifies that WebRtcSession does not start candidate allocation
3345// before SetLocalDescription is called.
3346TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003347 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003348 mediastream_signaling_.SendAudioVideoStream1();
3349 SessionDescriptionInterface* offer = CreateRemoteOffer();
3350 cricket::Candidate candidate;
3351 candidate.set_component(1);
3352 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3353 candidate);
3354 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3355 cricket::Candidate candidate1;
3356 candidate1.set_component(1);
3357 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3358 candidate1);
3359 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3360 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003361 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3362 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003363
3364 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003365 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003366 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3367 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3368
wu@webrtc.org91053e72013-08-10 07:18:04 +00003369 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003370 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003371 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3372}
3373
3374// This test verifies that crypto parameter is updated in local session
3375// description as per security policy set in MediaSessionDescriptionFactory.
3376TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003377 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003378 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003379 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003380
3381 // Making sure SetLocalDescription correctly sets crypto value in
3382 // SessionDescription object after de-serialization of sdp string. The value
3383 // will be set as per MediaSessionDescriptionFactory.
3384 std::string offer_str;
3385 offer->ToString(&offer_str);
3386 SessionDescriptionInterface* jsep_offer_str =
3387 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3388 SetLocalDescriptionWithoutError(jsep_offer_str);
3389 EXPECT_TRUE(session_->voice_channel()->secure_required());
3390 EXPECT_TRUE(session_->video_channel()->secure_required());
3391}
3392
3393// This test verifies the crypto parameter when security is disabled.
3394TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003395 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003396 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003397 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003398 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003399
3400 // Making sure SetLocalDescription correctly sets crypto value in
3401 // SessionDescription object after de-serialization of sdp string. The value
3402 // will be set as per MediaSessionDescriptionFactory.
3403 std::string offer_str;
3404 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003405 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003406 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3407 SetLocalDescriptionWithoutError(jsep_offer_str);
3408 EXPECT_FALSE(session_->voice_channel()->secure_required());
3409 EXPECT_FALSE(session_->video_channel()->secure_required());
3410}
3411
3412// This test verifies that an answer contains new ufrag and password if an offer
3413// with new ufrag and password is received.
3414TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003415 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003416 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003417 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003418 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003419 CreateRemoteOffer(options));
3420 SetRemoteDescriptionWithoutError(offer.release());
3421
3422 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003423 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003424 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003425 SetLocalDescriptionWithoutError(answer.release());
3426
3427 // Receive an offer with new ufrag and password.
3428 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003429 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003430 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003431 SetRemoteDescriptionWithoutError(updated_offer1.release());
3432
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003433 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003434 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003435
3436 CompareIceUfragAndPassword(updated_answer1->description(),
3437 session_->local_description()->description(),
3438 false);
3439
3440 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003441}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003442
wu@webrtc.org91053e72013-08-10 07:18:04 +00003443// This test verifies that an answer contains old ufrag and password if an offer
3444// with old ufrag and password is received.
3445TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003446 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003447 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003448 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003449 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003450 CreateRemoteOffer(options));
3451 SetRemoteDescriptionWithoutError(offer.release());
3452
3453 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003454 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003455 CreateAnswer(NULL));
3456 SetLocalDescriptionWithoutError(answer.release());
3457
3458 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003459 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003460 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003461 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003462 SetRemoteDescriptionWithoutError(updated_offer2.release());
3463
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003464 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003465 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003466
3467 CompareIceUfragAndPassword(updated_answer2->description(),
3468 session_->local_description()->description(),
3469 true);
3470
3471 SetLocalDescriptionWithoutError(updated_answer2.release());
3472}
3473
3474TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003475 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003476 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003477 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003478 const std::string session_id_orig = offer->session_id();
3479 const std::string session_version_orig = offer->session_version();
3480 SetLocalDescriptionWithoutError(offer);
3481
3482 video_channel_ = media_engine_->GetVideoChannel(0);
3483 video_channel_->set_fail_set_send_codecs(true);
3484
3485 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003486 SessionDescriptionInterface* answer =
3487 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003488 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003489}
3490
3491// Runs the loopback call test with BUNDLE and STUN disabled.
3492TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3493 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003494 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003495 cricket::PORTALLOCATOR_DISABLE_STUN |
3496 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003497 TestLoopbackCall();
3498}
3499
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003500TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003501 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003502 cricket::PORTALLOCATOR_DISABLE_STUN |
3503 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3504 cricket::PORTALLOCATOR_DISABLE_RELAY);
3505
3506 // best connection is IPv6 since it has higher network preference.
3507 LoopbackNetworkConfiguration config;
3508 config.test_ipv6_network_ = true;
3509 config.best_connection_after_initial_ice_converged_ =
3510 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3511
3512 TestLoopbackCall(config);
3513}
3514
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003515// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003516TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003517 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3518 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003519 TestLoopbackCall();
3520}
3521
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003522TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003523 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003524 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003525 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003526
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003527 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
3528 std::string error_code_str = "ERROR_CONTENT";
3529 std::string error_desc = "Fake session error description.";
3530 session_->SetError(error_code, error_desc);
3531
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003532 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
3533 SessionDescriptionInterface* answer =
3534 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003535
3536 std::string action;
3537 std::ostringstream session_error_msg;
3538 session_error_msg << kSessionError << error_code_str << ". ";
3539 session_error_msg << kSessionErrorDesc << error_desc << ".";
3540 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
3541 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003542}
3543
3544TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3545 constraints_.reset(new FakeConstraints());
3546 constraints_->AddOptional(
3547 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003548 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003549
3550 SetLocalDescriptionWithDataChannel();
3551 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3552}
3553
Henrik Boström87713d02015-08-25 09:53:21 +02003554TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003555 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003556
3557 constraints_.reset(new FakeConstraints());
3558 constraints_->AddOptional(
3559 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003560 options_.disable_sctp_data_channels = false;
3561
Henrik Boström87713d02015-08-25 09:53:21 +02003562 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003563
3564 SetLocalDescriptionWithDataChannel();
3565 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3566}
3567
Henrik Boström87713d02015-08-25 09:53:21 +02003568TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003569 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003570
Henrik Boström87713d02015-08-25 09:53:21 +02003571 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003572
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003573 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003574 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003575 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3576}
3577
Henrik Boström87713d02015-08-25 09:53:21 +02003578TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003579 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003580 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003581 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003582
3583 // Create remote offer with SCTP.
3584 cricket::MediaSessionOptions options;
3585 options.data_channel_type = cricket::DCT_SCTP;
3586 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003587 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003588 SetRemoteDescriptionWithoutError(offer);
3589
3590 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003591 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003592 EXPECT_TRUE(answer != NULL);
3593 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3594 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003595}
3596
Henrik Boström87713d02015-08-25 09:53:21 +02003597TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003598 constraints_.reset(new FakeConstraints());
3599 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003600 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
Henrik Boström87713d02015-08-25 09:53:21 +02003601 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003602
3603 SetLocalDescriptionWithDataChannel();
3604 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3605}
3606
Henrik Boström87713d02015-08-25 09:53:21 +02003607TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003608 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003609
Henrik Boström87713d02015-08-25 09:53:21 +02003610 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003611
3612 SetLocalDescriptionWithDataChannel();
3613 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3614}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003615
Henrik Boström87713d02015-08-25 09:53:21 +02003616TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003617 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003618 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003619 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003620
3621 SetLocalDescriptionWithDataChannel();
3622 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3623}
3624
Henrik Boström87713d02015-08-25 09:53:21 +02003625TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003626 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003627 const int new_send_port = 9998;
3628 const int new_recv_port = 7775;
3629
Henrik Boström87713d02015-08-25 09:53:21 +02003630 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003631 SetFactoryDtlsSrtp();
3632
3633 // By default, don't actually add the codecs to desc_factory_; they don't
3634 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3635 // let the session description get parsed. That'll get the proper codecs
3636 // into the stream.
3637 cricket::MediaSessionOptions options;
3638 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3639 "stream1", new_send_port, options);
3640
3641 // SetRemoteDescription will take the ownership of the offer.
3642 SetRemoteDescriptionWithoutError(offer);
3643
3644 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3645 new_recv_port, CreateAnswer(NULL));
3646 ASSERT_TRUE(answer != NULL);
3647
3648 // Now set the local description, which'll take ownership of the answer.
3649 SetLocalDescriptionWithoutError(answer);
3650
3651 // TEST PLAN: Set the port number to something new, set it in the SDP,
3652 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003653 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003654 dci.reliable = true;
3655 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003656 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003657 session_->CreateDataChannel("datachannel", &dci);
3658
3659 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3660 int portnum = -1;
3661 ASSERT_TRUE(ch != NULL);
3662 ASSERT_EQ(1UL, ch->send_codecs().size());
3663 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003664 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003665 ch->send_codecs()[0].name.c_str()));
3666 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3667 &portnum));
3668 EXPECT_EQ(new_send_port, portnum);
3669
3670 ASSERT_EQ(1UL, ch->recv_codecs().size());
3671 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003672 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003673 ch->recv_codecs()[0].name.c_str()));
3674 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3675 &portnum));
3676 EXPECT_EQ(new_recv_port, portnum);
3677}
3678
Henrik Boströmd8281982015-08-27 10:12:24 +02003679TEST_F(WebRtcSessionTest, TestUsesProvidedCertificate) {
3680 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
3681 FakeDtlsIdentityStore::GenerateCertificate();
3682
3683 PeerConnectionInterface::RTCConfiguration configuration;
3684 configuration.certificates.push_back(certificate);
3685 Init(nullptr, configuration);
3686 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3687
3688 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3689}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003690
Henrik Boström87713d02015-08-25 09:53:21 +02003691// Verifies that CreateOffer succeeds when CreateOffer is called before async
3692// identity generation is finished (even if a certificate is provided this is
3693// an async op).
3694TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3695 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3696 InitWithDtls(GetParam());
3697
Henrik Boströmd8281982015-08-27 10:12:24 +02003698 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003699 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003700 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3701
wu@webrtc.org91053e72013-08-10 07:18:04 +00003702 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003703 VerifyNoCryptoParams(offer->description(), true);
3704 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003705}
3706
3707// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02003708// identity generation is finished (even if a certificate is provided this is
3709// an async op).
3710TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003711 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003712 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003713 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003714
3715 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003716 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003717 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003718 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003719 ASSERT_TRUE(offer.get() != NULL);
3720 SetRemoteDescriptionWithoutError(offer.release());
3721
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003722 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003723 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003724 VerifyNoCryptoParams(answer->description(), true);
3725 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003726}
3727
3728// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02003729// identity generation is finished (even if a certificate is provided this is
3730// an async op).
3731TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003732 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003733 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003734
Henrik Boströmd8281982015-08-27 10:12:24 +02003735 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003736
3737 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003738 EXPECT_TRUE(offer != NULL);
3739}
3740
3741// Verifies that CreateOffer fails when CreateOffer is called after async
3742// identity generation fails.
3743TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003744 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003745 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003746
Henrik Boströmd8281982015-08-27 10:12:24 +02003747 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003748
3749 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003750 EXPECT_TRUE(offer == NULL);
3751}
3752
3753// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3754// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003755TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003756 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003757 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07003758 VerifyMultipleAsyncCreateDescription(GetParam(),
3759 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003760}
3761
3762// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3763// before async identity generation fails.
3764TEST_F(WebRtcSessionTest,
3765 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003766 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003767 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
3768 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003769}
3770
3771// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3772// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003773TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003774 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003775 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003776 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02003777 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003778}
3779
3780// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3781// before async identity generation fails.
3782TEST_F(WebRtcSessionTest,
3783 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003784 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003785 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
3786 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003787}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003788
3789// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3790// offer has no SDES crypto but only DTLS fingerprint.
3791TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3792 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003793 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003794 // Create a remote offer with secured transport disabled.
3795 cricket::MediaSessionOptions options;
3796 JsepSessionDescription* offer(CreateRemoteOffer(
3797 options, cricket::SEC_DISABLED));
3798 // Adds a DTLS fingerprint to the remote offer.
3799 cricket::SessionDescription* sdp = offer->description();
3800 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3801 ASSERT_TRUE(audio != NULL);
3802 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3803 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003804 rtc::SSLFingerprint::CreateFromRfc4572(
3805 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003806 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003807 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003808}
3809
wu@webrtc.orgde305012013-10-31 15:40:38 +00003810// This test verifies DSCP is properly applied on the media channels.
3811TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3812 constraints_.reset(new FakeConstraints());
3813 constraints_->AddOptional(
3814 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003815 Init();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003816 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003817 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003818
3819 SetLocalDescriptionWithoutError(offer);
3820
3821 video_channel_ = media_engine_->GetVideoChannel(0);
3822 voice_channel_ = media_engine_->GetVoiceChannel(0);
3823
3824 ASSERT_TRUE(video_channel_ != NULL);
3825 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07003826 const cricket::AudioOptions& audio_options = voice_channel_->options();
3827 const cricket::VideoOptions& video_options = video_channel_->options();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003828 EXPECT_TRUE(audio_options.dscp.IsSet());
3829 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3830 EXPECT_TRUE(video_options.dscp.IsSet());
3831 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3832}
3833
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003834TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3835 constraints_.reset(new FakeConstraints());
3836 constraints_->AddOptional(
3837 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3838 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003839 Init();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003840 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003841 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003842
3843 SetLocalDescriptionWithoutError(offer);
3844
3845 video_channel_ = media_engine_->GetVideoChannel(0);
3846
3847 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07003848 const cricket::VideoOptions& video_options = video_channel_->options();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003849 EXPECT_TRUE(
3850 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3851}
3852
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00003853TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
3854 // Number of unsignalled receiving streams should be between 0 and
3855 // kMaxUnsignalledRecvStreams.
3856 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
3857 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
3858 kMaxUnsignalledRecvStreams);
3859 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
3860}
3861
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003862TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
3863 constraints_.reset(new FakeConstraints());
3864 constraints_->AddOptional(
3865 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
3866 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003867 Init();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003868 mediastream_signaling_.SendAudioVideoStream1();
3869 SessionDescriptionInterface* offer = CreateOffer();
3870
3871 SetLocalDescriptionWithoutError(offer);
3872
3873 voice_channel_ = media_engine_->GetVoiceChannel(0);
3874
3875 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07003876 const cricket::AudioOptions& audio_options = voice_channel_->options();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003877 EXPECT_TRUE(
3878 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
3879}
3880
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003881// Tests that we can renegotiate new media content with ICE candidates in the
3882// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02003883TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003884 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003885 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003886 SetFactoryDtlsSrtp();
3887
3888 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003889 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003890 SetLocalDescriptionWithoutError(offer);
3891
3892 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3893 SetRemoteDescriptionWithoutError(answer);
3894
3895 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003896 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003897 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3898
3899 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003900 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003901 candidate1.set_component(1);
3902 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3903 candidate1);
3904 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3905 SetRemoteDescriptionWithoutError(offer);
3906
3907 answer = CreateAnswer(NULL);
3908 SetLocalDescriptionWithoutError(answer);
3909}
3910
3911// Tests that we can renegotiate new media content with ICE candidates separated
3912// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02003913TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003914 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003915 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003916 SetFactoryDtlsSrtp();
3917
3918 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003919 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003920 SetLocalDescriptionWithoutError(offer);
3921
3922 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3923 SetRemoteDescriptionWithoutError(answer);
3924
3925 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003926 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003927 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3928 SetRemoteDescriptionWithoutError(offer);
3929
3930 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003931 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003932 candidate1.set_component(1);
3933 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3934 candidate1);
3935 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3936
3937 answer = CreateAnswer(NULL);
3938 SetLocalDescriptionWithoutError(answer);
3939}
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00003940// Tests that RTX codec is removed from the answer when it isn't supported
3941// by local side.
3942TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
3943 Init();
3944 mediastream_signaling_.SendAudioVideoStream1();
3945 std::string offer_sdp(kSdpWithRtx);
3946
3947 SessionDescriptionInterface* offer =
3948 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
3949 EXPECT_TRUE(offer->ToString(&offer_sdp));
3950
3951 // Offer SDP contains the RTX codec.
3952 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
3953 SetRemoteDescriptionWithoutError(offer);
3954
3955 SessionDescriptionInterface* answer = CreateAnswer(NULL);
3956 std::string answer_sdp;
3957 answer->ToString(&answer_sdp);
3958 // Answer SDP removes the unsupported RTX codec.
3959 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
3960 SetLocalDescriptionWithoutError(answer);
3961}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003962
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003963// This verifies that the voice channel after bundle has both options from video
3964// and voice channels.
3965TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
3966 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
3967 mediastream_signaling_.SendAudioVideoStream1();
3968
3969 PeerConnectionInterface::RTCOfferAnswerOptions options;
3970 options.use_rtp_mux = true;
3971
3972 SessionDescriptionInterface* offer = CreateOffer(options);
3973 SetLocalDescriptionWithoutError(offer);
3974
3975 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3976 rtc::Socket::Option::OPT_SNDBUF, 4000);
3977
3978 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3979 rtc::Socket::Option::OPT_RCVBUF, 8000);
3980
3981 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07003982 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003983 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3984 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07003985 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003986 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3987
deadbeefcbecd352015-09-23 11:50:27 -07003988 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003989 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3990 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07003991 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003992 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3993
deadbeefcbecd352015-09-23 11:50:27 -07003994 EXPECT_NE(session_->voice_rtp_transport_channel(),
3995 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003996
3997 mediastream_signaling_.SendAudioVideoStream2();
3998 SessionDescriptionInterface* answer =
3999 CreateRemoteAnswer(session_->local_description());
4000 SetRemoteDescriptionWithoutError(answer);
4001
deadbeefcbecd352015-09-23 11:50:27 -07004002 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004003 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4004 EXPECT_EQ(4000, option_val);
4005
deadbeefcbecd352015-09-23 11:50:27 -07004006 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004007 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4008 EXPECT_EQ(8000, option_val);
4009}
4010
tommi0f620f42015-07-09 03:25:02 -07004011// Test creating a session, request multiple offers, destroy the session
4012// and make sure we got success/failure callbacks for all of the requests.
4013// Background: crbug.com/507307
4014TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4015 Init();
4016
4017 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4018 PeerConnectionInterface::RTCOfferAnswerOptions options;
4019 options.offer_to_receive_audio =
4020 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
4021
4022 for (auto& o : observers) {
4023 o = new WebRtcSessionCreateSDPObserverForTest();
4024 session_->CreateOffer(o, options);
4025 }
4026
4027 session_.reset();
4028
tommi0f620f42015-07-09 03:25:02 -07004029 for (auto& o : observers) {
4030 // We expect to have received a notification now even if the session was
4031 // terminated. The offer creation may or may not have succeeded, but we
4032 // must have received a notification which, so the only invalid state
4033 // is kInit.
4034 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4035 }
4036}
4037
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004038// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4039// currently fails because upon disconnection and reconnection OnIceComplete is
4040// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004041
deadbeefcbecd352015-09-23 11:50:27 -07004042INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4043 WebRtcSessionTest,
4044 testing::Values(ALREADY_GENERATED,
4045 DTLS_IDENTITY_STORE));