blob: ab711edfb82ef4ba8f847bc3521c9c6e2975d600 [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"
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +000046#include "webrtc/p2p/base/transportchannel.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000047#include "webrtc/p2p/client/basicportallocator.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000048#include "talk/session/media/channelmanager.h"
49#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000050#include "webrtc/base/fakenetwork.h"
51#include "webrtc/base/firewallsocketserver.h"
52#include "webrtc/base/gunit.h"
53#include "webrtc/base/logging.h"
54#include "webrtc/base/network.h"
55#include "webrtc/base/physicalsocketserver.h"
56#include "webrtc/base/ssladapter.h"
57#include "webrtc/base/sslstreamadapter.h"
58#include "webrtc/base/stringutils.h"
59#include "webrtc/base/thread.h"
60#include "webrtc/base/virtualsocketserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061
62#define MAYBE_SKIP_TEST(feature) \
63 if (!(feature())) { \
64 LOG(LS_INFO) << "Feature disabled... skipping"; \
65 return; \
66 }
67
68using cricket::BaseSession;
69using cricket::DF_PLAY;
70using cricket::DF_SEND;
71using cricket::FakeVoiceMediaChannel;
72using cricket::NS_GINGLE_P2P;
73using cricket::NS_JINGLE_ICE_UDP;
74using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000075using rtc::SocketAddress;
76using rtc::scoped_ptr;
77using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000079using webrtc::CreateSessionDescriptionObserver;
80using webrtc::CreateSessionDescriptionRequest;
81using webrtc::DTLSIdentityRequestObserver;
82using webrtc::DTLSIdentityServiceInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083using webrtc::FakeConstraints;
84using webrtc::IceCandidateCollection;
85using webrtc::JsepIceCandidate;
86using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000087using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088using webrtc::PeerConnectionInterface;
89using webrtc::SessionDescriptionInterface;
90using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000091using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000092using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000093using webrtc::kCreateChannelFailed;
94using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000096using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000097using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000098using webrtc::kSdpWithoutDtlsFingerprint;
99using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000101using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000102using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000104typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
105
wu@webrtc.org364f2042013-11-20 21:49:41 +0000106static const int kClientAddrPort = 0;
107static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000108static const char kClientIPv6AddrHost1[] =
109 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +0000110static const char kClientAddrHost2[] = "22.22.22.22";
111static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000112static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
113static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000114static const char kTurnUsername[] = "test";
115static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116
117static const char kSessionVersion[] = "1";
118
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119// Media index of candidates belonging to the first media content.
120static const int kMediaContentIndex0 = 0;
121static const char kMediaContentName0[] = "audio";
122
123// Media index of candidates belonging to the second media content.
124static const int kMediaContentIndex1 = 1;
125static const char kMediaContentName1[] = "video";
126
127static const int kIceCandidatesTimeout = 10000;
128
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000129static const char kFakeDtlsFingerprint[] =
130 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
131 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
132
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000133static const char kTooLongIceUfragPwd[] =
134 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
135 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
136 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
137 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
138
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000139// Add some extra |newlines| to the |message| after |line|.
140static void InjectAfter(const std::string& line,
141 const std::string& newlines,
142 std::string* message) {
143 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000144 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000145 tmp.c_str(), tmp.length(), message);
146}
147
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000148class FakeMetricsObserver : public webrtc::MetricsObserverInterface {
149 public:
150 FakeMetricsObserver() { Reset(); }
151 void Reset() {
152 memset(peer_connection_metrics_counters_, 0,
153 sizeof(peer_connection_metrics_counters_));
154 memset(peer_connection_metrics_name_, 0,
155 sizeof(peer_connection_metrics_name_));
156 }
157
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000158 void IncrementCounter(webrtc::PeerConnectionMetricsCounter type) override {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000159 peer_connection_metrics_counters_[type]++;
160 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000161 void AddHistogramSample(webrtc::PeerConnectionMetricsName type,
162 int value) override {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000163 ASSERT(peer_connection_metrics_name_[type] == 0);
164 peer_connection_metrics_name_[type] = value;
165 }
166
167 int peer_connection_metrics_counters_
168 [webrtc::kPeerConnectionMetricsCounter_Max];
169 int peer_connection_metrics_name_[webrtc::kPeerConnectionMetricsCounter_Max];
170
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000171 int AddRef() override { return 1; }
172 int Release() override { return 1; }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000173};
174
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000175class MockIceObserver : public webrtc::IceObserver {
176 public:
177 MockIceObserver()
178 : oncandidatesready_(false),
179 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
180 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
181 }
182
183 virtual void OnIceConnectionChange(
184 PeerConnectionInterface::IceConnectionState new_state) {
185 ice_connection_state_ = new_state;
186 }
187 virtual void OnIceGatheringChange(
188 PeerConnectionInterface::IceGatheringState new_state) {
189 // We can never transition back to "new".
190 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
191 ice_gathering_state_ = new_state;
192
193 // oncandidatesready_ really means "ICE gathering is complete".
194 // This if statement ensures that this value remains correct when we
195 // transition from kIceGatheringComplete to kIceGatheringGathering.
196 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
197 oncandidatesready_ = false;
198 }
199 }
200
201 // Found a new candidate.
202 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000203 switch (candidate->sdp_mline_index()) {
204 case kMediaContentIndex0:
205 mline_0_candidates_.push_back(candidate->candidate());
206 break;
207 case kMediaContentIndex1:
208 mline_1_candidates_.push_back(candidate->candidate());
209 break;
210 default:
211 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000212 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000213
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000214 // The ICE gathering state should always be Gathering when a candidate is
215 // received (or possibly Completed in the case of the final candidate).
216 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
217 }
218
219 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
220 virtual void OnIceComplete() {
221 EXPECT_FALSE(oncandidatesready_);
222 oncandidatesready_ = true;
223
224 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
225 // be called approximately simultaneously. For ease of testing, this
226 // check additionally requires that they be called in the above order.
227 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
228 ice_gathering_state_);
229 }
230
231 bool oncandidatesready_;
232 std::vector<cricket::Candidate> mline_0_candidates_;
233 std::vector<cricket::Candidate> mline_1_candidates_;
234 PeerConnectionInterface::IceConnectionState ice_connection_state_;
235 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
236};
237
238class WebRtcSessionForTest : public webrtc::WebRtcSession {
239 public:
240 WebRtcSessionForTest(cricket::ChannelManager* cmgr,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000241 rtc::Thread* signaling_thread,
242 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000243 cricket::PortAllocator* port_allocator,
244 webrtc::IceObserver* ice_observer,
245 webrtc::MediaStreamSignaling* mediastream_signaling)
246 : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator,
247 mediastream_signaling) {
248 RegisterIceObserver(ice_observer);
249 }
250 virtual ~WebRtcSessionForTest() {}
251
252 using cricket::BaseSession::GetTransportProxy;
253 using webrtc::WebRtcSession::SetAudioPlayout;
254 using webrtc::WebRtcSession::SetAudioSend;
255 using webrtc::WebRtcSession::SetCaptureDevice;
256 using webrtc::WebRtcSession::SetVideoPlayout;
257 using webrtc::WebRtcSession::SetVideoSend;
258};
259
wu@webrtc.org91053e72013-08-10 07:18:04 +0000260class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000261 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000262 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000263 enum State {
264 kInit,
265 kFailed,
266 kSucceeded,
267 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000268 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000269
270 // CreateSessionDescriptionObserver implementation.
271 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000272 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000273 state_ = kSucceeded;
274 }
275 virtual void OnFailure(const std::string& error) {
276 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000277 }
278
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000279 SessionDescriptionInterface* description() { return description_.get(); }
280
281 SessionDescriptionInterface* ReleaseDescription() {
282 return description_.release();
283 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000284
wu@webrtc.org91053e72013-08-10 07:18:04 +0000285 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000286
wu@webrtc.org91053e72013-08-10 07:18:04 +0000287 protected:
288 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000289
290 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000291 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000292 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000293};
294
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000295class FakeAudioRenderer : public cricket::AudioRenderer {
296 public:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000297 FakeAudioRenderer() : channel_id_(-1), sink_(NULL) {}
298 virtual ~FakeAudioRenderer() {
299 if (sink_)
300 sink_->OnClose();
301 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000302
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000303 void AddChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000304 ASSERT(channel_id_ == -1);
305 channel_id_ = channel_id;
306 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000307 void RemoveChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000308 ASSERT(channel_id == channel_id_);
309 channel_id_ = -1;
310 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000311 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000312
313 int channel_id() const { return channel_id_; }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000314 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000315 private:
316 int channel_id_;
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000317 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000318};
319
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000320class WebRtcSessionTest : public testing::Test {
321 protected:
322 // TODO Investigate why ChannelManager crashes, if it's created
323 // after stun_server.
324 WebRtcSessionTest()
325 : media_engine_(new cricket::FakeMediaEngine()),
326 data_engine_(new cricket::FakeDataEngine()),
327 device_manager_(new cricket::FakeDeviceManager()),
328 channel_manager_(new cricket::ChannelManager(
329 media_engine_, data_engine_, device_manager_,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000330 new cricket::CaptureManager(), rtc::Thread::Current())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000331 tdesc_factory_(new cricket::TransportDescriptionFactory()),
332 desc_factory_(new cricket::MediaSessionDescriptionFactory(
333 channel_manager_.get(), tdesc_factory_.get())),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000334 pss_(new rtc::PhysicalSocketServer),
335 vss_(new rtc::VirtualSocketServer(pss_.get())),
336 fss_(new rtc::FirewallSocketServer(vss_.get())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000337 ss_scope_(fss_.get()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000338 stun_socket_addr_(rtc::SocketAddress(kStunAddrHost,
wu@webrtc.org364f2042013-11-20 21:49:41 +0000339 cricket::STUN_SERVER_PORT)),
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +0000340 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
341 stun_socket_addr_)),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000342 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000343 mediastream_signaling_(channel_manager_.get()) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000344 tdesc_factory_->set_protocol(cricket::ICEPROTO_HYBRID);
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000345
346 cricket::ServerAddresses stun_servers;
347 stun_servers.insert(stun_socket_addr_);
348 allocator_.reset(new cricket::BasicPortAllocator(
349 &network_manager_,
350 stun_servers,
351 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000352 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353 cricket::PORTALLOCATOR_DISABLE_RELAY |
jiayl@webrtc.orgdacdd942015-01-23 17:33:34 +0000354 cricket::PORTALLOCATOR_ENABLE_BUNDLE |
355 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356 EXPECT_TRUE(channel_manager_->Init());
357 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000358 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000359 }
360
361 void AddInterface(const SocketAddress& addr) {
362 network_manager_.AddInterface(addr);
363 }
364
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000365 void Init(
366 DTLSIdentityServiceInterface* identity_service,
367 PeerConnectionInterface::IceTransportsType ice_transport_type,
368 PeerConnectionInterface::BundlePolicy bundle_policy) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369 ASSERT_TRUE(session_.get() == NULL);
370 session_.reset(new WebRtcSessionForTest(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000371 channel_manager_.get(), rtc::Thread::Current(),
372 rtc::Thread::Current(), allocator_.get(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000373 &observer_,
374 &mediastream_signaling_));
375
376 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
377 observer_.ice_connection_state_);
378 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
379 observer_.ice_gathering_state_);
380
wu@webrtc.org97077a32013-10-25 21:18:33 +0000381 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000382 identity_service, ice_transport_type,
383 bundle_policy));
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000384 session_->set_metrics_observer(&metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000385 }
386
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000387 void Init() {
388 Init(NULL, PeerConnectionInterface::kAll,
389 PeerConnectionInterface::kBundlePolicyBalanced);
390 }
391
392 void InitWithIceTransport(
393 PeerConnectionInterface::IceTransportsType ice_transport_type) {
394 Init(NULL, ice_transport_type,
395 PeerConnectionInterface::kBundlePolicyBalanced);
396 }
397
398 void InitWithBundlePolicy(
399 PeerConnectionInterface::BundlePolicy bundle_policy) {
400 Init(NULL, PeerConnectionInterface::kAll, bundle_policy);
401 }
402
403 void InitWithDtls(bool identity_request_should_fail = false) {
404 FakeIdentityService* identity_service = new FakeIdentityService();
405 identity_service->set_should_fail(identity_request_should_fail);
406 Init(identity_service,
407 PeerConnectionInterface::kAll,
408 PeerConnectionInterface::kBundlePolicyBalanced);
409 }
410
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000411 void InitWithDtmfCodec() {
412 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000413 const cricket::AudioCodec kTelephoneEventCodec(
414 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000415 std::vector<cricket::AudioCodec> codecs;
416 codecs.push_back(kTelephoneEventCodec);
417 media_engine_->SetAudioCodecs(codecs);
418 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000419 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000420 }
421
422 // Creates a local offer and applies it. Starts ice.
423 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
424 // to decide which streams to create.
425 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000426 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000427 SetLocalDescriptionWithoutError(offer);
428 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
429 observer_.ice_gathering_state_,
430 kIceCandidatesTimeout);
431 }
432
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000433 SessionDescriptionInterface* CreateOffer() {
434 PeerConnectionInterface::RTCOfferAnswerOptions options;
435 options.offer_to_receive_audio =
436 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
437
438 return CreateOffer(options);
439 }
440
wu@webrtc.org91053e72013-08-10 07:18:04 +0000441 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000442 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000443 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000444 observer = new WebRtcSessionCreateSDPObserverForTest();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000445 session_->CreateOffer(observer, options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000446 EXPECT_TRUE_WAIT(
447 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000448 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000449 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000450 }
451
452 SessionDescriptionInterface* CreateAnswer(
453 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000454 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000455 = new WebRtcSessionCreateSDPObserverForTest();
456 session_->CreateAnswer(observer, constraints);
457 EXPECT_TRUE_WAIT(
458 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000459 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000460 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000461 }
462
wu@webrtc.org364f2042013-11-20 21:49:41 +0000463 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000464 return (session_->voice_channel() != NULL &&
465 session_->video_channel() != NULL);
466 }
467
wu@webrtc.org364f2042013-11-20 21:49:41 +0000468 void CheckTransportChannels() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000469 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 1) != NULL);
470 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 2) != NULL);
471 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 1) != NULL);
472 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 2) != NULL);
473 }
474
475 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
476 ASSERT_TRUE(session_.get() != NULL);
477 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
478 ASSERT_TRUE(content != NULL);
479 const cricket::AudioContentDescription* audio_content =
480 static_cast<const cricket::AudioContentDescription*>(
481 content->description);
482 ASSERT_TRUE(audio_content != NULL);
483 ASSERT_EQ(1U, audio_content->cryptos().size());
484 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
485 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
486 audio_content->cryptos()[0].cipher_suite);
487 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
488 audio_content->protocol());
489
490 content = cricket::GetFirstVideoContent(sdp);
491 ASSERT_TRUE(content != NULL);
492 const cricket::VideoContentDescription* video_content =
493 static_cast<const cricket::VideoContentDescription*>(
494 content->description);
495 ASSERT_TRUE(video_content != NULL);
496 ASSERT_EQ(1U, video_content->cryptos().size());
497 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
498 video_content->cryptos()[0].cipher_suite);
499 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
500 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
501 video_content->protocol());
502 }
503
504 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
505 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
506 ASSERT_TRUE(content != NULL);
507 const cricket::AudioContentDescription* audio_content =
508 static_cast<const cricket::AudioContentDescription*>(
509 content->description);
510 ASSERT_TRUE(audio_content != NULL);
511 ASSERT_EQ(0U, audio_content->cryptos().size());
512
513 content = cricket::GetFirstVideoContent(sdp);
514 ASSERT_TRUE(content != NULL);
515 const cricket::VideoContentDescription* video_content =
516 static_cast<const cricket::VideoContentDescription*>(
517 content->description);
518 ASSERT_TRUE(video_content != NULL);
519 ASSERT_EQ(0U, video_content->cryptos().size());
520
521 if (dtls) {
522 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
523 audio_content->protocol());
524 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
525 video_content->protocol());
526 } else {
527 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
528 audio_content->protocol());
529 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
530 video_content->protocol());
531 }
532 }
533
534 // Set the internal fake description factories to do DTLS-SRTP.
535 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000536 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000537 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000538 rtc::ToString(rtc::CreateRandomId());
539 identity_.reset(rtc::SSLIdentity::Generate(identity_name));
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000540 tdesc_factory_->set_identity(identity_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000541 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
542 }
543
544 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
545 bool expected) {
546 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
547 ASSERT_TRUE(audio != NULL);
548 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000549 const TransportInfo* video = sdp->GetTransportInfoByName("video");
550 ASSERT_TRUE(video != NULL);
551 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000552 }
553
554 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000555 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000556 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000557 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000558 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000559 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000560 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000561 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000562 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
563 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000564 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000565 // Answer should be NULL as no crypto params in offer.
566 ASSERT_TRUE(answer == NULL);
567 }
568
569 void VerifyAnswerFromCryptoOffer() {
570 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000571 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000572 options.bundle_enabled = true;
573 scoped_ptr<JsepSessionDescription> offer(
574 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
575 ASSERT_TRUE(offer.get() != NULL);
576 VerifyCryptoParams(offer->description());
577 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000578 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000579 ASSERT_TRUE(answer.get() != NULL);
580 VerifyCryptoParams(answer->description());
581 }
582
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000583 void SetAndVerifyNumUnsignalledRecvStreams(
584 int value_set, int value_expected) {
585 constraints_.reset(new FakeConstraints());
586 constraints_->AddOptional(
587 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
588 value_set);
589 session_.reset();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000590 Init();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000591 mediastream_signaling_.SendAudioVideoStream1();
592 SessionDescriptionInterface* offer = CreateOffer();
593
594 SetLocalDescriptionWithoutError(offer);
595
596 video_channel_ = media_engine_->GetVideoChannel(0);
597
598 ASSERT_TRUE(video_channel_ != NULL);
599 cricket::VideoOptions video_options;
600 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
601 EXPECT_EQ(value_expected,
602 video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1));
603 }
604
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000605 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
606 const cricket::SessionDescription* desc2,
607 bool expect_equal) {
608 if (desc1->contents().size() != desc2->contents().size()) {
609 EXPECT_FALSE(expect_equal);
610 return;
611 }
612
613 const cricket::ContentInfos& contents = desc1->contents();
614 cricket::ContentInfos::const_iterator it = contents.begin();
615
616 for (; it != contents.end(); ++it) {
617 const cricket::TransportDescription* transport_desc1 =
618 desc1->GetTransportDescriptionByName(it->name);
619 const cricket::TransportDescription* transport_desc2 =
620 desc2->GetTransportDescriptionByName(it->name);
621 if (!transport_desc1 || !transport_desc2) {
622 EXPECT_FALSE(expect_equal);
623 return;
624 }
625 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
626 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
627 EXPECT_FALSE(expect_equal);
628 return;
629 }
630 }
631 EXPECT_TRUE(expect_equal);
632 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000633
634 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
635 std::string *sdp) {
636 const cricket::SessionDescription* desc = current_desc->description();
637 EXPECT_TRUE(current_desc->ToString(sdp));
638
639 const cricket::ContentInfos& contents = desc->contents();
640 cricket::ContentInfos::const_iterator it = contents.begin();
641 // Replace ufrag and pwd lines with empty strings.
642 for (; it != contents.end(); ++it) {
643 const cricket::TransportDescription* transport_desc =
644 desc->GetTransportDescriptionByName(it->name);
645 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
646 + "\r\n";
647 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
648 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000649 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000650 "", 0,
651 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000652 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000653 "", 0,
654 sdp);
655 }
656 }
657
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000658 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
659 const std::string& modified_ice_ufrag,
660 const std::string& modified_ice_pwd,
661 std::string* sdp) {
662 const cricket::SessionDescription* desc = current_desc->description();
663 EXPECT_TRUE(current_desc->ToString(sdp));
664
665 const cricket::ContentInfos& contents = desc->contents();
666 cricket::ContentInfos::const_iterator it = contents.begin();
667 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
668 // |modified_ice_pwd| strings.
669 for (; it != contents.end(); ++it) {
670 const cricket::TransportDescription* transport_desc =
671 desc->GetTransportDescriptionByName(it->name);
672 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
673 + "\r\n";
674 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
675 + "\r\n";
676 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
677 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000678 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000679 mod_ufrag.c_str(), mod_ufrag.length(),
680 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000681 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000682 mod_pwd.c_str(), mod_pwd.length(),
683 sdp);
684 }
685 }
686
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000687 // Creates a remote offer and and applies it as a remote description,
688 // creates a local answer and applies is as a local description.
689 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
690 // to decide which local and remote streams to create.
691 void CreateAndSetRemoteOfferAndLocalAnswer() {
692 SessionDescriptionInterface* offer = CreateRemoteOffer();
693 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000694 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000695 SetLocalDescriptionWithoutError(answer);
696 }
697 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
698 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
699 }
700 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
701 BaseSession::State expected_state) {
702 SetLocalDescriptionWithoutError(desc);
703 EXPECT_EQ(expected_state, session_->state());
704 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000705 void SetLocalDescriptionExpectError(const std::string& action,
706 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000707 SessionDescriptionInterface* desc) {
708 std::string error;
709 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000710 std::string sdp_type = "local ";
711 sdp_type.append(action);
712 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713 EXPECT_NE(std::string::npos, error.find(expected_error));
714 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000715 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
716 SessionDescriptionInterface* desc) {
717 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
718 expected_error, desc);
719 }
720 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
721 SessionDescriptionInterface* desc) {
722 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
723 expected_error, desc);
724 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000725 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
726 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
727 }
728 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
729 BaseSession::State expected_state) {
730 SetRemoteDescriptionWithoutError(desc);
731 EXPECT_EQ(expected_state, session_->state());
732 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000733 void SetRemoteDescriptionExpectError(const std::string& action,
734 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000735 SessionDescriptionInterface* desc) {
736 std::string error;
737 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000738 std::string sdp_type = "remote ";
739 sdp_type.append(action);
740 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000741 EXPECT_NE(std::string::npos, error.find(expected_error));
742 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000743 void SetRemoteDescriptionOfferExpectError(
744 const std::string& expected_error, SessionDescriptionInterface* desc) {
745 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
746 expected_error, desc);
747 }
748 void SetRemoteDescriptionPranswerExpectError(
749 const std::string& expected_error, SessionDescriptionInterface* desc) {
750 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
751 expected_error, desc);
752 }
753 void SetRemoteDescriptionAnswerExpectError(
754 const std::string& expected_error, SessionDescriptionInterface* desc) {
755 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
756 expected_error, desc);
757 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000758
759 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
760 SessionDescriptionInterface** nocrypto_answer) {
761 // Create a SDP without Crypto.
762 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000763 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000764 options.bundle_enabled = true;
765 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
766 ASSERT_TRUE(*offer != NULL);
767 VerifyCryptoParams((*offer)->description());
768
769 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
770 cricket::SEC_DISABLED);
771 EXPECT_TRUE(*nocrypto_answer != NULL);
772 }
773
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000774 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
775 SessionDescriptionInterface** nodtls_answer) {
776 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000777 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000778 options.bundle_enabled = true;
779
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000780 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000781 CreateRemoteOffer(options, cricket::SEC_ENABLED));
782
783 *nodtls_answer =
784 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
785 EXPECT_TRUE(*nodtls_answer != NULL);
786 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
787 VerifyCryptoParams((*nodtls_answer)->description());
788
789 SetFactoryDtlsSrtp();
790 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
791 ASSERT_TRUE(*offer != NULL);
792 VerifyFingerprintStatus((*offer)->description(), true);
793 VerifyCryptoParams((*offer)->description());
794 }
795
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000796 JsepSessionDescription* CreateRemoteOfferWithVersion(
797 cricket::MediaSessionOptions options,
798 cricket::SecurePolicy secure_policy,
799 const std::string& session_version,
800 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000801 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000802 const cricket::SessionDescription* cricket_desc = NULL;
803 if (current_desc) {
804 cricket_desc = current_desc->description();
805 session_id = current_desc->session_id();
806 }
807
808 desc_factory_->set_secure(secure_policy);
809 JsepSessionDescription* offer(
810 new JsepSessionDescription(JsepSessionDescription::kOffer));
811 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
812 session_id, session_version)) {
813 delete offer;
814 offer = NULL;
815 }
816 return offer;
817 }
818 JsepSessionDescription* CreateRemoteOffer(
819 cricket::MediaSessionOptions options) {
820 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
821 kSessionVersion, NULL);
822 }
823 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000824 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
825 return CreateRemoteOfferWithVersion(
826 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000827 }
828 JsepSessionDescription* CreateRemoteOffer(
829 cricket::MediaSessionOptions options,
830 const SessionDescriptionInterface* current_desc) {
831 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
832 kSessionVersion, current_desc);
833 }
834
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000835 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
836 const char* sctp_stream_name, int new_port,
837 cricket::MediaSessionOptions options) {
838 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000839 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
840 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000841 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
842 }
843
844 // Takes ownership of offer_basis (and deletes it).
845 JsepSessionDescription* ChangeSDPSctpPort(
846 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
847 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
848 // SessionDescription from the mutated string.
849 const char* default_port_str = "5000";
850 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000851 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000852 std::string offer_str;
853 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000854 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000855 new_port_str, strlen(new_port_str),
856 &offer_str);
857 JsepSessionDescription* offer = new JsepSessionDescription(
858 offer_basis->type());
859 delete offer_basis;
860 offer->Initialize(offer_str, NULL);
861 return offer;
862 }
863
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000864 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
865 // before this function to decide which streams to create.
866 JsepSessionDescription* CreateRemoteOffer() {
867 cricket::MediaSessionOptions options;
868 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
869 return CreateRemoteOffer(options, session_->remote_description());
870 }
871
872 JsepSessionDescription* CreateRemoteAnswer(
873 const SessionDescriptionInterface* offer,
874 cricket::MediaSessionOptions options,
875 cricket::SecurePolicy policy) {
876 desc_factory_->set_secure(policy);
877 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000878 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000879 JsepSessionDescription* answer(
880 new JsepSessionDescription(JsepSessionDescription::kAnswer));
881 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
882 options, NULL),
883 session_id, kSessionVersion)) {
884 delete answer;
885 answer = NULL;
886 }
887 return answer;
888 }
889
890 JsepSessionDescription* CreateRemoteAnswer(
891 const SessionDescriptionInterface* offer,
892 cricket::MediaSessionOptions options) {
893 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
894 }
895
896 // Creates an answer session description with streams based on
897 // |mediastream_signaling_|. Call
898 // mediastream_signaling_.UseOptionsWithStreamX() before this function
899 // to decide which streams to create.
900 JsepSessionDescription* CreateRemoteAnswer(
901 const SessionDescriptionInterface* offer) {
902 cricket::MediaSessionOptions options;
903 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
904 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
905 }
906
907 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000908 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000909 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000910 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000911
912 PeerConnectionInterface::RTCOfferAnswerOptions options;
913 options.use_rtp_mux = bundle;
914
915 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000916 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
917 // and answer.
918 SetLocalDescriptionWithoutError(offer);
919
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000920 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000921 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922 std::string sdp;
923 EXPECT_TRUE(answer->ToString(&sdp));
924
925 size_t expected_candidate_num = 2;
926 if (!rtcp_mux) {
927 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
928 // for rtp and rtcp.
929 expected_candidate_num = 4;
930 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931 const std::string kRtcpMux = "a=rtcp-mux";
932 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000933 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000934 kXRtcpMux.c_str(), kXRtcpMux.length(),
935 &sdp);
936 }
937
938 SessionDescriptionInterface* new_answer = CreateSessionDescription(
939 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000940
941 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000942 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000943 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
944 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
945 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
946 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
947 cricket::Candidate c0 = observer_.mline_0_candidates_[i];
948 cricket::Candidate c1 = observer_.mline_1_candidates_[i];
949 if (bundle) {
950 EXPECT_TRUE(c0.IsEquivalent(c1));
951 } else {
952 EXPECT_FALSE(c0.IsEquivalent(c1));
953 }
954 }
955 }
956 // Tests that we can only send DTMF when the dtmf codec is supported.
957 void TestCanInsertDtmf(bool can) {
958 if (can) {
959 InitWithDtmfCodec();
960 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000961 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962 }
963 mediastream_signaling_.SendAudioVideoStream1();
964 CreateAndSetRemoteOfferAndLocalAnswer();
965 EXPECT_FALSE(session_->CanInsertDtmf(""));
966 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
967 }
968
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000969 // Helper class to configure loopback network and verify Best
970 // Connection using right IP protocol for TestLoopbackCall
971 // method. LoopbackNetworkManager applies firewall rules to block
972 // all ping traffic once ICE completed, and remove them to observe
973 // ICE reconnected again. This LoopbackNetworkConfiguration struct
974 // verifies the best connection is using the right IP protocol after
975 // initial ICE convergences.
976
977 class LoopbackNetworkConfiguration {
978 public:
979 LoopbackNetworkConfiguration()
980 : test_ipv6_network_(false),
981 test_extra_ipv4_network_(false),
982 best_connection_after_initial_ice_converged_(1, 0) {}
983
984 // Used to track the expected best connection count in each IP protocol.
985 struct ExpectedBestConnection {
986 ExpectedBestConnection(int ipv4_count, int ipv6_count)
987 : ipv4_count_(ipv4_count),
988 ipv6_count_(ipv6_count) {}
989
990 int ipv4_count_;
991 int ipv6_count_;
992 };
993
994 bool test_ipv6_network_;
995 bool test_extra_ipv4_network_;
996 ExpectedBestConnection best_connection_after_initial_ice_converged_;
997
998 void VerifyBestConnectionAfterIceConverge(
999 const FakeMetricsObserver& metrics_observer) const {
1000 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1001 }
1002
1003 private:
1004 void Verify(const FakeMetricsObserver& metrics_observer,
1005 const ExpectedBestConnection& expected) const {
1006 EXPECT_EQ(
1007 metrics_observer
1008 .peer_connection_metrics_counters_[webrtc::kBestConnections_IPv4],
1009 expected.ipv4_count_);
1010 EXPECT_EQ(
1011 metrics_observer
1012 .peer_connection_metrics_counters_[webrtc::kBestConnections_IPv6],
1013 expected.ipv6_count_);
1014 }
1015 };
1016
1017 class LoopbackNetworkManager {
1018 public:
1019 LoopbackNetworkManager(WebRtcSessionTest* session,
1020 const LoopbackNetworkConfiguration& config)
1021 : config_(config) {
1022 session->AddInterface(
1023 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1024 if (config_.test_extra_ipv4_network_) {
1025 session->AddInterface(
1026 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1027 }
1028 if (config_.test_ipv6_network_) {
1029 session->AddInterface(
1030 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1031 }
1032 }
1033
1034 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1035 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1036 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1037 if (config_.test_extra_ipv4_network_) {
1038 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1039 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1040 }
1041 if (config_.test_ipv6_network_) {
1042 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1043 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1044 }
1045 }
1046
1047 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1048
1049 private:
1050 LoopbackNetworkConfiguration config_;
1051 };
1052
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001053 // The method sets up a call from the session to itself, in a loopback
1054 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001055 // disconnection, and then a permanent disconnection.
1056 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001057 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1058 // While running the call, this method also checks if the session goes through
1059 // the correct sequence of ICE states when a connection is established,
1060 // broken, and re-established.
1061 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001062 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1063 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001064 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001065
1066 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1067 LoopbackNetworkManager loopback_network_manager(this, config);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001068 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001070 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001071
1072 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1073 observer_.ice_gathering_state_);
1074 SetLocalDescriptionWithoutError(offer);
1075 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1076 observer_.ice_connection_state_);
1077 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
1078 observer_.ice_gathering_state_,
1079 kIceCandidatesTimeout);
1080 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1081 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
1082 observer_.ice_gathering_state_,
1083 kIceCandidatesTimeout);
1084
1085 std::string sdp;
1086 offer->ToString(&sdp);
1087 SessionDescriptionInterface* desc =
1088 webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer, sdp);
1089 ASSERT_TRUE(desc != NULL);
1090 SetRemoteDescriptionWithoutError(desc);
1091
1092 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
1093 observer_.ice_connection_state_,
1094 kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001095
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001096 // The ice connection state is "Connected" too briefly to catch in a test.
1097 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001098 observer_.ice_connection_state_,
1099 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001100
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001101 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001102 // Adding firewall rule to block ping requests, which should cause
1103 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001104
1105 loopback_network_manager.ApplyFirewallRules(fss_.get());
1106
1107 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001108 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1109 observer_.ice_connection_state_,
1110 kIceCandidatesTimeout);
1111
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001112 metrics_observer_.Reset();
1113
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001114 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001115 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001116 // Session is automatically calling OnSignalingReady after creation of
1117 // new portallocator session which will allocate new set of candidates.
1118
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001119 LOG(LS_INFO) << "Firewall Rules cleared";
1120
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001121 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001122 observer_.ice_connection_state_,
1123 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001124
1125 // Now we block ping requests and wait until the ICE connection transitions
1126 // to the Failed state. This will take at least 30 seconds because it must
1127 // wait for the Port to timeout.
1128 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001129
1130 loopback_network_manager.ApplyFirewallRules(fss_.get());
1131 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001132 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001133 observer_.ice_connection_state_,
1134 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001135 }
1136
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001137 void TestLoopbackCall() {
1138 LoopbackNetworkConfiguration config;
1139 TestLoopbackCall(config);
1140 }
1141
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001142 void VerifyTransportType(const std::string& content_name,
1143 cricket::TransportProtocol protocol) {
1144 const cricket::Transport* transport = session_->GetTransport(content_name);
1145 ASSERT_TRUE(transport != NULL);
1146 EXPECT_EQ(protocol, transport->protocol());
1147 }
1148
1149 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1150 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001151 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1152 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1153
1154 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001155 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1156 codecs.push_back(kCNCodec1);
1157 codecs.push_back(kCNCodec2);
1158 media_engine_->SetAudioCodecs(codecs);
1159 desc_factory_->set_audio_codecs(codecs);
1160 }
1161
1162 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1163 const cricket::ContentDescription* description = content->description;
1164 ASSERT(description != NULL);
1165 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001166 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001167 ASSERT(audio_content_desc != NULL);
1168 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1169 if (audio_content_desc->codecs()[i].name == "CN")
1170 return false;
1171 }
1172 return true;
1173 }
1174
1175 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001176 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001177 dci.reliable = false;
1178 session_->CreateDataChannel("datachannel", &dci);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001179 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001180 SetLocalDescriptionWithoutError(offer);
1181 }
1182
wu@webrtc.org91053e72013-08-10 07:18:04 +00001183 void VerifyMultipleAsyncCreateDescription(
1184 bool success, CreateSessionDescriptionRequest::Type type) {
henrike@webrtc.org7666db72013-08-22 14:45:42 +00001185 InitWithDtls(!success);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001186 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001187 if (type == CreateSessionDescriptionRequest::kAnswer) {
1188 cricket::MediaSessionOptions options;
1189 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001190 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001191 ASSERT_TRUE(offer.get() != NULL);
1192 SetRemoteDescriptionWithoutError(offer.release());
1193 }
1194
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001195 PeerConnectionInterface::RTCOfferAnswerOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001196 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001197 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001198 observers[kNumber];
1199 for (int i = 0; i < kNumber; ++i) {
1200 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1201 if (type == CreateSessionDescriptionRequest::kOffer) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001202 session_->CreateOffer(observers[i], options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001203 } else {
1204 session_->CreateAnswer(observers[i], NULL);
1205 }
1206 }
1207
1208 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1209 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1210 WebRtcSessionCreateSDPObserverForTest::kFailed;
1211
1212 for (int i = 0; i < kNumber; ++i) {
1213 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1214 if (success) {
1215 EXPECT_TRUE(observers[i]->description() != NULL);
1216 } else {
1217 EXPECT_TRUE(observers[i]->description() == NULL);
1218 }
1219 }
1220 }
1221
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001222 void ConfigureAllocatorWithTurn() {
1223 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1224 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
1225 relay_server.credentials = credentials;
1226 relay_server.ports.push_back(cricket::ProtocolAddress(
1227 kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1228 allocator_->AddRelay(relay_server);
1229 allocator_->set_step_delay(cricket::kMinimumStepDelay);
1230 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
jiayl@webrtc.orgdacdd942015-01-23 17:33:34 +00001231 cricket::PORTALLOCATOR_ENABLE_BUNDLE |
1232 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001233 }
1234
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001235 cricket::FakeMediaEngine* media_engine_;
1236 cricket::FakeDataEngine* data_engine_;
1237 cricket::FakeDeviceManager* device_manager_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001238 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
1239 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1240 rtc::scoped_ptr<rtc::SSLIdentity> identity_;
1241 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1242 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1243 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1244 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1245 rtc::SocketServerScope ss_scope_;
1246 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001247 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001248 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001249 rtc::FakeNetworkManager network_manager_;
1250 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001251 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001252 rtc::scoped_ptr<FakeConstraints> constraints_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001253 FakeMediaStreamSignaling mediastream_signaling_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001254 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001255 MockIceObserver observer_;
1256 cricket::FakeVideoMediaChannel* video_channel_;
1257 cricket::FakeVoiceMediaChannel* voice_channel_;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001258 FakeMetricsObserver metrics_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001259};
1260
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001261TEST_F(WebRtcSessionTest, TestInitializeWithDtls) {
1262 InitWithDtls();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001263 // SDES is disabled when DTLS is on.
1264 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001265}
1266
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001267TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001268 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001269 // SDES is required if DTLS is off.
1270 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001271}
1272
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001273TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1274 TestSessionCandidatesWithBundleRtcpMux(false, false);
1275}
1276
1277// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1278// with rtcp-mux and/or bundle.
1279TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1280 TestSessionCandidatesWithBundleRtcpMux(false, true);
1281}
1282
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001283TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1284 TestSessionCandidatesWithBundleRtcpMux(true, true);
1285}
1286
1287TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001288 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1289 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001290 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001291 mediastream_signaling_.SendAudioVideoStream1();
1292 InitiateCall();
1293 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1294 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1295 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1296}
1297
1298TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001299 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1300 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001301 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001302 rtc::FP_UDP,
1303 rtc::FD_ANY,
1304 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001305 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001306 mediastream_signaling_.SendAudioVideoStream1();
1307 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001308 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001309 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1310 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1311 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1312}
1313
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001314// Test session delivers no candidates gathered when constraint set to "none".
1315TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1316 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001317 InitWithIceTransport(PeerConnectionInterface::kNone);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001318 mediastream_signaling_.SendAudioVideoStream1();
1319 InitiateCall();
1320 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1321 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1322 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1323}
1324
1325// Test session delivers only relay candidates gathered when constaint set to
1326// "relay".
1327TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1328 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1329 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001330 InitWithIceTransport(PeerConnectionInterface::kRelay);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001331 mediastream_signaling_.SendAudioVideoStream1();
1332 InitiateCall();
1333 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1334 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1335 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1336 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1337 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1338 observer_.mline_0_candidates_[i].type());
1339 }
1340 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1341 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1342 observer_.mline_1_candidates_[i].type());
1343 }
1344}
1345
1346// Test session delivers all candidates gathered when constaint set to "all".
1347TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1348 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001349 InitWithIceTransport(PeerConnectionInterface::kAll);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001350 mediastream_signaling_.SendAudioVideoStream1();
1351 InitiateCall();
1352 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1353 // Host + STUN. By default allocator is disabled to gather relay candidates.
1354 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1355 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1356}
1357
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001358TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001359 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001360 SessionDescriptionInterface* offer = NULL;
1361 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1362 std::string unknown_action;
1363 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1364 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1365}
1366
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001367// Test creating offers and receive answers and make sure the
1368// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001369TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001370 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001371 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001372 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001373 const std::string session_id_orig = offer->session_id();
1374 const std::string session_version_orig = offer->session_version();
1375 SetLocalDescriptionWithoutError(offer);
1376
1377 mediastream_signaling_.SendAudioVideoStream2();
1378 SessionDescriptionInterface* answer =
1379 CreateRemoteAnswer(session_->local_description());
1380 SetRemoteDescriptionWithoutError(answer);
1381
1382 video_channel_ = media_engine_->GetVideoChannel(0);
1383 voice_channel_ = media_engine_->GetVoiceChannel(0);
1384
1385 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1386 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1387
1388 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1389 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1390
1391 ASSERT_EQ(1u, video_channel_->send_streams().size());
1392 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1393 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1394 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1395
1396 // Create new offer without send streams.
1397 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001398 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001399
1400 // Verify the session id is the same and the session version is
1401 // increased.
1402 EXPECT_EQ(session_id_orig, offer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001403 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1404 rtc::FromString<uint64>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001405
1406 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001407 EXPECT_EQ(0u, video_channel_->send_streams().size());
1408 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001409
1410 mediastream_signaling_.SendAudioVideoStream2();
1411 answer = CreateRemoteAnswer(session_->local_description());
1412 SetRemoteDescriptionWithoutError(answer);
1413
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001414 // Make sure the receive streams have not changed.
1415 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1416 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1417 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1418 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1419}
1420
1421// Test receiving offers and creating answers and make sure the
1422// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001423TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001424 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001425 mediastream_signaling_.SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001426 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001427 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001428 SetRemoteDescriptionWithoutError(offer);
1429
1430 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001431 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001432 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001433 SetLocalDescriptionWithoutError(answer);
1434
1435 const std::string session_id_orig = answer->session_id();
1436 const std::string session_version_orig = answer->session_version();
1437
1438 video_channel_ = media_engine_->GetVideoChannel(0);
1439 voice_channel_ = media_engine_->GetVoiceChannel(0);
1440
1441 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1442 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1443
1444 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1445 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1446
1447 ASSERT_EQ(1u, video_channel_->send_streams().size());
1448 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1449 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1450 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1451
1452 mediastream_signaling_.SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001453 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001454 SetRemoteDescriptionWithoutError(offer);
1455
1456 // Answer by turning off all send streams.
1457 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001458 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001459
1460 // Verify the session id is the same and the session version is
1461 // increased.
1462 EXPECT_EQ(session_id_orig, answer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001463 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1464 rtc::FromString<uint64>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001465 SetLocalDescriptionWithoutError(answer);
1466
1467 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1468 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1469 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1470 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1471 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1472 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1473
1474 // Make sure we have no send streams.
1475 EXPECT_EQ(0u, video_channel_->send_streams().size());
1476 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1477}
1478
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001479TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001480 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001481 media_engine_->set_fail_create_channel(true);
1482
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001483 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001484 ASSERT_TRUE(offer != NULL);
1485 // SetRemoteDescription and SetLocalDescription will take the ownership of
1486 // the offer.
1487 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001488 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001489 ASSERT_TRUE(offer != NULL);
1490 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1491}
1492
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001493//
1494// Tests for creating/setting SDP under different SDES/DTLS polices:
1495//
1496// --DTLS off and SDES on
1497// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1498// set local/remote offer/answer with crypto --> success
1499// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1500// failure
1501// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1502// failure
1503// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1504// failure
1505//
1506// --DTLS on and SDES off
1507// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1508// set local/remote offer/answer with DTLS fingerprint --> success
1509// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1510// fingerprint --> failure
1511// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1512// --> failure
1513// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1514// --> failure
1515//
1516// --Encryption disabled: DTLS off and SDES off
1517// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1518// answer without SDES or DTLS --> success
1519// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1520// answer without SDES or DTLS --> success
1521//
1522
1523// Test that we return a failure when applying a remote/local offer that doesn't
1524// have cryptos enabled when DTLS is off.
1525TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001526 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001527 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001528 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001529 JsepSessionDescription* offer = CreateRemoteOffer(
1530 options, cricket::SEC_DISABLED);
1531 ASSERT_TRUE(offer != NULL);
1532 VerifyNoCryptoParams(offer->description(), false);
1533 // SetRemoteDescription and SetLocalDescription will take the ownership of
1534 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001535 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001536 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1537 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001538 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001539}
1540
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001541// Test that we return a failure when applying a local answer that doesn't have
1542// cryptos enabled when DTLS is off.
1543TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001544 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001545 SessionDescriptionInterface* offer = NULL;
1546 SessionDescriptionInterface* answer = NULL;
1547 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1548 // SetRemoteDescription and SetLocalDescription will take the ownership of
1549 // the offer.
1550 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001551 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001552}
1553
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001554// Test we will return fail when apply an remote answer that doesn't have
1555// crypto enabled when DTLS is off.
1556TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001557 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001558 SessionDescriptionInterface* offer = NULL;
1559 SessionDescriptionInterface* answer = NULL;
1560 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1561 // SetRemoteDescription and SetLocalDescription will take the ownership of
1562 // the offer.
1563 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001564 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001565}
1566
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001567// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1568// and that we return an answer with a DTLS fingerprint.
1569TEST_F(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001570 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001571 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001572 InitWithDtls();
1573 SetFactoryDtlsSrtp();
1574 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001575 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001576 JsepSessionDescription* offer =
1577 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001578 ASSERT_TRUE(offer != NULL);
1579 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001580 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001581
1582 // SetRemoteDescription will take the ownership of the offer.
1583 SetRemoteDescriptionWithoutError(offer);
1584
1585 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001586 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001587 ASSERT_TRUE(answer != NULL);
1588 VerifyFingerprintStatus(answer->description(), true);
1589 // Check that we don't have an a=crypto line in the answer.
1590 VerifyNoCryptoParams(answer->description(), true);
1591
1592 // Now set the local description, which should work, even without a=crypto.
1593 SetLocalDescriptionWithoutError(answer);
1594}
1595
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001596// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1597// and then we accept a remote answer with a DTLS fingerprint successfully.
1598TEST_F(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001599 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001600 mediastream_signaling_.SendAudioVideoStream1();
1601 InitWithDtls();
1602 SetFactoryDtlsSrtp();
1603
1604 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001605 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001606 ASSERT_TRUE(offer != NULL);
1607 VerifyFingerprintStatus(offer->description(), true);
1608 // Check that we don't have an a=crypto line in the offer.
1609 VerifyNoCryptoParams(offer->description(), true);
1610
1611 // Now set the local description, which should work, even without a=crypto.
1612 SetLocalDescriptionWithoutError(offer);
1613
1614 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001615 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001616 JsepSessionDescription* answer =
1617 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1618 ASSERT_TRUE(answer != NULL);
1619 VerifyFingerprintStatus(answer->description(), true);
1620 VerifyNoCryptoParams(answer->description(), true);
1621
1622 // SetRemoteDescription will take the ownership of the answer.
1623 SetRemoteDescriptionWithoutError(answer);
1624}
1625
1626// Test that if we support DTLS and the other side didn't offer a fingerprint,
1627// we will fail to set the remote description.
1628TEST_F(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001629 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001630 InitWithDtls();
1631 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001632 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001633 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001634 JsepSessionDescription* offer = CreateRemoteOffer(
1635 options, cricket::SEC_REQUIRED);
1636 ASSERT_TRUE(offer != NULL);
1637 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001638 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001639
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001640 // SetRemoteDescription will take the ownership of the offer.
1641 SetRemoteDescriptionOfferExpectError(
1642 kSdpWithoutDtlsFingerprint, offer);
1643
1644 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1645 // SetLocalDescription will take the ownership of the offer.
1646 SetLocalDescriptionOfferExpectError(
1647 kSdpWithoutDtlsFingerprint, offer);
1648}
1649
1650// Test that we return a failure when applying a local answer that doesn't have
1651// a DTLS fingerprint when DTLS is required.
1652TEST_F(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001653 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001654 InitWithDtls();
1655 SessionDescriptionInterface* offer = NULL;
1656 SessionDescriptionInterface* answer = NULL;
1657 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1658
1659 // SetRemoteDescription and SetLocalDescription will take the ownership of
1660 // the offer and answer.
1661 SetRemoteDescriptionWithoutError(offer);
1662 SetLocalDescriptionAnswerExpectError(
1663 kSdpWithoutDtlsFingerprint, answer);
1664}
1665
1666// Test that we return a failure when applying a remote answer that doesn't have
1667// a DTLS fingerprint when DTLS is required.
1668TEST_F(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001669 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001670 InitWithDtls();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001671 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001672 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001673 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001674 JsepSessionDescription* answer =
1675 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
1676
1677 // SetRemoteDescription and SetLocalDescription will take the ownership of
1678 // the offer and answer.
1679 SetLocalDescriptionWithoutError(offer);
1680 SetRemoteDescriptionAnswerExpectError(
1681 kSdpWithoutDtlsFingerprint, answer);
1682}
1683
1684// Test that we create a local offer without SDES or DTLS and accept a remote
1685// answer without SDES or DTLS when encryption is disabled.
1686TEST_F(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
1687 mediastream_signaling_.SendAudioVideoStream1();
1688 options_.disable_encryption = true;
1689 InitWithDtls();
1690
1691 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001692 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001693 ASSERT_TRUE(offer != NULL);
1694 VerifyFingerprintStatus(offer->description(), false);
1695 // Check that we don't have an a=crypto line in the offer.
1696 VerifyNoCryptoParams(offer->description(), false);
1697
1698 // Now set the local description, which should work, even without a=crypto.
1699 SetLocalDescriptionWithoutError(offer);
1700
1701 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001702 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001703 JsepSessionDescription* answer =
1704 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1705 ASSERT_TRUE(answer != NULL);
1706 VerifyFingerprintStatus(answer->description(), false);
1707 VerifyNoCryptoParams(answer->description(), false);
1708
1709 // SetRemoteDescription will take the ownership of the answer.
1710 SetRemoteDescriptionWithoutError(answer);
1711}
1712
1713// Test that we create a local answer without SDES or DTLS and accept a remote
1714// offer without SDES or DTLS when encryption is disabled.
1715TEST_F(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
1716 options_.disable_encryption = true;
1717 InitWithDtls();
1718
1719 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001720 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001721 JsepSessionDescription* offer =
1722 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1723 ASSERT_TRUE(offer != NULL);
1724 VerifyFingerprintStatus(offer->description(), false);
1725 VerifyNoCryptoParams(offer->description(), false);
1726
1727 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001728 SetRemoteDescriptionWithoutError(offer);
1729
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001730 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001731 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001732 ASSERT_TRUE(answer != NULL);
1733 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001734 // Check that we don't have an a=crypto line in the answer.
1735 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001736
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001737 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001738 SetLocalDescriptionWithoutError(answer);
1739}
1740
1741TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001742 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001743 mediastream_signaling_.SendNothing();
1744 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001745 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001746 SetLocalDescriptionWithoutError(offer);
1747
1748 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001749 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001750 SetLocalDescriptionWithoutError(offer2);
1751}
1752
1753TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001754 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755 mediastream_signaling_.SendNothing();
1756 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001757 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758 SetRemoteDescriptionWithoutError(offer);
1759
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001760 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761 SetRemoteDescriptionWithoutError(offer2);
1762}
1763
1764TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001765 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001767 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001769 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001770 SetRemoteDescriptionOfferExpectError(
1771 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772}
1773
1774TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001775 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001777 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001779 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001780 SetLocalDescriptionOfferExpectError(
1781 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782}
1783
1784TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001785 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786 mediastream_signaling_.SendNothing();
1787 SessionDescriptionInterface* offer = CreateRemoteOffer();
1788 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1789
1790 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001791 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001792 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1793 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1794
1795 mediastream_signaling_.SendAudioVideoStream1();
1796 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001797 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1799
1800 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1801
1802 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001803 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001804 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1805}
1806
1807TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001808 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001809 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001810 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001811 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1812
1813 JsepSessionDescription* pranswer =
1814 CreateRemoteAnswer(session_->local_description());
1815 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1816
1817 SetRemoteDescriptionExpectState(pranswer,
1818 BaseSession::STATE_RECEIVEDPRACCEPT);
1819
1820 mediastream_signaling_.SendAudioVideoStream1();
1821 JsepSessionDescription* pranswer2 =
1822 CreateRemoteAnswer(session_->local_description());
1823 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1824
1825 SetRemoteDescriptionExpectState(pranswer2,
1826 BaseSession::STATE_RECEIVEDPRACCEPT);
1827
1828 mediastream_signaling_.SendAudioVideoStream2();
1829 SessionDescriptionInterface* answer =
1830 CreateRemoteAnswer(session_->local_description());
1831 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1832}
1833
1834TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001835 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001836 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001837 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1838
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001839 SessionDescriptionInterface* answer =
1840 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001841 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1842 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001843}
1844
1845TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001846 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001847 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001848 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1849
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001850 SessionDescriptionInterface* answer =
1851 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001852 SetRemoteDescriptionAnswerExpectError(
1853 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001854}
1855
1856TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001857 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001858 mediastream_signaling_.SendAudioVideoStream1();
1859
1860 cricket::Candidate candidate;
1861 candidate.set_component(1);
1862 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1863
1864 // Fail since we have not set a offer description.
1865 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1866
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001867 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001868 SetLocalDescriptionWithoutError(offer);
1869 // Candidate should be allowed to add before remote description.
1870 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1871 candidate.set_component(2);
1872 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1873 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1874
1875 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1876 session_->local_description());
1877 SetRemoteDescriptionWithoutError(answer);
1878
1879 // Verifying the candidates are copied properly from internal vector.
1880 const SessionDescriptionInterface* remote_desc =
1881 session_->remote_description();
1882 ASSERT_TRUE(remote_desc != NULL);
1883 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1884 const IceCandidateCollection* candidates =
1885 remote_desc->candidates(kMediaContentIndex0);
1886 ASSERT_EQ(2u, candidates->count());
1887 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1888 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1889 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1890 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1891
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001892 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1893 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001894 candidate.set_component(2);
1895 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1896 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001897 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001898
1899 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1900 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1901}
1902
1903// Test that a remote candidate is added to the remote session description and
1904// that it is retained if the remote session description is changed.
1905TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001906 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907 cricket::Candidate candidate1;
1908 candidate1.set_component(1);
1909 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1910 candidate1);
1911 mediastream_signaling_.SendAudioVideoStream1();
1912 CreateAndSetRemoteOfferAndLocalAnswer();
1913
1914 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1915 const SessionDescriptionInterface* remote_desc =
1916 session_->remote_description();
1917 ASSERT_TRUE(remote_desc != NULL);
1918 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1919 const IceCandidateCollection* candidates =
1920 remote_desc->candidates(kMediaContentIndex0);
1921 ASSERT_EQ(1u, candidates->count());
1922 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1923
1924 // Update the RemoteSessionDescription with a new session description and
1925 // a candidate and check that the new remote session description contains both
1926 // candidates.
1927 SessionDescriptionInterface* offer = CreateRemoteOffer();
1928 cricket::Candidate candidate2;
1929 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1930 candidate2);
1931 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1932 SetRemoteDescriptionWithoutError(offer);
1933
1934 remote_desc = session_->remote_description();
1935 ASSERT_TRUE(remote_desc != NULL);
1936 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1937 candidates = remote_desc->candidates(kMediaContentIndex0);
1938 ASSERT_EQ(2u, candidates->count());
1939 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1940 // Username and password have be updated with the TransportInfo of the
1941 // SessionDescription, won't be equal to the original one.
1942 candidate2.set_username(candidates->at(0)->candidate().username());
1943 candidate2.set_password(candidates->at(0)->candidate().password());
1944 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
1945 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
1946 // No need to verify the username and password.
1947 candidate1.set_username(candidates->at(1)->candidate().username());
1948 candidate1.set_password(candidates->at(1)->candidate().password());
1949 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
1950
1951 // Test that the candidate is ignored if we can add the same candidate again.
1952 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1953}
1954
1955// Test that local candidates are added to the local session description and
1956// that they are retained if the local session description is changed.
1957TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001958 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001959 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001960 mediastream_signaling_.SendAudioVideoStream1();
1961 CreateAndSetRemoteOfferAndLocalAnswer();
1962
1963 const SessionDescriptionInterface* local_desc = session_->local_description();
1964 const IceCandidateCollection* candidates =
1965 local_desc->candidates(kMediaContentIndex0);
1966 ASSERT_TRUE(candidates != NULL);
1967 EXPECT_EQ(0u, candidates->count());
1968
1969 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1970
1971 local_desc = session_->local_description();
1972 candidates = local_desc->candidates(kMediaContentIndex0);
1973 ASSERT_TRUE(candidates != NULL);
1974 EXPECT_LT(0u, candidates->count());
1975 candidates = local_desc->candidates(1);
1976 ASSERT_TRUE(candidates != NULL);
1977 EXPECT_LT(0u, candidates->count());
1978
1979 // Update the session descriptions.
1980 mediastream_signaling_.SendAudioVideoStream1();
1981 CreateAndSetRemoteOfferAndLocalAnswer();
1982
1983 local_desc = session_->local_description();
1984 candidates = local_desc->candidates(kMediaContentIndex0);
1985 ASSERT_TRUE(candidates != NULL);
1986 EXPECT_LT(0u, candidates->count());
1987 candidates = local_desc->candidates(1);
1988 ASSERT_TRUE(candidates != NULL);
1989 EXPECT_LT(0u, candidates->count());
1990}
1991
1992// Test that we can set a remote session description with remote candidates.
1993TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001994 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001995
1996 cricket::Candidate candidate1;
1997 candidate1.set_component(1);
1998 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
1999 candidate1);
2000 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002001 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002002
2003 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2004 SetRemoteDescriptionWithoutError(offer);
2005
2006 const SessionDescriptionInterface* remote_desc =
2007 session_->remote_description();
2008 ASSERT_TRUE(remote_desc != NULL);
2009 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2010 const IceCandidateCollection* candidates =
2011 remote_desc->candidates(kMediaContentIndex0);
2012 ASSERT_EQ(1u, candidates->count());
2013 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2014
wu@webrtc.org91053e72013-08-10 07:18:04 +00002015 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002016 SetLocalDescriptionWithoutError(answer);
2017}
2018
2019// Test that offers and answers contains ice candidates when Ice candidates have
2020// been gathered.
2021TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002022 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002023 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002024 mediastream_signaling_.SendAudioVideoStream1();
2025 // Ice is started but candidates are not provided until SetLocalDescription
2026 // is called.
2027 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2028 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2029 CreateAndSetRemoteOfferAndLocalAnswer();
2030 // Wait until at least one local candidate has been collected.
2031 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2032 kIceCandidatesTimeout);
2033 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
2034 kIceCandidatesTimeout);
2035
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002036 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2037
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002038 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2039 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
2040 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
2041 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
2042
2043 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2044 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002045 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002046 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2047 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
2048 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
2049 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
2050 SetLocalDescriptionWithoutError(answer);
2051}
2052
2053// Verifies TransportProxy and media channels are created with content names
2054// present in the SessionDescription.
2055TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002056 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002057 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002058 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002059
2060 // CreateOffer creates session description with the content names "audio" and
2061 // "video". Goal is to modify these content names and verify transport channel
2062 // proxy in the BaseSession, as proxies are created with the content names
2063 // present in SDP.
2064 std::string sdp;
2065 EXPECT_TRUE(offer->ToString(&sdp));
2066 const std::string kAudioMid = "a=mid:audio";
2067 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2068 const std::string kVideoMid = "a=mid:video";
2069 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2070
2071 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002072 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002073 kAudioMidReplaceStr.c_str(),
2074 kAudioMidReplaceStr.length(),
2075 &sdp);
2076 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002077 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002078 kVideoMidReplaceStr.c_str(),
2079 kVideoMidReplaceStr.length(),
2080 &sdp);
2081
2082 SessionDescriptionInterface* modified_offer =
2083 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2084
2085 SetRemoteDescriptionWithoutError(modified_offer);
2086
2087 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002088 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002089 SetLocalDescriptionWithoutError(answer);
2090
2091 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
2092 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
2093 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2094 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2095}
2096
2097// Test that an offer contains the correct media content descriptions based on
2098// the send streams when no constraints have been set.
2099TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002100 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002101 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2102
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103 ASSERT_TRUE(offer != NULL);
2104 const cricket::ContentInfo* content =
2105 cricket::GetFirstAudioContent(offer->description());
2106 EXPECT_TRUE(content != NULL);
2107 content = cricket::GetFirstVideoContent(offer->description());
2108 EXPECT_TRUE(content == NULL);
2109}
2110
2111// Test that an offer contains the correct media content descriptions based on
2112// the send streams when no constraints have been set.
2113TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002114 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115 // Test Audio only offer.
2116 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002117 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2118
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002119 const cricket::ContentInfo* content =
2120 cricket::GetFirstAudioContent(offer->description());
2121 EXPECT_TRUE(content != NULL);
2122 content = cricket::GetFirstVideoContent(offer->description());
2123 EXPECT_TRUE(content == NULL);
2124
2125 // Test Audio / Video offer.
2126 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002127 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002128 content = cricket::GetFirstAudioContent(offer->description());
2129 EXPECT_TRUE(content != NULL);
2130 content = cricket::GetFirstVideoContent(offer->description());
2131 EXPECT_TRUE(content != NULL);
2132}
2133
2134// Test that an offer contains no media content descriptions if
2135// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2136TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002137 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002138 PeerConnectionInterface::RTCOfferAnswerOptions options;
2139 options.offer_to_receive_audio = 0;
2140 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002141
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002142 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002143 CreateOffer(options));
2144
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145 ASSERT_TRUE(offer != NULL);
2146 const cricket::ContentInfo* content =
2147 cricket::GetFirstAudioContent(offer->description());
2148 EXPECT_TRUE(content == NULL);
2149 content = cricket::GetFirstVideoContent(offer->description());
2150 EXPECT_TRUE(content == NULL);
2151}
2152
2153// Test that an offer contains only audio media content descriptions if
2154// kOfferToReceiveAudio constraints are set to true.
2155TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002156 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002157 PeerConnectionInterface::RTCOfferAnswerOptions options;
2158 options.offer_to_receive_audio =
2159 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2160
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002161 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002162 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163
2164 const cricket::ContentInfo* content =
2165 cricket::GetFirstAudioContent(offer->description());
2166 EXPECT_TRUE(content != NULL);
2167 content = cricket::GetFirstVideoContent(offer->description());
2168 EXPECT_TRUE(content == NULL);
2169}
2170
2171// Test that an offer contains audio and video media content descriptions if
2172// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2173TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002174 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002175 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002176 PeerConnectionInterface::RTCOfferAnswerOptions options;
2177 options.offer_to_receive_audio =
2178 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2179 options.offer_to_receive_video =
2180 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2181
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002182 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002183 CreateOffer(options));
2184
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002185 const cricket::ContentInfo* content =
2186 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002187 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002188
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002189 content = cricket::GetFirstVideoContent(offer->description());
2190 EXPECT_TRUE(content != NULL);
2191
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002192 // Sets constraints to false and verifies that audio/video contents are
2193 // removed.
2194 options.offer_to_receive_audio = 0;
2195 options.offer_to_receive_video = 0;
2196 offer.reset(CreateOffer(options));
2197
2198 content = cricket::GetFirstAudioContent(offer->description());
2199 EXPECT_TRUE(content == NULL);
2200 content = cricket::GetFirstVideoContent(offer->description());
2201 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002202}
2203
2204// Test that an answer can not be created if the last remote description is not
2205// an offer.
2206TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002207 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002208 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002209 SetLocalDescriptionWithoutError(offer);
2210 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2211 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002212 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002213}
2214
2215// Test that an answer contains the correct media content descriptions when no
2216// constraints have been set.
2217TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002218 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002219 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002220 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002221 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002222 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002223 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002224 const cricket::ContentInfo* content =
2225 cricket::GetFirstAudioContent(answer->description());
2226 ASSERT_TRUE(content != NULL);
2227 EXPECT_FALSE(content->rejected);
2228
2229 content = cricket::GetFirstVideoContent(answer->description());
2230 ASSERT_TRUE(content != NULL);
2231 EXPECT_FALSE(content->rejected);
2232}
2233
2234// Test that an answer contains the correct media content descriptions when no
2235// constraints have been set and the offer only contain audio.
2236TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002237 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002238 // Create a remote offer with audio only.
2239 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002240
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002241 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002242 CreateRemoteOffer(options));
2243 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2244 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2245
2246 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002247 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002248 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002249 const cricket::ContentInfo* content =
2250 cricket::GetFirstAudioContent(answer->description());
2251 ASSERT_TRUE(content != NULL);
2252 EXPECT_FALSE(content->rejected);
2253
2254 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2255}
2256
2257// Test that an answer contains the correct media content descriptions when no
2258// constraints have been set.
2259TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002260 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002261 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002262 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002263 SetRemoteDescriptionWithoutError(offer.release());
2264 // Test with a stream with tracks.
2265 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002266 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002267 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002268 const cricket::ContentInfo* content =
2269 cricket::GetFirstAudioContent(answer->description());
2270 ASSERT_TRUE(content != NULL);
2271 EXPECT_FALSE(content->rejected);
2272
2273 content = cricket::GetFirstVideoContent(answer->description());
2274 ASSERT_TRUE(content != NULL);
2275 EXPECT_FALSE(content->rejected);
2276}
2277
2278// Test that an answer contains the correct media content descriptions when
2279// constraints have been set but no stream is sent.
2280TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002281 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002282 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002283 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002284 SetRemoteDescriptionWithoutError(offer.release());
2285
2286 webrtc::FakeConstraints constraints_no_receive;
2287 constraints_no_receive.SetMandatoryReceiveAudio(false);
2288 constraints_no_receive.SetMandatoryReceiveVideo(false);
2289
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002290 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002291 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002292 const cricket::ContentInfo* content =
2293 cricket::GetFirstAudioContent(answer->description());
2294 ASSERT_TRUE(content != NULL);
2295 EXPECT_TRUE(content->rejected);
2296
2297 content = cricket::GetFirstVideoContent(answer->description());
2298 ASSERT_TRUE(content != NULL);
2299 EXPECT_TRUE(content->rejected);
2300}
2301
2302// Test that an answer contains the correct media content descriptions when
2303// constraints have been set and streams are sent.
2304TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002305 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002306 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002307 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002308 SetRemoteDescriptionWithoutError(offer.release());
2309
2310 webrtc::FakeConstraints constraints_no_receive;
2311 constraints_no_receive.SetMandatoryReceiveAudio(false);
2312 constraints_no_receive.SetMandatoryReceiveVideo(false);
2313
2314 // Test with a stream with tracks.
2315 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002316 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002317 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002318
2319 // TODO(perkj): Should the direction be set to SEND_ONLY?
2320 const cricket::ContentInfo* content =
2321 cricket::GetFirstAudioContent(answer->description());
2322 ASSERT_TRUE(content != NULL);
2323 EXPECT_FALSE(content->rejected);
2324
2325 // TODO(perkj): Should the direction be set to SEND_ONLY?
2326 content = cricket::GetFirstVideoContent(answer->description());
2327 ASSERT_TRUE(content != NULL);
2328 EXPECT_FALSE(content->rejected);
2329}
2330
2331TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2332 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002333 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002334 PeerConnectionInterface::RTCOfferAnswerOptions options;
2335 options.offer_to_receive_audio =
2336 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2337 options.voice_activity_detection = false;
2338
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002339 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002340 CreateOffer(options));
2341
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002342 const cricket::ContentInfo* content =
2343 cricket::GetFirstAudioContent(offer->description());
2344 EXPECT_TRUE(content != NULL);
2345 EXPECT_TRUE(VerifyNoCNCodecs(content));
2346}
2347
2348TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2349 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002350 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002351 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002352 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002353 SetRemoteDescriptionWithoutError(offer.release());
2354
2355 webrtc::FakeConstraints constraints;
2356 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002357 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002358 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359 const cricket::ContentInfo* content =
2360 cricket::GetFirstAudioContent(answer->description());
2361 ASSERT_TRUE(content != NULL);
2362 EXPECT_TRUE(VerifyNoCNCodecs(content));
2363}
2364
2365// This test verifies the call setup when remote answer with audio only and
2366// later updates with video.
2367TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002368 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2370 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2371
2372 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002373 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002374
2375 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002376 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2377
2378 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2379 // and answer;
2380 SetLocalDescriptionWithoutError(offer);
2381 SetRemoteDescriptionWithoutError(answer);
2382
2383 video_channel_ = media_engine_->GetVideoChannel(0);
2384 voice_channel_ = media_engine_->GetVoiceChannel(0);
2385
2386 ASSERT_TRUE(video_channel_ == NULL);
2387
2388 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2389 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2390 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2391
2392 // Let the remote end update the session descriptions, with Audio and Video.
2393 mediastream_signaling_.SendAudioVideoStream2();
2394 CreateAndSetRemoteOfferAndLocalAnswer();
2395
2396 video_channel_ = media_engine_->GetVideoChannel(0);
2397 voice_channel_ = media_engine_->GetVoiceChannel(0);
2398
2399 ASSERT_TRUE(video_channel_ != NULL);
2400 ASSERT_TRUE(voice_channel_ != NULL);
2401
2402 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2403 ASSERT_EQ(1u, video_channel_->send_streams().size());
2404 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2405 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2406 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2407 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2408 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2409 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2410
2411 // Change session back to audio only.
2412 mediastream_signaling_.UseOptionsAudioOnly();
2413 CreateAndSetRemoteOfferAndLocalAnswer();
2414
2415 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2416 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2417 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2418 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2419 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2420}
2421
2422// This test verifies the call setup when remote answer with video only and
2423// later updates with audio.
2424TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002425 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002426 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2427 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2428 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002429 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002430
2431 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002432 options.recv_audio = false;
2433 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002434 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2435 offer, options, cricket::SEC_ENABLED);
2436
2437 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2438 // and answer.
2439 SetLocalDescriptionWithoutError(offer);
2440 SetRemoteDescriptionWithoutError(answer);
2441
2442 video_channel_ = media_engine_->GetVideoChannel(0);
2443 voice_channel_ = media_engine_->GetVoiceChannel(0);
2444
2445 ASSERT_TRUE(voice_channel_ == NULL);
2446 ASSERT_TRUE(video_channel_ != NULL);
2447
2448 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2449 ASSERT_EQ(1u, video_channel_->send_streams().size());
2450 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2451
2452 // Update the session descriptions, with Audio and Video.
2453 mediastream_signaling_.SendAudioVideoStream2();
2454 CreateAndSetRemoteOfferAndLocalAnswer();
2455
2456 voice_channel_ = media_engine_->GetVoiceChannel(0);
2457 ASSERT_TRUE(voice_channel_ != NULL);
2458
2459 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2460 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2461 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2462 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2463
2464 // Change session back to video only.
2465 mediastream_signaling_.UseOptionsVideoOnly();
2466 CreateAndSetRemoteOfferAndLocalAnswer();
2467
2468 video_channel_ = media_engine_->GetVideoChannel(0);
2469 voice_channel_ = media_engine_->GetVoiceChannel(0);
2470
2471 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2472 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2473 ASSERT_EQ(1u, video_channel_->send_streams().size());
2474 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2475}
2476
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002477TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002478 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002479 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002480 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002481 VerifyCryptoParams(offer->description());
2482 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002483 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002484 VerifyCryptoParams(answer->description());
2485}
2486
2487TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002488 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002489 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002490 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002491 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002492 VerifyNoCryptoParams(offer->description(), false);
2493}
2494
2495TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002496 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002497 VerifyAnswerFromNonCryptoOffer();
2498}
2499
2500TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002501 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002502 VerifyAnswerFromCryptoOffer();
2503}
2504
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002505// This test verifies that setLocalDescription fails if
2506// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2507TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002508 Init();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002509 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002510 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2511
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002512 std::string sdp;
2513 RemoveIceUfragPwdLines(offer.get(), &sdp);
2514 SessionDescriptionInterface* modified_offer =
2515 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002516 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002517}
2518
2519// This test verifies that setRemoteDescription fails if
2520// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2521TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002522 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002523 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002524 std::string sdp;
2525 RemoveIceUfragPwdLines(offer.get(), &sdp);
2526 SessionDescriptionInterface* modified_offer =
2527 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002528 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002529}
2530
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002531// This test verifies that setLocalDescription fails if local offer has
2532// too short ice ufrag and pwd strings.
2533TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002534 Init();
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002535 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
2536 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002537 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2538
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002539 std::string sdp;
2540 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2541 // recommended values of 4 and 22 bytes respectively.
2542 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2543 SessionDescriptionInterface* modified_offer =
2544 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2545 std::string error;
2546 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2547
2548 // Test with string greater than 256.
2549 sdp.clear();
2550 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2551 &sdp);
2552 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2553 NULL);
2554 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2555}
2556
2557// This test verifies that setRemoteDescription fails if remote offer has
2558// too short ice ufrag and pwd strings.
2559TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002560 Init();
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002561 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002562 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002563 std::string sdp;
2564 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2565 // recommended values of 4 and 22 bytes respectively.
2566 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2567 SessionDescriptionInterface* modified_offer =
2568 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2569 std::string error;
2570 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2571
2572 sdp.clear();
2573 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2574 &sdp);
2575 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2576 NULL);
2577 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2578}
2579
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002580TEST_F(WebRtcSessionTest, VerifyBundleFlagInPA) {
2581 // This test verifies BUNDLE flag in PortAllocator, if BUNDLE information in
2582 // local description is removed by the application, BUNDLE flag should be
2583 // disabled in PortAllocator. By default BUNDLE is enabled in the WebRtc.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002584 Init();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002585 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2586 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002587 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2588
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002589 cricket::SessionDescription* offer_copy =
2590 offer->description()->Copy();
2591 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2592 JsepSessionDescription* modified_offer =
2593 new JsepSessionDescription(JsepSessionDescription::kOffer);
2594 modified_offer->Initialize(offer_copy, "1", "1");
2595
2596 SetLocalDescriptionWithoutError(modified_offer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002597 EXPECT_FALSE(allocator_->flags() & cricket::PORTALLOCATOR_ENABLE_BUNDLE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002598}
2599
2600TEST_F(WebRtcSessionTest, TestDisabledBundleInAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002601 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002602 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002603 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2604 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002605
2606 PeerConnectionInterface::RTCOfferAnswerOptions options;
2607 options.use_rtp_mux = true;
2608
2609 SessionDescriptionInterface* offer = CreateOffer(options);
2610
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002611 SetLocalDescriptionWithoutError(offer);
2612 mediastream_signaling_.SendAudioVideoStream2();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002613 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002614 CreateRemoteAnswer(session_->local_description()));
2615 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2616 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2617 JsepSessionDescription* modified_answer =
2618 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2619 modified_answer->Initialize(answer_copy, "1", "1");
2620 SetRemoteDescriptionWithoutError(modified_answer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002621 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2622 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002623
2624 video_channel_ = media_engine_->GetVideoChannel(0);
2625 voice_channel_ = media_engine_->GetVoiceChannel(0);
2626
2627 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2628 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
2629
2630 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2631 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
2632
2633 ASSERT_EQ(1u, video_channel_->send_streams().size());
2634 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
2635 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2636 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
2637}
2638
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002639// This test verifies that SetLocalDescription and SetRemoteDescription fails
2640// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2641TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002642 Init();
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002643 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002644 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2645 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002646
2647 PeerConnectionInterface::RTCOfferAnswerOptions options;
2648 options.use_rtp_mux = true;
2649
2650 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002651 std::string offer_str;
2652 offer->ToString(&offer_str);
2653 // Disable rtcp-mux
2654 const std::string rtcp_mux = "rtcp-mux";
2655 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002656 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002657 xrtcp_mux.c_str(), xrtcp_mux.length(),
2658 &offer_str);
2659 JsepSessionDescription *local_offer =
2660 new JsepSessionDescription(JsepSessionDescription::kOffer);
2661 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002662 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002663 JsepSessionDescription *remote_offer =
2664 new JsepSessionDescription(JsepSessionDescription::kOffer);
2665 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002666 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002667 // Trying unmodified SDP.
2668 SetLocalDescriptionWithoutError(offer);
2669}
2670
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002671TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002672 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002673 mediastream_signaling_.SendAudioVideoStream1();
2674 CreateAndSetRemoteOfferAndLocalAnswer();
2675 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2676 ASSERT_TRUE(channel != NULL);
2677 ASSERT_EQ(1u, channel->recv_streams().size());
2678 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2679 double left_vol, right_vol;
2680 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2681 EXPECT_EQ(1, left_vol);
2682 EXPECT_EQ(1, right_vol);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002683 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002684 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002685 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2686 EXPECT_EQ(0, left_vol);
2687 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002688 EXPECT_EQ(0, renderer->channel_id());
2689 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002690 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2691 EXPECT_EQ(1, left_vol);
2692 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002693 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002694}
2695
2696TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002697 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002698 mediastream_signaling_.SendAudioVideoStream1();
2699 CreateAndSetRemoteOfferAndLocalAnswer();
2700 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2701 ASSERT_TRUE(channel != NULL);
2702 ASSERT_EQ(1u, channel->send_streams().size());
2703 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2704 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2705
2706 cricket::AudioOptions options;
2707 options.echo_cancellation.Set(true);
2708
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002709 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002710 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002711 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2712 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002713 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002714 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002715
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002716 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002717 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002718 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2719 bool value;
2720 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
2721 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002722 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002723 EXPECT_TRUE(renderer->sink() == NULL);
2724}
2725
2726TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002727 Init();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002728 mediastream_signaling_.SendAudioVideoStream1();
2729 CreateAndSetRemoteOfferAndLocalAnswer();
2730 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2731 ASSERT_TRUE(channel != NULL);
2732 ASSERT_EQ(1u, channel->send_streams().size());
2733 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2734
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002735 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002736 cricket::AudioOptions options;
2737 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
2738 EXPECT_TRUE(renderer->sink() != NULL);
2739
2740 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
2741 // will invalidate the |renderer_| pointer in the sink and prevent getting a
2742 // SetSink(NULL) callback afterwards.
2743 renderer.reset();
2744
2745 // This will trigger SetSink(NULL) if no OnClose() callback.
2746 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002747}
2748
2749TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002750 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002751 mediastream_signaling_.SendAudioVideoStream1();
2752 CreateAndSetRemoteOfferAndLocalAnswer();
2753 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2754 ASSERT_TRUE(channel != NULL);
2755 ASSERT_LT(0u, channel->renderers().size());
2756 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2757 ASSERT_EQ(1u, channel->recv_streams().size());
2758 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2759 cricket::FakeVideoRenderer renderer;
2760 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
2761 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
2762 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
2763 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2764}
2765
2766TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002767 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002768 mediastream_signaling_.SendAudioVideoStream1();
2769 CreateAndSetRemoteOfferAndLocalAnswer();
2770 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2771 ASSERT_TRUE(channel != NULL);
2772 ASSERT_EQ(1u, channel->send_streams().size());
2773 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2774 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2775 cricket::VideoOptions* options = NULL;
2776 session_->SetVideoSend(send_ssrc, false, options);
2777 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2778 session_->SetVideoSend(send_ssrc, true, options);
2779 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2780}
2781
2782TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
2783 TestCanInsertDtmf(false);
2784}
2785
2786TEST_F(WebRtcSessionTest, CanInsertDtmf) {
2787 TestCanInsertDtmf(true);
2788}
2789
2790TEST_F(WebRtcSessionTest, InsertDtmf) {
2791 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002792 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002793 mediastream_signaling_.SendAudioVideoStream1();
2794 CreateAndSetRemoteOfferAndLocalAnswer();
2795 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2796 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
2797
2798 // Insert DTMF
2799 const int expected_flags = DF_SEND;
2800 const int expected_duration = 90;
2801 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
2802 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
2803 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
2804
2805 // Verify
2806 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
2807 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2808 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
2809 expected_duration, expected_flags));
2810 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
2811 expected_duration, expected_flags));
2812 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
2813 expected_duration, expected_flags));
2814}
2815
2816// This test verifies the |initiator| flag when session initiates the call.
2817TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002818 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002819 EXPECT_FALSE(session_->initiator());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002820 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002821 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2822 SetLocalDescriptionWithoutError(offer);
2823 EXPECT_TRUE(session_->initiator());
2824 SetRemoteDescriptionWithoutError(answer);
2825 EXPECT_TRUE(session_->initiator());
2826}
2827
2828// This test verifies the |initiator| flag when session receives the call.
2829TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002830 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002831 EXPECT_FALSE(session_->initiator());
2832 SessionDescriptionInterface* offer = CreateRemoteOffer();
2833 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002834 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002835
2836 EXPECT_FALSE(session_->initiator());
2837 SetLocalDescriptionWithoutError(answer);
2838 EXPECT_FALSE(session_->initiator());
2839}
2840
2841// This test verifies the ice protocol type at initiator of the call
2842// if |a=ice-options:google-ice| is present in answer.
2843TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002844 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002845 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002846 SessionDescriptionInterface* offer = CreateOffer();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002847 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002848 CreateRemoteAnswer(offer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002849 SetLocalDescriptionWithoutError(offer);
2850 std::string sdp;
2851 EXPECT_TRUE(answer->ToString(&sdp));
2852 // Adding ice-options to the session level.
2853 InjectAfter("t=0 0\r\n",
2854 "a=ice-options:google-ice\r\n",
2855 &sdp);
2856 SessionDescriptionInterface* answer_with_gice =
2857 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00002858 // Default offer is ICEPROTO_RFC5245, so we expect responder with
2859 // only gice to fail.
2860 SetRemoteDescriptionAnswerExpectError(kPushDownTDFailed, answer_with_gice);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002861}
2862
2863// This test verifies the ice protocol type at initiator of the call
2864// if ICE RFC5245 is supported in answer.
2865TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002866 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002867 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002868 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002869 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2870 SetLocalDescriptionWithoutError(offer);
2871
2872 SetRemoteDescriptionWithoutError(answer);
2873 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2874 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2875}
2876
2877// This test verifies the ice protocol type at receiver side of the call if
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002878// receiver decides to use ice RFC 5245.
2879TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002880 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002881 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002882 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002883 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002884 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002885 SetLocalDescriptionWithoutError(answer);
2886 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2887 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2888}
2889
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002890// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
2891TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002892 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002893 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002894 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002895 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002896 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002897 CreateRemoteAnswer(session_->local_description()));
2898
2899 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2900 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002901 JsepSessionDescription* modified_answer =
2902 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002903
2904 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2905 answer->session_id(),
2906 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002907 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002908
wu@webrtc.org4e393072014-04-07 17:04:35 +00002909 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002910 std::string sdp;
2911 EXPECT_TRUE(answer->ToString(&sdp));
2912 const std::string kAudioMid = "a=mid:audio";
2913 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002914 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002915 kAudioMidReplaceStr.c_str(),
2916 kAudioMidReplaceStr.length(),
2917 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002918 SessionDescriptionInterface* modified_answer1 =
2919 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002920 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002921
wu@webrtc.org4e393072014-04-07 17:04:35 +00002922 // Different media types.
2923 EXPECT_TRUE(answer->ToString(&sdp));
2924 const std::string kAudioMline = "m=audio";
2925 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002926 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00002927 kAudioMlineReplaceStr.c_str(),
2928 kAudioMlineReplaceStr.length(),
2929 &sdp);
2930 SessionDescriptionInterface* modified_answer2 =
2931 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2932 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
2933
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002934 SetRemoteDescriptionWithoutError(answer.release());
2935}
2936
2937// Verifying remote offer and local answer have matching m-lines as per
2938// RFC 3264.
2939TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002940 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002941 mediastream_signaling_.SendAudioVideoStream1();
2942 SessionDescriptionInterface* offer = CreateRemoteOffer();
2943 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002944 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002945
2946 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2947 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002948 JsepSessionDescription* modified_answer =
2949 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002950
2951 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2952 answer->session_id(),
2953 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002954 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002955 SetLocalDescriptionWithoutError(answer);
2956}
2957
2958// This test verifies that WebRtcSession does not start candidate allocation
2959// before SetLocalDescription is called.
2960TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002961 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002962 mediastream_signaling_.SendAudioVideoStream1();
2963 SessionDescriptionInterface* offer = CreateRemoteOffer();
2964 cricket::Candidate candidate;
2965 candidate.set_component(1);
2966 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2967 candidate);
2968 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2969 cricket::Candidate candidate1;
2970 candidate1.set_component(1);
2971 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2972 candidate1);
2973 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2974 SetRemoteDescriptionWithoutError(offer);
2975 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
2976 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
2977
2978 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002979 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002980 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
2981 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
2982
wu@webrtc.org91053e72013-08-10 07:18:04 +00002983 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002984 SetLocalDescriptionWithoutError(answer);
2985 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
2986 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
2987 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2988}
2989
2990// This test verifies that crypto parameter is updated in local session
2991// description as per security policy set in MediaSessionDescriptionFactory.
2992TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002993 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002994 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002995 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002996
2997 // Making sure SetLocalDescription correctly sets crypto value in
2998 // SessionDescription object after de-serialization of sdp string. The value
2999 // will be set as per MediaSessionDescriptionFactory.
3000 std::string offer_str;
3001 offer->ToString(&offer_str);
3002 SessionDescriptionInterface* jsep_offer_str =
3003 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3004 SetLocalDescriptionWithoutError(jsep_offer_str);
3005 EXPECT_TRUE(session_->voice_channel()->secure_required());
3006 EXPECT_TRUE(session_->video_channel()->secure_required());
3007}
3008
3009// This test verifies the crypto parameter when security is disabled.
3010TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003011 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003012 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003013 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003014 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003015
3016 // Making sure SetLocalDescription correctly sets crypto value in
3017 // SessionDescription object after de-serialization of sdp string. The value
3018 // will be set as per MediaSessionDescriptionFactory.
3019 std::string offer_str;
3020 offer->ToString(&offer_str);
3021 SessionDescriptionInterface *jsep_offer_str =
3022 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3023 SetLocalDescriptionWithoutError(jsep_offer_str);
3024 EXPECT_FALSE(session_->voice_channel()->secure_required());
3025 EXPECT_FALSE(session_->video_channel()->secure_required());
3026}
3027
3028// This test verifies that an answer contains new ufrag and password if an offer
3029// with new ufrag and password is received.
3030TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003031 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003032 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003033 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003034 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003035 CreateRemoteOffer(options));
3036 SetRemoteDescriptionWithoutError(offer.release());
3037
3038 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003039 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003040 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003041 SetLocalDescriptionWithoutError(answer.release());
3042
3043 // Receive an offer with new ufrag and password.
3044 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003045 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003046 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003047 SetRemoteDescriptionWithoutError(updated_offer1.release());
3048
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003049 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003050 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003051
3052 CompareIceUfragAndPassword(updated_answer1->description(),
3053 session_->local_description()->description(),
3054 false);
3055
3056 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003057}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003058
wu@webrtc.org91053e72013-08-10 07:18:04 +00003059// This test verifies that an answer contains old ufrag and password if an offer
3060// with old ufrag and password is received.
3061TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003062 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003063 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003064 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003065 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003066 CreateRemoteOffer(options));
3067 SetRemoteDescriptionWithoutError(offer.release());
3068
3069 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003070 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003071 CreateAnswer(NULL));
3072 SetLocalDescriptionWithoutError(answer.release());
3073
3074 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003075 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003076 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003077 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003078 SetRemoteDescriptionWithoutError(updated_offer2.release());
3079
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003080 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003081 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003082
3083 CompareIceUfragAndPassword(updated_answer2->description(),
3084 session_->local_description()->description(),
3085 true);
3086
3087 SetLocalDescriptionWithoutError(updated_answer2.release());
3088}
3089
3090TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003091 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003092 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003093 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003094 const std::string session_id_orig = offer->session_id();
3095 const std::string session_version_orig = offer->session_version();
3096 SetLocalDescriptionWithoutError(offer);
3097
3098 video_channel_ = media_engine_->GetVideoChannel(0);
3099 video_channel_->set_fail_set_send_codecs(true);
3100
3101 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003102 SessionDescriptionInterface* answer =
3103 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003104 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003105}
3106
3107// Runs the loopback call test with BUNDLE and STUN disabled.
3108TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3109 // Lets try with only UDP ports.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00003110 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003111 cricket::PORTALLOCATOR_DISABLE_TCP |
3112 cricket::PORTALLOCATOR_DISABLE_STUN |
3113 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003114 TestLoopbackCall();
3115}
3116
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003117TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
3118 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
3119 cricket::PORTALLOCATOR_DISABLE_TCP |
3120 cricket::PORTALLOCATOR_DISABLE_STUN |
3121 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3122 cricket::PORTALLOCATOR_DISABLE_RELAY);
3123
3124 // best connection is IPv6 since it has higher network preference.
3125 LoopbackNetworkConfiguration config;
3126 config.test_ipv6_network_ = true;
3127 config.best_connection_after_initial_ice_converged_ =
3128 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3129
3130 TestLoopbackCall(config);
3131}
3132
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003133// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003134TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00003135 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003136 cricket::PORTALLOCATOR_ENABLE_BUNDLE |
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003137 cricket::PORTALLOCATOR_DISABLE_TCP |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003138 cricket::PORTALLOCATOR_DISABLE_RELAY);
3139 TestLoopbackCall();
3140}
3141
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003142TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003143 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003144 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003145 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003146
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003147 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
3148 std::string error_code_str = "ERROR_CONTENT";
3149 std::string error_desc = "Fake session error description.";
3150 session_->SetError(error_code, error_desc);
3151
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003152 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
3153 SessionDescriptionInterface* answer =
3154 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003155
3156 std::string action;
3157 std::ostringstream session_error_msg;
3158 session_error_msg << kSessionError << error_code_str << ". ";
3159 session_error_msg << kSessionErrorDesc << error_desc << ".";
3160 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
3161 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003162}
3163
3164TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3165 constraints_.reset(new FakeConstraints());
3166 constraints_->AddOptional(
3167 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003168 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003169
3170 SetLocalDescriptionWithDataChannel();
3171 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3172}
3173
3174TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003175 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003176
3177 constraints_.reset(new FakeConstraints());
3178 constraints_->AddOptional(
3179 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003180 options_.disable_sctp_data_channels = false;
3181
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003182 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003183
3184 SetLocalDescriptionWithDataChannel();
3185 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3186}
3187
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003188TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003189 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003190
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003191 InitWithDtls();
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003192
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003193 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003194 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003195 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3196}
3197
3198TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003199 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003200 SetFactoryDtlsSrtp();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003201 InitWithDtls();
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003202
3203 // Create remote offer with SCTP.
3204 cricket::MediaSessionOptions options;
3205 options.data_channel_type = cricket::DCT_SCTP;
3206 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003207 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003208 SetRemoteDescriptionWithoutError(offer);
3209
3210 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003211 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003212 EXPECT_TRUE(answer != NULL);
3213 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3214 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003215}
3216
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003217TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
3218 constraints_.reset(new FakeConstraints());
3219 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003220 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003221 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003222
3223 SetLocalDescriptionWithDataChannel();
3224 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3225}
3226
3227TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003228 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003229
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003230 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003231
3232 SetLocalDescriptionWithDataChannel();
3233 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3234}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003235
wu@webrtc.org97077a32013-10-25 21:18:33 +00003236TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003237 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003238 options_.disable_sctp_data_channels = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003239 InitWithDtls();
wu@webrtc.org97077a32013-10-25 21:18:33 +00003240
3241 SetLocalDescriptionWithDataChannel();
3242 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3243}
3244
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003245TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003246 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003247 const int new_send_port = 9998;
3248 const int new_recv_port = 7775;
3249
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003250 InitWithDtls();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003251 SetFactoryDtlsSrtp();
3252
3253 // By default, don't actually add the codecs to desc_factory_; they don't
3254 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3255 // let the session description get parsed. That'll get the proper codecs
3256 // into the stream.
3257 cricket::MediaSessionOptions options;
3258 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3259 "stream1", new_send_port, options);
3260
3261 // SetRemoteDescription will take the ownership of the offer.
3262 SetRemoteDescriptionWithoutError(offer);
3263
3264 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3265 new_recv_port, CreateAnswer(NULL));
3266 ASSERT_TRUE(answer != NULL);
3267
3268 // Now set the local description, which'll take ownership of the answer.
3269 SetLocalDescriptionWithoutError(answer);
3270
3271 // TEST PLAN: Set the port number to something new, set it in the SDP,
3272 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003273 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003274 dci.reliable = true;
3275 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003276 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003277 session_->CreateDataChannel("datachannel", &dci);
3278
3279 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3280 int portnum = -1;
3281 ASSERT_TRUE(ch != NULL);
3282 ASSERT_EQ(1UL, ch->send_codecs().size());
3283 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
3284 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3285 ch->send_codecs()[0].name.c_str()));
3286 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3287 &portnum));
3288 EXPECT_EQ(new_send_port, portnum);
3289
3290 ASSERT_EQ(1UL, ch->recv_codecs().size());
3291 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
3292 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3293 ch->recv_codecs()[0].name.c_str()));
3294 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3295 &portnum));
3296 EXPECT_EQ(new_recv_port, portnum);
3297}
3298
wu@webrtc.org91053e72013-08-10 07:18:04 +00003299// Verifies that CreateOffer succeeds when CreateOffer is called before async
3300// identity generation is finished.
3301TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003302 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003303 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003304
3305 EXPECT_TRUE(session_->waiting_for_identity());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003306 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003307 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3308
wu@webrtc.org91053e72013-08-10 07:18:04 +00003309 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003310 VerifyNoCryptoParams(offer->description(), true);
3311 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003312}
3313
3314// Verifies that CreateAnswer succeeds when CreateOffer is called before async
3315// identity generation is finished.
3316TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003317 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003318 InitWithDtls();
3319 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003320
3321 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003322 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003323 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003324 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003325 ASSERT_TRUE(offer.get() != NULL);
3326 SetRemoteDescriptionWithoutError(offer.release());
3327
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003328 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003329 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003330 VerifyNoCryptoParams(answer->description(), true);
3331 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003332}
3333
3334// Verifies that CreateOffer succeeds when CreateOffer is called after async
3335// identity generation is finished.
3336TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003337 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003338 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003339
3340 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003341
3342 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003343 EXPECT_TRUE(offer != NULL);
3344}
3345
3346// Verifies that CreateOffer fails when CreateOffer is called after async
3347// identity generation fails.
3348TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003349 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00003350 InitWithDtls(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003351
3352 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003353
3354 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003355 EXPECT_TRUE(offer == NULL);
3356}
3357
3358// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3359// before async identity generation is finished.
3360TEST_F(WebRtcSessionTest,
3361 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003362 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003363 VerifyMultipleAsyncCreateDescription(
3364 true, CreateSessionDescriptionRequest::kOffer);
3365}
3366
3367// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3368// before async identity generation fails.
3369TEST_F(WebRtcSessionTest,
3370 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003371 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003372 VerifyMultipleAsyncCreateDescription(
3373 false, CreateSessionDescriptionRequest::kOffer);
3374}
3375
3376// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3377// before async identity generation is finished.
3378TEST_F(WebRtcSessionTest,
3379 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003380 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003381 VerifyMultipleAsyncCreateDescription(
3382 true, CreateSessionDescriptionRequest::kAnswer);
3383}
3384
3385// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3386// before async identity generation fails.
3387TEST_F(WebRtcSessionTest,
3388 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003389 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003390 VerifyMultipleAsyncCreateDescription(
3391 false, CreateSessionDescriptionRequest::kAnswer);
3392}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003393
3394// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3395// offer has no SDES crypto but only DTLS fingerprint.
3396TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3397 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003398 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003399 // Create a remote offer with secured transport disabled.
3400 cricket::MediaSessionOptions options;
3401 JsepSessionDescription* offer(CreateRemoteOffer(
3402 options, cricket::SEC_DISABLED));
3403 // Adds a DTLS fingerprint to the remote offer.
3404 cricket::SessionDescription* sdp = offer->description();
3405 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3406 ASSERT_TRUE(audio != NULL);
3407 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3408 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003409 rtc::SSLFingerprint::CreateFromRfc4572(
3410 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003411 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003412 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003413}
3414
wu@webrtc.orgde305012013-10-31 15:40:38 +00003415// This test verifies DSCP is properly applied on the media channels.
3416TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3417 constraints_.reset(new FakeConstraints());
3418 constraints_->AddOptional(
3419 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003420 Init();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003421 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003422 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003423
3424 SetLocalDescriptionWithoutError(offer);
3425
3426 video_channel_ = media_engine_->GetVideoChannel(0);
3427 voice_channel_ = media_engine_->GetVoiceChannel(0);
3428
3429 ASSERT_TRUE(video_channel_ != NULL);
3430 ASSERT_TRUE(voice_channel_ != NULL);
3431 cricket::AudioOptions audio_options;
3432 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3433 cricket::VideoOptions video_options;
3434 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3435 EXPECT_TRUE(audio_options.dscp.IsSet());
3436 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3437 EXPECT_TRUE(video_options.dscp.IsSet());
3438 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3439}
3440
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003441TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3442 constraints_.reset(new FakeConstraints());
3443 constraints_->AddOptional(
3444 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3445 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003446 Init();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003447 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003448 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003449
3450 SetLocalDescriptionWithoutError(offer);
3451
3452 video_channel_ = media_engine_->GetVideoChannel(0);
3453
3454 ASSERT_TRUE(video_channel_ != NULL);
3455 cricket::VideoOptions video_options;
3456 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3457 EXPECT_TRUE(
3458 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3459}
3460
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00003461TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
3462 // Number of unsignalled receiving streams should be between 0 and
3463 // kMaxUnsignalledRecvStreams.
3464 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
3465 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
3466 kMaxUnsignalledRecvStreams);
3467 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
3468}
3469
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003470TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
3471 constraints_.reset(new FakeConstraints());
3472 constraints_->AddOptional(
3473 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
3474 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003475 Init();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003476 mediastream_signaling_.SendAudioVideoStream1();
3477 SessionDescriptionInterface* offer = CreateOffer();
3478
3479 SetLocalDescriptionWithoutError(offer);
3480
3481 voice_channel_ = media_engine_->GetVoiceChannel(0);
3482
3483 ASSERT_TRUE(voice_channel_ != NULL);
3484 cricket::AudioOptions audio_options;
3485 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3486 EXPECT_TRUE(
3487 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
3488}
3489
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003490// Tests that we can renegotiate new media content with ICE candidates in the
3491// new remote SDP.
3492TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003493 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003494 InitWithDtls();
3495 SetFactoryDtlsSrtp();
3496
3497 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003498 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003499 SetLocalDescriptionWithoutError(offer);
3500
3501 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3502 SetRemoteDescriptionWithoutError(answer);
3503
3504 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003505 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003506 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3507
3508 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003509 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003510 candidate1.set_component(1);
3511 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3512 candidate1);
3513 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3514 SetRemoteDescriptionWithoutError(offer);
3515
3516 answer = CreateAnswer(NULL);
3517 SetLocalDescriptionWithoutError(answer);
3518}
3519
3520// Tests that we can renegotiate new media content with ICE candidates separated
3521// from the remote SDP.
3522TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003523 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003524 InitWithDtls();
3525 SetFactoryDtlsSrtp();
3526
3527 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003528 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003529 SetLocalDescriptionWithoutError(offer);
3530
3531 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3532 SetRemoteDescriptionWithoutError(answer);
3533
3534 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003535 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003536 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3537 SetRemoteDescriptionWithoutError(offer);
3538
3539 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003540 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003541 candidate1.set_component(1);
3542 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3543 candidate1);
3544 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3545
3546 answer = CreateAnswer(NULL);
3547 SetLocalDescriptionWithoutError(answer);
3548}
3549
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003550// This verifies that the voice channel after bundle has both options from video
3551// and voice channels.
3552TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
3553 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
3554 mediastream_signaling_.SendAudioVideoStream1();
3555
3556 PeerConnectionInterface::RTCOfferAnswerOptions options;
3557 options.use_rtp_mux = true;
3558
3559 SessionDescriptionInterface* offer = CreateOffer(options);
3560 SetLocalDescriptionWithoutError(offer);
3561
3562 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3563 rtc::Socket::Option::OPT_SNDBUF, 4000);
3564
3565 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3566 rtc::Socket::Option::OPT_RCVBUF, 8000);
3567
3568 int option_val;
3569 EXPECT_TRUE(session_->video_channel()->transport_channel()->GetOption(
3570 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3571 EXPECT_EQ(4000, option_val);
3572 EXPECT_FALSE(session_->voice_channel()->transport_channel()->GetOption(
3573 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3574
3575 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3576 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3577 EXPECT_EQ(8000, option_val);
3578 EXPECT_FALSE(session_->video_channel()->transport_channel()->GetOption(
3579 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3580
3581 EXPECT_NE(session_->voice_channel()->transport_channel(),
3582 session_->video_channel()->transport_channel());
3583
3584 mediastream_signaling_.SendAudioVideoStream2();
3585 SessionDescriptionInterface* answer =
3586 CreateRemoteAnswer(session_->local_description());
3587 SetRemoteDescriptionWithoutError(answer);
3588
3589 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3590 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3591 EXPECT_EQ(4000, option_val);
3592
3593 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3594 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3595 EXPECT_EQ(8000, option_val);
3596}
3597
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003598// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
3599// currently fails because upon disconnection and reconnection OnIceComplete is
3600// called more than once without returning to IceGatheringGathering.