blob: 9bdd8203f64405dd1f6e2765f65d23460111af5d [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
28#include "talk/app/webrtc/audiotrack.h"
jbauchac8869e2015-07-03 01:36:14 -070029#include "talk/app/webrtc/fakemetricsobserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030#include "talk/app/webrtc/jsepicecandidate.h"
31#include "talk/app/webrtc/jsepsessiondescription.h"
32#include "talk/app/webrtc/mediastreamsignaling.h"
33#include "talk/app/webrtc/streamcollection.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000034#include "talk/app/webrtc/test/fakeconstraints.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000035#include "talk/app/webrtc/test/fakedtlsidentityservice.h"
36#include "talk/app/webrtc/test/fakemediastreamsignaling.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000037#include "talk/app/webrtc/videotrack.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038#include "talk/app/webrtc/webrtcsession.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000039#include "talk/app/webrtc/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000040#include "talk/media/base/fakemediaengine.h"
41#include "talk/media/base/fakevideorenderer.h"
42#include "talk/media/base/mediachannel.h"
43#include "talk/media/devices/fakedevicemanager.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000044#include "webrtc/p2p/base/stunserver.h"
45#include "webrtc/p2p/base/teststunserver.h"
46#include "webrtc/p2p/base/testturnserver.h"
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +000047#include "webrtc/p2p/base/transportchannel.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000048#include "webrtc/p2p/client/basicportallocator.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000049#include "talk/session/media/channelmanager.h"
50#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000051#include "webrtc/base/fakenetwork.h"
52#include "webrtc/base/firewallsocketserver.h"
53#include "webrtc/base/gunit.h"
54#include "webrtc/base/logging.h"
55#include "webrtc/base/network.h"
56#include "webrtc/base/physicalsocketserver.h"
57#include "webrtc/base/ssladapter.h"
58#include "webrtc/base/sslstreamadapter.h"
59#include "webrtc/base/stringutils.h"
60#include "webrtc/base/thread.h"
61#include "webrtc/base/virtualsocketserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062
63#define MAYBE_SKIP_TEST(feature) \
64 if (!(feature())) { \
65 LOG(LS_INFO) << "Feature disabled... skipping"; \
66 return; \
67 }
68
69using cricket::BaseSession;
70using cricket::DF_PLAY;
71using cricket::DF_SEND;
72using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000074using rtc::SocketAddress;
75using rtc::scoped_ptr;
76using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000078using webrtc::CreateSessionDescriptionObserver;
79using webrtc::CreateSessionDescriptionRequest;
80using webrtc::DTLSIdentityRequestObserver;
81using webrtc::DTLSIdentityServiceInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082using webrtc::FakeConstraints;
jbauchac8869e2015-07-03 01:36:14 -070083using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084using webrtc::IceCandidateCollection;
85using webrtc::JsepIceCandidate;
86using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000087using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088using webrtc::PeerConnectionInterface;
89using webrtc::SessionDescriptionInterface;
90using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000091using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000092using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000093using webrtc::kCreateChannelFailed;
94using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000096using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000097using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000098using webrtc::kSdpWithoutDtlsFingerprint;
99using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000101using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000102using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000104typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
105
wu@webrtc.org364f2042013-11-20 21:49:41 +0000106static const int kClientAddrPort = 0;
107static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000108static const char kClientIPv6AddrHost1[] =
109 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +0000110static const char kClientAddrHost2[] = "22.22.22.22";
111static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000112static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
113static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000114static const char kTurnUsername[] = "test";
115static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116
117static const char kSessionVersion[] = "1";
118
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119// Media index of candidates belonging to the first media content.
120static const int kMediaContentIndex0 = 0;
121static const char kMediaContentName0[] = "audio";
122
123// Media index of candidates belonging to the second media content.
124static const int kMediaContentIndex1 = 1;
125static const char kMediaContentName1[] = "video";
126
127static const int kIceCandidatesTimeout = 10000;
128
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000129static const char kFakeDtlsFingerprint[] =
130 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
131 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
132
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000133static const char kTooLongIceUfragPwd[] =
134 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
135 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
136 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
137 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
138
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000139static const char kSdpWithRtx[] =
140 "v=0\r\n"
141 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
142 "s=-\r\n"
143 "t=0 0\r\n"
144 "a=msid-semantic: WMS stream1\r\n"
145 "m=video 9 RTP/SAVPF 0 96\r\n"
146 "c=IN IP4 0.0.0.0\r\n"
147 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
148 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
149 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
150 "a=mid:video\r\n"
151 "a=sendrecv\r\n"
152 "a=rtcp-mux\r\n"
153 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
154 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
155 "a=rtpmap:0 fake_video_codec/90000\r\n"
156 "a=rtpmap:96 rtx/90000\r\n"
157 "a=fmtp:96 apt=0\r\n";
158
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000159// Add some extra |newlines| to the |message| after |line|.
160static void InjectAfter(const std::string& line,
161 const std::string& newlines,
162 std::string* message) {
163 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000164 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165 tmp.c_str(), tmp.length(), message);
166}
167
168class MockIceObserver : public webrtc::IceObserver {
169 public:
170 MockIceObserver()
171 : oncandidatesready_(false),
172 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
173 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
174 }
175
176 virtual void OnIceConnectionChange(
177 PeerConnectionInterface::IceConnectionState new_state) {
178 ice_connection_state_ = new_state;
179 }
180 virtual void OnIceGatheringChange(
181 PeerConnectionInterface::IceGatheringState new_state) {
182 // We can never transition back to "new".
183 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
184 ice_gathering_state_ = new_state;
185
186 // oncandidatesready_ really means "ICE gathering is complete".
187 // This if statement ensures that this value remains correct when we
188 // transition from kIceGatheringComplete to kIceGatheringGathering.
189 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
190 oncandidatesready_ = false;
191 }
192 }
193
194 // Found a new candidate.
195 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000196 switch (candidate->sdp_mline_index()) {
197 case kMediaContentIndex0:
198 mline_0_candidates_.push_back(candidate->candidate());
199 break;
200 case kMediaContentIndex1:
201 mline_1_candidates_.push_back(candidate->candidate());
202 break;
203 default:
204 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000205 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000206
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207 // The ICE gathering state should always be Gathering when a candidate is
208 // received (or possibly Completed in the case of the final candidate).
209 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
210 }
211
212 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
213 virtual void OnIceComplete() {
214 EXPECT_FALSE(oncandidatesready_);
215 oncandidatesready_ = true;
216
217 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
218 // be called approximately simultaneously. For ease of testing, this
219 // check additionally requires that they be called in the above order.
220 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
221 ice_gathering_state_);
222 }
223
224 bool oncandidatesready_;
225 std::vector<cricket::Candidate> mline_0_candidates_;
226 std::vector<cricket::Candidate> mline_1_candidates_;
227 PeerConnectionInterface::IceConnectionState ice_connection_state_;
228 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
229};
230
231class WebRtcSessionForTest : public webrtc::WebRtcSession {
232 public:
233 WebRtcSessionForTest(cricket::ChannelManager* cmgr,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000234 rtc::Thread* signaling_thread,
235 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000236 cricket::PortAllocator* port_allocator,
237 webrtc::IceObserver* ice_observer,
238 webrtc::MediaStreamSignaling* mediastream_signaling)
239 : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator,
240 mediastream_signaling) {
241 RegisterIceObserver(ice_observer);
242 }
243 virtual ~WebRtcSessionForTest() {}
244
245 using cricket::BaseSession::GetTransportProxy;
246 using webrtc::WebRtcSession::SetAudioPlayout;
247 using webrtc::WebRtcSession::SetAudioSend;
248 using webrtc::WebRtcSession::SetCaptureDevice;
249 using webrtc::WebRtcSession::SetVideoPlayout;
250 using webrtc::WebRtcSession::SetVideoSend;
251};
252
wu@webrtc.org91053e72013-08-10 07:18:04 +0000253class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000254 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000256 enum State {
257 kInit,
258 kFailed,
259 kSucceeded,
260 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000261 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000262
263 // CreateSessionDescriptionObserver implementation.
264 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000265 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000266 state_ = kSucceeded;
267 }
268 virtual void OnFailure(const std::string& error) {
269 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000270 }
271
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000272 SessionDescriptionInterface* description() { return description_.get(); }
273
274 SessionDescriptionInterface* ReleaseDescription() {
275 return description_.release();
276 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277
wu@webrtc.org91053e72013-08-10 07:18:04 +0000278 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279
wu@webrtc.org91053e72013-08-10 07:18:04 +0000280 protected:
281 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000282
283 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000284 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000285 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286};
287
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000288class FakeAudioRenderer : public cricket::AudioRenderer {
289 public:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000290 FakeAudioRenderer() : channel_id_(-1), sink_(NULL) {}
291 virtual ~FakeAudioRenderer() {
292 if (sink_)
293 sink_->OnClose();
294 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000295
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000296 void AddChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000297 ASSERT(channel_id_ == -1);
298 channel_id_ = channel_id;
299 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000300 void RemoveChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000301 ASSERT(channel_id == channel_id_);
302 channel_id_ = -1;
303 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000304 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000305
306 int channel_id() const { return channel_id_; }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000307 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000308 private:
309 int channel_id_;
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000310 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000311};
312
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313class WebRtcSessionTest : public testing::Test {
314 protected:
315 // TODO Investigate why ChannelManager crashes, if it's created
316 // after stun_server.
317 WebRtcSessionTest()
318 : media_engine_(new cricket::FakeMediaEngine()),
319 data_engine_(new cricket::FakeDataEngine()),
320 device_manager_(new cricket::FakeDeviceManager()),
321 channel_manager_(new cricket::ChannelManager(
322 media_engine_, data_engine_, device_manager_,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000323 new cricket::CaptureManager(), rtc::Thread::Current())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000324 tdesc_factory_(new cricket::TransportDescriptionFactory()),
325 desc_factory_(new cricket::MediaSessionDescriptionFactory(
326 channel_manager_.get(), tdesc_factory_.get())),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000327 pss_(new rtc::PhysicalSocketServer),
328 vss_(new rtc::VirtualSocketServer(pss_.get())),
329 fss_(new rtc::FirewallSocketServer(vss_.get())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330 ss_scope_(fss_.get()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000331 stun_socket_addr_(rtc::SocketAddress(kStunAddrHost,
wu@webrtc.org364f2042013-11-20 21:49:41 +0000332 cricket::STUN_SERVER_PORT)),
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +0000333 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
334 stun_socket_addr_)),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000335 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
jbauchac8869e2015-07-03 01:36:14 -0700336 mediastream_signaling_(channel_manager_.get()),
337 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000338 cricket::ServerAddresses stun_servers;
339 stun_servers.insert(stun_socket_addr_);
340 allocator_.reset(new cricket::BasicPortAllocator(
341 &network_manager_,
342 stun_servers,
343 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000344 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher3449faa2015-08-10 12:22:51 -0700345 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000346 EXPECT_TRUE(channel_manager_->Init());
347 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000348 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349 }
350
351 void AddInterface(const SocketAddress& addr) {
352 network_manager_.AddInterface(addr);
353 }
354
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000355 void Init(
356 DTLSIdentityServiceInterface* identity_service,
Henrik Lundin64dad832015-05-11 12:44:23 +0200357 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000358 ASSERT_TRUE(session_.get() == NULL);
359 session_.reset(new WebRtcSessionForTest(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000360 channel_manager_.get(), rtc::Thread::Current(),
361 rtc::Thread::Current(), allocator_.get(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000362 &observer_,
363 &mediastream_signaling_));
364
365 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
366 observer_.ice_connection_state_);
367 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
368 observer_.ice_gathering_state_);
369
wu@webrtc.org97077a32013-10-25 21:18:33 +0000370 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
Henrik Lundin64dad832015-05-11 12:44:23 +0200371 identity_service, rtc_configuration));
jbauchac8869e2015-07-03 01:36:14 -0700372 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000373 }
374
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000375 void Init() {
Henrik Lundin64dad832015-05-11 12:44:23 +0200376 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Lundin64dad832015-05-11 12:44:23 +0200377 Init(NULL, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000378 }
379
380 void InitWithIceTransport(
381 PeerConnectionInterface::IceTransportsType ice_transport_type) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200382 PeerConnectionInterface::RTCConfiguration configuration;
383 configuration.type = ice_transport_type;
Henrik Lundin64dad832015-05-11 12:44:23 +0200384 Init(NULL, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000385 }
386
387 void InitWithBundlePolicy(
388 PeerConnectionInterface::BundlePolicy bundle_policy) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200389 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Lundin64dad832015-05-11 12:44:23 +0200390 configuration.bundle_policy = bundle_policy;
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700391 Init(NULL, configuration);
392 }
393
394 void InitWithRtcpMuxPolicy(
395 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
396 PeerConnectionInterface::RTCConfiguration configuration;
397 configuration.rtcp_mux_policy = rtcp_mux_policy;
Henrik Lundin64dad832015-05-11 12:44:23 +0200398 Init(NULL, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000399 }
400
401 void InitWithDtls(bool identity_request_should_fail = false) {
402 FakeIdentityService* identity_service = new FakeIdentityService();
403 identity_service->set_should_fail(identity_request_should_fail);
Henrik Lundin64dad832015-05-11 12:44:23 +0200404 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Lundin64dad832015-05-11 12:44:23 +0200405 Init(identity_service, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000406 }
407
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000408 void InitWithDtmfCodec() {
409 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000410 const cricket::AudioCodec kTelephoneEventCodec(
411 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000412 std::vector<cricket::AudioCodec> codecs;
413 codecs.push_back(kTelephoneEventCodec);
414 media_engine_->SetAudioCodecs(codecs);
415 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000416 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000417 }
418
419 // Creates a local offer and applies it. Starts ice.
420 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
421 // to decide which streams to create.
422 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000423 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000424 SetLocalDescriptionWithoutError(offer);
425 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
426 observer_.ice_gathering_state_,
427 kIceCandidatesTimeout);
428 }
429
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000430 SessionDescriptionInterface* CreateOffer() {
431 PeerConnectionInterface::RTCOfferAnswerOptions options;
432 options.offer_to_receive_audio =
433 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
434
435 return CreateOffer(options);
436 }
437
wu@webrtc.org91053e72013-08-10 07:18:04 +0000438 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000439 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000440 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000441 observer = new WebRtcSessionCreateSDPObserverForTest();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000442 session_->CreateOffer(observer, options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000443 EXPECT_TRUE_WAIT(
444 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000445 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000446 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000447 }
448
449 SessionDescriptionInterface* CreateAnswer(
450 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000451 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000452 = new WebRtcSessionCreateSDPObserverForTest();
453 session_->CreateAnswer(observer, constraints);
454 EXPECT_TRUE_WAIT(
455 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000456 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000457 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000458 }
459
wu@webrtc.org364f2042013-11-20 21:49:41 +0000460 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000461 return (session_->voice_channel() != NULL &&
462 session_->video_channel() != NULL);
463 }
464
wu@webrtc.org364f2042013-11-20 21:49:41 +0000465 void CheckTransportChannels() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000466 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 1) != NULL);
467 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 2) != NULL);
468 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 1) != NULL);
469 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 2) != NULL);
470 }
471
472 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
473 ASSERT_TRUE(session_.get() != NULL);
474 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
475 ASSERT_TRUE(content != NULL);
476 const cricket::AudioContentDescription* audio_content =
477 static_cast<const cricket::AudioContentDescription*>(
478 content->description);
479 ASSERT_TRUE(audio_content != NULL);
480 ASSERT_EQ(1U, audio_content->cryptos().size());
481 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
482 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
483 audio_content->cryptos()[0].cipher_suite);
484 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
485 audio_content->protocol());
486
487 content = cricket::GetFirstVideoContent(sdp);
488 ASSERT_TRUE(content != NULL);
489 const cricket::VideoContentDescription* video_content =
490 static_cast<const cricket::VideoContentDescription*>(
491 content->description);
492 ASSERT_TRUE(video_content != NULL);
493 ASSERT_EQ(1U, video_content->cryptos().size());
494 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
495 video_content->cryptos()[0].cipher_suite);
496 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
497 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
498 video_content->protocol());
499 }
500
501 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
502 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
503 ASSERT_TRUE(content != NULL);
504 const cricket::AudioContentDescription* audio_content =
505 static_cast<const cricket::AudioContentDescription*>(
506 content->description);
507 ASSERT_TRUE(audio_content != NULL);
508 ASSERT_EQ(0U, audio_content->cryptos().size());
509
510 content = cricket::GetFirstVideoContent(sdp);
511 ASSERT_TRUE(content != NULL);
512 const cricket::VideoContentDescription* video_content =
513 static_cast<const cricket::VideoContentDescription*>(
514 content->description);
515 ASSERT_TRUE(video_content != NULL);
516 ASSERT_EQ(0U, video_content->cryptos().size());
517
518 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700519 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000520 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700521 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000522 video_content->protocol());
523 } else {
524 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
525 audio_content->protocol());
526 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
527 video_content->protocol());
528 }
529 }
530
531 // Set the internal fake description factories to do DTLS-SRTP.
532 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000533 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000534 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000535 rtc::ToString(rtc::CreateRandomId());
536 identity_.reset(rtc::SSLIdentity::Generate(identity_name));
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000537 tdesc_factory_->set_identity(identity_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000538 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
539 }
540
541 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
542 bool expected) {
543 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
544 ASSERT_TRUE(audio != NULL);
545 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000546 const TransportInfo* video = sdp->GetTransportInfoByName("video");
547 ASSERT_TRUE(video != NULL);
548 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000549 }
550
551 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000552 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000553 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000554 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000555 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000556 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000557 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000558 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000559 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
560 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000561 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000562 // Answer should be NULL as no crypto params in offer.
563 ASSERT_TRUE(answer == NULL);
564 }
565
566 void VerifyAnswerFromCryptoOffer() {
567 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000568 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000569 options.bundle_enabled = true;
570 scoped_ptr<JsepSessionDescription> offer(
571 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
572 ASSERT_TRUE(offer.get() != NULL);
573 VerifyCryptoParams(offer->description());
574 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000575 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000576 ASSERT_TRUE(answer.get() != NULL);
577 VerifyCryptoParams(answer->description());
578 }
579
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000580 void SetAndVerifyNumUnsignalledRecvStreams(
581 int value_set, int value_expected) {
582 constraints_.reset(new FakeConstraints());
583 constraints_->AddOptional(
584 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
585 value_set);
586 session_.reset();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000587 Init();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000588 mediastream_signaling_.SendAudioVideoStream1();
589 SessionDescriptionInterface* offer = CreateOffer();
590
591 SetLocalDescriptionWithoutError(offer);
592
593 video_channel_ = media_engine_->GetVideoChannel(0);
594
595 ASSERT_TRUE(video_channel_ != NULL);
596 cricket::VideoOptions video_options;
597 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
598 EXPECT_EQ(value_expected,
599 video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1));
600 }
601
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000602 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
603 const cricket::SessionDescription* desc2,
604 bool expect_equal) {
605 if (desc1->contents().size() != desc2->contents().size()) {
606 EXPECT_FALSE(expect_equal);
607 return;
608 }
609
610 const cricket::ContentInfos& contents = desc1->contents();
611 cricket::ContentInfos::const_iterator it = contents.begin();
612
613 for (; it != contents.end(); ++it) {
614 const cricket::TransportDescription* transport_desc1 =
615 desc1->GetTransportDescriptionByName(it->name);
616 const cricket::TransportDescription* transport_desc2 =
617 desc2->GetTransportDescriptionByName(it->name);
618 if (!transport_desc1 || !transport_desc2) {
619 EXPECT_FALSE(expect_equal);
620 return;
621 }
622 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
623 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
624 EXPECT_FALSE(expect_equal);
625 return;
626 }
627 }
628 EXPECT_TRUE(expect_equal);
629 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000630
631 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
632 std::string *sdp) {
633 const cricket::SessionDescription* desc = current_desc->description();
634 EXPECT_TRUE(current_desc->ToString(sdp));
635
636 const cricket::ContentInfos& contents = desc->contents();
637 cricket::ContentInfos::const_iterator it = contents.begin();
638 // Replace ufrag and pwd lines with empty strings.
639 for (; it != contents.end(); ++it) {
640 const cricket::TransportDescription* transport_desc =
641 desc->GetTransportDescriptionByName(it->name);
642 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
643 + "\r\n";
644 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
645 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000646 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000647 "", 0,
648 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000649 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000650 "", 0,
651 sdp);
652 }
653 }
654
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000655 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
656 const std::string& modified_ice_ufrag,
657 const std::string& modified_ice_pwd,
658 std::string* sdp) {
659 const cricket::SessionDescription* desc = current_desc->description();
660 EXPECT_TRUE(current_desc->ToString(sdp));
661
662 const cricket::ContentInfos& contents = desc->contents();
663 cricket::ContentInfos::const_iterator it = contents.begin();
664 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
665 // |modified_ice_pwd| strings.
666 for (; it != contents.end(); ++it) {
667 const cricket::TransportDescription* transport_desc =
668 desc->GetTransportDescriptionByName(it->name);
669 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
670 + "\r\n";
671 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
672 + "\r\n";
673 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
674 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000675 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000676 mod_ufrag.c_str(), mod_ufrag.length(),
677 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000678 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000679 mod_pwd.c_str(), mod_pwd.length(),
680 sdp);
681 }
682 }
683
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000684 // Creates a remote offer and and applies it as a remote description,
685 // creates a local answer and applies is as a local description.
686 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
687 // to decide which local and remote streams to create.
688 void CreateAndSetRemoteOfferAndLocalAnswer() {
689 SessionDescriptionInterface* offer = CreateRemoteOffer();
690 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000691 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000692 SetLocalDescriptionWithoutError(answer);
693 }
694 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
695 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
696 }
697 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
698 BaseSession::State expected_state) {
699 SetLocalDescriptionWithoutError(desc);
700 EXPECT_EQ(expected_state, session_->state());
701 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000702 void SetLocalDescriptionExpectError(const std::string& action,
703 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000704 SessionDescriptionInterface* desc) {
705 std::string error;
706 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000707 std::string sdp_type = "local ";
708 sdp_type.append(action);
709 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710 EXPECT_NE(std::string::npos, error.find(expected_error));
711 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000712 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
713 SessionDescriptionInterface* desc) {
714 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
715 expected_error, desc);
716 }
717 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
718 SessionDescriptionInterface* desc) {
719 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
720 expected_error, desc);
721 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000722 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
723 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
724 }
725 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
726 BaseSession::State expected_state) {
727 SetRemoteDescriptionWithoutError(desc);
728 EXPECT_EQ(expected_state, session_->state());
729 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000730 void SetRemoteDescriptionExpectError(const std::string& action,
731 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000732 SessionDescriptionInterface* desc) {
733 std::string error;
734 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000735 std::string sdp_type = "remote ";
736 sdp_type.append(action);
737 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000738 EXPECT_NE(std::string::npos, error.find(expected_error));
739 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000740 void SetRemoteDescriptionOfferExpectError(
741 const std::string& expected_error, SessionDescriptionInterface* desc) {
742 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
743 expected_error, desc);
744 }
745 void SetRemoteDescriptionPranswerExpectError(
746 const std::string& expected_error, SessionDescriptionInterface* desc) {
747 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
748 expected_error, desc);
749 }
750 void SetRemoteDescriptionAnswerExpectError(
751 const std::string& expected_error, SessionDescriptionInterface* desc) {
752 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
753 expected_error, desc);
754 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000755
756 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
757 SessionDescriptionInterface** nocrypto_answer) {
758 // Create a SDP without Crypto.
759 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000760 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000761 options.bundle_enabled = true;
762 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
763 ASSERT_TRUE(*offer != NULL);
764 VerifyCryptoParams((*offer)->description());
765
766 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
767 cricket::SEC_DISABLED);
768 EXPECT_TRUE(*nocrypto_answer != NULL);
769 }
770
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000771 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
772 SessionDescriptionInterface** nodtls_answer) {
773 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000774 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000775 options.bundle_enabled = true;
776
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000777 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000778 CreateRemoteOffer(options, cricket::SEC_ENABLED));
779
780 *nodtls_answer =
781 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
782 EXPECT_TRUE(*nodtls_answer != NULL);
783 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
784 VerifyCryptoParams((*nodtls_answer)->description());
785
786 SetFactoryDtlsSrtp();
787 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
788 ASSERT_TRUE(*offer != NULL);
789 VerifyFingerprintStatus((*offer)->description(), true);
790 VerifyCryptoParams((*offer)->description());
791 }
792
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793 JsepSessionDescription* CreateRemoteOfferWithVersion(
794 cricket::MediaSessionOptions options,
795 cricket::SecurePolicy secure_policy,
796 const std::string& session_version,
797 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000798 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799 const cricket::SessionDescription* cricket_desc = NULL;
800 if (current_desc) {
801 cricket_desc = current_desc->description();
802 session_id = current_desc->session_id();
803 }
804
805 desc_factory_->set_secure(secure_policy);
806 JsepSessionDescription* offer(
807 new JsepSessionDescription(JsepSessionDescription::kOffer));
808 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
809 session_id, session_version)) {
810 delete offer;
811 offer = NULL;
812 }
813 return offer;
814 }
815 JsepSessionDescription* CreateRemoteOffer(
816 cricket::MediaSessionOptions options) {
817 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
818 kSessionVersion, NULL);
819 }
820 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000821 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
822 return CreateRemoteOfferWithVersion(
823 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824 }
825 JsepSessionDescription* CreateRemoteOffer(
826 cricket::MediaSessionOptions options,
827 const SessionDescriptionInterface* current_desc) {
828 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
829 kSessionVersion, current_desc);
830 }
831
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000832 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
833 const char* sctp_stream_name, int new_port,
834 cricket::MediaSessionOptions options) {
835 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000836 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
837 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000838 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
839 }
840
841 // Takes ownership of offer_basis (and deletes it).
842 JsepSessionDescription* ChangeSDPSctpPort(
843 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
844 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
845 // SessionDescription from the mutated string.
846 const char* default_port_str = "5000";
847 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000848 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000849 std::string offer_str;
850 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000851 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000852 new_port_str, strlen(new_port_str),
853 &offer_str);
854 JsepSessionDescription* offer = new JsepSessionDescription(
855 offer_basis->type());
856 delete offer_basis;
857 offer->Initialize(offer_str, NULL);
858 return offer;
859 }
860
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000861 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
862 // before this function to decide which streams to create.
863 JsepSessionDescription* CreateRemoteOffer() {
864 cricket::MediaSessionOptions options;
865 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
866 return CreateRemoteOffer(options, session_->remote_description());
867 }
868
869 JsepSessionDescription* CreateRemoteAnswer(
870 const SessionDescriptionInterface* offer,
871 cricket::MediaSessionOptions options,
872 cricket::SecurePolicy policy) {
873 desc_factory_->set_secure(policy);
874 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000875 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 JsepSessionDescription* answer(
877 new JsepSessionDescription(JsepSessionDescription::kAnswer));
878 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
879 options, NULL),
880 session_id, kSessionVersion)) {
881 delete answer;
882 answer = NULL;
883 }
884 return answer;
885 }
886
887 JsepSessionDescription* CreateRemoteAnswer(
888 const SessionDescriptionInterface* offer,
889 cricket::MediaSessionOptions options) {
890 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
891 }
892
893 // Creates an answer session description with streams based on
894 // |mediastream_signaling_|. Call
895 // mediastream_signaling_.UseOptionsWithStreamX() before this function
896 // to decide which streams to create.
897 JsepSessionDescription* CreateRemoteAnswer(
898 const SessionDescriptionInterface* offer) {
899 cricket::MediaSessionOptions options;
900 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
901 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
902 }
903
904 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000905 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000906 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000907 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000908
909 PeerConnectionInterface::RTCOfferAnswerOptions options;
910 options.use_rtp_mux = bundle;
911
912 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
914 // and answer.
915 SetLocalDescriptionWithoutError(offer);
916
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000917 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000918 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 std::string sdp;
920 EXPECT_TRUE(answer->ToString(&sdp));
921
922 size_t expected_candidate_num = 2;
923 if (!rtcp_mux) {
924 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
925 // for rtp and rtcp.
926 expected_candidate_num = 4;
927 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000928 const std::string kRtcpMux = "a=rtcp-mux";
929 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000930 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931 kXRtcpMux.c_str(), kXRtcpMux.length(),
932 &sdp);
933 }
934
935 SessionDescriptionInterface* new_answer = CreateSessionDescription(
936 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000937
938 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000939 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000940 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
941 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
942 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
943 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
944 cricket::Candidate c0 = observer_.mline_0_candidates_[i];
945 cricket::Candidate c1 = observer_.mline_1_candidates_[i];
946 if (bundle) {
947 EXPECT_TRUE(c0.IsEquivalent(c1));
948 } else {
949 EXPECT_FALSE(c0.IsEquivalent(c1));
950 }
951 }
952 }
953 // Tests that we can only send DTMF when the dtmf codec is supported.
954 void TestCanInsertDtmf(bool can) {
955 if (can) {
956 InitWithDtmfCodec();
957 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000958 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000959 }
960 mediastream_signaling_.SendAudioVideoStream1();
961 CreateAndSetRemoteOfferAndLocalAnswer();
962 EXPECT_FALSE(session_->CanInsertDtmf(""));
963 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
964 }
965
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000966 // Helper class to configure loopback network and verify Best
967 // Connection using right IP protocol for TestLoopbackCall
968 // method. LoopbackNetworkManager applies firewall rules to block
969 // all ping traffic once ICE completed, and remove them to observe
970 // ICE reconnected again. This LoopbackNetworkConfiguration struct
971 // verifies the best connection is using the right IP protocol after
972 // initial ICE convergences.
973
974 class LoopbackNetworkConfiguration {
975 public:
976 LoopbackNetworkConfiguration()
977 : test_ipv6_network_(false),
978 test_extra_ipv4_network_(false),
979 best_connection_after_initial_ice_converged_(1, 0) {}
980
981 // Used to track the expected best connection count in each IP protocol.
982 struct ExpectedBestConnection {
983 ExpectedBestConnection(int ipv4_count, int ipv6_count)
984 : ipv4_count_(ipv4_count),
985 ipv6_count_(ipv6_count) {}
986
987 int ipv4_count_;
988 int ipv6_count_;
989 };
990
991 bool test_ipv6_network_;
992 bool test_extra_ipv4_network_;
993 ExpectedBestConnection best_connection_after_initial_ice_converged_;
994
995 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -0700996 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000997 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
998 }
999
1000 private:
jbauchac8869e2015-07-03 01:36:14 -07001001 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001002 const ExpectedBestConnection& expected) const {
1003 EXPECT_EQ(
jbauchac8869e2015-07-03 01:36:14 -07001004 metrics_observer->GetCounter(webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001005 expected.ipv4_count_);
1006 EXPECT_EQ(
jbauchac8869e2015-07-03 01:36:14 -07001007 metrics_observer->GetCounter(webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001008 expected.ipv6_count_);
1009 }
1010 };
1011
1012 class LoopbackNetworkManager {
1013 public:
1014 LoopbackNetworkManager(WebRtcSessionTest* session,
1015 const LoopbackNetworkConfiguration& config)
1016 : config_(config) {
1017 session->AddInterface(
1018 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1019 if (config_.test_extra_ipv4_network_) {
1020 session->AddInterface(
1021 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1022 }
1023 if (config_.test_ipv6_network_) {
1024 session->AddInterface(
1025 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1026 }
1027 }
1028
1029 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1030 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1031 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1032 if (config_.test_extra_ipv4_network_) {
1033 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1034 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1035 }
1036 if (config_.test_ipv6_network_) {
1037 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1038 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1039 }
1040 }
1041
1042 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1043
1044 private:
1045 LoopbackNetworkConfiguration config_;
1046 };
1047
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001048 // The method sets up a call from the session to itself, in a loopback
1049 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001050 // disconnection, and then a permanent disconnection.
1051 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001052 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1053 // While running the call, this method also checks if the session goes through
1054 // the correct sequence of ICE states when a connection is established,
1055 // broken, and re-established.
1056 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001057 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1058 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001059 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001060
1061 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1062 LoopbackNetworkManager loopback_network_manager(this, config);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001063 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001064 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001065 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001066
1067 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1068 observer_.ice_gathering_state_);
1069 SetLocalDescriptionWithoutError(offer);
1070 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1071 observer_.ice_connection_state_);
1072 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
1073 observer_.ice_gathering_state_,
1074 kIceCandidatesTimeout);
1075 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1076 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
1077 observer_.ice_gathering_state_,
1078 kIceCandidatesTimeout);
1079
1080 std::string sdp;
1081 offer->ToString(&sdp);
1082 SessionDescriptionInterface* desc =
jbauchfabe2c92015-07-16 13:43:14 -07001083 webrtc::CreateSessionDescription(
1084 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001085 ASSERT_TRUE(desc != NULL);
1086 SetRemoteDescriptionWithoutError(desc);
1087
1088 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
1089 observer_.ice_connection_state_,
1090 kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001091
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001092 // The ice connection state is "Connected" too briefly to catch in a test.
1093 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001094 observer_.ice_connection_state_,
1095 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001096
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001097 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001098 // Adding firewall rule to block ping requests, which should cause
1099 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001100
1101 loopback_network_manager.ApplyFirewallRules(fss_.get());
1102
1103 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001104 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1105 observer_.ice_connection_state_,
1106 kIceCandidatesTimeout);
1107
jbauchac8869e2015-07-03 01:36:14 -07001108 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001109
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001110 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001111 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001112 // Session is automatically calling OnSignalingReady after creation of
1113 // new portallocator session which will allocate new set of candidates.
1114
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001115 LOG(LS_INFO) << "Firewall Rules cleared";
1116
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001117 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001118 observer_.ice_connection_state_,
1119 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001120
1121 // Now we block ping requests and wait until the ICE connection transitions
1122 // to the Failed state. This will take at least 30 seconds because it must
1123 // wait for the Port to timeout.
1124 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001125
1126 loopback_network_manager.ApplyFirewallRules(fss_.get());
1127 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001128 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001129 observer_.ice_connection_state_,
1130 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001131 }
1132
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001133 void TestLoopbackCall() {
1134 LoopbackNetworkConfiguration config;
1135 TestLoopbackCall(config);
1136 }
1137
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001138 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1139 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001140 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1141 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1142
1143 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001144 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1145 codecs.push_back(kCNCodec1);
1146 codecs.push_back(kCNCodec2);
1147 media_engine_->SetAudioCodecs(codecs);
1148 desc_factory_->set_audio_codecs(codecs);
1149 }
1150
1151 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1152 const cricket::ContentDescription* description = content->description;
1153 ASSERT(description != NULL);
1154 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001155 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001156 ASSERT(audio_content_desc != NULL);
1157 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1158 if (audio_content_desc->codecs()[i].name == "CN")
1159 return false;
1160 }
1161 return true;
1162 }
1163
1164 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001165 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001166 dci.reliable = false;
1167 session_->CreateDataChannel("datachannel", &dci);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001168 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001169 SetLocalDescriptionWithoutError(offer);
1170 }
1171
wu@webrtc.org91053e72013-08-10 07:18:04 +00001172 void VerifyMultipleAsyncCreateDescription(
1173 bool success, CreateSessionDescriptionRequest::Type type) {
henrike@webrtc.org7666db72013-08-22 14:45:42 +00001174 InitWithDtls(!success);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001175 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001176 if (type == CreateSessionDescriptionRequest::kAnswer) {
1177 cricket::MediaSessionOptions options;
1178 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001179 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001180 ASSERT_TRUE(offer.get() != NULL);
1181 SetRemoteDescriptionWithoutError(offer.release());
1182 }
1183
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001184 PeerConnectionInterface::RTCOfferAnswerOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001185 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001186 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001187 observers[kNumber];
1188 for (int i = 0; i < kNumber; ++i) {
1189 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1190 if (type == CreateSessionDescriptionRequest::kOffer) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001191 session_->CreateOffer(observers[i], options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001192 } else {
1193 session_->CreateAnswer(observers[i], NULL);
1194 }
1195 }
1196
1197 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1198 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1199 WebRtcSessionCreateSDPObserverForTest::kFailed;
1200
1201 for (int i = 0; i < kNumber; ++i) {
1202 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1203 if (success) {
1204 EXPECT_TRUE(observers[i]->description() != NULL);
1205 } else {
1206 EXPECT_TRUE(observers[i]->description() == NULL);
1207 }
1208 }
1209 }
1210
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001211 void ConfigureAllocatorWithTurn() {
1212 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1213 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
1214 relay_server.credentials = credentials;
1215 relay_server.ports.push_back(cricket::ProtocolAddress(
1216 kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1217 allocator_->AddRelay(relay_server);
1218 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher3449faa2015-08-10 12:22:51 -07001219 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001220 }
1221
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001222 cricket::FakeMediaEngine* media_engine_;
1223 cricket::FakeDataEngine* data_engine_;
1224 cricket::FakeDeviceManager* device_manager_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001225 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
1226 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1227 rtc::scoped_ptr<rtc::SSLIdentity> identity_;
1228 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1229 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1230 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1231 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1232 rtc::SocketServerScope ss_scope_;
1233 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001234 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001235 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001236 rtc::FakeNetworkManager network_manager_;
1237 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001238 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001239 rtc::scoped_ptr<FakeConstraints> constraints_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001240 FakeMediaStreamSignaling mediastream_signaling_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001241 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001242 MockIceObserver observer_;
1243 cricket::FakeVideoMediaChannel* video_channel_;
1244 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001245 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001246};
1247
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001248TEST_F(WebRtcSessionTest, TestInitializeWithDtls) {
1249 InitWithDtls();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001250 // SDES is disabled when DTLS is on.
1251 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001252}
1253
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001254TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001255 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001256 // SDES is required if DTLS is off.
1257 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001258}
1259
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001260TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1261 TestSessionCandidatesWithBundleRtcpMux(false, false);
1262}
1263
1264// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1265// with rtcp-mux and/or bundle.
1266TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1267 TestSessionCandidatesWithBundleRtcpMux(false, true);
1268}
1269
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001270TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1271 TestSessionCandidatesWithBundleRtcpMux(true, true);
1272}
1273
1274TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001275 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1276 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001277 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001278 mediastream_signaling_.SendAudioVideoStream1();
1279 InitiateCall();
1280 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1281 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1282 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1283}
1284
1285TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001286 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1287 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001288 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001289 rtc::FP_UDP,
1290 rtc::FD_ANY,
1291 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001292 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001293 mediastream_signaling_.SendAudioVideoStream1();
1294 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001295 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001296 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1297 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1298 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1299}
1300
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001301// Test session delivers no candidates gathered when constraint set to "none".
1302TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1303 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001304 InitWithIceTransport(PeerConnectionInterface::kNone);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001305 mediastream_signaling_.SendAudioVideoStream1();
1306 InitiateCall();
1307 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1308 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1309 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1310}
1311
1312// Test session delivers only relay candidates gathered when constaint set to
1313// "relay".
1314TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1315 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1316 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001317 InitWithIceTransport(PeerConnectionInterface::kRelay);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001318 mediastream_signaling_.SendAudioVideoStream1();
1319 InitiateCall();
1320 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1321 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1322 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1323 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1324 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1325 observer_.mline_0_candidates_[i].type());
1326 }
1327 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1328 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1329 observer_.mline_1_candidates_[i].type());
1330 }
1331}
1332
1333// Test session delivers all candidates gathered when constaint set to "all".
1334TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1335 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001336 InitWithIceTransport(PeerConnectionInterface::kAll);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001337 mediastream_signaling_.SendAudioVideoStream1();
1338 InitiateCall();
1339 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1340 // Host + STUN. By default allocator is disabled to gather relay candidates.
1341 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1342 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1343}
1344
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001345TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001346 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001347 SessionDescriptionInterface* offer = NULL;
1348 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1349 std::string unknown_action;
1350 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1351 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1352}
1353
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001354// Test creating offers and receive answers and make sure the
1355// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001356TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001357 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001358 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001359 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001360 const std::string session_id_orig = offer->session_id();
1361 const std::string session_version_orig = offer->session_version();
1362 SetLocalDescriptionWithoutError(offer);
1363
1364 mediastream_signaling_.SendAudioVideoStream2();
1365 SessionDescriptionInterface* answer =
1366 CreateRemoteAnswer(session_->local_description());
1367 SetRemoteDescriptionWithoutError(answer);
1368
1369 video_channel_ = media_engine_->GetVideoChannel(0);
1370 voice_channel_ = media_engine_->GetVoiceChannel(0);
1371
1372 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1373 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1374
1375 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1376 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1377
1378 ASSERT_EQ(1u, video_channel_->send_streams().size());
1379 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1380 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1381 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1382
1383 // Create new offer without send streams.
1384 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001385 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001386
1387 // Verify the session id is the same and the session version is
1388 // increased.
1389 EXPECT_EQ(session_id_orig, offer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001390 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1391 rtc::FromString<uint64>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001392
1393 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001394 EXPECT_EQ(0u, video_channel_->send_streams().size());
1395 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001396
1397 mediastream_signaling_.SendAudioVideoStream2();
1398 answer = CreateRemoteAnswer(session_->local_description());
1399 SetRemoteDescriptionWithoutError(answer);
1400
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001401 // Make sure the receive streams have not changed.
1402 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1403 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1404 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1405 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1406}
1407
1408// Test receiving offers and creating answers and make sure the
1409// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001410TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001411 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001412 mediastream_signaling_.SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001413 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001414 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001415 SetRemoteDescriptionWithoutError(offer);
1416
1417 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001418 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001419 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001420 SetLocalDescriptionWithoutError(answer);
1421
1422 const std::string session_id_orig = answer->session_id();
1423 const std::string session_version_orig = answer->session_version();
1424
1425 video_channel_ = media_engine_->GetVideoChannel(0);
1426 voice_channel_ = media_engine_->GetVoiceChannel(0);
1427
1428 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1429 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1430
1431 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1432 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1433
1434 ASSERT_EQ(1u, video_channel_->send_streams().size());
1435 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1436 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1437 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1438
1439 mediastream_signaling_.SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001440 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001441 SetRemoteDescriptionWithoutError(offer);
1442
1443 // Answer by turning off all send streams.
1444 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001445 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001446
1447 // Verify the session id is the same and the session version is
1448 // increased.
1449 EXPECT_EQ(session_id_orig, answer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001450 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1451 rtc::FromString<uint64>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001452 SetLocalDescriptionWithoutError(answer);
1453
1454 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1455 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1456 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1457 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1458 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1459 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1460
1461 // Make sure we have no send streams.
1462 EXPECT_EQ(0u, video_channel_->send_streams().size());
1463 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1464}
1465
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001466TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001467 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001468 media_engine_->set_fail_create_channel(true);
1469
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001470 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001471 ASSERT_TRUE(offer != NULL);
1472 // SetRemoteDescription and SetLocalDescription will take the ownership of
1473 // the offer.
1474 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001475 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001476 ASSERT_TRUE(offer != NULL);
1477 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1478}
1479
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001480//
1481// Tests for creating/setting SDP under different SDES/DTLS polices:
1482//
1483// --DTLS off and SDES on
1484// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1485// set local/remote offer/answer with crypto --> success
1486// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1487// failure
1488// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1489// failure
1490// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1491// failure
1492//
1493// --DTLS on and SDES off
1494// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1495// set local/remote offer/answer with DTLS fingerprint --> success
1496// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1497// fingerprint --> failure
1498// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1499// --> failure
1500// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1501// --> failure
1502//
1503// --Encryption disabled: DTLS off and SDES off
1504// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1505// answer without SDES or DTLS --> success
1506// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1507// answer without SDES or DTLS --> success
1508//
1509
1510// Test that we return a failure when applying a remote/local offer that doesn't
1511// have cryptos enabled when DTLS is off.
1512TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001513 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001514 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001515 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001516 JsepSessionDescription* offer = CreateRemoteOffer(
1517 options, cricket::SEC_DISABLED);
1518 ASSERT_TRUE(offer != NULL);
1519 VerifyNoCryptoParams(offer->description(), false);
1520 // SetRemoteDescription and SetLocalDescription will take the ownership of
1521 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001522 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001523 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1524 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001525 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001526}
1527
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001528// Test that we return a failure when applying a local answer that doesn't have
1529// cryptos enabled when DTLS is off.
1530TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001531 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001532 SessionDescriptionInterface* offer = NULL;
1533 SessionDescriptionInterface* answer = NULL;
1534 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1535 // SetRemoteDescription and SetLocalDescription will take the ownership of
1536 // the offer.
1537 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001538 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001539}
1540
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001541// Test we will return fail when apply an remote answer that doesn't have
1542// crypto enabled when DTLS is off.
1543TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001544 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001545 SessionDescriptionInterface* offer = NULL;
1546 SessionDescriptionInterface* answer = NULL;
1547 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1548 // SetRemoteDescription and SetLocalDescription will take the ownership of
1549 // the offer.
1550 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001551 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001552}
1553
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001554// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1555// and that we return an answer with a DTLS fingerprint.
1556TEST_F(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001557 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001558 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001559 InitWithDtls();
1560 SetFactoryDtlsSrtp();
1561 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001562 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001563 JsepSessionDescription* offer =
1564 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001565 ASSERT_TRUE(offer != NULL);
1566 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001567 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001568
1569 // SetRemoteDescription will take the ownership of the offer.
1570 SetRemoteDescriptionWithoutError(offer);
1571
1572 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001573 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001574 ASSERT_TRUE(answer != NULL);
1575 VerifyFingerprintStatus(answer->description(), true);
1576 // Check that we don't have an a=crypto line in the answer.
1577 VerifyNoCryptoParams(answer->description(), true);
1578
1579 // Now set the local description, which should work, even without a=crypto.
1580 SetLocalDescriptionWithoutError(answer);
1581}
1582
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001583// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1584// and then we accept a remote answer with a DTLS fingerprint successfully.
1585TEST_F(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001586 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001587 mediastream_signaling_.SendAudioVideoStream1();
1588 InitWithDtls();
1589 SetFactoryDtlsSrtp();
1590
1591 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001592 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001593 ASSERT_TRUE(offer != NULL);
1594 VerifyFingerprintStatus(offer->description(), true);
1595 // Check that we don't have an a=crypto line in the offer.
1596 VerifyNoCryptoParams(offer->description(), true);
1597
1598 // Now set the local description, which should work, even without a=crypto.
1599 SetLocalDescriptionWithoutError(offer);
1600
1601 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001602 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001603 JsepSessionDescription* answer =
1604 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1605 ASSERT_TRUE(answer != NULL);
1606 VerifyFingerprintStatus(answer->description(), true);
1607 VerifyNoCryptoParams(answer->description(), true);
1608
1609 // SetRemoteDescription will take the ownership of the answer.
1610 SetRemoteDescriptionWithoutError(answer);
1611}
1612
1613// Test that if we support DTLS and the other side didn't offer a fingerprint,
1614// we will fail to set the remote description.
1615TEST_F(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001616 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001617 InitWithDtls();
1618 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001619 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001620 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001621 JsepSessionDescription* offer = CreateRemoteOffer(
1622 options, cricket::SEC_REQUIRED);
1623 ASSERT_TRUE(offer != NULL);
1624 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001625 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001627 // SetRemoteDescription will take the ownership of the offer.
1628 SetRemoteDescriptionOfferExpectError(
1629 kSdpWithoutDtlsFingerprint, offer);
1630
1631 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1632 // SetLocalDescription will take the ownership of the offer.
1633 SetLocalDescriptionOfferExpectError(
1634 kSdpWithoutDtlsFingerprint, offer);
1635}
1636
1637// Test that we return a failure when applying a local answer that doesn't have
1638// a DTLS fingerprint when DTLS is required.
1639TEST_F(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001640 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001641 InitWithDtls();
1642 SessionDescriptionInterface* offer = NULL;
1643 SessionDescriptionInterface* answer = NULL;
1644 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1645
1646 // SetRemoteDescription and SetLocalDescription will take the ownership of
1647 // the offer and answer.
1648 SetRemoteDescriptionWithoutError(offer);
1649 SetLocalDescriptionAnswerExpectError(
1650 kSdpWithoutDtlsFingerprint, answer);
1651}
1652
1653// Test that we return a failure when applying a remote answer that doesn't have
1654// a DTLS fingerprint when DTLS is required.
1655TEST_F(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001656 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeeff3938292015-07-15 12:20:53 -07001657 // Enable both SDES and DTLS, so that offer won't be outright rejected as a
1658 // result of using the "UDP/TLS/RTP/SAVPF" profile.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001659 InitWithDtls();
deadbeeff3938292015-07-15 12:20:53 -07001660 session_->SetSdesPolicy(cricket::SEC_ENABLED);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001661 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001662 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001663 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001664 JsepSessionDescription* answer =
1665 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
1666
1667 // SetRemoteDescription and SetLocalDescription will take the ownership of
1668 // the offer and answer.
1669 SetLocalDescriptionWithoutError(offer);
1670 SetRemoteDescriptionAnswerExpectError(
1671 kSdpWithoutDtlsFingerprint, answer);
1672}
1673
1674// Test that we create a local offer without SDES or DTLS and accept a remote
1675// answer without SDES or DTLS when encryption is disabled.
1676TEST_F(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
1677 mediastream_signaling_.SendAudioVideoStream1();
1678 options_.disable_encryption = true;
1679 InitWithDtls();
1680
1681 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001682 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001683 ASSERT_TRUE(offer != NULL);
1684 VerifyFingerprintStatus(offer->description(), false);
1685 // Check that we don't have an a=crypto line in the offer.
1686 VerifyNoCryptoParams(offer->description(), false);
1687
1688 // Now set the local description, which should work, even without a=crypto.
1689 SetLocalDescriptionWithoutError(offer);
1690
1691 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001692 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001693 JsepSessionDescription* answer =
1694 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1695 ASSERT_TRUE(answer != NULL);
1696 VerifyFingerprintStatus(answer->description(), false);
1697 VerifyNoCryptoParams(answer->description(), false);
1698
1699 // SetRemoteDescription will take the ownership of the answer.
1700 SetRemoteDescriptionWithoutError(answer);
1701}
1702
1703// Test that we create a local answer without SDES or DTLS and accept a remote
1704// offer without SDES or DTLS when encryption is disabled.
1705TEST_F(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
1706 options_.disable_encryption = true;
1707 InitWithDtls();
1708
1709 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001710 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001711 JsepSessionDescription* offer =
1712 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1713 ASSERT_TRUE(offer != NULL);
1714 VerifyFingerprintStatus(offer->description(), false);
1715 VerifyNoCryptoParams(offer->description(), false);
1716
1717 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001718 SetRemoteDescriptionWithoutError(offer);
1719
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001720 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001721 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001722 ASSERT_TRUE(answer != NULL);
1723 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001724 // Check that we don't have an a=crypto line in the answer.
1725 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001726
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001727 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001728 SetLocalDescriptionWithoutError(answer);
1729}
1730
1731TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001732 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001733 mediastream_signaling_.SendNothing();
1734 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001735 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001736 SetLocalDescriptionWithoutError(offer);
1737
1738 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001739 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001740 SetLocalDescriptionWithoutError(offer2);
1741}
1742
1743TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001744 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745 mediastream_signaling_.SendNothing();
1746 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001747 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001748 SetRemoteDescriptionWithoutError(offer);
1749
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001750 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001751 SetRemoteDescriptionWithoutError(offer2);
1752}
1753
1754TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001755 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001756 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001757 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001759 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001760 SetRemoteDescriptionOfferExpectError(
1761 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001762}
1763
1764TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001765 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001767 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001769 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001770 SetLocalDescriptionOfferExpectError(
1771 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772}
1773
1774TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001775 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776 mediastream_signaling_.SendNothing();
1777 SessionDescriptionInterface* offer = CreateRemoteOffer();
1778 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1779
1780 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001781 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1783 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1784
1785 mediastream_signaling_.SendAudioVideoStream1();
1786 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001787 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1789
1790 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1791
1792 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001793 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001794 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1795}
1796
1797TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001798 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001799 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001800 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001801 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1802
1803 JsepSessionDescription* pranswer =
1804 CreateRemoteAnswer(session_->local_description());
1805 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1806
1807 SetRemoteDescriptionExpectState(pranswer,
1808 BaseSession::STATE_RECEIVEDPRACCEPT);
1809
1810 mediastream_signaling_.SendAudioVideoStream1();
1811 JsepSessionDescription* pranswer2 =
1812 CreateRemoteAnswer(session_->local_description());
1813 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1814
1815 SetRemoteDescriptionExpectState(pranswer2,
1816 BaseSession::STATE_RECEIVEDPRACCEPT);
1817
1818 mediastream_signaling_.SendAudioVideoStream2();
1819 SessionDescriptionInterface* answer =
1820 CreateRemoteAnswer(session_->local_description());
1821 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1822}
1823
1824TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001825 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001826 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001827 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1828
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001829 SessionDescriptionInterface* answer =
1830 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001831 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1832 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001833}
1834
1835TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001836 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001837 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001838 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1839
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001840 SessionDescriptionInterface* answer =
1841 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001842 SetRemoteDescriptionAnswerExpectError(
1843 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001844}
1845
1846TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001847 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001848 mediastream_signaling_.SendAudioVideoStream1();
1849
1850 cricket::Candidate candidate;
1851 candidate.set_component(1);
1852 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1853
1854 // Fail since we have not set a offer description.
1855 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1856
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001857 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001858 SetLocalDescriptionWithoutError(offer);
1859 // Candidate should be allowed to add before remote description.
1860 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1861 candidate.set_component(2);
1862 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1863 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1864
1865 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1866 session_->local_description());
1867 SetRemoteDescriptionWithoutError(answer);
1868
1869 // Verifying the candidates are copied properly from internal vector.
1870 const SessionDescriptionInterface* remote_desc =
1871 session_->remote_description();
1872 ASSERT_TRUE(remote_desc != NULL);
1873 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1874 const IceCandidateCollection* candidates =
1875 remote_desc->candidates(kMediaContentIndex0);
1876 ASSERT_EQ(2u, candidates->count());
1877 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1878 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1879 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1880 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1881
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001882 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1883 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001884 candidate.set_component(2);
1885 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1886 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001887 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001888
1889 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1890 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1891}
1892
1893// Test that a remote candidate is added to the remote session description and
1894// that it is retained if the remote session description is changed.
1895TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001896 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001897 cricket::Candidate candidate1;
1898 candidate1.set_component(1);
1899 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1900 candidate1);
1901 mediastream_signaling_.SendAudioVideoStream1();
1902 CreateAndSetRemoteOfferAndLocalAnswer();
1903
1904 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1905 const SessionDescriptionInterface* remote_desc =
1906 session_->remote_description();
1907 ASSERT_TRUE(remote_desc != NULL);
1908 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1909 const IceCandidateCollection* candidates =
1910 remote_desc->candidates(kMediaContentIndex0);
1911 ASSERT_EQ(1u, candidates->count());
1912 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1913
1914 // Update the RemoteSessionDescription with a new session description and
1915 // a candidate and check that the new remote session description contains both
1916 // candidates.
1917 SessionDescriptionInterface* offer = CreateRemoteOffer();
1918 cricket::Candidate candidate2;
1919 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1920 candidate2);
1921 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1922 SetRemoteDescriptionWithoutError(offer);
1923
1924 remote_desc = session_->remote_description();
1925 ASSERT_TRUE(remote_desc != NULL);
1926 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1927 candidates = remote_desc->candidates(kMediaContentIndex0);
1928 ASSERT_EQ(2u, candidates->count());
1929 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1930 // Username and password have be updated with the TransportInfo of the
1931 // SessionDescription, won't be equal to the original one.
1932 candidate2.set_username(candidates->at(0)->candidate().username());
1933 candidate2.set_password(candidates->at(0)->candidate().password());
1934 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
1935 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
1936 // No need to verify the username and password.
1937 candidate1.set_username(candidates->at(1)->candidate().username());
1938 candidate1.set_password(candidates->at(1)->candidate().password());
1939 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
1940
1941 // Test that the candidate is ignored if we can add the same candidate again.
1942 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1943}
1944
1945// Test that local candidates are added to the local session description and
1946// that they are retained if the local session description is changed.
1947TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001948 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001949 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001950 mediastream_signaling_.SendAudioVideoStream1();
1951 CreateAndSetRemoteOfferAndLocalAnswer();
1952
1953 const SessionDescriptionInterface* local_desc = session_->local_description();
1954 const IceCandidateCollection* candidates =
1955 local_desc->candidates(kMediaContentIndex0);
1956 ASSERT_TRUE(candidates != NULL);
1957 EXPECT_EQ(0u, candidates->count());
1958
1959 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1960
1961 local_desc = session_->local_description();
1962 candidates = local_desc->candidates(kMediaContentIndex0);
1963 ASSERT_TRUE(candidates != NULL);
1964 EXPECT_LT(0u, candidates->count());
1965 candidates = local_desc->candidates(1);
1966 ASSERT_TRUE(candidates != NULL);
1967 EXPECT_LT(0u, candidates->count());
1968
1969 // Update the session descriptions.
1970 mediastream_signaling_.SendAudioVideoStream1();
1971 CreateAndSetRemoteOfferAndLocalAnswer();
1972
1973 local_desc = session_->local_description();
1974 candidates = local_desc->candidates(kMediaContentIndex0);
1975 ASSERT_TRUE(candidates != NULL);
1976 EXPECT_LT(0u, candidates->count());
1977 candidates = local_desc->candidates(1);
1978 ASSERT_TRUE(candidates != NULL);
1979 EXPECT_LT(0u, candidates->count());
1980}
1981
1982// Test that we can set a remote session description with remote candidates.
1983TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001984 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001985
1986 cricket::Candidate candidate1;
1987 candidate1.set_component(1);
1988 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
1989 candidate1);
1990 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001991 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001992
1993 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
1994 SetRemoteDescriptionWithoutError(offer);
1995
1996 const SessionDescriptionInterface* remote_desc =
1997 session_->remote_description();
1998 ASSERT_TRUE(remote_desc != NULL);
1999 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2000 const IceCandidateCollection* candidates =
2001 remote_desc->candidates(kMediaContentIndex0);
2002 ASSERT_EQ(1u, candidates->count());
2003 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2004
wu@webrtc.org91053e72013-08-10 07:18:04 +00002005 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002006 SetLocalDescriptionWithoutError(answer);
2007}
2008
2009// Test that offers and answers contains ice candidates when Ice candidates have
2010// been gathered.
2011TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002012 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002013 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002014 mediastream_signaling_.SendAudioVideoStream1();
2015 // Ice is started but candidates are not provided until SetLocalDescription
2016 // is called.
2017 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2018 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2019 CreateAndSetRemoteOfferAndLocalAnswer();
2020 // Wait until at least one local candidate has been collected.
2021 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2022 kIceCandidatesTimeout);
2023 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
2024 kIceCandidatesTimeout);
2025
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002026 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2027
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002028 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2029 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
2030 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
2031 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
2032
2033 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2034 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002035 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002036 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2037 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
2038 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
2039 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
2040 SetLocalDescriptionWithoutError(answer);
2041}
2042
2043// Verifies TransportProxy and media channels are created with content names
2044// present in the SessionDescription.
2045TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002046 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002047 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002048 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049
2050 // CreateOffer creates session description with the content names "audio" and
2051 // "video". Goal is to modify these content names and verify transport channel
2052 // proxy in the BaseSession, as proxies are created with the content names
2053 // present in SDP.
2054 std::string sdp;
2055 EXPECT_TRUE(offer->ToString(&sdp));
2056 const std::string kAudioMid = "a=mid:audio";
2057 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2058 const std::string kVideoMid = "a=mid:video";
2059 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2060
2061 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002062 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002063 kAudioMidReplaceStr.c_str(),
2064 kAudioMidReplaceStr.length(),
2065 &sdp);
2066 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002067 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002068 kVideoMidReplaceStr.c_str(),
2069 kVideoMidReplaceStr.length(),
2070 &sdp);
2071
2072 SessionDescriptionInterface* modified_offer =
2073 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2074
2075 SetRemoteDescriptionWithoutError(modified_offer);
2076
2077 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002078 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002079 SetLocalDescriptionWithoutError(answer);
2080
2081 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
2082 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
2083 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2084 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2085}
2086
2087// Test that an offer contains the correct media content descriptions based on
2088// the send streams when no constraints have been set.
2089TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002090 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002091 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2092
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093 ASSERT_TRUE(offer != NULL);
2094 const cricket::ContentInfo* content =
2095 cricket::GetFirstAudioContent(offer->description());
2096 EXPECT_TRUE(content != NULL);
2097 content = cricket::GetFirstVideoContent(offer->description());
2098 EXPECT_TRUE(content == NULL);
2099}
2100
2101// Test that an offer contains the correct media content descriptions based on
2102// the send streams when no constraints have been set.
2103TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002104 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002105 // Test Audio only offer.
2106 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002107 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2108
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002109 const cricket::ContentInfo* content =
2110 cricket::GetFirstAudioContent(offer->description());
2111 EXPECT_TRUE(content != NULL);
2112 content = cricket::GetFirstVideoContent(offer->description());
2113 EXPECT_TRUE(content == NULL);
2114
2115 // Test Audio / Video offer.
2116 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002117 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118 content = cricket::GetFirstAudioContent(offer->description());
2119 EXPECT_TRUE(content != NULL);
2120 content = cricket::GetFirstVideoContent(offer->description());
2121 EXPECT_TRUE(content != NULL);
2122}
2123
2124// Test that an offer contains no media content descriptions if
2125// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2126TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002127 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002128 PeerConnectionInterface::RTCOfferAnswerOptions options;
2129 options.offer_to_receive_audio = 0;
2130 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002131
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002132 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002133 CreateOffer(options));
2134
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002135 ASSERT_TRUE(offer != NULL);
2136 const cricket::ContentInfo* content =
2137 cricket::GetFirstAudioContent(offer->description());
2138 EXPECT_TRUE(content == NULL);
2139 content = cricket::GetFirstVideoContent(offer->description());
2140 EXPECT_TRUE(content == NULL);
2141}
2142
2143// Test that an offer contains only audio media content descriptions if
2144// kOfferToReceiveAudio constraints are set to true.
2145TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002146 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002147 PeerConnectionInterface::RTCOfferAnswerOptions options;
2148 options.offer_to_receive_audio =
2149 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2150
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002151 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002152 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002153
2154 const cricket::ContentInfo* content =
2155 cricket::GetFirstAudioContent(offer->description());
2156 EXPECT_TRUE(content != NULL);
2157 content = cricket::GetFirstVideoContent(offer->description());
2158 EXPECT_TRUE(content == NULL);
2159}
2160
2161// Test that an offer contains audio and video media content descriptions if
2162// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2163TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002164 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002165 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002166 PeerConnectionInterface::RTCOfferAnswerOptions options;
2167 options.offer_to_receive_audio =
2168 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2169 options.offer_to_receive_video =
2170 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2171
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002172 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002173 CreateOffer(options));
2174
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002175 const cricket::ContentInfo* content =
2176 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002177 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002178
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002179 content = cricket::GetFirstVideoContent(offer->description());
2180 EXPECT_TRUE(content != NULL);
2181
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002182 // Sets constraints to false and verifies that audio/video contents are
2183 // removed.
2184 options.offer_to_receive_audio = 0;
2185 options.offer_to_receive_video = 0;
2186 offer.reset(CreateOffer(options));
2187
2188 content = cricket::GetFirstAudioContent(offer->description());
2189 EXPECT_TRUE(content == NULL);
2190 content = cricket::GetFirstVideoContent(offer->description());
2191 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002192}
2193
2194// Test that an answer can not be created if the last remote description is not
2195// an offer.
2196TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002197 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002198 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002199 SetLocalDescriptionWithoutError(offer);
2200 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2201 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002202 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002203}
2204
2205// Test that an answer contains the correct media content descriptions when no
2206// constraints have been set.
2207TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002208 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002209 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002210 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002211 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002212 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002213 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002214 const cricket::ContentInfo* content =
2215 cricket::GetFirstAudioContent(answer->description());
2216 ASSERT_TRUE(content != NULL);
2217 EXPECT_FALSE(content->rejected);
2218
2219 content = cricket::GetFirstVideoContent(answer->description());
2220 ASSERT_TRUE(content != NULL);
2221 EXPECT_FALSE(content->rejected);
2222}
2223
2224// Test that an answer contains the correct media content descriptions when no
2225// constraints have been set and the offer only contain audio.
2226TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002227 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002228 // Create a remote offer with audio only.
2229 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002230
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002231 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002232 CreateRemoteOffer(options));
2233 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2234 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2235
2236 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002237 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002238 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002239 const cricket::ContentInfo* content =
2240 cricket::GetFirstAudioContent(answer->description());
2241 ASSERT_TRUE(content != NULL);
2242 EXPECT_FALSE(content->rejected);
2243
2244 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2245}
2246
2247// Test that an answer contains the correct media content descriptions when no
2248// constraints have been set.
2249TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002250 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002251 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002252 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002253 SetRemoteDescriptionWithoutError(offer.release());
2254 // Test with a stream with tracks.
2255 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002256 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002257 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002258 const cricket::ContentInfo* content =
2259 cricket::GetFirstAudioContent(answer->description());
2260 ASSERT_TRUE(content != NULL);
2261 EXPECT_FALSE(content->rejected);
2262
2263 content = cricket::GetFirstVideoContent(answer->description());
2264 ASSERT_TRUE(content != NULL);
2265 EXPECT_FALSE(content->rejected);
2266}
2267
2268// Test that an answer contains the correct media content descriptions when
2269// constraints have been set but no stream is sent.
2270TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002271 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002272 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002273 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002274 SetRemoteDescriptionWithoutError(offer.release());
2275
2276 webrtc::FakeConstraints constraints_no_receive;
2277 constraints_no_receive.SetMandatoryReceiveAudio(false);
2278 constraints_no_receive.SetMandatoryReceiveVideo(false);
2279
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002280 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002281 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002282 const cricket::ContentInfo* content =
2283 cricket::GetFirstAudioContent(answer->description());
2284 ASSERT_TRUE(content != NULL);
2285 EXPECT_TRUE(content->rejected);
2286
2287 content = cricket::GetFirstVideoContent(answer->description());
2288 ASSERT_TRUE(content != NULL);
2289 EXPECT_TRUE(content->rejected);
2290}
2291
2292// Test that an answer contains the correct media content descriptions when
2293// constraints have been set and streams are sent.
2294TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002295 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002296 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002297 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002298 SetRemoteDescriptionWithoutError(offer.release());
2299
2300 webrtc::FakeConstraints constraints_no_receive;
2301 constraints_no_receive.SetMandatoryReceiveAudio(false);
2302 constraints_no_receive.SetMandatoryReceiveVideo(false);
2303
2304 // Test with a stream with tracks.
2305 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002306 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002307 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002308
2309 // TODO(perkj): Should the direction be set to SEND_ONLY?
2310 const cricket::ContentInfo* content =
2311 cricket::GetFirstAudioContent(answer->description());
2312 ASSERT_TRUE(content != NULL);
2313 EXPECT_FALSE(content->rejected);
2314
2315 // TODO(perkj): Should the direction be set to SEND_ONLY?
2316 content = cricket::GetFirstVideoContent(answer->description());
2317 ASSERT_TRUE(content != NULL);
2318 EXPECT_FALSE(content->rejected);
2319}
2320
2321TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2322 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002323 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002324 PeerConnectionInterface::RTCOfferAnswerOptions options;
2325 options.offer_to_receive_audio =
2326 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2327 options.voice_activity_detection = false;
2328
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002329 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002330 CreateOffer(options));
2331
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002332 const cricket::ContentInfo* content =
2333 cricket::GetFirstAudioContent(offer->description());
2334 EXPECT_TRUE(content != NULL);
2335 EXPECT_TRUE(VerifyNoCNCodecs(content));
2336}
2337
2338TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2339 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002340 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002341 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002342 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002343 SetRemoteDescriptionWithoutError(offer.release());
2344
2345 webrtc::FakeConstraints constraints;
2346 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002347 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002348 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002349 const cricket::ContentInfo* content =
2350 cricket::GetFirstAudioContent(answer->description());
2351 ASSERT_TRUE(content != NULL);
2352 EXPECT_TRUE(VerifyNoCNCodecs(content));
2353}
2354
2355// This test verifies the call setup when remote answer with audio only and
2356// later updates with video.
2357TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002358 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2360 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2361
2362 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002363 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002364
2365 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002366 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2367
2368 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2369 // and answer;
2370 SetLocalDescriptionWithoutError(offer);
2371 SetRemoteDescriptionWithoutError(answer);
2372
2373 video_channel_ = media_engine_->GetVideoChannel(0);
2374 voice_channel_ = media_engine_->GetVoiceChannel(0);
2375
2376 ASSERT_TRUE(video_channel_ == NULL);
2377
2378 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2379 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2380 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2381
2382 // Let the remote end update the session descriptions, with Audio and Video.
2383 mediastream_signaling_.SendAudioVideoStream2();
2384 CreateAndSetRemoteOfferAndLocalAnswer();
2385
2386 video_channel_ = media_engine_->GetVideoChannel(0);
2387 voice_channel_ = media_engine_->GetVoiceChannel(0);
2388
2389 ASSERT_TRUE(video_channel_ != NULL);
2390 ASSERT_TRUE(voice_channel_ != NULL);
2391
2392 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2393 ASSERT_EQ(1u, video_channel_->send_streams().size());
2394 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2395 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2396 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2397 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2398 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2399 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2400
2401 // Change session back to audio only.
2402 mediastream_signaling_.UseOptionsAudioOnly();
2403 CreateAndSetRemoteOfferAndLocalAnswer();
2404
2405 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2406 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2407 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2408 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2409 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2410}
2411
2412// This test verifies the call setup when remote answer with video only and
2413// later updates with audio.
2414TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002415 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002416 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2417 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2418 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002419 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002420
2421 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002422 options.recv_audio = false;
2423 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002424 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2425 offer, options, cricket::SEC_ENABLED);
2426
2427 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2428 // and answer.
2429 SetLocalDescriptionWithoutError(offer);
2430 SetRemoteDescriptionWithoutError(answer);
2431
2432 video_channel_ = media_engine_->GetVideoChannel(0);
2433 voice_channel_ = media_engine_->GetVoiceChannel(0);
2434
2435 ASSERT_TRUE(voice_channel_ == NULL);
2436 ASSERT_TRUE(video_channel_ != NULL);
2437
2438 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2439 ASSERT_EQ(1u, video_channel_->send_streams().size());
2440 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2441
2442 // Update the session descriptions, with Audio and Video.
2443 mediastream_signaling_.SendAudioVideoStream2();
2444 CreateAndSetRemoteOfferAndLocalAnswer();
2445
2446 voice_channel_ = media_engine_->GetVoiceChannel(0);
2447 ASSERT_TRUE(voice_channel_ != NULL);
2448
2449 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2450 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2451 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2452 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2453
2454 // Change session back to video only.
2455 mediastream_signaling_.UseOptionsVideoOnly();
2456 CreateAndSetRemoteOfferAndLocalAnswer();
2457
2458 video_channel_ = media_engine_->GetVideoChannel(0);
2459 voice_channel_ = media_engine_->GetVoiceChannel(0);
2460
2461 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2462 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2463 ASSERT_EQ(1u, video_channel_->send_streams().size());
2464 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2465}
2466
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002467TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002468 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002469 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002470 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002471 VerifyCryptoParams(offer->description());
2472 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002473 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002474 VerifyCryptoParams(answer->description());
2475}
2476
2477TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002478 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002479 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002480 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002481 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002482 VerifyNoCryptoParams(offer->description(), false);
2483}
2484
2485TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002486 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002487 VerifyAnswerFromNonCryptoOffer();
2488}
2489
2490TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002491 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002492 VerifyAnswerFromCryptoOffer();
2493}
2494
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002495// This test verifies that setLocalDescription fails if
2496// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2497TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002498 Init();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002499 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002500 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2501
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002502 std::string sdp;
2503 RemoveIceUfragPwdLines(offer.get(), &sdp);
2504 SessionDescriptionInterface* modified_offer =
2505 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002506 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002507}
2508
2509// This test verifies that setRemoteDescription fails if
2510// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2511TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002512 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002513 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002514 std::string sdp;
2515 RemoveIceUfragPwdLines(offer.get(), &sdp);
2516 SessionDescriptionInterface* modified_offer =
2517 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002518 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002519}
2520
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002521// This test verifies that setLocalDescription fails if local offer has
2522// too short ice ufrag and pwd strings.
2523TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002524 Init();
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002525 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002526 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2527
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002528 std::string sdp;
2529 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2530 // recommended values of 4 and 22 bytes respectively.
2531 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2532 SessionDescriptionInterface* modified_offer =
2533 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2534 std::string error;
2535 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2536
2537 // Test with string greater than 256.
2538 sdp.clear();
2539 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2540 &sdp);
2541 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2542 NULL);
2543 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2544}
2545
2546// This test verifies that setRemoteDescription fails if remote offer has
2547// too short ice ufrag and pwd strings.
2548TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002549 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002550 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002551 std::string sdp;
2552 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2553 // recommended values of 4 and 22 bytes respectively.
2554 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2555 SessionDescriptionInterface* modified_offer =
2556 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2557 std::string error;
2558 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2559
2560 sdp.clear();
2561 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2562 &sdp);
2563 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2564 NULL);
2565 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2566}
2567
honghaiz503726c2015-07-31 12:37:38 -07002568// Test that if the remote description indicates the peer requested ICE restart
2569// (via a new ufrag or pwd), the old ICE candidates are not copied,
2570// and vice versa.
2571TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithIceRestart) {
2572 Init();
2573 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2574
2575 // Create the first offer.
2576 std::string sdp;
2577 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2578 "abcdefghijklmnopqrstuvwx", &sdp);
2579 SessionDescriptionInterface* offer1 =
2580 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2581 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2582 0, "", "", "relay", 0, "");
2583 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2584 candidate1);
2585 EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1));
2586 SetRemoteDescriptionWithoutError(offer1);
2587 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2588
2589 // The second offer has the same ufrag and pwd but different address.
2590 sdp.clear();
2591 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2592 "abcdefghijklmnopqrstuvwx", &sdp);
2593 SessionDescriptionInterface* offer2 =
2594 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2595 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2596 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2597 candidate1);
2598 EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2));
2599 SetRemoteDescriptionWithoutError(offer2);
2600 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2601
2602 // The third offer has a different ufrag and different address.
2603 sdp.clear();
2604 ModifyIceUfragPwdLines(offer.get(), "0123456789012333",
2605 "abcdefghijklmnopqrstuvwx", &sdp);
2606 SessionDescriptionInterface* offer3 =
2607 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2608 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2609 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2610 candidate1);
2611 EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3));
2612 SetRemoteDescriptionWithoutError(offer3);
2613 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2614
2615 // The fourth offer has no candidate but a different ufrag/pwd.
2616 sdp.clear();
2617 ModifyIceUfragPwdLines(offer.get(), "0123456789012444",
2618 "abcdefghijklmnopqrstuvyz", &sdp);
2619 SessionDescriptionInterface* offer4 =
2620 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2621 SetRemoteDescriptionWithoutError(offer4);
2622 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2623}
2624
Donald Curtisd4f769d2015-05-28 09:48:21 -07002625// Test that candidates sent to the "video" transport do not get pushed down to
2626// the "audio" transport channel when bundling using TransportProxy.
2627TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2628 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2629
2630 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2631 mediastream_signaling_.SendAudioVideoStream1();
2632
2633 PeerConnectionInterface::RTCOfferAnswerOptions options;
2634 options.use_rtp_mux = true;
2635
2636 SessionDescriptionInterface* offer = CreateRemoteOffer();
2637 SetRemoteDescriptionWithoutError(offer);
2638
2639 SessionDescriptionInterface* answer = CreateAnswer(NULL);
2640 SetLocalDescriptionWithoutError(answer);
2641
2642 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2643 session_->GetTransportProxy("video")->impl());
2644
2645 cricket::Transport* t = session_->GetTransport("audio");
2646
2647 // Checks if one of the transport channels contains a connection using a given
2648 // port.
2649 auto connection_with_remote_port = [t](int port) {
2650 cricket::TransportStats stats;
2651 t->GetStats(&stats);
2652 for (auto& chan_stat : stats.channel_stats) {
2653 for (auto& conn_info : chan_stat.connection_infos) {
2654 if (conn_info.remote_candidate.address().port() == port) {
2655 return true;
2656 }
2657 }
2658 }
2659 return false;
2660 };
2661
2662 EXPECT_FALSE(connection_with_remote_port(5000));
2663 EXPECT_FALSE(connection_with_remote_port(5001));
2664 EXPECT_FALSE(connection_with_remote_port(6000));
2665
2666 // The way the *_WAIT checks work is they only wait if the condition fails,
2667 // which does not help in the case where state is not changing. This is
2668 // problematic in this test since we want to verify that adding a video
2669 // candidate does _not_ change state. So we interleave candidates and assume
2670 // that messages are executed in the order they were posted.
2671
2672 // First audio candidate.
2673 cricket::Candidate candidate0;
2674 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2675 candidate0.set_component(1);
2676 candidate0.set_protocol("udp");
2677 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2678 candidate0);
2679 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2680
2681 // Video candidate.
2682 cricket::Candidate candidate1;
2683 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2684 candidate1.set_component(1);
2685 candidate1.set_protocol("udp");
2686 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2687 candidate1);
2688 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2689
2690 // Second audio candidate.
2691 cricket::Candidate candidate2;
2692 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
2693 candidate2.set_component(1);
2694 candidate2.set_protocol("udp");
2695 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2696 candidate2);
2697 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2698
2699 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
2700 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
2701
2702 // No need here for a _WAIT check since we are checking that state hasn't
2703 // changed: if this is false we would be doing waits for nothing and if this
2704 // is true then there will be no messages processed anyways.
2705 EXPECT_FALSE(connection_with_remote_port(6000));
2706}
2707
Peter Thatcher4eddf182015-04-30 10:55:59 -07002708// kBundlePolicyBalanced bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002709TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
2710 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002711 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002712
2713 PeerConnectionInterface::RTCOfferAnswerOptions options;
2714 options.use_rtp_mux = true;
2715
2716 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002717 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07002718
2719 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2720 session_->GetTransportProxy("video")->impl());
2721
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002722 mediastream_signaling_.SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002723 SessionDescriptionInterface* answer =
2724 CreateRemoteAnswer(session_->local_description());
2725 SetRemoteDescriptionWithoutError(answer);
2726
2727 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2728 session_->GetTransportProxy("video")->impl());
2729}
2730
2731// kBundlePolicyBalanced bundle policy but no BUNDLE in the answer.
2732TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
2733 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2734 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002735
Donald Curtis0e209b02015-03-24 09:29:54 -07002736 PeerConnectionInterface::RTCOfferAnswerOptions options;
2737 options.use_rtp_mux = true;
2738
2739 SessionDescriptionInterface* offer = CreateOffer(options);
2740 SetLocalDescriptionWithoutError(offer);
2741
2742 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2743 session_->GetTransportProxy("video")->impl());
2744
2745 mediastream_signaling_.SendAudioVideoStream2();
2746
2747 // Remove BUNDLE from the answer.
2748 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2749 CreateRemoteAnswer(session_->local_description()));
2750 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2751 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2752 JsepSessionDescription* modified_answer =
2753 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2754 modified_answer->Initialize(answer_copy, "1", "1");
2755 SetRemoteDescriptionWithoutError(modified_answer); //
2756
2757 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2758 session_->GetTransportProxy("video")->impl());
2759}
2760
2761// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
2762TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
2763 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2764 mediastream_signaling_.SendAudioVideoStream1();
2765
2766 PeerConnectionInterface::RTCOfferAnswerOptions options;
2767 options.use_rtp_mux = true;
2768
2769 SessionDescriptionInterface* offer = CreateOffer(options);
2770 SetLocalDescriptionWithoutError(offer);
2771
2772 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2773 session_->GetTransportProxy("video")->impl());
2774
2775 mediastream_signaling_.SendAudioVideoStream2();
2776 SessionDescriptionInterface* answer =
2777 CreateRemoteAnswer(session_->local_description());
2778 SetRemoteDescriptionWithoutError(answer);
2779
2780 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2781 session_->GetTransportProxy("video")->impl());
2782}
2783
2784// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
2785TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
2786 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2787 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002788
Donald Curtis0e209b02015-03-24 09:29:54 -07002789 PeerConnectionInterface::RTCOfferAnswerOptions options;
2790 options.use_rtp_mux = true;
2791
2792 SessionDescriptionInterface* offer = CreateOffer(options);
2793 SetLocalDescriptionWithoutError(offer);
2794
2795 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2796 session_->GetTransportProxy("video")->impl());
2797
2798 mediastream_signaling_.SendAudioVideoStream2();
2799
2800 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002801 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002802 CreateRemoteAnswer(session_->local_description()));
2803 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2804 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2805 JsepSessionDescription* modified_answer =
2806 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2807 modified_answer->Initialize(answer_copy, "1", "1");
2808 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002809
Donald Curtis0e209b02015-03-24 09:29:54 -07002810 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2811 session_->GetTransportProxy("video")->impl());
2812}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002813
Peter Thatcher4eddf182015-04-30 10:55:59 -07002814// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002815TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
2816 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2817 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002818
Donald Curtis0e209b02015-03-24 09:29:54 -07002819 PeerConnectionInterface::RTCOfferAnswerOptions options;
2820 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002821
Donald Curtis0e209b02015-03-24 09:29:54 -07002822 SessionDescriptionInterface* offer = CreateOffer(options);
2823 SetLocalDescriptionWithoutError(offer);
2824
2825 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2826 session_->GetTransportProxy("video")->impl());
2827
2828 mediastream_signaling_.SendAudioVideoStream2();
2829 SessionDescriptionInterface* answer =
2830 CreateRemoteAnswer(session_->local_description());
2831 SetRemoteDescriptionWithoutError(answer);
2832
2833 // This should lead to an audio-only call but isn't implemented
2834 // correctly yet.
2835 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2836 session_->GetTransportProxy("video")->impl());
2837}
2838
2839// kBundlePolicyMaxCompat bundle policy but no BUNDLE in the answer.
2840TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
2841 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2842 mediastream_signaling_.SendAudioVideoStream1();
2843 PeerConnectionInterface::RTCOfferAnswerOptions options;
2844 options.use_rtp_mux = true;
2845
2846 SessionDescriptionInterface* offer = CreateOffer(options);
2847 SetLocalDescriptionWithoutError(offer);
2848
2849 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2850 session_->GetTransportProxy("video")->impl());
2851
2852 mediastream_signaling_.SendAudioVideoStream2();
2853
2854 // Remove BUNDLE from the answer.
2855 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2856 CreateRemoteAnswer(session_->local_description()));
2857 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2858 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2859 JsepSessionDescription* modified_answer =
2860 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2861 modified_answer->Initialize(answer_copy, "1", "1");
2862 SetRemoteDescriptionWithoutError(modified_answer); //
2863
2864 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2865 session_->GetTransportProxy("video")->impl());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002866}
2867
Peter Thatcher4eddf182015-04-30 10:55:59 -07002868// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
2869TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
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 SetRemoteDescriptionWithoutError(offer);
2878
2879 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2880 session_->GetTransportProxy("video")->impl());
2881}
2882
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002883TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
2884 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
2885 mediastream_signaling_.SendAudioVideoStream1();
2886
2887 PeerConnectionInterface::RTCOfferAnswerOptions options;
2888 SessionDescriptionInterface* offer = CreateOffer(options);
2889 SetLocalDescriptionWithoutError(offer);
2890
2891 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2892 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2893
2894 mediastream_signaling_.SendAudioVideoStream2();
2895 SessionDescriptionInterface* answer =
2896 CreateRemoteAnswer(session_->local_description());
2897 SetRemoteDescriptionWithoutError(answer);
2898
2899 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2900 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2901}
2902
2903TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
2904 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
2905 mediastream_signaling_.SendAudioVideoStream1();
2906
2907 PeerConnectionInterface::RTCOfferAnswerOptions options;
2908 SessionDescriptionInterface* offer = CreateOffer(options);
2909 SetLocalDescriptionWithoutError(offer);
2910
2911 EXPECT_TRUE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2912 EXPECT_TRUE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2913
2914 mediastream_signaling_.SendAudioVideoStream2();
2915 SessionDescriptionInterface* answer =
2916 CreateRemoteAnswer(session_->local_description());
2917 SetRemoteDescriptionWithoutError(answer);
2918
2919 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2920 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2921}
2922
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002923// This test verifies that SetLocalDescription and SetRemoteDescription fails
2924// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2925TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002926 Init();
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002927 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002928
2929 PeerConnectionInterface::RTCOfferAnswerOptions options;
2930 options.use_rtp_mux = true;
2931
2932 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002933 std::string offer_str;
2934 offer->ToString(&offer_str);
2935 // Disable rtcp-mux
2936 const std::string rtcp_mux = "rtcp-mux";
2937 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002938 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002939 xrtcp_mux.c_str(), xrtcp_mux.length(),
2940 &offer_str);
2941 JsepSessionDescription *local_offer =
2942 new JsepSessionDescription(JsepSessionDescription::kOffer);
2943 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002944 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002945 JsepSessionDescription *remote_offer =
2946 new JsepSessionDescription(JsepSessionDescription::kOffer);
2947 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002948 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002949 // Trying unmodified SDP.
2950 SetLocalDescriptionWithoutError(offer);
2951}
2952
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002953TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002954 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002955 mediastream_signaling_.SendAudioVideoStream1();
2956 CreateAndSetRemoteOfferAndLocalAnswer();
2957 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2958 ASSERT_TRUE(channel != NULL);
2959 ASSERT_EQ(1u, channel->recv_streams().size());
2960 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2961 double left_vol, right_vol;
2962 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2963 EXPECT_EQ(1, left_vol);
2964 EXPECT_EQ(1, right_vol);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002965 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002966 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002967 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2968 EXPECT_EQ(0, left_vol);
2969 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002970 EXPECT_EQ(0, renderer->channel_id());
2971 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002972 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2973 EXPECT_EQ(1, left_vol);
2974 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002975 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002976}
2977
2978TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002979 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002980 mediastream_signaling_.SendAudioVideoStream1();
2981 CreateAndSetRemoteOfferAndLocalAnswer();
2982 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2983 ASSERT_TRUE(channel != NULL);
2984 ASSERT_EQ(1u, channel->send_streams().size());
2985 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2986 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2987
2988 cricket::AudioOptions options;
2989 options.echo_cancellation.Set(true);
2990
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002991 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002992 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002993 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2994 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002995 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002996 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002997
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002998 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002999 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003000 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3001 bool value;
3002 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
3003 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003004 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003005 EXPECT_TRUE(renderer->sink() == NULL);
3006}
3007
3008TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003009 Init();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003010 mediastream_signaling_.SendAudioVideoStream1();
3011 CreateAndSetRemoteOfferAndLocalAnswer();
3012 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3013 ASSERT_TRUE(channel != NULL);
3014 ASSERT_EQ(1u, channel->send_streams().size());
3015 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3016
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003017 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003018 cricket::AudioOptions options;
3019 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3020 EXPECT_TRUE(renderer->sink() != NULL);
3021
3022 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3023 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3024 // SetSink(NULL) callback afterwards.
3025 renderer.reset();
3026
3027 // This will trigger SetSink(NULL) if no OnClose() callback.
3028 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003029}
3030
3031TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003032 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003033 mediastream_signaling_.SendAudioVideoStream1();
3034 CreateAndSetRemoteOfferAndLocalAnswer();
3035 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3036 ASSERT_TRUE(channel != NULL);
3037 ASSERT_LT(0u, channel->renderers().size());
3038 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3039 ASSERT_EQ(1u, channel->recv_streams().size());
3040 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
3041 cricket::FakeVideoRenderer renderer;
3042 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
3043 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
3044 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
3045 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3046}
3047
3048TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003049 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003050 mediastream_signaling_.SendAudioVideoStream1();
3051 CreateAndSetRemoteOfferAndLocalAnswer();
3052 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3053 ASSERT_TRUE(channel != NULL);
3054 ASSERT_EQ(1u, channel->send_streams().size());
3055 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3056 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3057 cricket::VideoOptions* options = NULL;
3058 session_->SetVideoSend(send_ssrc, false, options);
3059 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3060 session_->SetVideoSend(send_ssrc, true, options);
3061 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3062}
3063
3064TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3065 TestCanInsertDtmf(false);
3066}
3067
3068TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3069 TestCanInsertDtmf(true);
3070}
3071
3072TEST_F(WebRtcSessionTest, InsertDtmf) {
3073 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003074 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003075 mediastream_signaling_.SendAudioVideoStream1();
3076 CreateAndSetRemoteOfferAndLocalAnswer();
3077 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3078 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3079
3080 // Insert DTMF
3081 const int expected_flags = DF_SEND;
3082 const int expected_duration = 90;
3083 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3084 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3085 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3086
3087 // Verify
3088 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
3089 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3090 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
3091 expected_duration, expected_flags));
3092 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
3093 expected_duration, expected_flags));
3094 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
3095 expected_duration, expected_flags));
3096}
3097
3098// This test verifies the |initiator| flag when session initiates the call.
3099TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003100 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003101 EXPECT_FALSE(session_->initiator());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003102 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003103 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3104 SetLocalDescriptionWithoutError(offer);
3105 EXPECT_TRUE(session_->initiator());
3106 SetRemoteDescriptionWithoutError(answer);
3107 EXPECT_TRUE(session_->initiator());
3108}
3109
3110// This test verifies the |initiator| flag when session receives the call.
3111TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003112 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003113 EXPECT_FALSE(session_->initiator());
3114 SessionDescriptionInterface* offer = CreateRemoteOffer();
3115 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003116 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003117
3118 EXPECT_FALSE(session_->initiator());
3119 SetLocalDescriptionWithoutError(answer);
3120 EXPECT_FALSE(session_->initiator());
3121}
3122
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003123// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3124TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003125 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003126 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003127 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003128 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003129 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003130 CreateRemoteAnswer(session_->local_description()));
3131
3132 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3133 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003134 JsepSessionDescription* modified_answer =
3135 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003136
3137 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3138 answer->session_id(),
3139 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003140 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003141
wu@webrtc.org4e393072014-04-07 17:04:35 +00003142 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003143 std::string sdp;
3144 EXPECT_TRUE(answer->ToString(&sdp));
3145 const std::string kAudioMid = "a=mid:audio";
3146 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003147 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003148 kAudioMidReplaceStr.c_str(),
3149 kAudioMidReplaceStr.length(),
3150 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003151 SessionDescriptionInterface* modified_answer1 =
3152 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003153 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003154
wu@webrtc.org4e393072014-04-07 17:04:35 +00003155 // Different media types.
3156 EXPECT_TRUE(answer->ToString(&sdp));
3157 const std::string kAudioMline = "m=audio";
3158 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003159 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003160 kAudioMlineReplaceStr.c_str(),
3161 kAudioMlineReplaceStr.length(),
3162 &sdp);
3163 SessionDescriptionInterface* modified_answer2 =
3164 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3165 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3166
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003167 SetRemoteDescriptionWithoutError(answer.release());
3168}
3169
3170// Verifying remote offer and local answer have matching m-lines as per
3171// RFC 3264.
3172TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003173 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003174 mediastream_signaling_.SendAudioVideoStream1();
3175 SessionDescriptionInterface* offer = CreateRemoteOffer();
3176 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003177 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003178
3179 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3180 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003181 JsepSessionDescription* modified_answer =
3182 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003183
3184 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3185 answer->session_id(),
3186 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003187 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003188 SetLocalDescriptionWithoutError(answer);
3189}
3190
3191// This test verifies that WebRtcSession does not start candidate allocation
3192// before SetLocalDescription is called.
3193TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003194 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003195 mediastream_signaling_.SendAudioVideoStream1();
3196 SessionDescriptionInterface* offer = CreateRemoteOffer();
3197 cricket::Candidate candidate;
3198 candidate.set_component(1);
3199 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3200 candidate);
3201 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3202 cricket::Candidate candidate1;
3203 candidate1.set_component(1);
3204 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3205 candidate1);
3206 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3207 SetRemoteDescriptionWithoutError(offer);
3208 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
3209 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
3210
3211 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003212 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003213 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3214 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3215
wu@webrtc.org91053e72013-08-10 07:18:04 +00003216 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003217 SetLocalDescriptionWithoutError(answer);
3218 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
3219 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
3220 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3221}
3222
3223// This test verifies that crypto parameter is updated in local session
3224// description as per security policy set in MediaSessionDescriptionFactory.
3225TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003226 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003227 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003228 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003229
3230 // Making sure SetLocalDescription correctly sets crypto value in
3231 // SessionDescription object after de-serialization of sdp string. The value
3232 // will be set as per MediaSessionDescriptionFactory.
3233 std::string offer_str;
3234 offer->ToString(&offer_str);
3235 SessionDescriptionInterface* jsep_offer_str =
3236 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3237 SetLocalDescriptionWithoutError(jsep_offer_str);
3238 EXPECT_TRUE(session_->voice_channel()->secure_required());
3239 EXPECT_TRUE(session_->video_channel()->secure_required());
3240}
3241
3242// This test verifies the crypto parameter when security is disabled.
3243TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003244 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003245 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003246 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003247 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003248
3249 // Making sure SetLocalDescription correctly sets crypto value in
3250 // SessionDescription object after de-serialization of sdp string. The value
3251 // will be set as per MediaSessionDescriptionFactory.
3252 std::string offer_str;
3253 offer->ToString(&offer_str);
3254 SessionDescriptionInterface *jsep_offer_str =
3255 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3256 SetLocalDescriptionWithoutError(jsep_offer_str);
3257 EXPECT_FALSE(session_->voice_channel()->secure_required());
3258 EXPECT_FALSE(session_->video_channel()->secure_required());
3259}
3260
3261// This test verifies that an answer contains new ufrag and password if an offer
3262// with new ufrag and password is received.
3263TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003264 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003265 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003266 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003267 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003268 CreateRemoteOffer(options));
3269 SetRemoteDescriptionWithoutError(offer.release());
3270
3271 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003272 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003273 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003274 SetLocalDescriptionWithoutError(answer.release());
3275
3276 // Receive an offer with new ufrag and password.
3277 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003278 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003279 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003280 SetRemoteDescriptionWithoutError(updated_offer1.release());
3281
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003282 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003283 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003284
3285 CompareIceUfragAndPassword(updated_answer1->description(),
3286 session_->local_description()->description(),
3287 false);
3288
3289 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003290}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003291
wu@webrtc.org91053e72013-08-10 07:18:04 +00003292// This test verifies that an answer contains old ufrag and password if an offer
3293// with old ufrag and password is received.
3294TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003295 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003296 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003297 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003298 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003299 CreateRemoteOffer(options));
3300 SetRemoteDescriptionWithoutError(offer.release());
3301
3302 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003303 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003304 CreateAnswer(NULL));
3305 SetLocalDescriptionWithoutError(answer.release());
3306
3307 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003308 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003309 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003310 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003311 SetRemoteDescriptionWithoutError(updated_offer2.release());
3312
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003313 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003314 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003315
3316 CompareIceUfragAndPassword(updated_answer2->description(),
3317 session_->local_description()->description(),
3318 true);
3319
3320 SetLocalDescriptionWithoutError(updated_answer2.release());
3321}
3322
3323TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003324 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003325 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003326 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003327 const std::string session_id_orig = offer->session_id();
3328 const std::string session_version_orig = offer->session_version();
3329 SetLocalDescriptionWithoutError(offer);
3330
3331 video_channel_ = media_engine_->GetVideoChannel(0);
3332 video_channel_->set_fail_set_send_codecs(true);
3333
3334 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003335 SessionDescriptionInterface* answer =
3336 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003337 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003338}
3339
3340// Runs the loopback call test with BUNDLE and STUN disabled.
3341TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3342 // Lets try with only UDP ports.
Peter Thatcher3449faa2015-08-10 12:22:51 -07003343 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003344 cricket::PORTALLOCATOR_DISABLE_STUN |
3345 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003346 TestLoopbackCall();
3347}
3348
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003349TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher3449faa2015-08-10 12:22:51 -07003350 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003351 cricket::PORTALLOCATOR_DISABLE_STUN |
3352 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3353 cricket::PORTALLOCATOR_DISABLE_RELAY);
3354
3355 // best connection is IPv6 since it has higher network preference.
3356 LoopbackNetworkConfiguration config;
3357 config.test_ipv6_network_ = true;
3358 config.best_connection_after_initial_ice_converged_ =
3359 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3360
3361 TestLoopbackCall(config);
3362}
3363
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003364// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003365TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher3449faa2015-08-10 12:22:51 -07003366 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3367 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003368 TestLoopbackCall();
3369}
3370
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003371TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003372 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003373 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003374 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003375
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003376 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
3377 std::string error_code_str = "ERROR_CONTENT";
3378 std::string error_desc = "Fake session error description.";
3379 session_->SetError(error_code, error_desc);
3380
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003381 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
3382 SessionDescriptionInterface* answer =
3383 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003384
3385 std::string action;
3386 std::ostringstream session_error_msg;
3387 session_error_msg << kSessionError << error_code_str << ". ";
3388 session_error_msg << kSessionErrorDesc << error_desc << ".";
3389 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
3390 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003391}
3392
3393TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3394 constraints_.reset(new FakeConstraints());
3395 constraints_->AddOptional(
3396 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003397 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003398
3399 SetLocalDescriptionWithDataChannel();
3400 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3401}
3402
3403TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003404 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003405
3406 constraints_.reset(new FakeConstraints());
3407 constraints_->AddOptional(
3408 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003409 options_.disable_sctp_data_channels = false;
3410
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003411 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003412
3413 SetLocalDescriptionWithDataChannel();
3414 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3415}
3416
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003417TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003418 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003419
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003420 InitWithDtls();
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003421
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003422 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003423 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003424 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3425}
3426
3427TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003428 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003429 SetFactoryDtlsSrtp();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003430 InitWithDtls();
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003431
3432 // Create remote offer with SCTP.
3433 cricket::MediaSessionOptions options;
3434 options.data_channel_type = cricket::DCT_SCTP;
3435 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003436 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003437 SetRemoteDescriptionWithoutError(offer);
3438
3439 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003440 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003441 EXPECT_TRUE(answer != NULL);
3442 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3443 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003444}
3445
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003446TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
3447 constraints_.reset(new FakeConstraints());
3448 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003449 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003450 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003451
3452 SetLocalDescriptionWithDataChannel();
3453 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3454}
3455
3456TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003457 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003458
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003459 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003460
3461 SetLocalDescriptionWithDataChannel();
3462 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3463}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003464
wu@webrtc.org97077a32013-10-25 21:18:33 +00003465TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003466 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003467 options_.disable_sctp_data_channels = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003468 InitWithDtls();
wu@webrtc.org97077a32013-10-25 21:18:33 +00003469
3470 SetLocalDescriptionWithDataChannel();
3471 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3472}
3473
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003474TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003475 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003476 const int new_send_port = 9998;
3477 const int new_recv_port = 7775;
3478
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003479 InitWithDtls();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003480 SetFactoryDtlsSrtp();
3481
3482 // By default, don't actually add the codecs to desc_factory_; they don't
3483 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3484 // let the session description get parsed. That'll get the proper codecs
3485 // into the stream.
3486 cricket::MediaSessionOptions options;
3487 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3488 "stream1", new_send_port, options);
3489
3490 // SetRemoteDescription will take the ownership of the offer.
3491 SetRemoteDescriptionWithoutError(offer);
3492
3493 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3494 new_recv_port, CreateAnswer(NULL));
3495 ASSERT_TRUE(answer != NULL);
3496
3497 // Now set the local description, which'll take ownership of the answer.
3498 SetLocalDescriptionWithoutError(answer);
3499
3500 // TEST PLAN: Set the port number to something new, set it in the SDP,
3501 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003502 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003503 dci.reliable = true;
3504 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003505 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003506 session_->CreateDataChannel("datachannel", &dci);
3507
3508 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3509 int portnum = -1;
3510 ASSERT_TRUE(ch != NULL);
3511 ASSERT_EQ(1UL, ch->send_codecs().size());
3512 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003513 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003514 ch->send_codecs()[0].name.c_str()));
3515 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3516 &portnum));
3517 EXPECT_EQ(new_send_port, portnum);
3518
3519 ASSERT_EQ(1UL, ch->recv_codecs().size());
3520 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003521 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003522 ch->recv_codecs()[0].name.c_str()));
3523 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3524 &portnum));
3525 EXPECT_EQ(new_recv_port, portnum);
3526}
3527
wu@webrtc.org91053e72013-08-10 07:18:04 +00003528// Verifies that CreateOffer succeeds when CreateOffer is called before async
3529// identity generation is finished.
3530TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003531 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003532 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003533
3534 EXPECT_TRUE(session_->waiting_for_identity());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003535 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003536 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3537
wu@webrtc.org91053e72013-08-10 07:18:04 +00003538 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003539 VerifyNoCryptoParams(offer->description(), true);
3540 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003541}
3542
3543// Verifies that CreateAnswer succeeds when CreateOffer is called before async
3544// identity generation is finished.
3545TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003546 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003547 InitWithDtls();
3548 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003549
3550 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003551 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003552 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003553 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003554 ASSERT_TRUE(offer.get() != NULL);
3555 SetRemoteDescriptionWithoutError(offer.release());
3556
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003557 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003558 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003559 VerifyNoCryptoParams(answer->description(), true);
3560 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003561}
3562
3563// Verifies that CreateOffer succeeds when CreateOffer is called after async
3564// identity generation is finished.
3565TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003566 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003567 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003568
3569 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003570
3571 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003572 EXPECT_TRUE(offer != NULL);
3573}
3574
3575// Verifies that CreateOffer fails when CreateOffer is called after async
3576// identity generation fails.
3577TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003578 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00003579 InitWithDtls(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003580
3581 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003582
3583 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003584 EXPECT_TRUE(offer == NULL);
3585}
3586
3587// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3588// before async identity generation is finished.
3589TEST_F(WebRtcSessionTest,
3590 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003591 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003592 VerifyMultipleAsyncCreateDescription(
3593 true, CreateSessionDescriptionRequest::kOffer);
3594}
3595
3596// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3597// before async identity generation fails.
3598TEST_F(WebRtcSessionTest,
3599 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003600 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003601 VerifyMultipleAsyncCreateDescription(
3602 false, CreateSessionDescriptionRequest::kOffer);
3603}
3604
3605// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3606// before async identity generation is finished.
3607TEST_F(WebRtcSessionTest,
3608 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003609 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003610 VerifyMultipleAsyncCreateDescription(
3611 true, CreateSessionDescriptionRequest::kAnswer);
3612}
3613
3614// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3615// before async identity generation fails.
3616TEST_F(WebRtcSessionTest,
3617 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003618 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003619 VerifyMultipleAsyncCreateDescription(
3620 false, CreateSessionDescriptionRequest::kAnswer);
3621}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003622
3623// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3624// offer has no SDES crypto but only DTLS fingerprint.
3625TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3626 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003627 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003628 // Create a remote offer with secured transport disabled.
3629 cricket::MediaSessionOptions options;
3630 JsepSessionDescription* offer(CreateRemoteOffer(
3631 options, cricket::SEC_DISABLED));
3632 // Adds a DTLS fingerprint to the remote offer.
3633 cricket::SessionDescription* sdp = offer->description();
3634 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3635 ASSERT_TRUE(audio != NULL);
3636 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3637 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003638 rtc::SSLFingerprint::CreateFromRfc4572(
3639 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003640 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003641 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003642}
3643
wu@webrtc.orgde305012013-10-31 15:40:38 +00003644// This test verifies DSCP is properly applied on the media channels.
3645TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3646 constraints_.reset(new FakeConstraints());
3647 constraints_->AddOptional(
3648 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003649 Init();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003650 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003651 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003652
3653 SetLocalDescriptionWithoutError(offer);
3654
3655 video_channel_ = media_engine_->GetVideoChannel(0);
3656 voice_channel_ = media_engine_->GetVoiceChannel(0);
3657
3658 ASSERT_TRUE(video_channel_ != NULL);
3659 ASSERT_TRUE(voice_channel_ != NULL);
3660 cricket::AudioOptions audio_options;
3661 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3662 cricket::VideoOptions video_options;
3663 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3664 EXPECT_TRUE(audio_options.dscp.IsSet());
3665 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3666 EXPECT_TRUE(video_options.dscp.IsSet());
3667 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3668}
3669
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003670TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3671 constraints_.reset(new FakeConstraints());
3672 constraints_->AddOptional(
3673 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3674 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003675 Init();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003676 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003677 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003678
3679 SetLocalDescriptionWithoutError(offer);
3680
3681 video_channel_ = media_engine_->GetVideoChannel(0);
3682
3683 ASSERT_TRUE(video_channel_ != NULL);
3684 cricket::VideoOptions video_options;
3685 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3686 EXPECT_TRUE(
3687 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3688}
3689
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00003690TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
3691 // Number of unsignalled receiving streams should be between 0 and
3692 // kMaxUnsignalledRecvStreams.
3693 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
3694 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
3695 kMaxUnsignalledRecvStreams);
3696 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
3697}
3698
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003699TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
3700 constraints_.reset(new FakeConstraints());
3701 constraints_->AddOptional(
3702 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
3703 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003704 Init();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003705 mediastream_signaling_.SendAudioVideoStream1();
3706 SessionDescriptionInterface* offer = CreateOffer();
3707
3708 SetLocalDescriptionWithoutError(offer);
3709
3710 voice_channel_ = media_engine_->GetVoiceChannel(0);
3711
3712 ASSERT_TRUE(voice_channel_ != NULL);
3713 cricket::AudioOptions audio_options;
3714 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3715 EXPECT_TRUE(
3716 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
3717}
3718
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003719// Tests that we can renegotiate new media content with ICE candidates in the
3720// new remote SDP.
3721TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003722 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003723 InitWithDtls();
3724 SetFactoryDtlsSrtp();
3725
3726 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003727 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003728 SetLocalDescriptionWithoutError(offer);
3729
3730 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3731 SetRemoteDescriptionWithoutError(answer);
3732
3733 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003734 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003735 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3736
3737 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003738 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003739 candidate1.set_component(1);
3740 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3741 candidate1);
3742 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3743 SetRemoteDescriptionWithoutError(offer);
3744
3745 answer = CreateAnswer(NULL);
3746 SetLocalDescriptionWithoutError(answer);
3747}
3748
3749// Tests that we can renegotiate new media content with ICE candidates separated
3750// from the remote SDP.
3751TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003752 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003753 InitWithDtls();
3754 SetFactoryDtlsSrtp();
3755
3756 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003757 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003758 SetLocalDescriptionWithoutError(offer);
3759
3760 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3761 SetRemoteDescriptionWithoutError(answer);
3762
3763 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003764 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003765 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3766 SetRemoteDescriptionWithoutError(offer);
3767
3768 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003769 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003770 candidate1.set_component(1);
3771 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3772 candidate1);
3773 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3774
3775 answer = CreateAnswer(NULL);
3776 SetLocalDescriptionWithoutError(answer);
3777}
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00003778// Tests that RTX codec is removed from the answer when it isn't supported
3779// by local side.
3780TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
3781 Init();
3782 mediastream_signaling_.SendAudioVideoStream1();
3783 std::string offer_sdp(kSdpWithRtx);
3784
3785 SessionDescriptionInterface* offer =
3786 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
3787 EXPECT_TRUE(offer->ToString(&offer_sdp));
3788
3789 // Offer SDP contains the RTX codec.
3790 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
3791 SetRemoteDescriptionWithoutError(offer);
3792
3793 SessionDescriptionInterface* answer = CreateAnswer(NULL);
3794 std::string answer_sdp;
3795 answer->ToString(&answer_sdp);
3796 // Answer SDP removes the unsupported RTX codec.
3797 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
3798 SetLocalDescriptionWithoutError(answer);
3799}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003800
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003801// This verifies that the voice channel after bundle has both options from video
3802// and voice channels.
3803TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
3804 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
3805 mediastream_signaling_.SendAudioVideoStream1();
3806
3807 PeerConnectionInterface::RTCOfferAnswerOptions options;
3808 options.use_rtp_mux = true;
3809
3810 SessionDescriptionInterface* offer = CreateOffer(options);
3811 SetLocalDescriptionWithoutError(offer);
3812
3813 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3814 rtc::Socket::Option::OPT_SNDBUF, 4000);
3815
3816 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3817 rtc::Socket::Option::OPT_RCVBUF, 8000);
3818
3819 int option_val;
3820 EXPECT_TRUE(session_->video_channel()->transport_channel()->GetOption(
3821 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3822 EXPECT_EQ(4000, option_val);
3823 EXPECT_FALSE(session_->voice_channel()->transport_channel()->GetOption(
3824 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3825
3826 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3827 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3828 EXPECT_EQ(8000, option_val);
3829 EXPECT_FALSE(session_->video_channel()->transport_channel()->GetOption(
3830 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3831
3832 EXPECT_NE(session_->voice_channel()->transport_channel(),
3833 session_->video_channel()->transport_channel());
3834
3835 mediastream_signaling_.SendAudioVideoStream2();
3836 SessionDescriptionInterface* answer =
3837 CreateRemoteAnswer(session_->local_description());
3838 SetRemoteDescriptionWithoutError(answer);
3839
3840 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3841 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3842 EXPECT_EQ(4000, option_val);
3843
3844 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3845 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3846 EXPECT_EQ(8000, option_val);
3847}
3848
tommi0f620f42015-07-09 03:25:02 -07003849// Test creating a session, request multiple offers, destroy the session
3850// and make sure we got success/failure callbacks for all of the requests.
3851// Background: crbug.com/507307
3852TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
3853 Init();
3854
3855 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
3856 PeerConnectionInterface::RTCOfferAnswerOptions options;
3857 options.offer_to_receive_audio =
3858 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
3859
3860 for (auto& o : observers) {
3861 o = new WebRtcSessionCreateSDPObserverForTest();
3862 session_->CreateOffer(o, options);
3863 }
3864
3865 session_.reset();
3866
3867 // Make sure we process pending messages on the current (signaling) thread
3868 // before checking we we got our callbacks. Quit() will do this and then
3869 // immediately exit. We won't need the queue after this point anyway.
3870 rtc::Thread::Current()->Quit();
3871
3872 for (auto& o : observers) {
3873 // We expect to have received a notification now even if the session was
3874 // terminated. The offer creation may or may not have succeeded, but we
3875 // must have received a notification which, so the only invalid state
3876 // is kInit.
3877 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
3878 }
3879}
3880
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003881// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
3882// currently fails because upon disconnection and reconnection OnIceComplete is
3883// called more than once without returning to IceGatheringGathering.