blob: b23ba54440419c2780c4cc43873c28bba8bd8456 [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"
29#include "talk/app/webrtc/jsepicecandidate.h"
30#include "talk/app/webrtc/jsepsessiondescription.h"
31#include "talk/app/webrtc/mediastreamsignaling.h"
32#include "talk/app/webrtc/streamcollection.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033#include "talk/app/webrtc/test/fakeconstraints.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000034#include "talk/app/webrtc/test/fakedtlsidentityservice.h"
35#include "talk/app/webrtc/test/fakemediastreamsignaling.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000036#include "talk/app/webrtc/videotrack.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037#include "talk/app/webrtc/webrtcsession.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000038#include "talk/app/webrtc/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000039#include "talk/media/base/fakemediaengine.h"
40#include "talk/media/base/fakevideorenderer.h"
41#include "talk/media/base/mediachannel.h"
42#include "talk/media/devices/fakedevicemanager.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000043#include "webrtc/p2p/base/stunserver.h"
44#include "webrtc/p2p/base/teststunserver.h"
45#include "webrtc/p2p/base/testturnserver.h"
46#include "webrtc/p2p/client/basicportallocator.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000047#include "talk/session/media/channelmanager.h"
48#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000049#include "webrtc/base/fakenetwork.h"
50#include "webrtc/base/firewallsocketserver.h"
51#include "webrtc/base/gunit.h"
52#include "webrtc/base/logging.h"
53#include "webrtc/base/network.h"
54#include "webrtc/base/physicalsocketserver.h"
55#include "webrtc/base/ssladapter.h"
56#include "webrtc/base/sslstreamadapter.h"
57#include "webrtc/base/stringutils.h"
58#include "webrtc/base/thread.h"
59#include "webrtc/base/virtualsocketserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060
61#define MAYBE_SKIP_TEST(feature) \
62 if (!(feature())) { \
63 LOG(LS_INFO) << "Feature disabled... skipping"; \
64 return; \
65 }
66
67using cricket::BaseSession;
68using cricket::DF_PLAY;
69using cricket::DF_SEND;
70using cricket::FakeVoiceMediaChannel;
71using cricket::NS_GINGLE_P2P;
72using cricket::NS_JINGLE_ICE_UDP;
73using 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;
83using webrtc::IceCandidateCollection;
84using webrtc::JsepIceCandidate;
85using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000086using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087using webrtc::PeerConnectionInterface;
88using webrtc::SessionDescriptionInterface;
89using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000090using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000091using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000092using webrtc::kCreateChannelFailed;
93using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000095using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000096using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000097using webrtc::kSdpWithoutDtlsFingerprint;
98using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000100using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000101using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000103typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
104
wu@webrtc.org364f2042013-11-20 21:49:41 +0000105static const int kClientAddrPort = 0;
106static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000107static const char kClientIPv6AddrHost1[] =
108 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +0000109static const char kClientAddrHost2[] = "22.22.22.22";
110static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000111static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
112static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000113static const char kTurnUsername[] = "test";
114static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115
116static const char kSessionVersion[] = "1";
117
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118// Media index of candidates belonging to the first media content.
119static const int kMediaContentIndex0 = 0;
120static const char kMediaContentName0[] = "audio";
121
122// Media index of candidates belonging to the second media content.
123static const int kMediaContentIndex1 = 1;
124static const char kMediaContentName1[] = "video";
125
126static const int kIceCandidatesTimeout = 10000;
127
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000128static const char kFakeDtlsFingerprint[] =
129 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
130 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
131
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000132static const char kTooLongIceUfragPwd[] =
133 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
134 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
135 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
136 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
137
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000138// Add some extra |newlines| to the |message| after |line|.
139static void InjectAfter(const std::string& line,
140 const std::string& newlines,
141 std::string* message) {
142 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000143 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000144 tmp.c_str(), tmp.length(), message);
145}
146
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000147class FakeMetricsObserver : public webrtc::MetricsObserverInterface {
148 public:
149 FakeMetricsObserver() { Reset(); }
150 void Reset() {
151 memset(peer_connection_metrics_counters_, 0,
152 sizeof(peer_connection_metrics_counters_));
153 memset(peer_connection_metrics_name_, 0,
154 sizeof(peer_connection_metrics_name_));
155 }
156
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000157 void IncrementCounter(webrtc::PeerConnectionMetricsCounter type) override {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000158 peer_connection_metrics_counters_[type]++;
159 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000160 void AddHistogramSample(webrtc::PeerConnectionMetricsName type,
161 int value) override {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000162 ASSERT(peer_connection_metrics_name_[type] == 0);
163 peer_connection_metrics_name_[type] = value;
164 }
165
166 int peer_connection_metrics_counters_
167 [webrtc::kPeerConnectionMetricsCounter_Max];
168 int peer_connection_metrics_name_[webrtc::kPeerConnectionMetricsCounter_Max];
169
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000170 int AddRef() override { return 1; }
171 int Release() override { return 1; }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000172};
173
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000174class MockIceObserver : public webrtc::IceObserver {
175 public:
176 MockIceObserver()
177 : oncandidatesready_(false),
178 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
179 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
180 }
181
182 virtual void OnIceConnectionChange(
183 PeerConnectionInterface::IceConnectionState new_state) {
184 ice_connection_state_ = new_state;
185 }
186 virtual void OnIceGatheringChange(
187 PeerConnectionInterface::IceGatheringState new_state) {
188 // We can never transition back to "new".
189 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
190 ice_gathering_state_ = new_state;
191
192 // oncandidatesready_ really means "ICE gathering is complete".
193 // This if statement ensures that this value remains correct when we
194 // transition from kIceGatheringComplete to kIceGatheringGathering.
195 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
196 oncandidatesready_ = false;
197 }
198 }
199
200 // Found a new candidate.
201 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000202 switch (candidate->sdp_mline_index()) {
203 case kMediaContentIndex0:
204 mline_0_candidates_.push_back(candidate->candidate());
205 break;
206 case kMediaContentIndex1:
207 mline_1_candidates_.push_back(candidate->candidate());
208 break;
209 default:
210 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000212
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 // The ICE gathering state should always be Gathering when a candidate is
214 // received (or possibly Completed in the case of the final candidate).
215 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
216 }
217
218 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
219 virtual void OnIceComplete() {
220 EXPECT_FALSE(oncandidatesready_);
221 oncandidatesready_ = true;
222
223 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
224 // be called approximately simultaneously. For ease of testing, this
225 // check additionally requires that they be called in the above order.
226 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
227 ice_gathering_state_);
228 }
229
230 bool oncandidatesready_;
231 std::vector<cricket::Candidate> mline_0_candidates_;
232 std::vector<cricket::Candidate> mline_1_candidates_;
233 PeerConnectionInterface::IceConnectionState ice_connection_state_;
234 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
235};
236
237class WebRtcSessionForTest : public webrtc::WebRtcSession {
238 public:
239 WebRtcSessionForTest(cricket::ChannelManager* cmgr,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000240 rtc::Thread* signaling_thread,
241 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 cricket::PortAllocator* port_allocator,
243 webrtc::IceObserver* ice_observer,
244 webrtc::MediaStreamSignaling* mediastream_signaling)
245 : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator,
246 mediastream_signaling) {
247 RegisterIceObserver(ice_observer);
248 }
249 virtual ~WebRtcSessionForTest() {}
250
251 using cricket::BaseSession::GetTransportProxy;
252 using webrtc::WebRtcSession::SetAudioPlayout;
253 using webrtc::WebRtcSession::SetAudioSend;
254 using webrtc::WebRtcSession::SetCaptureDevice;
255 using webrtc::WebRtcSession::SetVideoPlayout;
256 using webrtc::WebRtcSession::SetVideoSend;
257};
258
wu@webrtc.org91053e72013-08-10 07:18:04 +0000259class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000260 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000261 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000262 enum State {
263 kInit,
264 kFailed,
265 kSucceeded,
266 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000267 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000268
269 // CreateSessionDescriptionObserver implementation.
270 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000271 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000272 state_ = kSucceeded;
273 }
274 virtual void OnFailure(const std::string& error) {
275 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000276 }
277
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000278 SessionDescriptionInterface* description() { return description_.get(); }
279
280 SessionDescriptionInterface* ReleaseDescription() {
281 return description_.release();
282 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000283
wu@webrtc.org91053e72013-08-10 07:18:04 +0000284 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000285
wu@webrtc.org91053e72013-08-10 07:18:04 +0000286 protected:
287 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288
289 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000290 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000291 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000292};
293
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000294class FakeAudioRenderer : public cricket::AudioRenderer {
295 public:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000296 FakeAudioRenderer() : channel_id_(-1), sink_(NULL) {}
297 virtual ~FakeAudioRenderer() {
298 if (sink_)
299 sink_->OnClose();
300 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000301
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000302 void AddChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000303 ASSERT(channel_id_ == -1);
304 channel_id_ = channel_id;
305 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000306 void RemoveChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000307 ASSERT(channel_id == channel_id_);
308 channel_id_ = -1;
309 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000310 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000311
312 int channel_id() const { return channel_id_; }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000313 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000314 private:
315 int channel_id_;
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000316 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000317};
318
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000319class WebRtcSessionTest : public testing::Test {
320 protected:
321 // TODO Investigate why ChannelManager crashes, if it's created
322 // after stun_server.
323 WebRtcSessionTest()
324 : media_engine_(new cricket::FakeMediaEngine()),
325 data_engine_(new cricket::FakeDataEngine()),
326 device_manager_(new cricket::FakeDeviceManager()),
327 channel_manager_(new cricket::ChannelManager(
328 media_engine_, data_engine_, device_manager_,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000329 new cricket::CaptureManager(), rtc::Thread::Current())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330 tdesc_factory_(new cricket::TransportDescriptionFactory()),
331 desc_factory_(new cricket::MediaSessionDescriptionFactory(
332 channel_manager_.get(), tdesc_factory_.get())),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000333 pss_(new rtc::PhysicalSocketServer),
334 vss_(new rtc::VirtualSocketServer(pss_.get())),
335 fss_(new rtc::FirewallSocketServer(vss_.get())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000336 ss_scope_(fss_.get()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000337 stun_socket_addr_(rtc::SocketAddress(kStunAddrHost,
wu@webrtc.org364f2042013-11-20 21:49:41 +0000338 cricket::STUN_SERVER_PORT)),
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +0000339 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
340 stun_socket_addr_)),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000341 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000342 mediastream_signaling_(channel_manager_.get()) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000343 tdesc_factory_->set_protocol(cricket::ICEPROTO_HYBRID);
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000344
345 cricket::ServerAddresses stun_servers;
346 stun_servers.insert(stun_socket_addr_);
347 allocator_.reset(new cricket::BasicPortAllocator(
348 &network_manager_,
349 stun_servers,
350 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000351 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000352 cricket::PORTALLOCATOR_DISABLE_RELAY |
jiayl@webrtc.orgdacdd942015-01-23 17:33:34 +0000353 cricket::PORTALLOCATOR_ENABLE_BUNDLE |
354 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000355 EXPECT_TRUE(channel_manager_->Init());
356 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000357 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000358 }
359
360 void AddInterface(const SocketAddress& addr) {
361 network_manager_.AddInterface(addr);
362 }
363
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000364 void Init(
365 DTLSIdentityServiceInterface* identity_service,
366 PeerConnectionInterface::IceTransportsType ice_transport_type,
367 PeerConnectionInterface::BundlePolicy bundle_policy) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000368 ASSERT_TRUE(session_.get() == NULL);
369 session_.reset(new WebRtcSessionForTest(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000370 channel_manager_.get(), rtc::Thread::Current(),
371 rtc::Thread::Current(), allocator_.get(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000372 &observer_,
373 &mediastream_signaling_));
374
375 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
376 observer_.ice_connection_state_);
377 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
378 observer_.ice_gathering_state_);
379
wu@webrtc.org97077a32013-10-25 21:18:33 +0000380 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000381 identity_service, ice_transport_type,
382 bundle_policy));
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000383 session_->set_metrics_observer(&metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000384 }
385
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000386 void Init() {
387 Init(NULL, PeerConnectionInterface::kAll,
388 PeerConnectionInterface::kBundlePolicyBalanced);
389 }
390
391 void InitWithIceTransport(
392 PeerConnectionInterface::IceTransportsType ice_transport_type) {
393 Init(NULL, ice_transport_type,
394 PeerConnectionInterface::kBundlePolicyBalanced);
395 }
396
397 void InitWithBundlePolicy(
398 PeerConnectionInterface::BundlePolicy bundle_policy) {
399 Init(NULL, PeerConnectionInterface::kAll, bundle_policy);
400 }
401
402 void InitWithDtls(bool identity_request_should_fail = false) {
403 FakeIdentityService* identity_service = new FakeIdentityService();
404 identity_service->set_should_fail(identity_request_should_fail);
405 Init(identity_service,
406 PeerConnectionInterface::kAll,
407 PeerConnectionInterface::kBundlePolicyBalanced);
408 }
409
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000410 void InitWithDtmfCodec() {
411 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000412 const cricket::AudioCodec kTelephoneEventCodec(
413 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000414 std::vector<cricket::AudioCodec> codecs;
415 codecs.push_back(kTelephoneEventCodec);
416 media_engine_->SetAudioCodecs(codecs);
417 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000418 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000419 }
420
421 // Creates a local offer and applies it. Starts ice.
422 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
423 // to decide which streams to create.
424 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000425 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000426 SetLocalDescriptionWithoutError(offer);
427 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
428 observer_.ice_gathering_state_,
429 kIceCandidatesTimeout);
430 }
431
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000432 SessionDescriptionInterface* CreateOffer() {
433 PeerConnectionInterface::RTCOfferAnswerOptions options;
434 options.offer_to_receive_audio =
435 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
436
437 return CreateOffer(options);
438 }
439
wu@webrtc.org91053e72013-08-10 07:18:04 +0000440 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000441 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000442 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000443 observer = new WebRtcSessionCreateSDPObserverForTest();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000444 session_->CreateOffer(observer, options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000445 EXPECT_TRUE_WAIT(
446 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000447 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000448 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000449 }
450
451 SessionDescriptionInterface* CreateAnswer(
452 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000453 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000454 = new WebRtcSessionCreateSDPObserverForTest();
455 session_->CreateAnswer(observer, constraints);
456 EXPECT_TRUE_WAIT(
457 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000458 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000459 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000460 }
461
wu@webrtc.org364f2042013-11-20 21:49:41 +0000462 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000463 return (session_->voice_channel() != NULL &&
464 session_->video_channel() != NULL);
465 }
466
wu@webrtc.org364f2042013-11-20 21:49:41 +0000467 void CheckTransportChannels() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000468 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 1) != NULL);
469 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 2) != NULL);
470 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 1) != NULL);
471 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 2) != NULL);
472 }
473
474 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
475 ASSERT_TRUE(session_.get() != NULL);
476 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
477 ASSERT_TRUE(content != NULL);
478 const cricket::AudioContentDescription* audio_content =
479 static_cast<const cricket::AudioContentDescription*>(
480 content->description);
481 ASSERT_TRUE(audio_content != NULL);
482 ASSERT_EQ(1U, audio_content->cryptos().size());
483 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
484 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
485 audio_content->cryptos()[0].cipher_suite);
486 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
487 audio_content->protocol());
488
489 content = cricket::GetFirstVideoContent(sdp);
490 ASSERT_TRUE(content != NULL);
491 const cricket::VideoContentDescription* video_content =
492 static_cast<const cricket::VideoContentDescription*>(
493 content->description);
494 ASSERT_TRUE(video_content != NULL);
495 ASSERT_EQ(1U, video_content->cryptos().size());
496 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
497 video_content->cryptos()[0].cipher_suite);
498 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
499 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
500 video_content->protocol());
501 }
502
503 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
504 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
505 ASSERT_TRUE(content != NULL);
506 const cricket::AudioContentDescription* audio_content =
507 static_cast<const cricket::AudioContentDescription*>(
508 content->description);
509 ASSERT_TRUE(audio_content != NULL);
510 ASSERT_EQ(0U, audio_content->cryptos().size());
511
512 content = cricket::GetFirstVideoContent(sdp);
513 ASSERT_TRUE(content != NULL);
514 const cricket::VideoContentDescription* video_content =
515 static_cast<const cricket::VideoContentDescription*>(
516 content->description);
517 ASSERT_TRUE(video_content != NULL);
518 ASSERT_EQ(0U, video_content->cryptos().size());
519
520 if (dtls) {
521 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
522 audio_content->protocol());
523 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
524 video_content->protocol());
525 } else {
526 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
527 audio_content->protocol());
528 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
529 video_content->protocol());
530 }
531 }
532
533 // Set the internal fake description factories to do DTLS-SRTP.
534 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000535 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000536 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000537 rtc::ToString(rtc::CreateRandomId());
538 identity_.reset(rtc::SSLIdentity::Generate(identity_name));
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000539 tdesc_factory_->set_identity(identity_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000540 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
541 }
542
543 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
544 bool expected) {
545 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
546 ASSERT_TRUE(audio != NULL);
547 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000548 const TransportInfo* video = sdp->GetTransportInfoByName("video");
549 ASSERT_TRUE(video != NULL);
550 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000551 }
552
553 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000554 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000555 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000556 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000557 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000558 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000559 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000561 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
562 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000563 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000564 // Answer should be NULL as no crypto params in offer.
565 ASSERT_TRUE(answer == NULL);
566 }
567
568 void VerifyAnswerFromCryptoOffer() {
569 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000570 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000571 options.bundle_enabled = true;
572 scoped_ptr<JsepSessionDescription> offer(
573 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
574 ASSERT_TRUE(offer.get() != NULL);
575 VerifyCryptoParams(offer->description());
576 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000577 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000578 ASSERT_TRUE(answer.get() != NULL);
579 VerifyCryptoParams(answer->description());
580 }
581
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000582 void SetAndVerifyNumUnsignalledRecvStreams(
583 int value_set, int value_expected) {
584 constraints_.reset(new FakeConstraints());
585 constraints_->AddOptional(
586 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
587 value_set);
588 session_.reset();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000589 Init();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000590 mediastream_signaling_.SendAudioVideoStream1();
591 SessionDescriptionInterface* offer = CreateOffer();
592
593 SetLocalDescriptionWithoutError(offer);
594
595 video_channel_ = media_engine_->GetVideoChannel(0);
596
597 ASSERT_TRUE(video_channel_ != NULL);
598 cricket::VideoOptions video_options;
599 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
600 EXPECT_EQ(value_expected,
601 video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1));
602 }
603
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000604 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
605 const cricket::SessionDescription* desc2,
606 bool expect_equal) {
607 if (desc1->contents().size() != desc2->contents().size()) {
608 EXPECT_FALSE(expect_equal);
609 return;
610 }
611
612 const cricket::ContentInfos& contents = desc1->contents();
613 cricket::ContentInfos::const_iterator it = contents.begin();
614
615 for (; it != contents.end(); ++it) {
616 const cricket::TransportDescription* transport_desc1 =
617 desc1->GetTransportDescriptionByName(it->name);
618 const cricket::TransportDescription* transport_desc2 =
619 desc2->GetTransportDescriptionByName(it->name);
620 if (!transport_desc1 || !transport_desc2) {
621 EXPECT_FALSE(expect_equal);
622 return;
623 }
624 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
625 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
626 EXPECT_FALSE(expect_equal);
627 return;
628 }
629 }
630 EXPECT_TRUE(expect_equal);
631 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000632
633 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
634 std::string *sdp) {
635 const cricket::SessionDescription* desc = current_desc->description();
636 EXPECT_TRUE(current_desc->ToString(sdp));
637
638 const cricket::ContentInfos& contents = desc->contents();
639 cricket::ContentInfos::const_iterator it = contents.begin();
640 // Replace ufrag and pwd lines with empty strings.
641 for (; it != contents.end(); ++it) {
642 const cricket::TransportDescription* transport_desc =
643 desc->GetTransportDescriptionByName(it->name);
644 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
645 + "\r\n";
646 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
647 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000648 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000649 "", 0,
650 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000651 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000652 "", 0,
653 sdp);
654 }
655 }
656
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000657 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
658 const std::string& modified_ice_ufrag,
659 const std::string& modified_ice_pwd,
660 std::string* sdp) {
661 const cricket::SessionDescription* desc = current_desc->description();
662 EXPECT_TRUE(current_desc->ToString(sdp));
663
664 const cricket::ContentInfos& contents = desc->contents();
665 cricket::ContentInfos::const_iterator it = contents.begin();
666 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
667 // |modified_ice_pwd| strings.
668 for (; it != contents.end(); ++it) {
669 const cricket::TransportDescription* transport_desc =
670 desc->GetTransportDescriptionByName(it->name);
671 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
672 + "\r\n";
673 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
674 + "\r\n";
675 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
676 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000677 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000678 mod_ufrag.c_str(), mod_ufrag.length(),
679 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000680 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000681 mod_pwd.c_str(), mod_pwd.length(),
682 sdp);
683 }
684 }
685
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000686 // Creates a remote offer and and applies it as a remote description,
687 // creates a local answer and applies is as a local description.
688 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
689 // to decide which local and remote streams to create.
690 void CreateAndSetRemoteOfferAndLocalAnswer() {
691 SessionDescriptionInterface* offer = CreateRemoteOffer();
692 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000693 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000694 SetLocalDescriptionWithoutError(answer);
695 }
696 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
697 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
698 }
699 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
700 BaseSession::State expected_state) {
701 SetLocalDescriptionWithoutError(desc);
702 EXPECT_EQ(expected_state, session_->state());
703 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000704 void SetLocalDescriptionExpectError(const std::string& action,
705 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000706 SessionDescriptionInterface* desc) {
707 std::string error;
708 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000709 std::string sdp_type = "local ";
710 sdp_type.append(action);
711 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712 EXPECT_NE(std::string::npos, error.find(expected_error));
713 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000714 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
715 SessionDescriptionInterface* desc) {
716 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
717 expected_error, desc);
718 }
719 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
720 SessionDescriptionInterface* desc) {
721 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
722 expected_error, desc);
723 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
725 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
726 }
727 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
728 BaseSession::State expected_state) {
729 SetRemoteDescriptionWithoutError(desc);
730 EXPECT_EQ(expected_state, session_->state());
731 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000732 void SetRemoteDescriptionExpectError(const std::string& action,
733 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000734 SessionDescriptionInterface* desc) {
735 std::string error;
736 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000737 std::string sdp_type = "remote ";
738 sdp_type.append(action);
739 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000740 EXPECT_NE(std::string::npos, error.find(expected_error));
741 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000742 void SetRemoteDescriptionOfferExpectError(
743 const std::string& expected_error, SessionDescriptionInterface* desc) {
744 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
745 expected_error, desc);
746 }
747 void SetRemoteDescriptionPranswerExpectError(
748 const std::string& expected_error, SessionDescriptionInterface* desc) {
749 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
750 expected_error, desc);
751 }
752 void SetRemoteDescriptionAnswerExpectError(
753 const std::string& expected_error, SessionDescriptionInterface* desc) {
754 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
755 expected_error, desc);
756 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000757
758 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
759 SessionDescriptionInterface** nocrypto_answer) {
760 // Create a SDP without Crypto.
761 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000762 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763 options.bundle_enabled = true;
764 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
765 ASSERT_TRUE(*offer != NULL);
766 VerifyCryptoParams((*offer)->description());
767
768 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
769 cricket::SEC_DISABLED);
770 EXPECT_TRUE(*nocrypto_answer != NULL);
771 }
772
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000773 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
774 SessionDescriptionInterface** nodtls_answer) {
775 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000776 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000777 options.bundle_enabled = true;
778
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000779 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000780 CreateRemoteOffer(options, cricket::SEC_ENABLED));
781
782 *nodtls_answer =
783 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
784 EXPECT_TRUE(*nodtls_answer != NULL);
785 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
786 VerifyCryptoParams((*nodtls_answer)->description());
787
788 SetFactoryDtlsSrtp();
789 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
790 ASSERT_TRUE(*offer != NULL);
791 VerifyFingerprintStatus((*offer)->description(), true);
792 VerifyCryptoParams((*offer)->description());
793 }
794
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000795 JsepSessionDescription* CreateRemoteOfferWithVersion(
796 cricket::MediaSessionOptions options,
797 cricket::SecurePolicy secure_policy,
798 const std::string& session_version,
799 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000800 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000801 const cricket::SessionDescription* cricket_desc = NULL;
802 if (current_desc) {
803 cricket_desc = current_desc->description();
804 session_id = current_desc->session_id();
805 }
806
807 desc_factory_->set_secure(secure_policy);
808 JsepSessionDescription* offer(
809 new JsepSessionDescription(JsepSessionDescription::kOffer));
810 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
811 session_id, session_version)) {
812 delete offer;
813 offer = NULL;
814 }
815 return offer;
816 }
817 JsepSessionDescription* CreateRemoteOffer(
818 cricket::MediaSessionOptions options) {
819 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
820 kSessionVersion, NULL);
821 }
822 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000823 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
824 return CreateRemoteOfferWithVersion(
825 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000826 }
827 JsepSessionDescription* CreateRemoteOffer(
828 cricket::MediaSessionOptions options,
829 const SessionDescriptionInterface* current_desc) {
830 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
831 kSessionVersion, current_desc);
832 }
833
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000834 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
835 const char* sctp_stream_name, int new_port,
836 cricket::MediaSessionOptions options) {
837 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000838 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
839 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000840 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
841 }
842
843 // Takes ownership of offer_basis (and deletes it).
844 JsepSessionDescription* ChangeSDPSctpPort(
845 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
846 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
847 // SessionDescription from the mutated string.
848 const char* default_port_str = "5000";
849 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000850 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000851 std::string offer_str;
852 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000853 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000854 new_port_str, strlen(new_port_str),
855 &offer_str);
856 JsepSessionDescription* offer = new JsepSessionDescription(
857 offer_basis->type());
858 delete offer_basis;
859 offer->Initialize(offer_str, NULL);
860 return offer;
861 }
862
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000863 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
864 // before this function to decide which streams to create.
865 JsepSessionDescription* CreateRemoteOffer() {
866 cricket::MediaSessionOptions options;
867 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
868 return CreateRemoteOffer(options, session_->remote_description());
869 }
870
871 JsepSessionDescription* CreateRemoteAnswer(
872 const SessionDescriptionInterface* offer,
873 cricket::MediaSessionOptions options,
874 cricket::SecurePolicy policy) {
875 desc_factory_->set_secure(policy);
876 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000877 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878 JsepSessionDescription* answer(
879 new JsepSessionDescription(JsepSessionDescription::kAnswer));
880 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
881 options, NULL),
882 session_id, kSessionVersion)) {
883 delete answer;
884 answer = NULL;
885 }
886 return answer;
887 }
888
889 JsepSessionDescription* CreateRemoteAnswer(
890 const SessionDescriptionInterface* offer,
891 cricket::MediaSessionOptions options) {
892 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
893 }
894
895 // Creates an answer session description with streams based on
896 // |mediastream_signaling_|. Call
897 // mediastream_signaling_.UseOptionsWithStreamX() before this function
898 // to decide which streams to create.
899 JsepSessionDescription* CreateRemoteAnswer(
900 const SessionDescriptionInterface* offer) {
901 cricket::MediaSessionOptions options;
902 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
903 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
904 }
905
906 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000907 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000908 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000909 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000910
911 PeerConnectionInterface::RTCOfferAnswerOptions options;
912 options.use_rtp_mux = bundle;
913
914 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
916 // and answer.
917 SetLocalDescriptionWithoutError(offer);
918
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000919 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000920 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921 std::string sdp;
922 EXPECT_TRUE(answer->ToString(&sdp));
923
924 size_t expected_candidate_num = 2;
925 if (!rtcp_mux) {
926 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
927 // for rtp and rtcp.
928 expected_candidate_num = 4;
929 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000930 const std::string kRtcpMux = "a=rtcp-mux";
931 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000932 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 kXRtcpMux.c_str(), kXRtcpMux.length(),
934 &sdp);
935 }
936
937 SessionDescriptionInterface* new_answer = CreateSessionDescription(
938 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000939
940 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000941 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000942 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
943 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
944 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
945 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
946 cricket::Candidate c0 = observer_.mline_0_candidates_[i];
947 cricket::Candidate c1 = observer_.mline_1_candidates_[i];
948 if (bundle) {
949 EXPECT_TRUE(c0.IsEquivalent(c1));
950 } else {
951 EXPECT_FALSE(c0.IsEquivalent(c1));
952 }
953 }
954 }
955 // Tests that we can only send DTMF when the dtmf codec is supported.
956 void TestCanInsertDtmf(bool can) {
957 if (can) {
958 InitWithDtmfCodec();
959 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000960 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000961 }
962 mediastream_signaling_.SendAudioVideoStream1();
963 CreateAndSetRemoteOfferAndLocalAnswer();
964 EXPECT_FALSE(session_->CanInsertDtmf(""));
965 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
966 }
967
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000968 // Helper class to configure loopback network and verify Best
969 // Connection using right IP protocol for TestLoopbackCall
970 // method. LoopbackNetworkManager applies firewall rules to block
971 // all ping traffic once ICE completed, and remove them to observe
972 // ICE reconnected again. This LoopbackNetworkConfiguration struct
973 // verifies the best connection is using the right IP protocol after
974 // initial ICE convergences.
975
976 class LoopbackNetworkConfiguration {
977 public:
978 LoopbackNetworkConfiguration()
979 : test_ipv6_network_(false),
980 test_extra_ipv4_network_(false),
981 best_connection_after_initial_ice_converged_(1, 0) {}
982
983 // Used to track the expected best connection count in each IP protocol.
984 struct ExpectedBestConnection {
985 ExpectedBestConnection(int ipv4_count, int ipv6_count)
986 : ipv4_count_(ipv4_count),
987 ipv6_count_(ipv6_count) {}
988
989 int ipv4_count_;
990 int ipv6_count_;
991 };
992
993 bool test_ipv6_network_;
994 bool test_extra_ipv4_network_;
995 ExpectedBestConnection best_connection_after_initial_ice_converged_;
996
997 void VerifyBestConnectionAfterIceConverge(
998 const FakeMetricsObserver& metrics_observer) const {
999 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1000 }
1001
1002 private:
1003 void Verify(const FakeMetricsObserver& metrics_observer,
1004 const ExpectedBestConnection& expected) const {
1005 EXPECT_EQ(
1006 metrics_observer
1007 .peer_connection_metrics_counters_[webrtc::kBestConnections_IPv4],
1008 expected.ipv4_count_);
1009 EXPECT_EQ(
1010 metrics_observer
1011 .peer_connection_metrics_counters_[webrtc::kBestConnections_IPv6],
1012 expected.ipv6_count_);
1013 }
1014 };
1015
1016 class LoopbackNetworkManager {
1017 public:
1018 LoopbackNetworkManager(WebRtcSessionTest* session,
1019 const LoopbackNetworkConfiguration& config)
1020 : config_(config) {
1021 session->AddInterface(
1022 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1023 if (config_.test_extra_ipv4_network_) {
1024 session->AddInterface(
1025 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1026 }
1027 if (config_.test_ipv6_network_) {
1028 session->AddInterface(
1029 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1030 }
1031 }
1032
1033 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1034 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1035 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1036 if (config_.test_extra_ipv4_network_) {
1037 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1038 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1039 }
1040 if (config_.test_ipv6_network_) {
1041 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1042 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1043 }
1044 }
1045
1046 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1047
1048 private:
1049 LoopbackNetworkConfiguration config_;
1050 };
1051
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001052 // The method sets up a call from the session to itself, in a loopback
1053 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001054 // disconnection, and then a permanent disconnection.
1055 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001056 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1057 // While running the call, this method also checks if the session goes through
1058 // the correct sequence of ICE states when a connection is established,
1059 // broken, and re-established.
1060 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001061 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1062 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001064
1065 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1066 LoopbackNetworkManager loopback_network_manager(this, config);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001067 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001068 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001069 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001070
1071 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1072 observer_.ice_gathering_state_);
1073 SetLocalDescriptionWithoutError(offer);
1074 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1075 observer_.ice_connection_state_);
1076 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
1077 observer_.ice_gathering_state_,
1078 kIceCandidatesTimeout);
1079 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1080 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
1081 observer_.ice_gathering_state_,
1082 kIceCandidatesTimeout);
1083
1084 std::string sdp;
1085 offer->ToString(&sdp);
1086 SessionDescriptionInterface* desc =
1087 webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer, sdp);
1088 ASSERT_TRUE(desc != NULL);
1089 SetRemoteDescriptionWithoutError(desc);
1090
1091 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
1092 observer_.ice_connection_state_,
1093 kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001094
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001095 // The ice connection state is "Connected" too briefly to catch in a test.
1096 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001097 observer_.ice_connection_state_,
1098 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001099
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001100 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001101 // Adding firewall rule to block ping requests, which should cause
1102 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001103
1104 loopback_network_manager.ApplyFirewallRules(fss_.get());
1105
1106 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001107 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1108 observer_.ice_connection_state_,
1109 kIceCandidatesTimeout);
1110
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001111 metrics_observer_.Reset();
1112
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001113 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001114 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001115 // Session is automatically calling OnSignalingReady after creation of
1116 // new portallocator session which will allocate new set of candidates.
1117
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001118 LOG(LS_INFO) << "Firewall Rules cleared";
1119
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001120 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001121 observer_.ice_connection_state_,
1122 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001123
1124 // Now we block ping requests and wait until the ICE connection transitions
1125 // to the Failed state. This will take at least 30 seconds because it must
1126 // wait for the Port to timeout.
1127 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001128
1129 loopback_network_manager.ApplyFirewallRules(fss_.get());
1130 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001131 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001132 observer_.ice_connection_state_,
1133 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001134 }
1135
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001136 void TestLoopbackCall() {
1137 LoopbackNetworkConfiguration config;
1138 TestLoopbackCall(config);
1139 }
1140
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001141 void VerifyTransportType(const std::string& content_name,
1142 cricket::TransportProtocol protocol) {
1143 const cricket::Transport* transport = session_->GetTransport(content_name);
1144 ASSERT_TRUE(transport != NULL);
1145 EXPECT_EQ(protocol, transport->protocol());
1146 }
1147
1148 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1149 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001150 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1151 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1152
1153 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001154 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1155 codecs.push_back(kCNCodec1);
1156 codecs.push_back(kCNCodec2);
1157 media_engine_->SetAudioCodecs(codecs);
1158 desc_factory_->set_audio_codecs(codecs);
1159 }
1160
1161 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1162 const cricket::ContentDescription* description = content->description;
1163 ASSERT(description != NULL);
1164 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001165 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001166 ASSERT(audio_content_desc != NULL);
1167 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1168 if (audio_content_desc->codecs()[i].name == "CN")
1169 return false;
1170 }
1171 return true;
1172 }
1173
1174 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001175 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001176 dci.reliable = false;
1177 session_->CreateDataChannel("datachannel", &dci);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001178 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001179 SetLocalDescriptionWithoutError(offer);
1180 }
1181
wu@webrtc.org91053e72013-08-10 07:18:04 +00001182 void VerifyMultipleAsyncCreateDescription(
1183 bool success, CreateSessionDescriptionRequest::Type type) {
henrike@webrtc.org7666db72013-08-22 14:45:42 +00001184 InitWithDtls(!success);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001185 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001186 if (type == CreateSessionDescriptionRequest::kAnswer) {
1187 cricket::MediaSessionOptions options;
1188 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001189 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001190 ASSERT_TRUE(offer.get() != NULL);
1191 SetRemoteDescriptionWithoutError(offer.release());
1192 }
1193
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001194 PeerConnectionInterface::RTCOfferAnswerOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001195 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001196 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001197 observers[kNumber];
1198 for (int i = 0; i < kNumber; ++i) {
1199 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1200 if (type == CreateSessionDescriptionRequest::kOffer) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001201 session_->CreateOffer(observers[i], options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001202 } else {
1203 session_->CreateAnswer(observers[i], NULL);
1204 }
1205 }
1206
1207 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1208 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1209 WebRtcSessionCreateSDPObserverForTest::kFailed;
1210
1211 for (int i = 0; i < kNumber; ++i) {
1212 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1213 if (success) {
1214 EXPECT_TRUE(observers[i]->description() != NULL);
1215 } else {
1216 EXPECT_TRUE(observers[i]->description() == NULL);
1217 }
1218 }
1219 }
1220
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001221 void ConfigureAllocatorWithTurn() {
1222 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1223 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
1224 relay_server.credentials = credentials;
1225 relay_server.ports.push_back(cricket::ProtocolAddress(
1226 kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1227 allocator_->AddRelay(relay_server);
1228 allocator_->set_step_delay(cricket::kMinimumStepDelay);
1229 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
jiayl@webrtc.orgdacdd942015-01-23 17:33:34 +00001230 cricket::PORTALLOCATOR_ENABLE_BUNDLE |
1231 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001232 }
1233
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001234 cricket::FakeMediaEngine* media_engine_;
1235 cricket::FakeDataEngine* data_engine_;
1236 cricket::FakeDeviceManager* device_manager_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001237 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
1238 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1239 rtc::scoped_ptr<rtc::SSLIdentity> identity_;
1240 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1241 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1242 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1243 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1244 rtc::SocketServerScope ss_scope_;
1245 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001246 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001247 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001248 rtc::FakeNetworkManager network_manager_;
1249 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001250 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001251 rtc::scoped_ptr<FakeConstraints> constraints_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001252 FakeMediaStreamSignaling mediastream_signaling_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001253 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001254 MockIceObserver observer_;
1255 cricket::FakeVideoMediaChannel* video_channel_;
1256 cricket::FakeVoiceMediaChannel* voice_channel_;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001257 FakeMetricsObserver metrics_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001258};
1259
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001260TEST_F(WebRtcSessionTest, TestInitializeWithDtls) {
1261 InitWithDtls();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001262 // SDES is disabled when DTLS is on.
1263 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001264}
1265
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001266TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001267 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001268 // SDES is required if DTLS is off.
1269 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001270}
1271
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001272TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1273 TestSessionCandidatesWithBundleRtcpMux(false, false);
1274}
1275
1276// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1277// with rtcp-mux and/or bundle.
1278TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1279 TestSessionCandidatesWithBundleRtcpMux(false, true);
1280}
1281
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001282TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1283 TestSessionCandidatesWithBundleRtcpMux(true, true);
1284}
1285
1286TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001287 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1288 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001289 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290 mediastream_signaling_.SendAudioVideoStream1();
1291 InitiateCall();
1292 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1293 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1294 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1295}
1296
1297TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001298 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1299 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001300 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001301 rtc::FP_UDP,
1302 rtc::FD_ANY,
1303 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001304 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001305 mediastream_signaling_.SendAudioVideoStream1();
1306 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001307 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001308 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1309 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1310 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1311}
1312
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001313// Test session delivers no candidates gathered when constraint set to "none".
1314TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1315 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001316 InitWithIceTransport(PeerConnectionInterface::kNone);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001317 mediastream_signaling_.SendAudioVideoStream1();
1318 InitiateCall();
1319 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1320 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1321 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1322}
1323
1324// Test session delivers only relay candidates gathered when constaint set to
1325// "relay".
1326TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1327 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1328 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001329 InitWithIceTransport(PeerConnectionInterface::kRelay);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001330 mediastream_signaling_.SendAudioVideoStream1();
1331 InitiateCall();
1332 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1333 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1334 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1335 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1336 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1337 observer_.mline_0_candidates_[i].type());
1338 }
1339 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1340 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1341 observer_.mline_1_candidates_[i].type());
1342 }
1343}
1344
1345// Test session delivers all candidates gathered when constaint set to "all".
1346TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1347 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001348 InitWithIceTransport(PeerConnectionInterface::kAll);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001349 mediastream_signaling_.SendAudioVideoStream1();
1350 InitiateCall();
1351 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1352 // Host + STUN. By default allocator is disabled to gather relay candidates.
1353 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1354 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1355}
1356
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001357TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001358 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001359 SessionDescriptionInterface* offer = NULL;
1360 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1361 std::string unknown_action;
1362 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1363 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1364}
1365
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001366// Test creating offers and receive answers and make sure the
1367// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001368TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001369 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001370 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001371 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001372 const std::string session_id_orig = offer->session_id();
1373 const std::string session_version_orig = offer->session_version();
1374 SetLocalDescriptionWithoutError(offer);
1375
1376 mediastream_signaling_.SendAudioVideoStream2();
1377 SessionDescriptionInterface* answer =
1378 CreateRemoteAnswer(session_->local_description());
1379 SetRemoteDescriptionWithoutError(answer);
1380
1381 video_channel_ = media_engine_->GetVideoChannel(0);
1382 voice_channel_ = media_engine_->GetVoiceChannel(0);
1383
1384 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1385 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1386
1387 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1388 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1389
1390 ASSERT_EQ(1u, video_channel_->send_streams().size());
1391 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1392 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1393 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1394
1395 // Create new offer without send streams.
1396 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001397 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001398
1399 // Verify the session id is the same and the session version is
1400 // increased.
1401 EXPECT_EQ(session_id_orig, offer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001402 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1403 rtc::FromString<uint64>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001404
1405 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001406 EXPECT_EQ(0u, video_channel_->send_streams().size());
1407 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001408
1409 mediastream_signaling_.SendAudioVideoStream2();
1410 answer = CreateRemoteAnswer(session_->local_description());
1411 SetRemoteDescriptionWithoutError(answer);
1412
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001413 // Make sure the receive streams have not changed.
1414 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1415 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1416 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1417 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1418}
1419
1420// Test receiving offers and creating answers and make sure the
1421// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001422TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001423 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001424 mediastream_signaling_.SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001425 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001426 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001427 SetRemoteDescriptionWithoutError(offer);
1428
1429 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001430 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001431 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001432 SetLocalDescriptionWithoutError(answer);
1433
1434 const std::string session_id_orig = answer->session_id();
1435 const std::string session_version_orig = answer->session_version();
1436
1437 video_channel_ = media_engine_->GetVideoChannel(0);
1438 voice_channel_ = media_engine_->GetVoiceChannel(0);
1439
1440 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1441 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1442
1443 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1444 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1445
1446 ASSERT_EQ(1u, video_channel_->send_streams().size());
1447 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1448 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1449 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1450
1451 mediastream_signaling_.SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001452 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001453 SetRemoteDescriptionWithoutError(offer);
1454
1455 // Answer by turning off all send streams.
1456 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001457 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001458
1459 // Verify the session id is the same and the session version is
1460 // increased.
1461 EXPECT_EQ(session_id_orig, answer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001462 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1463 rtc::FromString<uint64>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001464 SetLocalDescriptionWithoutError(answer);
1465
1466 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1467 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1468 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1469 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1470 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1471 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1472
1473 // Make sure we have no send streams.
1474 EXPECT_EQ(0u, video_channel_->send_streams().size());
1475 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1476}
1477
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001478TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001479 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001480 media_engine_->set_fail_create_channel(true);
1481
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001482 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001483 ASSERT_TRUE(offer != NULL);
1484 // SetRemoteDescription and SetLocalDescription will take the ownership of
1485 // the offer.
1486 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001487 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001488 ASSERT_TRUE(offer != NULL);
1489 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1490}
1491
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001492//
1493// Tests for creating/setting SDP under different SDES/DTLS polices:
1494//
1495// --DTLS off and SDES on
1496// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1497// set local/remote offer/answer with crypto --> success
1498// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1499// failure
1500// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1501// failure
1502// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1503// failure
1504//
1505// --DTLS on and SDES off
1506// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1507// set local/remote offer/answer with DTLS fingerprint --> success
1508// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1509// fingerprint --> failure
1510// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1511// --> failure
1512// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1513// --> failure
1514//
1515// --Encryption disabled: DTLS off and SDES off
1516// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1517// answer without SDES or DTLS --> success
1518// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1519// answer without SDES or DTLS --> success
1520//
1521
1522// Test that we return a failure when applying a remote/local offer that doesn't
1523// have cryptos enabled when DTLS is off.
1524TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001525 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001526 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001527 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001528 JsepSessionDescription* offer = CreateRemoteOffer(
1529 options, cricket::SEC_DISABLED);
1530 ASSERT_TRUE(offer != NULL);
1531 VerifyNoCryptoParams(offer->description(), false);
1532 // SetRemoteDescription and SetLocalDescription will take the ownership of
1533 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001534 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001535 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1536 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001537 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001538}
1539
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001540// Test that we return a failure when applying a local answer that doesn't have
1541// cryptos enabled when DTLS is off.
1542TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001543 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001544 SessionDescriptionInterface* offer = NULL;
1545 SessionDescriptionInterface* answer = NULL;
1546 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1547 // SetRemoteDescription and SetLocalDescription will take the ownership of
1548 // the offer.
1549 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001550 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001551}
1552
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001553// Test we will return fail when apply an remote answer that doesn't have
1554// crypto enabled when DTLS is off.
1555TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001556 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001557 SessionDescriptionInterface* offer = NULL;
1558 SessionDescriptionInterface* answer = NULL;
1559 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1560 // SetRemoteDescription and SetLocalDescription will take the ownership of
1561 // the offer.
1562 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001563 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001564}
1565
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001566// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1567// and that we return an answer with a DTLS fingerprint.
1568TEST_F(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001569 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001570 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001571 InitWithDtls();
1572 SetFactoryDtlsSrtp();
1573 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001574 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001575 JsepSessionDescription* offer =
1576 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001577 ASSERT_TRUE(offer != NULL);
1578 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001579 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001580
1581 // SetRemoteDescription will take the ownership of the offer.
1582 SetRemoteDescriptionWithoutError(offer);
1583
1584 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001585 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001586 ASSERT_TRUE(answer != NULL);
1587 VerifyFingerprintStatus(answer->description(), true);
1588 // Check that we don't have an a=crypto line in the answer.
1589 VerifyNoCryptoParams(answer->description(), true);
1590
1591 // Now set the local description, which should work, even without a=crypto.
1592 SetLocalDescriptionWithoutError(answer);
1593}
1594
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001595// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1596// and then we accept a remote answer with a DTLS fingerprint successfully.
1597TEST_F(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001598 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001599 mediastream_signaling_.SendAudioVideoStream1();
1600 InitWithDtls();
1601 SetFactoryDtlsSrtp();
1602
1603 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001604 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001605 ASSERT_TRUE(offer != NULL);
1606 VerifyFingerprintStatus(offer->description(), true);
1607 // Check that we don't have an a=crypto line in the offer.
1608 VerifyNoCryptoParams(offer->description(), true);
1609
1610 // Now set the local description, which should work, even without a=crypto.
1611 SetLocalDescriptionWithoutError(offer);
1612
1613 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001614 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001615 JsepSessionDescription* answer =
1616 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1617 ASSERT_TRUE(answer != NULL);
1618 VerifyFingerprintStatus(answer->description(), true);
1619 VerifyNoCryptoParams(answer->description(), true);
1620
1621 // SetRemoteDescription will take the ownership of the answer.
1622 SetRemoteDescriptionWithoutError(answer);
1623}
1624
1625// Test that if we support DTLS and the other side didn't offer a fingerprint,
1626// we will fail to set the remote description.
1627TEST_F(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001628 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001629 InitWithDtls();
1630 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001631 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001632 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001633 JsepSessionDescription* offer = CreateRemoteOffer(
1634 options, cricket::SEC_REQUIRED);
1635 ASSERT_TRUE(offer != NULL);
1636 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001637 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001638
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001639 // SetRemoteDescription will take the ownership of the offer.
1640 SetRemoteDescriptionOfferExpectError(
1641 kSdpWithoutDtlsFingerprint, offer);
1642
1643 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1644 // SetLocalDescription will take the ownership of the offer.
1645 SetLocalDescriptionOfferExpectError(
1646 kSdpWithoutDtlsFingerprint, offer);
1647}
1648
1649// Test that we return a failure when applying a local answer that doesn't have
1650// a DTLS fingerprint when DTLS is required.
1651TEST_F(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001652 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001653 InitWithDtls();
1654 SessionDescriptionInterface* offer = NULL;
1655 SessionDescriptionInterface* answer = NULL;
1656 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1657
1658 // SetRemoteDescription and SetLocalDescription will take the ownership of
1659 // the offer and answer.
1660 SetRemoteDescriptionWithoutError(offer);
1661 SetLocalDescriptionAnswerExpectError(
1662 kSdpWithoutDtlsFingerprint, answer);
1663}
1664
1665// Test that we return a failure when applying a remote answer that doesn't have
1666// a DTLS fingerprint when DTLS is required.
1667TEST_F(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001668 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001669 InitWithDtls();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001670 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001671 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001672 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001673 JsepSessionDescription* answer =
1674 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
1675
1676 // SetRemoteDescription and SetLocalDescription will take the ownership of
1677 // the offer and answer.
1678 SetLocalDescriptionWithoutError(offer);
1679 SetRemoteDescriptionAnswerExpectError(
1680 kSdpWithoutDtlsFingerprint, answer);
1681}
1682
1683// Test that we create a local offer without SDES or DTLS and accept a remote
1684// answer without SDES or DTLS when encryption is disabled.
1685TEST_F(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
1686 mediastream_signaling_.SendAudioVideoStream1();
1687 options_.disable_encryption = true;
1688 InitWithDtls();
1689
1690 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001691 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001692 ASSERT_TRUE(offer != NULL);
1693 VerifyFingerprintStatus(offer->description(), false);
1694 // Check that we don't have an a=crypto line in the offer.
1695 VerifyNoCryptoParams(offer->description(), false);
1696
1697 // Now set the local description, which should work, even without a=crypto.
1698 SetLocalDescriptionWithoutError(offer);
1699
1700 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001701 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001702 JsepSessionDescription* answer =
1703 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1704 ASSERT_TRUE(answer != NULL);
1705 VerifyFingerprintStatus(answer->description(), false);
1706 VerifyNoCryptoParams(answer->description(), false);
1707
1708 // SetRemoteDescription will take the ownership of the answer.
1709 SetRemoteDescriptionWithoutError(answer);
1710}
1711
1712// Test that we create a local answer without SDES or DTLS and accept a remote
1713// offer without SDES or DTLS when encryption is disabled.
1714TEST_F(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
1715 options_.disable_encryption = true;
1716 InitWithDtls();
1717
1718 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001719 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001720 JsepSessionDescription* offer =
1721 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1722 ASSERT_TRUE(offer != NULL);
1723 VerifyFingerprintStatus(offer->description(), false);
1724 VerifyNoCryptoParams(offer->description(), false);
1725
1726 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001727 SetRemoteDescriptionWithoutError(offer);
1728
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001729 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001730 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731 ASSERT_TRUE(answer != NULL);
1732 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001733 // Check that we don't have an a=crypto line in the answer.
1734 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001735
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001736 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001737 SetLocalDescriptionWithoutError(answer);
1738}
1739
1740TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001741 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001742 mediastream_signaling_.SendNothing();
1743 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001744 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745 SetLocalDescriptionWithoutError(offer);
1746
1747 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001748 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001749 SetLocalDescriptionWithoutError(offer2);
1750}
1751
1752TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001753 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001754 mediastream_signaling_.SendNothing();
1755 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001756 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001757 SetRemoteDescriptionWithoutError(offer);
1758
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001759 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760 SetRemoteDescriptionWithoutError(offer2);
1761}
1762
1763TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001764 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001766 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001767 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001768 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001769 SetRemoteDescriptionOfferExpectError(
1770 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001771}
1772
1773TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001774 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001776 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001777 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001778 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001779 SetLocalDescriptionOfferExpectError(
1780 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781}
1782
1783TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001784 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785 mediastream_signaling_.SendNothing();
1786 SessionDescriptionInterface* offer = CreateRemoteOffer();
1787 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1788
1789 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001790 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001791 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1792 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1793
1794 mediastream_signaling_.SendAudioVideoStream1();
1795 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001796 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001797 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1798
1799 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1800
1801 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001802 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1804}
1805
1806TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001807 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001808 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001809 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1811
1812 JsepSessionDescription* pranswer =
1813 CreateRemoteAnswer(session_->local_description());
1814 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1815
1816 SetRemoteDescriptionExpectState(pranswer,
1817 BaseSession::STATE_RECEIVEDPRACCEPT);
1818
1819 mediastream_signaling_.SendAudioVideoStream1();
1820 JsepSessionDescription* pranswer2 =
1821 CreateRemoteAnswer(session_->local_description());
1822 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1823
1824 SetRemoteDescriptionExpectState(pranswer2,
1825 BaseSession::STATE_RECEIVEDPRACCEPT);
1826
1827 mediastream_signaling_.SendAudioVideoStream2();
1828 SessionDescriptionInterface* answer =
1829 CreateRemoteAnswer(session_->local_description());
1830 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1831}
1832
1833TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001834 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001835 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001836 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1837
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001838 SessionDescriptionInterface* answer =
1839 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001840 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1841 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001842}
1843
1844TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001845 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001846 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001847 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1848
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001849 SessionDescriptionInterface* answer =
1850 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001851 SetRemoteDescriptionAnswerExpectError(
1852 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001853}
1854
1855TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001856 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857 mediastream_signaling_.SendAudioVideoStream1();
1858
1859 cricket::Candidate candidate;
1860 candidate.set_component(1);
1861 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1862
1863 // Fail since we have not set a offer description.
1864 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1865
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001866 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001867 SetLocalDescriptionWithoutError(offer);
1868 // Candidate should be allowed to add before remote description.
1869 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1870 candidate.set_component(2);
1871 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1872 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1873
1874 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1875 session_->local_description());
1876 SetRemoteDescriptionWithoutError(answer);
1877
1878 // Verifying the candidates are copied properly from internal vector.
1879 const SessionDescriptionInterface* remote_desc =
1880 session_->remote_description();
1881 ASSERT_TRUE(remote_desc != NULL);
1882 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1883 const IceCandidateCollection* candidates =
1884 remote_desc->candidates(kMediaContentIndex0);
1885 ASSERT_EQ(2u, candidates->count());
1886 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1887 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1888 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1889 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1890
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001891 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1892 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001893 candidate.set_component(2);
1894 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1895 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001896 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001897
1898 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1899 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1900}
1901
1902// Test that a remote candidate is added to the remote session description and
1903// that it is retained if the remote session description is changed.
1904TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001905 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001906 cricket::Candidate candidate1;
1907 candidate1.set_component(1);
1908 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1909 candidate1);
1910 mediastream_signaling_.SendAudioVideoStream1();
1911 CreateAndSetRemoteOfferAndLocalAnswer();
1912
1913 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1914 const SessionDescriptionInterface* remote_desc =
1915 session_->remote_description();
1916 ASSERT_TRUE(remote_desc != NULL);
1917 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1918 const IceCandidateCollection* candidates =
1919 remote_desc->candidates(kMediaContentIndex0);
1920 ASSERT_EQ(1u, candidates->count());
1921 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1922
1923 // Update the RemoteSessionDescription with a new session description and
1924 // a candidate and check that the new remote session description contains both
1925 // candidates.
1926 SessionDescriptionInterface* offer = CreateRemoteOffer();
1927 cricket::Candidate candidate2;
1928 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1929 candidate2);
1930 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1931 SetRemoteDescriptionWithoutError(offer);
1932
1933 remote_desc = session_->remote_description();
1934 ASSERT_TRUE(remote_desc != NULL);
1935 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1936 candidates = remote_desc->candidates(kMediaContentIndex0);
1937 ASSERT_EQ(2u, candidates->count());
1938 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1939 // Username and password have be updated with the TransportInfo of the
1940 // SessionDescription, won't be equal to the original one.
1941 candidate2.set_username(candidates->at(0)->candidate().username());
1942 candidate2.set_password(candidates->at(0)->candidate().password());
1943 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
1944 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
1945 // No need to verify the username and password.
1946 candidate1.set_username(candidates->at(1)->candidate().username());
1947 candidate1.set_password(candidates->at(1)->candidate().password());
1948 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
1949
1950 // Test that the candidate is ignored if we can add the same candidate again.
1951 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1952}
1953
1954// Test that local candidates are added to the local session description and
1955// that they are retained if the local session description is changed.
1956TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001957 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001958 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001959 mediastream_signaling_.SendAudioVideoStream1();
1960 CreateAndSetRemoteOfferAndLocalAnswer();
1961
1962 const SessionDescriptionInterface* local_desc = session_->local_description();
1963 const IceCandidateCollection* candidates =
1964 local_desc->candidates(kMediaContentIndex0);
1965 ASSERT_TRUE(candidates != NULL);
1966 EXPECT_EQ(0u, candidates->count());
1967
1968 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1969
1970 local_desc = session_->local_description();
1971 candidates = local_desc->candidates(kMediaContentIndex0);
1972 ASSERT_TRUE(candidates != NULL);
1973 EXPECT_LT(0u, candidates->count());
1974 candidates = local_desc->candidates(1);
1975 ASSERT_TRUE(candidates != NULL);
1976 EXPECT_LT(0u, candidates->count());
1977
1978 // Update the session descriptions.
1979 mediastream_signaling_.SendAudioVideoStream1();
1980 CreateAndSetRemoteOfferAndLocalAnswer();
1981
1982 local_desc = session_->local_description();
1983 candidates = local_desc->candidates(kMediaContentIndex0);
1984 ASSERT_TRUE(candidates != NULL);
1985 EXPECT_LT(0u, candidates->count());
1986 candidates = local_desc->candidates(1);
1987 ASSERT_TRUE(candidates != NULL);
1988 EXPECT_LT(0u, candidates->count());
1989}
1990
1991// Test that we can set a remote session description with remote candidates.
1992TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001993 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001994
1995 cricket::Candidate candidate1;
1996 candidate1.set_component(1);
1997 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
1998 candidate1);
1999 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002000 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001
2002 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2003 SetRemoteDescriptionWithoutError(offer);
2004
2005 const SessionDescriptionInterface* remote_desc =
2006 session_->remote_description();
2007 ASSERT_TRUE(remote_desc != NULL);
2008 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2009 const IceCandidateCollection* candidates =
2010 remote_desc->candidates(kMediaContentIndex0);
2011 ASSERT_EQ(1u, candidates->count());
2012 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2013
wu@webrtc.org91053e72013-08-10 07:18:04 +00002014 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002015 SetLocalDescriptionWithoutError(answer);
2016}
2017
2018// Test that offers and answers contains ice candidates when Ice candidates have
2019// been gathered.
2020TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002021 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002022 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002023 mediastream_signaling_.SendAudioVideoStream1();
2024 // Ice is started but candidates are not provided until SetLocalDescription
2025 // is called.
2026 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2027 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2028 CreateAndSetRemoteOfferAndLocalAnswer();
2029 // Wait until at least one local candidate has been collected.
2030 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2031 kIceCandidatesTimeout);
2032 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
2033 kIceCandidatesTimeout);
2034
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002035 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2036
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002037 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2038 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
2039 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
2040 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
2041
2042 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2043 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002044 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002045 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2046 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
2047 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
2048 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
2049 SetLocalDescriptionWithoutError(answer);
2050}
2051
2052// Verifies TransportProxy and media channels are created with content names
2053// present in the SessionDescription.
2054TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002055 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002056 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002057 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058
2059 // CreateOffer creates session description with the content names "audio" and
2060 // "video". Goal is to modify these content names and verify transport channel
2061 // proxy in the BaseSession, as proxies are created with the content names
2062 // present in SDP.
2063 std::string sdp;
2064 EXPECT_TRUE(offer->ToString(&sdp));
2065 const std::string kAudioMid = "a=mid:audio";
2066 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2067 const std::string kVideoMid = "a=mid:video";
2068 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2069
2070 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002071 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072 kAudioMidReplaceStr.c_str(),
2073 kAudioMidReplaceStr.length(),
2074 &sdp);
2075 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002076 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002077 kVideoMidReplaceStr.c_str(),
2078 kVideoMidReplaceStr.length(),
2079 &sdp);
2080
2081 SessionDescriptionInterface* modified_offer =
2082 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2083
2084 SetRemoteDescriptionWithoutError(modified_offer);
2085
2086 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002087 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002088 SetLocalDescriptionWithoutError(answer);
2089
2090 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
2091 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
2092 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2093 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2094}
2095
2096// Test that an offer contains the correct media content descriptions based on
2097// the send streams when no constraints have been set.
2098TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002099 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002100 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2101
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002102 ASSERT_TRUE(offer != NULL);
2103 const cricket::ContentInfo* content =
2104 cricket::GetFirstAudioContent(offer->description());
2105 EXPECT_TRUE(content != NULL);
2106 content = cricket::GetFirstVideoContent(offer->description());
2107 EXPECT_TRUE(content == NULL);
2108}
2109
2110// Test that an offer contains the correct media content descriptions based on
2111// the send streams when no constraints have been set.
2112TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002113 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002114 // Test Audio only offer.
2115 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002116 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2117
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118 const cricket::ContentInfo* content =
2119 cricket::GetFirstAudioContent(offer->description());
2120 EXPECT_TRUE(content != NULL);
2121 content = cricket::GetFirstVideoContent(offer->description());
2122 EXPECT_TRUE(content == NULL);
2123
2124 // Test Audio / Video offer.
2125 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002126 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002127 content = cricket::GetFirstAudioContent(offer->description());
2128 EXPECT_TRUE(content != NULL);
2129 content = cricket::GetFirstVideoContent(offer->description());
2130 EXPECT_TRUE(content != NULL);
2131}
2132
2133// Test that an offer contains no media content descriptions if
2134// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2135TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002136 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002137 PeerConnectionInterface::RTCOfferAnswerOptions options;
2138 options.offer_to_receive_audio = 0;
2139 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002141 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002142 CreateOffer(options));
2143
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002144 ASSERT_TRUE(offer != NULL);
2145 const cricket::ContentInfo* content =
2146 cricket::GetFirstAudioContent(offer->description());
2147 EXPECT_TRUE(content == NULL);
2148 content = cricket::GetFirstVideoContent(offer->description());
2149 EXPECT_TRUE(content == NULL);
2150}
2151
2152// Test that an offer contains only audio media content descriptions if
2153// kOfferToReceiveAudio constraints are set to true.
2154TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002155 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002156 PeerConnectionInterface::RTCOfferAnswerOptions options;
2157 options.offer_to_receive_audio =
2158 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2159
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002160 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002161 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002162
2163 const cricket::ContentInfo* content =
2164 cricket::GetFirstAudioContent(offer->description());
2165 EXPECT_TRUE(content != NULL);
2166 content = cricket::GetFirstVideoContent(offer->description());
2167 EXPECT_TRUE(content == NULL);
2168}
2169
2170// Test that an offer contains audio and video media content descriptions if
2171// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2172TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002173 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002174 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002175 PeerConnectionInterface::RTCOfferAnswerOptions options;
2176 options.offer_to_receive_audio =
2177 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2178 options.offer_to_receive_video =
2179 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2180
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002181 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002182 CreateOffer(options));
2183
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002184 const cricket::ContentInfo* content =
2185 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002186 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002187
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002188 content = cricket::GetFirstVideoContent(offer->description());
2189 EXPECT_TRUE(content != NULL);
2190
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002191 // Sets constraints to false and verifies that audio/video contents are
2192 // removed.
2193 options.offer_to_receive_audio = 0;
2194 options.offer_to_receive_video = 0;
2195 offer.reset(CreateOffer(options));
2196
2197 content = cricket::GetFirstAudioContent(offer->description());
2198 EXPECT_TRUE(content == NULL);
2199 content = cricket::GetFirstVideoContent(offer->description());
2200 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002201}
2202
2203// Test that an answer can not be created if the last remote description is not
2204// an offer.
2205TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002206 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002207 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002208 SetLocalDescriptionWithoutError(offer);
2209 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2210 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002211 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002212}
2213
2214// Test that an answer contains the correct media content descriptions when no
2215// constraints have been set.
2216TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002217 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002218 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002219 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002220 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002221 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002222 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002223 const cricket::ContentInfo* content =
2224 cricket::GetFirstAudioContent(answer->description());
2225 ASSERT_TRUE(content != NULL);
2226 EXPECT_FALSE(content->rejected);
2227
2228 content = cricket::GetFirstVideoContent(answer->description());
2229 ASSERT_TRUE(content != NULL);
2230 EXPECT_FALSE(content->rejected);
2231}
2232
2233// Test that an answer contains the correct media content descriptions when no
2234// constraints have been set and the offer only contain audio.
2235TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002236 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002237 // Create a remote offer with audio only.
2238 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002239
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002240 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002241 CreateRemoteOffer(options));
2242 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2243 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2244
2245 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002246 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002247 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002248 const cricket::ContentInfo* content =
2249 cricket::GetFirstAudioContent(answer->description());
2250 ASSERT_TRUE(content != NULL);
2251 EXPECT_FALSE(content->rejected);
2252
2253 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2254}
2255
2256// Test that an answer contains the correct media content descriptions when no
2257// constraints have been set.
2258TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002259 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002260 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002261 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002262 SetRemoteDescriptionWithoutError(offer.release());
2263 // Test with a stream with tracks.
2264 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002265 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002266 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002267 const cricket::ContentInfo* content =
2268 cricket::GetFirstAudioContent(answer->description());
2269 ASSERT_TRUE(content != NULL);
2270 EXPECT_FALSE(content->rejected);
2271
2272 content = cricket::GetFirstVideoContent(answer->description());
2273 ASSERT_TRUE(content != NULL);
2274 EXPECT_FALSE(content->rejected);
2275}
2276
2277// Test that an answer contains the correct media content descriptions when
2278// constraints have been set but no stream is sent.
2279TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002280 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002281 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002282 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002283 SetRemoteDescriptionWithoutError(offer.release());
2284
2285 webrtc::FakeConstraints constraints_no_receive;
2286 constraints_no_receive.SetMandatoryReceiveAudio(false);
2287 constraints_no_receive.SetMandatoryReceiveVideo(false);
2288
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002289 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002290 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002291 const cricket::ContentInfo* content =
2292 cricket::GetFirstAudioContent(answer->description());
2293 ASSERT_TRUE(content != NULL);
2294 EXPECT_TRUE(content->rejected);
2295
2296 content = cricket::GetFirstVideoContent(answer->description());
2297 ASSERT_TRUE(content != NULL);
2298 EXPECT_TRUE(content->rejected);
2299}
2300
2301// Test that an answer contains the correct media content descriptions when
2302// constraints have been set and streams are sent.
2303TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002304 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002305 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002306 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002307 SetRemoteDescriptionWithoutError(offer.release());
2308
2309 webrtc::FakeConstraints constraints_no_receive;
2310 constraints_no_receive.SetMandatoryReceiveAudio(false);
2311 constraints_no_receive.SetMandatoryReceiveVideo(false);
2312
2313 // Test with a stream with tracks.
2314 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002315 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002316 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002317
2318 // TODO(perkj): Should the direction be set to SEND_ONLY?
2319 const cricket::ContentInfo* content =
2320 cricket::GetFirstAudioContent(answer->description());
2321 ASSERT_TRUE(content != NULL);
2322 EXPECT_FALSE(content->rejected);
2323
2324 // TODO(perkj): Should the direction be set to SEND_ONLY?
2325 content = cricket::GetFirstVideoContent(answer->description());
2326 ASSERT_TRUE(content != NULL);
2327 EXPECT_FALSE(content->rejected);
2328}
2329
2330TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2331 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002332 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002333 PeerConnectionInterface::RTCOfferAnswerOptions options;
2334 options.offer_to_receive_audio =
2335 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2336 options.voice_activity_detection = false;
2337
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002338 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002339 CreateOffer(options));
2340
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002341 const cricket::ContentInfo* content =
2342 cricket::GetFirstAudioContent(offer->description());
2343 EXPECT_TRUE(content != NULL);
2344 EXPECT_TRUE(VerifyNoCNCodecs(content));
2345}
2346
2347TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2348 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002349 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002350 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002351 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002352 SetRemoteDescriptionWithoutError(offer.release());
2353
2354 webrtc::FakeConstraints constraints;
2355 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002356 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002357 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002358 const cricket::ContentInfo* content =
2359 cricket::GetFirstAudioContent(answer->description());
2360 ASSERT_TRUE(content != NULL);
2361 EXPECT_TRUE(VerifyNoCNCodecs(content));
2362}
2363
2364// This test verifies the call setup when remote answer with audio only and
2365// later updates with video.
2366TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002367 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002368 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2369 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2370
2371 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002372 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002373
2374 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002375 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2376
2377 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2378 // and answer;
2379 SetLocalDescriptionWithoutError(offer);
2380 SetRemoteDescriptionWithoutError(answer);
2381
2382 video_channel_ = media_engine_->GetVideoChannel(0);
2383 voice_channel_ = media_engine_->GetVoiceChannel(0);
2384
2385 ASSERT_TRUE(video_channel_ == NULL);
2386
2387 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2388 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2389 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2390
2391 // Let the remote end update the session descriptions, with Audio and Video.
2392 mediastream_signaling_.SendAudioVideoStream2();
2393 CreateAndSetRemoteOfferAndLocalAnswer();
2394
2395 video_channel_ = media_engine_->GetVideoChannel(0);
2396 voice_channel_ = media_engine_->GetVoiceChannel(0);
2397
2398 ASSERT_TRUE(video_channel_ != NULL);
2399 ASSERT_TRUE(voice_channel_ != NULL);
2400
2401 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2402 ASSERT_EQ(1u, video_channel_->send_streams().size());
2403 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2404 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2405 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2406 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2407 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2408 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2409
2410 // Change session back to audio only.
2411 mediastream_signaling_.UseOptionsAudioOnly();
2412 CreateAndSetRemoteOfferAndLocalAnswer();
2413
2414 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2415 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2416 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2417 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2418 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2419}
2420
2421// This test verifies the call setup when remote answer with video only and
2422// later updates with audio.
2423TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002424 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002425 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2426 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2427 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002428 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002429
2430 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002431 options.recv_audio = false;
2432 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002433 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2434 offer, options, cricket::SEC_ENABLED);
2435
2436 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2437 // and answer.
2438 SetLocalDescriptionWithoutError(offer);
2439 SetRemoteDescriptionWithoutError(answer);
2440
2441 video_channel_ = media_engine_->GetVideoChannel(0);
2442 voice_channel_ = media_engine_->GetVoiceChannel(0);
2443
2444 ASSERT_TRUE(voice_channel_ == NULL);
2445 ASSERT_TRUE(video_channel_ != NULL);
2446
2447 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2448 ASSERT_EQ(1u, video_channel_->send_streams().size());
2449 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2450
2451 // Update the session descriptions, with Audio and Video.
2452 mediastream_signaling_.SendAudioVideoStream2();
2453 CreateAndSetRemoteOfferAndLocalAnswer();
2454
2455 voice_channel_ = media_engine_->GetVoiceChannel(0);
2456 ASSERT_TRUE(voice_channel_ != NULL);
2457
2458 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2459 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2460 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2461 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2462
2463 // Change session back to video only.
2464 mediastream_signaling_.UseOptionsVideoOnly();
2465 CreateAndSetRemoteOfferAndLocalAnswer();
2466
2467 video_channel_ = media_engine_->GetVideoChannel(0);
2468 voice_channel_ = media_engine_->GetVoiceChannel(0);
2469
2470 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2471 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2472 ASSERT_EQ(1u, video_channel_->send_streams().size());
2473 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2474}
2475
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002476TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002477 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002478 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002479 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002480 VerifyCryptoParams(offer->description());
2481 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002482 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002483 VerifyCryptoParams(answer->description());
2484}
2485
2486TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002487 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002488 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002489 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002490 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002491 VerifyNoCryptoParams(offer->description(), false);
2492}
2493
2494TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002495 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002496 VerifyAnswerFromNonCryptoOffer();
2497}
2498
2499TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002500 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002501 VerifyAnswerFromCryptoOffer();
2502}
2503
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002504// This test verifies that setLocalDescription fails if
2505// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2506TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002507 Init();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002508 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002509 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2510
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002511 std::string sdp;
2512 RemoveIceUfragPwdLines(offer.get(), &sdp);
2513 SessionDescriptionInterface* modified_offer =
2514 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002515 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002516}
2517
2518// This test verifies that setRemoteDescription fails if
2519// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2520TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002521 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002522 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002523 std::string sdp;
2524 RemoveIceUfragPwdLines(offer.get(), &sdp);
2525 SessionDescriptionInterface* modified_offer =
2526 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002527 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002528}
2529
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002530// This test verifies that setLocalDescription fails if local offer has
2531// too short ice ufrag and pwd strings.
2532TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002533 Init();
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002534 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
2535 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002536 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2537
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002538 std::string sdp;
2539 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2540 // recommended values of 4 and 22 bytes respectively.
2541 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2542 SessionDescriptionInterface* modified_offer =
2543 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2544 std::string error;
2545 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2546
2547 // Test with string greater than 256.
2548 sdp.clear();
2549 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2550 &sdp);
2551 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2552 NULL);
2553 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2554}
2555
2556// This test verifies that setRemoteDescription fails if remote offer has
2557// too short ice ufrag and pwd strings.
2558TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002559 Init();
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002560 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002561 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002562 std::string sdp;
2563 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2564 // recommended values of 4 and 22 bytes respectively.
2565 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2566 SessionDescriptionInterface* modified_offer =
2567 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2568 std::string error;
2569 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2570
2571 sdp.clear();
2572 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2573 &sdp);
2574 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2575 NULL);
2576 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2577}
2578
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002579TEST_F(WebRtcSessionTest, VerifyBundleFlagInPA) {
2580 // This test verifies BUNDLE flag in PortAllocator, if BUNDLE information in
2581 // local description is removed by the application, BUNDLE flag should be
2582 // disabled in PortAllocator. By default BUNDLE is enabled in the WebRtc.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002583 Init();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002584 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2585 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002586 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2587
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002588 cricket::SessionDescription* offer_copy =
2589 offer->description()->Copy();
2590 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2591 JsepSessionDescription* modified_offer =
2592 new JsepSessionDescription(JsepSessionDescription::kOffer);
2593 modified_offer->Initialize(offer_copy, "1", "1");
2594
2595 SetLocalDescriptionWithoutError(modified_offer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002596 EXPECT_FALSE(allocator_->flags() & cricket::PORTALLOCATOR_ENABLE_BUNDLE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002597}
2598
2599TEST_F(WebRtcSessionTest, TestDisabledBundleInAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002600 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002601 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002602 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2603 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002604
2605 PeerConnectionInterface::RTCOfferAnswerOptions options;
2606 options.use_rtp_mux = true;
2607
2608 SessionDescriptionInterface* offer = CreateOffer(options);
2609
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002610 SetLocalDescriptionWithoutError(offer);
2611 mediastream_signaling_.SendAudioVideoStream2();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002612 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002613 CreateRemoteAnswer(session_->local_description()));
2614 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2615 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2616 JsepSessionDescription* modified_answer =
2617 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2618 modified_answer->Initialize(answer_copy, "1", "1");
2619 SetRemoteDescriptionWithoutError(modified_answer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002620 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2621 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002622
2623 video_channel_ = media_engine_->GetVideoChannel(0);
2624 voice_channel_ = media_engine_->GetVoiceChannel(0);
2625
2626 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2627 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
2628
2629 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2630 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
2631
2632 ASSERT_EQ(1u, video_channel_->send_streams().size());
2633 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
2634 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2635 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
2636}
2637
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002638// This test verifies that SetLocalDescription and SetRemoteDescription fails
2639// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2640TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002641 Init();
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002642 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002643 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2644 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002645
2646 PeerConnectionInterface::RTCOfferAnswerOptions options;
2647 options.use_rtp_mux = true;
2648
2649 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002650 std::string offer_str;
2651 offer->ToString(&offer_str);
2652 // Disable rtcp-mux
2653 const std::string rtcp_mux = "rtcp-mux";
2654 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002655 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002656 xrtcp_mux.c_str(), xrtcp_mux.length(),
2657 &offer_str);
2658 JsepSessionDescription *local_offer =
2659 new JsepSessionDescription(JsepSessionDescription::kOffer);
2660 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002661 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002662 JsepSessionDescription *remote_offer =
2663 new JsepSessionDescription(JsepSessionDescription::kOffer);
2664 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002665 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002666 // Trying unmodified SDP.
2667 SetLocalDescriptionWithoutError(offer);
2668}
2669
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002670TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002671 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002672 mediastream_signaling_.SendAudioVideoStream1();
2673 CreateAndSetRemoteOfferAndLocalAnswer();
2674 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2675 ASSERT_TRUE(channel != NULL);
2676 ASSERT_EQ(1u, channel->recv_streams().size());
2677 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2678 double left_vol, right_vol;
2679 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2680 EXPECT_EQ(1, left_vol);
2681 EXPECT_EQ(1, right_vol);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002682 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002683 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002684 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2685 EXPECT_EQ(0, left_vol);
2686 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002687 EXPECT_EQ(0, renderer->channel_id());
2688 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002689 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2690 EXPECT_EQ(1, left_vol);
2691 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002692 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002693}
2694
2695TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002696 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002697 mediastream_signaling_.SendAudioVideoStream1();
2698 CreateAndSetRemoteOfferAndLocalAnswer();
2699 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2700 ASSERT_TRUE(channel != NULL);
2701 ASSERT_EQ(1u, channel->send_streams().size());
2702 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2703 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2704
2705 cricket::AudioOptions options;
2706 options.echo_cancellation.Set(true);
2707
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002708 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002709 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002710 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2711 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002712 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002713 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002714
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002715 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002716 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002717 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2718 bool value;
2719 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
2720 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002721 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002722 EXPECT_TRUE(renderer->sink() == NULL);
2723}
2724
2725TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002726 Init();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002727 mediastream_signaling_.SendAudioVideoStream1();
2728 CreateAndSetRemoteOfferAndLocalAnswer();
2729 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2730 ASSERT_TRUE(channel != NULL);
2731 ASSERT_EQ(1u, channel->send_streams().size());
2732 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2733
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002734 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002735 cricket::AudioOptions options;
2736 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
2737 EXPECT_TRUE(renderer->sink() != NULL);
2738
2739 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
2740 // will invalidate the |renderer_| pointer in the sink and prevent getting a
2741 // SetSink(NULL) callback afterwards.
2742 renderer.reset();
2743
2744 // This will trigger SetSink(NULL) if no OnClose() callback.
2745 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002746}
2747
2748TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002749 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002750 mediastream_signaling_.SendAudioVideoStream1();
2751 CreateAndSetRemoteOfferAndLocalAnswer();
2752 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2753 ASSERT_TRUE(channel != NULL);
2754 ASSERT_LT(0u, channel->renderers().size());
2755 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2756 ASSERT_EQ(1u, channel->recv_streams().size());
2757 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2758 cricket::FakeVideoRenderer renderer;
2759 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
2760 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
2761 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
2762 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2763}
2764
2765TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002766 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002767 mediastream_signaling_.SendAudioVideoStream1();
2768 CreateAndSetRemoteOfferAndLocalAnswer();
2769 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2770 ASSERT_TRUE(channel != NULL);
2771 ASSERT_EQ(1u, channel->send_streams().size());
2772 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2773 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2774 cricket::VideoOptions* options = NULL;
2775 session_->SetVideoSend(send_ssrc, false, options);
2776 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2777 session_->SetVideoSend(send_ssrc, true, options);
2778 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2779}
2780
2781TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
2782 TestCanInsertDtmf(false);
2783}
2784
2785TEST_F(WebRtcSessionTest, CanInsertDtmf) {
2786 TestCanInsertDtmf(true);
2787}
2788
2789TEST_F(WebRtcSessionTest, InsertDtmf) {
2790 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002791 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002792 mediastream_signaling_.SendAudioVideoStream1();
2793 CreateAndSetRemoteOfferAndLocalAnswer();
2794 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2795 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
2796
2797 // Insert DTMF
2798 const int expected_flags = DF_SEND;
2799 const int expected_duration = 90;
2800 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
2801 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
2802 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
2803
2804 // Verify
2805 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
2806 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2807 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
2808 expected_duration, expected_flags));
2809 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
2810 expected_duration, expected_flags));
2811 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
2812 expected_duration, expected_flags));
2813}
2814
2815// This test verifies the |initiator| flag when session initiates the call.
2816TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002817 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002818 EXPECT_FALSE(session_->initiator());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002819 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002820 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2821 SetLocalDescriptionWithoutError(offer);
2822 EXPECT_TRUE(session_->initiator());
2823 SetRemoteDescriptionWithoutError(answer);
2824 EXPECT_TRUE(session_->initiator());
2825}
2826
2827// This test verifies the |initiator| flag when session receives the call.
2828TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002829 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002830 EXPECT_FALSE(session_->initiator());
2831 SessionDescriptionInterface* offer = CreateRemoteOffer();
2832 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002833 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002834
2835 EXPECT_FALSE(session_->initiator());
2836 SetLocalDescriptionWithoutError(answer);
2837 EXPECT_FALSE(session_->initiator());
2838}
2839
2840// This test verifies the ice protocol type at initiator of the call
2841// if |a=ice-options:google-ice| is present in answer.
2842TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002843 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002844 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002845 SessionDescriptionInterface* offer = CreateOffer();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002846 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002847 CreateRemoteAnswer(offer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002848 SetLocalDescriptionWithoutError(offer);
2849 std::string sdp;
2850 EXPECT_TRUE(answer->ToString(&sdp));
2851 // Adding ice-options to the session level.
2852 InjectAfter("t=0 0\r\n",
2853 "a=ice-options:google-ice\r\n",
2854 &sdp);
2855 SessionDescriptionInterface* answer_with_gice =
2856 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00002857 // Default offer is ICEPROTO_RFC5245, so we expect responder with
2858 // only gice to fail.
2859 SetRemoteDescriptionAnswerExpectError(kPushDownTDFailed, answer_with_gice);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002860}
2861
2862// This test verifies the ice protocol type at initiator of the call
2863// if ICE RFC5245 is supported in answer.
2864TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002865 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002866 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002867 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002868 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2869 SetLocalDescriptionWithoutError(offer);
2870
2871 SetRemoteDescriptionWithoutError(answer);
2872 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2873 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2874}
2875
2876// This test verifies the ice protocol type at receiver side of the call if
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002877// receiver decides to use ice RFC 5245.
2878TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002879 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002880 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002881 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002882 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002883 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002884 SetLocalDescriptionWithoutError(answer);
2885 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2886 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2887}
2888
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002889// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
2890TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002891 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002892 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002893 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002894 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002895 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002896 CreateRemoteAnswer(session_->local_description()));
2897
2898 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2899 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002900 JsepSessionDescription* modified_answer =
2901 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002902
2903 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2904 answer->session_id(),
2905 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002906 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002907
wu@webrtc.org4e393072014-04-07 17:04:35 +00002908 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002909 std::string sdp;
2910 EXPECT_TRUE(answer->ToString(&sdp));
2911 const std::string kAudioMid = "a=mid:audio";
2912 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002913 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002914 kAudioMidReplaceStr.c_str(),
2915 kAudioMidReplaceStr.length(),
2916 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002917 SessionDescriptionInterface* modified_answer1 =
2918 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002919 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002920
wu@webrtc.org4e393072014-04-07 17:04:35 +00002921 // Different media types.
2922 EXPECT_TRUE(answer->ToString(&sdp));
2923 const std::string kAudioMline = "m=audio";
2924 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002925 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00002926 kAudioMlineReplaceStr.c_str(),
2927 kAudioMlineReplaceStr.length(),
2928 &sdp);
2929 SessionDescriptionInterface* modified_answer2 =
2930 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2931 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
2932
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002933 SetRemoteDescriptionWithoutError(answer.release());
2934}
2935
2936// Verifying remote offer and local answer have matching m-lines as per
2937// RFC 3264.
2938TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002939 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002940 mediastream_signaling_.SendAudioVideoStream1();
2941 SessionDescriptionInterface* offer = CreateRemoteOffer();
2942 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002943 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002944
2945 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2946 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002947 JsepSessionDescription* modified_answer =
2948 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002949
2950 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2951 answer->session_id(),
2952 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002953 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002954 SetLocalDescriptionWithoutError(answer);
2955}
2956
2957// This test verifies that WebRtcSession does not start candidate allocation
2958// before SetLocalDescription is called.
2959TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002960 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002961 mediastream_signaling_.SendAudioVideoStream1();
2962 SessionDescriptionInterface* offer = CreateRemoteOffer();
2963 cricket::Candidate candidate;
2964 candidate.set_component(1);
2965 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2966 candidate);
2967 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2968 cricket::Candidate candidate1;
2969 candidate1.set_component(1);
2970 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2971 candidate1);
2972 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2973 SetRemoteDescriptionWithoutError(offer);
2974 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
2975 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
2976
2977 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002978 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002979 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
2980 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
2981
wu@webrtc.org91053e72013-08-10 07:18:04 +00002982 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002983 SetLocalDescriptionWithoutError(answer);
2984 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
2985 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
2986 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2987}
2988
2989// This test verifies that crypto parameter is updated in local session
2990// description as per security policy set in MediaSessionDescriptionFactory.
2991TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002992 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002993 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002994 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002995
2996 // Making sure SetLocalDescription correctly sets crypto value in
2997 // SessionDescription object after de-serialization of sdp string. The value
2998 // will be set as per MediaSessionDescriptionFactory.
2999 std::string offer_str;
3000 offer->ToString(&offer_str);
3001 SessionDescriptionInterface* jsep_offer_str =
3002 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3003 SetLocalDescriptionWithoutError(jsep_offer_str);
3004 EXPECT_TRUE(session_->voice_channel()->secure_required());
3005 EXPECT_TRUE(session_->video_channel()->secure_required());
3006}
3007
3008// This test verifies the crypto parameter when security is disabled.
3009TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003010 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003011 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003012 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003013 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003014
3015 // Making sure SetLocalDescription correctly sets crypto value in
3016 // SessionDescription object after de-serialization of sdp string. The value
3017 // will be set as per MediaSessionDescriptionFactory.
3018 std::string offer_str;
3019 offer->ToString(&offer_str);
3020 SessionDescriptionInterface *jsep_offer_str =
3021 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3022 SetLocalDescriptionWithoutError(jsep_offer_str);
3023 EXPECT_FALSE(session_->voice_channel()->secure_required());
3024 EXPECT_FALSE(session_->video_channel()->secure_required());
3025}
3026
3027// This test verifies that an answer contains new ufrag and password if an offer
3028// with new ufrag and password is received.
3029TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003030 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003031 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003032 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003033 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003034 CreateRemoteOffer(options));
3035 SetRemoteDescriptionWithoutError(offer.release());
3036
3037 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003038 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003039 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003040 SetLocalDescriptionWithoutError(answer.release());
3041
3042 // Receive an offer with new ufrag and password.
3043 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003044 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003045 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003046 SetRemoteDescriptionWithoutError(updated_offer1.release());
3047
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003048 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003049 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003050
3051 CompareIceUfragAndPassword(updated_answer1->description(),
3052 session_->local_description()->description(),
3053 false);
3054
3055 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003056}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003057
wu@webrtc.org91053e72013-08-10 07:18:04 +00003058// This test verifies that an answer contains old ufrag and password if an offer
3059// with old ufrag and password is received.
3060TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003061 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003062 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003063 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003064 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003065 CreateRemoteOffer(options));
3066 SetRemoteDescriptionWithoutError(offer.release());
3067
3068 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003069 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003070 CreateAnswer(NULL));
3071 SetLocalDescriptionWithoutError(answer.release());
3072
3073 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003074 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003075 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003076 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003077 SetRemoteDescriptionWithoutError(updated_offer2.release());
3078
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003079 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003080 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003081
3082 CompareIceUfragAndPassword(updated_answer2->description(),
3083 session_->local_description()->description(),
3084 true);
3085
3086 SetLocalDescriptionWithoutError(updated_answer2.release());
3087}
3088
3089TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003090 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003091 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003092 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003093 const std::string session_id_orig = offer->session_id();
3094 const std::string session_version_orig = offer->session_version();
3095 SetLocalDescriptionWithoutError(offer);
3096
3097 video_channel_ = media_engine_->GetVideoChannel(0);
3098 video_channel_->set_fail_set_send_codecs(true);
3099
3100 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003101 SessionDescriptionInterface* answer =
3102 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003103 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003104}
3105
3106// Runs the loopback call test with BUNDLE and STUN disabled.
3107TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3108 // Lets try with only UDP ports.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00003109 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003110 cricket::PORTALLOCATOR_DISABLE_TCP |
3111 cricket::PORTALLOCATOR_DISABLE_STUN |
3112 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003113 TestLoopbackCall();
3114}
3115
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003116TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
3117 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
3118 cricket::PORTALLOCATOR_DISABLE_TCP |
3119 cricket::PORTALLOCATOR_DISABLE_STUN |
3120 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3121 cricket::PORTALLOCATOR_DISABLE_RELAY);
3122
3123 // best connection is IPv6 since it has higher network preference.
3124 LoopbackNetworkConfiguration config;
3125 config.test_ipv6_network_ = true;
3126 config.best_connection_after_initial_ice_converged_ =
3127 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3128
3129 TestLoopbackCall(config);
3130}
3131
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003132// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003133TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00003134 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003135 cricket::PORTALLOCATOR_ENABLE_BUNDLE |
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003136 cricket::PORTALLOCATOR_DISABLE_TCP |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003137 cricket::PORTALLOCATOR_DISABLE_RELAY);
3138 TestLoopbackCall();
3139}
3140
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003141TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003142 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003143 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003144 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003145
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003146 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
3147 std::string error_code_str = "ERROR_CONTENT";
3148 std::string error_desc = "Fake session error description.";
3149 session_->SetError(error_code, error_desc);
3150
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003151 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
3152 SessionDescriptionInterface* answer =
3153 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003154
3155 std::string action;
3156 std::ostringstream session_error_msg;
3157 session_error_msg << kSessionError << error_code_str << ". ";
3158 session_error_msg << kSessionErrorDesc << error_desc << ".";
3159 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
3160 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003161}
3162
3163TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3164 constraints_.reset(new FakeConstraints());
3165 constraints_->AddOptional(
3166 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003167 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003168
3169 SetLocalDescriptionWithDataChannel();
3170 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3171}
3172
3173TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003174 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003175
3176 constraints_.reset(new FakeConstraints());
3177 constraints_->AddOptional(
3178 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003179 options_.disable_sctp_data_channels = false;
3180
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003181 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003182
3183 SetLocalDescriptionWithDataChannel();
3184 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3185}
3186
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003187TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003188 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003189
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003190 InitWithDtls();
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003191
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003192 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003193 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003194 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3195}
3196
3197TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003198 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003199 SetFactoryDtlsSrtp();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003200 InitWithDtls();
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003201
3202 // Create remote offer with SCTP.
3203 cricket::MediaSessionOptions options;
3204 options.data_channel_type = cricket::DCT_SCTP;
3205 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003206 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003207 SetRemoteDescriptionWithoutError(offer);
3208
3209 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003210 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003211 EXPECT_TRUE(answer != NULL);
3212 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3213 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003214}
3215
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003216TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
3217 constraints_.reset(new FakeConstraints());
3218 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003219 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003220 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003221
3222 SetLocalDescriptionWithDataChannel();
3223 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3224}
3225
3226TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003227 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003228
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003229 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003230
3231 SetLocalDescriptionWithDataChannel();
3232 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3233}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003234
wu@webrtc.org97077a32013-10-25 21:18:33 +00003235TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003236 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003237 options_.disable_sctp_data_channels = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003238 InitWithDtls();
wu@webrtc.org97077a32013-10-25 21:18:33 +00003239
3240 SetLocalDescriptionWithDataChannel();
3241 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3242}
3243
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003244TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003245 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003246 const int new_send_port = 9998;
3247 const int new_recv_port = 7775;
3248
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003249 InitWithDtls();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003250 SetFactoryDtlsSrtp();
3251
3252 // By default, don't actually add the codecs to desc_factory_; they don't
3253 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3254 // let the session description get parsed. That'll get the proper codecs
3255 // into the stream.
3256 cricket::MediaSessionOptions options;
3257 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3258 "stream1", new_send_port, options);
3259
3260 // SetRemoteDescription will take the ownership of the offer.
3261 SetRemoteDescriptionWithoutError(offer);
3262
3263 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3264 new_recv_port, CreateAnswer(NULL));
3265 ASSERT_TRUE(answer != NULL);
3266
3267 // Now set the local description, which'll take ownership of the answer.
3268 SetLocalDescriptionWithoutError(answer);
3269
3270 // TEST PLAN: Set the port number to something new, set it in the SDP,
3271 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003272 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003273 dci.reliable = true;
3274 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003275 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003276 session_->CreateDataChannel("datachannel", &dci);
3277
3278 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3279 int portnum = -1;
3280 ASSERT_TRUE(ch != NULL);
3281 ASSERT_EQ(1UL, ch->send_codecs().size());
3282 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
3283 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3284 ch->send_codecs()[0].name.c_str()));
3285 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3286 &portnum));
3287 EXPECT_EQ(new_send_port, portnum);
3288
3289 ASSERT_EQ(1UL, ch->recv_codecs().size());
3290 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
3291 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3292 ch->recv_codecs()[0].name.c_str()));
3293 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3294 &portnum));
3295 EXPECT_EQ(new_recv_port, portnum);
3296}
3297
wu@webrtc.org91053e72013-08-10 07:18:04 +00003298// Verifies that CreateOffer succeeds when CreateOffer is called before async
3299// identity generation is finished.
3300TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003301 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003302 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003303
3304 EXPECT_TRUE(session_->waiting_for_identity());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003305 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003306 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3307
wu@webrtc.org91053e72013-08-10 07:18:04 +00003308 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003309 VerifyNoCryptoParams(offer->description(), true);
3310 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003311}
3312
3313// Verifies that CreateAnswer succeeds when CreateOffer is called before async
3314// identity generation is finished.
3315TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003316 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003317 InitWithDtls();
3318 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003319
3320 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003321 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003322 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003323 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003324 ASSERT_TRUE(offer.get() != NULL);
3325 SetRemoteDescriptionWithoutError(offer.release());
3326
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003327 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003328 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003329 VerifyNoCryptoParams(answer->description(), true);
3330 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003331}
3332
3333// Verifies that CreateOffer succeeds when CreateOffer is called after async
3334// identity generation is finished.
3335TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003336 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003337 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003338
3339 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003340
3341 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003342 EXPECT_TRUE(offer != NULL);
3343}
3344
3345// Verifies that CreateOffer fails when CreateOffer is called after async
3346// identity generation fails.
3347TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003348 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00003349 InitWithDtls(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003350
3351 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003352
3353 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003354 EXPECT_TRUE(offer == NULL);
3355}
3356
3357// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3358// before async identity generation is finished.
3359TEST_F(WebRtcSessionTest,
3360 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003361 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003362 VerifyMultipleAsyncCreateDescription(
3363 true, CreateSessionDescriptionRequest::kOffer);
3364}
3365
3366// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3367// before async identity generation fails.
3368TEST_F(WebRtcSessionTest,
3369 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003370 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003371 VerifyMultipleAsyncCreateDescription(
3372 false, CreateSessionDescriptionRequest::kOffer);
3373}
3374
3375// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3376// before async identity generation is finished.
3377TEST_F(WebRtcSessionTest,
3378 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003379 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003380 VerifyMultipleAsyncCreateDescription(
3381 true, CreateSessionDescriptionRequest::kAnswer);
3382}
3383
3384// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3385// before async identity generation fails.
3386TEST_F(WebRtcSessionTest,
3387 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003388 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003389 VerifyMultipleAsyncCreateDescription(
3390 false, CreateSessionDescriptionRequest::kAnswer);
3391}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003392
3393// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3394// offer has no SDES crypto but only DTLS fingerprint.
3395TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3396 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003397 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003398 // Create a remote offer with secured transport disabled.
3399 cricket::MediaSessionOptions options;
3400 JsepSessionDescription* offer(CreateRemoteOffer(
3401 options, cricket::SEC_DISABLED));
3402 // Adds a DTLS fingerprint to the remote offer.
3403 cricket::SessionDescription* sdp = offer->description();
3404 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3405 ASSERT_TRUE(audio != NULL);
3406 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3407 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003408 rtc::SSLFingerprint::CreateFromRfc4572(
3409 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003410 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003411 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003412}
3413
wu@webrtc.orgde305012013-10-31 15:40:38 +00003414// This test verifies DSCP is properly applied on the media channels.
3415TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3416 constraints_.reset(new FakeConstraints());
3417 constraints_->AddOptional(
3418 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003419 Init();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003420 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003421 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003422
3423 SetLocalDescriptionWithoutError(offer);
3424
3425 video_channel_ = media_engine_->GetVideoChannel(0);
3426 voice_channel_ = media_engine_->GetVoiceChannel(0);
3427
3428 ASSERT_TRUE(video_channel_ != NULL);
3429 ASSERT_TRUE(voice_channel_ != NULL);
3430 cricket::AudioOptions audio_options;
3431 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3432 cricket::VideoOptions video_options;
3433 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3434 EXPECT_TRUE(audio_options.dscp.IsSet());
3435 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3436 EXPECT_TRUE(video_options.dscp.IsSet());
3437 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3438}
3439
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003440TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3441 constraints_.reset(new FakeConstraints());
3442 constraints_->AddOptional(
3443 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3444 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003445 Init();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003446 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003447 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003448
3449 SetLocalDescriptionWithoutError(offer);
3450
3451 video_channel_ = media_engine_->GetVideoChannel(0);
3452
3453 ASSERT_TRUE(video_channel_ != NULL);
3454 cricket::VideoOptions video_options;
3455 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3456 EXPECT_TRUE(
3457 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3458}
3459
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00003460TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
3461 // Number of unsignalled receiving streams should be between 0 and
3462 // kMaxUnsignalledRecvStreams.
3463 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
3464 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
3465 kMaxUnsignalledRecvStreams);
3466 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
3467}
3468
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003469TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
3470 constraints_.reset(new FakeConstraints());
3471 constraints_->AddOptional(
3472 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
3473 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003474 Init();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003475 mediastream_signaling_.SendAudioVideoStream1();
3476 SessionDescriptionInterface* offer = CreateOffer();
3477
3478 SetLocalDescriptionWithoutError(offer);
3479
3480 voice_channel_ = media_engine_->GetVoiceChannel(0);
3481
3482 ASSERT_TRUE(voice_channel_ != NULL);
3483 cricket::AudioOptions audio_options;
3484 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3485 EXPECT_TRUE(
3486 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
3487}
3488
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003489// Tests that we can renegotiate new media content with ICE candidates in the
3490// new remote SDP.
3491TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003492 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003493 InitWithDtls();
3494 SetFactoryDtlsSrtp();
3495
3496 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003497 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003498 SetLocalDescriptionWithoutError(offer);
3499
3500 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3501 SetRemoteDescriptionWithoutError(answer);
3502
3503 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003504 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003505 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3506
3507 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003508 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003509 candidate1.set_component(1);
3510 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3511 candidate1);
3512 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3513 SetRemoteDescriptionWithoutError(offer);
3514
3515 answer = CreateAnswer(NULL);
3516 SetLocalDescriptionWithoutError(answer);
3517}
3518
3519// Tests that we can renegotiate new media content with ICE candidates separated
3520// from the remote SDP.
3521TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003522 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003523 InitWithDtls();
3524 SetFactoryDtlsSrtp();
3525
3526 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003527 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003528 SetLocalDescriptionWithoutError(offer);
3529
3530 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3531 SetRemoteDescriptionWithoutError(answer);
3532
3533 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003534 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003535 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3536 SetRemoteDescriptionWithoutError(offer);
3537
3538 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003539 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003540 candidate1.set_component(1);
3541 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3542 candidate1);
3543 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3544
3545 answer = CreateAnswer(NULL);
3546 SetLocalDescriptionWithoutError(answer);
3547}
3548
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003549// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
3550// currently fails because upon disconnection and reconnection OnIceComplete is
3551// called more than once without returning to IceGatheringGathering.