blob: 4e0066b0f53b5168d81988a3d6bfa4b4af6cee11 [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
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000139static const char kSdpWithRtx[] =
140 "v=0\r\n"
141 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
142 "s=-\r\n"
143 "t=0 0\r\n"
144 "a=msid-semantic: WMS stream1\r\n"
145 "m=video 9 RTP/SAVPF 0 96\r\n"
146 "c=IN IP4 0.0.0.0\r\n"
147 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
148 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
149 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
150 "a=mid:video\r\n"
151 "a=sendrecv\r\n"
152 "a=rtcp-mux\r\n"
153 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
154 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
155 "a=rtpmap:0 fake_video_codec/90000\r\n"
156 "a=rtpmap:96 rtx/90000\r\n"
157 "a=fmtp:96 apt=0\r\n";
158
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000159// Add some extra |newlines| to the |message| after |line|.
160static void InjectAfter(const std::string& line,
161 const std::string& newlines,
162 std::string* message) {
163 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000164 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165 tmp.c_str(), tmp.length(), message);
166}
167
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000168class FakeMetricsObserver : public webrtc::MetricsObserverInterface {
169 public:
170 FakeMetricsObserver() { Reset(); }
171 void Reset() {
172 memset(peer_connection_metrics_counters_, 0,
173 sizeof(peer_connection_metrics_counters_));
174 memset(peer_connection_metrics_name_, 0,
175 sizeof(peer_connection_metrics_name_));
176 }
177
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000178 void IncrementCounter(webrtc::PeerConnectionMetricsCounter type) override {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000179 peer_connection_metrics_counters_[type]++;
180 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000181 void AddHistogramSample(webrtc::PeerConnectionMetricsName type,
182 int value) override {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000183 ASSERT(peer_connection_metrics_name_[type] == 0);
184 peer_connection_metrics_name_[type] = value;
185 }
186
187 int peer_connection_metrics_counters_
188 [webrtc::kPeerConnectionMetricsCounter_Max];
189 int peer_connection_metrics_name_[webrtc::kPeerConnectionMetricsCounter_Max];
190
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000191 int AddRef() override { return 1; }
192 int Release() override { return 1; }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000193};
194
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000195class MockIceObserver : public webrtc::IceObserver {
196 public:
197 MockIceObserver()
198 : oncandidatesready_(false),
199 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
200 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
201 }
202
203 virtual void OnIceConnectionChange(
204 PeerConnectionInterface::IceConnectionState new_state) {
205 ice_connection_state_ = new_state;
206 }
207 virtual void OnIceGatheringChange(
208 PeerConnectionInterface::IceGatheringState new_state) {
209 // We can never transition back to "new".
210 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
211 ice_gathering_state_ = new_state;
212
213 // oncandidatesready_ really means "ICE gathering is complete".
214 // This if statement ensures that this value remains correct when we
215 // transition from kIceGatheringComplete to kIceGatheringGathering.
216 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
217 oncandidatesready_ = false;
218 }
219 }
220
221 // Found a new candidate.
222 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000223 switch (candidate->sdp_mline_index()) {
224 case kMediaContentIndex0:
225 mline_0_candidates_.push_back(candidate->candidate());
226 break;
227 case kMediaContentIndex1:
228 mline_1_candidates_.push_back(candidate->candidate());
229 break;
230 default:
231 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000233
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000234 // The ICE gathering state should always be Gathering when a candidate is
235 // received (or possibly Completed in the case of the final candidate).
236 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
237 }
238
239 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
240 virtual void OnIceComplete() {
241 EXPECT_FALSE(oncandidatesready_);
242 oncandidatesready_ = true;
243
244 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
245 // be called approximately simultaneously. For ease of testing, this
246 // check additionally requires that they be called in the above order.
247 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
248 ice_gathering_state_);
249 }
250
251 bool oncandidatesready_;
252 std::vector<cricket::Candidate> mline_0_candidates_;
253 std::vector<cricket::Candidate> mline_1_candidates_;
254 PeerConnectionInterface::IceConnectionState ice_connection_state_;
255 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
256};
257
258class WebRtcSessionForTest : public webrtc::WebRtcSession {
259 public:
260 WebRtcSessionForTest(cricket::ChannelManager* cmgr,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000261 rtc::Thread* signaling_thread,
262 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000263 cricket::PortAllocator* port_allocator,
264 webrtc::IceObserver* ice_observer,
265 webrtc::MediaStreamSignaling* mediastream_signaling)
266 : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator,
267 mediastream_signaling) {
268 RegisterIceObserver(ice_observer);
269 }
270 virtual ~WebRtcSessionForTest() {}
271
272 using cricket::BaseSession::GetTransportProxy;
273 using webrtc::WebRtcSession::SetAudioPlayout;
274 using webrtc::WebRtcSession::SetAudioSend;
275 using webrtc::WebRtcSession::SetCaptureDevice;
276 using webrtc::WebRtcSession::SetVideoPlayout;
277 using webrtc::WebRtcSession::SetVideoSend;
278};
279
wu@webrtc.org91053e72013-08-10 07:18:04 +0000280class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000281 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000282 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000283 enum State {
284 kInit,
285 kFailed,
286 kSucceeded,
287 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000288 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000289
290 // CreateSessionDescriptionObserver implementation.
291 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000292 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000293 state_ = kSucceeded;
294 }
295 virtual void OnFailure(const std::string& error) {
296 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000297 }
298
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000299 SessionDescriptionInterface* description() { return description_.get(); }
300
301 SessionDescriptionInterface* ReleaseDescription() {
302 return description_.release();
303 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304
wu@webrtc.org91053e72013-08-10 07:18:04 +0000305 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000306
wu@webrtc.org91053e72013-08-10 07:18:04 +0000307 protected:
308 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309
310 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000311 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000312 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313};
314
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000315class FakeAudioRenderer : public cricket::AudioRenderer {
316 public:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000317 FakeAudioRenderer() : channel_id_(-1), sink_(NULL) {}
318 virtual ~FakeAudioRenderer() {
319 if (sink_)
320 sink_->OnClose();
321 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000322
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000323 void AddChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000324 ASSERT(channel_id_ == -1);
325 channel_id_ = channel_id;
326 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000327 void RemoveChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000328 ASSERT(channel_id == channel_id_);
329 channel_id_ = -1;
330 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000331 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000332
333 int channel_id() const { return channel_id_; }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000334 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000335 private:
336 int channel_id_;
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000337 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000338};
339
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000340class WebRtcSessionTest : public testing::Test {
341 protected:
342 // TODO Investigate why ChannelManager crashes, if it's created
343 // after stun_server.
344 WebRtcSessionTest()
345 : media_engine_(new cricket::FakeMediaEngine()),
346 data_engine_(new cricket::FakeDataEngine()),
347 device_manager_(new cricket::FakeDeviceManager()),
348 channel_manager_(new cricket::ChannelManager(
349 media_engine_, data_engine_, device_manager_,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000350 new cricket::CaptureManager(), rtc::Thread::Current())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351 tdesc_factory_(new cricket::TransportDescriptionFactory()),
352 desc_factory_(new cricket::MediaSessionDescriptionFactory(
353 channel_manager_.get(), tdesc_factory_.get())),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000354 pss_(new rtc::PhysicalSocketServer),
355 vss_(new rtc::VirtualSocketServer(pss_.get())),
356 fss_(new rtc::FirewallSocketServer(vss_.get())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000357 ss_scope_(fss_.get()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000358 stun_socket_addr_(rtc::SocketAddress(kStunAddrHost,
wu@webrtc.org364f2042013-11-20 21:49:41 +0000359 cricket::STUN_SERVER_PORT)),
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +0000360 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
361 stun_socket_addr_)),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000362 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000363 mediastream_signaling_(channel_manager_.get()) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000364 tdesc_factory_->set_protocol(cricket::ICEPROTO_HYBRID);
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000365
366 cricket::ServerAddresses stun_servers;
367 stun_servers.insert(stun_socket_addr_);
368 allocator_.reset(new cricket::BasicPortAllocator(
369 &network_manager_,
370 stun_servers,
371 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000372 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000373 cricket::PORTALLOCATOR_DISABLE_RELAY |
jiayl@webrtc.orgdacdd942015-01-23 17:33:34 +0000374 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000375 EXPECT_TRUE(channel_manager_->Init());
376 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000377 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000378 }
379
380 void AddInterface(const SocketAddress& addr) {
381 network_manager_.AddInterface(addr);
382 }
383
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000384 void Init(
385 DTLSIdentityServiceInterface* identity_service,
386 PeerConnectionInterface::IceTransportsType ice_transport_type,
387 PeerConnectionInterface::BundlePolicy bundle_policy) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 ASSERT_TRUE(session_.get() == NULL);
389 session_.reset(new WebRtcSessionForTest(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000390 channel_manager_.get(), rtc::Thread::Current(),
391 rtc::Thread::Current(), allocator_.get(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000392 &observer_,
393 &mediastream_signaling_));
394
395 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
396 observer_.ice_connection_state_);
397 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
398 observer_.ice_gathering_state_);
399
wu@webrtc.org97077a32013-10-25 21:18:33 +0000400 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000401 identity_service, ice_transport_type,
402 bundle_policy));
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000403 session_->set_metrics_observer(&metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000404 }
405
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000406 void Init() {
407 Init(NULL, PeerConnectionInterface::kAll,
408 PeerConnectionInterface::kBundlePolicyBalanced);
409 }
410
411 void InitWithIceTransport(
412 PeerConnectionInterface::IceTransportsType ice_transport_type) {
413 Init(NULL, ice_transport_type,
414 PeerConnectionInterface::kBundlePolicyBalanced);
415 }
416
417 void InitWithBundlePolicy(
418 PeerConnectionInterface::BundlePolicy bundle_policy) {
419 Init(NULL, PeerConnectionInterface::kAll, bundle_policy);
420 }
421
422 void InitWithDtls(bool identity_request_should_fail = false) {
423 FakeIdentityService* identity_service = new FakeIdentityService();
424 identity_service->set_should_fail(identity_request_should_fail);
425 Init(identity_service,
426 PeerConnectionInterface::kAll,
427 PeerConnectionInterface::kBundlePolicyBalanced);
428 }
429
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000430 void InitWithDtmfCodec() {
431 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000432 const cricket::AudioCodec kTelephoneEventCodec(
433 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000434 std::vector<cricket::AudioCodec> codecs;
435 codecs.push_back(kTelephoneEventCodec);
436 media_engine_->SetAudioCodecs(codecs);
437 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000438 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000439 }
440
441 // Creates a local offer and applies it. Starts ice.
442 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
443 // to decide which streams to create.
444 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000445 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000446 SetLocalDescriptionWithoutError(offer);
447 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
448 observer_.ice_gathering_state_,
449 kIceCandidatesTimeout);
450 }
451
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000452 SessionDescriptionInterface* CreateOffer() {
453 PeerConnectionInterface::RTCOfferAnswerOptions options;
454 options.offer_to_receive_audio =
455 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
456
457 return CreateOffer(options);
458 }
459
wu@webrtc.org91053e72013-08-10 07:18:04 +0000460 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000461 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000462 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000463 observer = new WebRtcSessionCreateSDPObserverForTest();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000464 session_->CreateOffer(observer, options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000465 EXPECT_TRUE_WAIT(
466 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000467 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000468 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000469 }
470
471 SessionDescriptionInterface* CreateAnswer(
472 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000473 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000474 = new WebRtcSessionCreateSDPObserverForTest();
475 session_->CreateAnswer(observer, constraints);
476 EXPECT_TRUE_WAIT(
477 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000478 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000479 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000480 }
481
wu@webrtc.org364f2042013-11-20 21:49:41 +0000482 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000483 return (session_->voice_channel() != NULL &&
484 session_->video_channel() != NULL);
485 }
486
wu@webrtc.org364f2042013-11-20 21:49:41 +0000487 void CheckTransportChannels() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000488 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 1) != NULL);
489 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 2) != NULL);
490 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 1) != NULL);
491 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 2) != NULL);
492 }
493
494 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
495 ASSERT_TRUE(session_.get() != NULL);
496 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
497 ASSERT_TRUE(content != NULL);
498 const cricket::AudioContentDescription* audio_content =
499 static_cast<const cricket::AudioContentDescription*>(
500 content->description);
501 ASSERT_TRUE(audio_content != NULL);
502 ASSERT_EQ(1U, audio_content->cryptos().size());
503 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
504 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
505 audio_content->cryptos()[0].cipher_suite);
506 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
507 audio_content->protocol());
508
509 content = cricket::GetFirstVideoContent(sdp);
510 ASSERT_TRUE(content != NULL);
511 const cricket::VideoContentDescription* video_content =
512 static_cast<const cricket::VideoContentDescription*>(
513 content->description);
514 ASSERT_TRUE(video_content != NULL);
515 ASSERT_EQ(1U, video_content->cryptos().size());
516 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
517 video_content->cryptos()[0].cipher_suite);
518 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
519 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
520 video_content->protocol());
521 }
522
523 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
524 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
525 ASSERT_TRUE(content != NULL);
526 const cricket::AudioContentDescription* audio_content =
527 static_cast<const cricket::AudioContentDescription*>(
528 content->description);
529 ASSERT_TRUE(audio_content != NULL);
530 ASSERT_EQ(0U, audio_content->cryptos().size());
531
532 content = cricket::GetFirstVideoContent(sdp);
533 ASSERT_TRUE(content != NULL);
534 const cricket::VideoContentDescription* video_content =
535 static_cast<const cricket::VideoContentDescription*>(
536 content->description);
537 ASSERT_TRUE(video_content != NULL);
538 ASSERT_EQ(0U, video_content->cryptos().size());
539
540 if (dtls) {
541 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
542 audio_content->protocol());
543 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
544 video_content->protocol());
545 } else {
546 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
547 audio_content->protocol());
548 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
549 video_content->protocol());
550 }
551 }
552
553 // Set the internal fake description factories to do DTLS-SRTP.
554 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000555 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000556 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000557 rtc::ToString(rtc::CreateRandomId());
558 identity_.reset(rtc::SSLIdentity::Generate(identity_name));
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000559 tdesc_factory_->set_identity(identity_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000560 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
561 }
562
563 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
564 bool expected) {
565 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
566 ASSERT_TRUE(audio != NULL);
567 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000568 const TransportInfo* video = sdp->GetTransportInfoByName("video");
569 ASSERT_TRUE(video != NULL);
570 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000571 }
572
573 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000574 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000575 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000576 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000577 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000578 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000579 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000580 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000581 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
582 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000583 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000584 // Answer should be NULL as no crypto params in offer.
585 ASSERT_TRUE(answer == NULL);
586 }
587
588 void VerifyAnswerFromCryptoOffer() {
589 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000590 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000591 options.bundle_enabled = true;
592 scoped_ptr<JsepSessionDescription> offer(
593 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
594 ASSERT_TRUE(offer.get() != NULL);
595 VerifyCryptoParams(offer->description());
596 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000597 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000598 ASSERT_TRUE(answer.get() != NULL);
599 VerifyCryptoParams(answer->description());
600 }
601
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000602 void SetAndVerifyNumUnsignalledRecvStreams(
603 int value_set, int value_expected) {
604 constraints_.reset(new FakeConstraints());
605 constraints_->AddOptional(
606 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
607 value_set);
608 session_.reset();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000609 Init();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000610 mediastream_signaling_.SendAudioVideoStream1();
611 SessionDescriptionInterface* offer = CreateOffer();
612
613 SetLocalDescriptionWithoutError(offer);
614
615 video_channel_ = media_engine_->GetVideoChannel(0);
616
617 ASSERT_TRUE(video_channel_ != NULL);
618 cricket::VideoOptions video_options;
619 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
620 EXPECT_EQ(value_expected,
621 video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1));
622 }
623
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000624 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
625 const cricket::SessionDescription* desc2,
626 bool expect_equal) {
627 if (desc1->contents().size() != desc2->contents().size()) {
628 EXPECT_FALSE(expect_equal);
629 return;
630 }
631
632 const cricket::ContentInfos& contents = desc1->contents();
633 cricket::ContentInfos::const_iterator it = contents.begin();
634
635 for (; it != contents.end(); ++it) {
636 const cricket::TransportDescription* transport_desc1 =
637 desc1->GetTransportDescriptionByName(it->name);
638 const cricket::TransportDescription* transport_desc2 =
639 desc2->GetTransportDescriptionByName(it->name);
640 if (!transport_desc1 || !transport_desc2) {
641 EXPECT_FALSE(expect_equal);
642 return;
643 }
644 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
645 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
646 EXPECT_FALSE(expect_equal);
647 return;
648 }
649 }
650 EXPECT_TRUE(expect_equal);
651 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000652
653 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
654 std::string *sdp) {
655 const cricket::SessionDescription* desc = current_desc->description();
656 EXPECT_TRUE(current_desc->ToString(sdp));
657
658 const cricket::ContentInfos& contents = desc->contents();
659 cricket::ContentInfos::const_iterator it = contents.begin();
660 // Replace ufrag and pwd lines with empty strings.
661 for (; it != contents.end(); ++it) {
662 const cricket::TransportDescription* transport_desc =
663 desc->GetTransportDescriptionByName(it->name);
664 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
665 + "\r\n";
666 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
667 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000668 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000669 "", 0,
670 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000671 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000672 "", 0,
673 sdp);
674 }
675 }
676
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000677 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
678 const std::string& modified_ice_ufrag,
679 const std::string& modified_ice_pwd,
680 std::string* sdp) {
681 const cricket::SessionDescription* desc = current_desc->description();
682 EXPECT_TRUE(current_desc->ToString(sdp));
683
684 const cricket::ContentInfos& contents = desc->contents();
685 cricket::ContentInfos::const_iterator it = contents.begin();
686 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
687 // |modified_ice_pwd| strings.
688 for (; it != contents.end(); ++it) {
689 const cricket::TransportDescription* transport_desc =
690 desc->GetTransportDescriptionByName(it->name);
691 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
692 + "\r\n";
693 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
694 + "\r\n";
695 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
696 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000697 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000698 mod_ufrag.c_str(), mod_ufrag.length(),
699 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000700 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000701 mod_pwd.c_str(), mod_pwd.length(),
702 sdp);
703 }
704 }
705
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000706 // Creates a remote offer and and applies it as a remote description,
707 // creates a local answer and applies is as a local description.
708 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
709 // to decide which local and remote streams to create.
710 void CreateAndSetRemoteOfferAndLocalAnswer() {
711 SessionDescriptionInterface* offer = CreateRemoteOffer();
712 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000713 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000714 SetLocalDescriptionWithoutError(answer);
715 }
716 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
717 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
718 }
719 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
720 BaseSession::State expected_state) {
721 SetLocalDescriptionWithoutError(desc);
722 EXPECT_EQ(expected_state, session_->state());
723 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000724 void SetLocalDescriptionExpectError(const std::string& action,
725 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000726 SessionDescriptionInterface* desc) {
727 std::string error;
728 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000729 std::string sdp_type = "local ";
730 sdp_type.append(action);
731 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000732 EXPECT_NE(std::string::npos, error.find(expected_error));
733 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000734 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
735 SessionDescriptionInterface* desc) {
736 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
737 expected_error, desc);
738 }
739 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
740 SessionDescriptionInterface* desc) {
741 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
742 expected_error, desc);
743 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000744 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
745 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
746 }
747 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
748 BaseSession::State expected_state) {
749 SetRemoteDescriptionWithoutError(desc);
750 EXPECT_EQ(expected_state, session_->state());
751 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000752 void SetRemoteDescriptionExpectError(const std::string& action,
753 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754 SessionDescriptionInterface* desc) {
755 std::string error;
756 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000757 std::string sdp_type = "remote ";
758 sdp_type.append(action);
759 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760 EXPECT_NE(std::string::npos, error.find(expected_error));
761 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000762 void SetRemoteDescriptionOfferExpectError(
763 const std::string& expected_error, SessionDescriptionInterface* desc) {
764 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
765 expected_error, desc);
766 }
767 void SetRemoteDescriptionPranswerExpectError(
768 const std::string& expected_error, SessionDescriptionInterface* desc) {
769 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
770 expected_error, desc);
771 }
772 void SetRemoteDescriptionAnswerExpectError(
773 const std::string& expected_error, SessionDescriptionInterface* desc) {
774 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
775 expected_error, desc);
776 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000777
778 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
779 SessionDescriptionInterface** nocrypto_answer) {
780 // Create a SDP without Crypto.
781 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000782 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000783 options.bundle_enabled = true;
784 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
785 ASSERT_TRUE(*offer != NULL);
786 VerifyCryptoParams((*offer)->description());
787
788 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
789 cricket::SEC_DISABLED);
790 EXPECT_TRUE(*nocrypto_answer != NULL);
791 }
792
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000793 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
794 SessionDescriptionInterface** nodtls_answer) {
795 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000796 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000797 options.bundle_enabled = true;
798
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000799 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000800 CreateRemoteOffer(options, cricket::SEC_ENABLED));
801
802 *nodtls_answer =
803 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
804 EXPECT_TRUE(*nodtls_answer != NULL);
805 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
806 VerifyCryptoParams((*nodtls_answer)->description());
807
808 SetFactoryDtlsSrtp();
809 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
810 ASSERT_TRUE(*offer != NULL);
811 VerifyFingerprintStatus((*offer)->description(), true);
812 VerifyCryptoParams((*offer)->description());
813 }
814
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000815 JsepSessionDescription* CreateRemoteOfferWithVersion(
816 cricket::MediaSessionOptions options,
817 cricket::SecurePolicy secure_policy,
818 const std::string& session_version,
819 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000820 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000821 const cricket::SessionDescription* cricket_desc = NULL;
822 if (current_desc) {
823 cricket_desc = current_desc->description();
824 session_id = current_desc->session_id();
825 }
826
827 desc_factory_->set_secure(secure_policy);
828 JsepSessionDescription* offer(
829 new JsepSessionDescription(JsepSessionDescription::kOffer));
830 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
831 session_id, session_version)) {
832 delete offer;
833 offer = NULL;
834 }
835 return offer;
836 }
837 JsepSessionDescription* CreateRemoteOffer(
838 cricket::MediaSessionOptions options) {
839 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
840 kSessionVersion, NULL);
841 }
842 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000843 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
844 return CreateRemoteOfferWithVersion(
845 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000846 }
847 JsepSessionDescription* CreateRemoteOffer(
848 cricket::MediaSessionOptions options,
849 const SessionDescriptionInterface* current_desc) {
850 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
851 kSessionVersion, current_desc);
852 }
853
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000854 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
855 const char* sctp_stream_name, int new_port,
856 cricket::MediaSessionOptions options) {
857 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000858 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
859 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000860 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
861 }
862
863 // Takes ownership of offer_basis (and deletes it).
864 JsepSessionDescription* ChangeSDPSctpPort(
865 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
866 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
867 // SessionDescription from the mutated string.
868 const char* default_port_str = "5000";
869 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000870 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000871 std::string offer_str;
872 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000873 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000874 new_port_str, strlen(new_port_str),
875 &offer_str);
876 JsepSessionDescription* offer = new JsepSessionDescription(
877 offer_basis->type());
878 delete offer_basis;
879 offer->Initialize(offer_str, NULL);
880 return offer;
881 }
882
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
884 // before this function to decide which streams to create.
885 JsepSessionDescription* CreateRemoteOffer() {
886 cricket::MediaSessionOptions options;
887 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
888 return CreateRemoteOffer(options, session_->remote_description());
889 }
890
891 JsepSessionDescription* CreateRemoteAnswer(
892 const SessionDescriptionInterface* offer,
893 cricket::MediaSessionOptions options,
894 cricket::SecurePolicy policy) {
895 desc_factory_->set_secure(policy);
896 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000897 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898 JsepSessionDescription* answer(
899 new JsepSessionDescription(JsepSessionDescription::kAnswer));
900 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
901 options, NULL),
902 session_id, kSessionVersion)) {
903 delete answer;
904 answer = NULL;
905 }
906 return answer;
907 }
908
909 JsepSessionDescription* CreateRemoteAnswer(
910 const SessionDescriptionInterface* offer,
911 cricket::MediaSessionOptions options) {
912 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
913 }
914
915 // Creates an answer session description with streams based on
916 // |mediastream_signaling_|. Call
917 // mediastream_signaling_.UseOptionsWithStreamX() before this function
918 // to decide which streams to create.
919 JsepSessionDescription* CreateRemoteAnswer(
920 const SessionDescriptionInterface* offer) {
921 cricket::MediaSessionOptions options;
922 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
923 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
924 }
925
926 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000927 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000928 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000929 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000930
931 PeerConnectionInterface::RTCOfferAnswerOptions options;
932 options.use_rtp_mux = bundle;
933
934 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000935 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
936 // and answer.
937 SetLocalDescriptionWithoutError(offer);
938
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000939 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000940 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941 std::string sdp;
942 EXPECT_TRUE(answer->ToString(&sdp));
943
944 size_t expected_candidate_num = 2;
945 if (!rtcp_mux) {
946 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
947 // for rtp and rtcp.
948 expected_candidate_num = 4;
949 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000950 const std::string kRtcpMux = "a=rtcp-mux";
951 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000952 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953 kXRtcpMux.c_str(), kXRtcpMux.length(),
954 &sdp);
955 }
956
957 SessionDescriptionInterface* new_answer = CreateSessionDescription(
958 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000959
960 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000961 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000962 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
963 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
964 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
965 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
966 cricket::Candidate c0 = observer_.mline_0_candidates_[i];
967 cricket::Candidate c1 = observer_.mline_1_candidates_[i];
968 if (bundle) {
969 EXPECT_TRUE(c0.IsEquivalent(c1));
970 } else {
971 EXPECT_FALSE(c0.IsEquivalent(c1));
972 }
973 }
974 }
975 // Tests that we can only send DTMF when the dtmf codec is supported.
976 void TestCanInsertDtmf(bool can) {
977 if (can) {
978 InitWithDtmfCodec();
979 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000980 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000981 }
982 mediastream_signaling_.SendAudioVideoStream1();
983 CreateAndSetRemoteOfferAndLocalAnswer();
984 EXPECT_FALSE(session_->CanInsertDtmf(""));
985 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
986 }
987
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000988 // Helper class to configure loopback network and verify Best
989 // Connection using right IP protocol for TestLoopbackCall
990 // method. LoopbackNetworkManager applies firewall rules to block
991 // all ping traffic once ICE completed, and remove them to observe
992 // ICE reconnected again. This LoopbackNetworkConfiguration struct
993 // verifies the best connection is using the right IP protocol after
994 // initial ICE convergences.
995
996 class LoopbackNetworkConfiguration {
997 public:
998 LoopbackNetworkConfiguration()
999 : test_ipv6_network_(false),
1000 test_extra_ipv4_network_(false),
1001 best_connection_after_initial_ice_converged_(1, 0) {}
1002
1003 // Used to track the expected best connection count in each IP protocol.
1004 struct ExpectedBestConnection {
1005 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1006 : ipv4_count_(ipv4_count),
1007 ipv6_count_(ipv6_count) {}
1008
1009 int ipv4_count_;
1010 int ipv6_count_;
1011 };
1012
1013 bool test_ipv6_network_;
1014 bool test_extra_ipv4_network_;
1015 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1016
1017 void VerifyBestConnectionAfterIceConverge(
1018 const FakeMetricsObserver& metrics_observer) const {
1019 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1020 }
1021
1022 private:
1023 void Verify(const FakeMetricsObserver& metrics_observer,
1024 const ExpectedBestConnection& expected) const {
1025 EXPECT_EQ(
1026 metrics_observer
1027 .peer_connection_metrics_counters_[webrtc::kBestConnections_IPv4],
1028 expected.ipv4_count_);
1029 EXPECT_EQ(
1030 metrics_observer
1031 .peer_connection_metrics_counters_[webrtc::kBestConnections_IPv6],
1032 expected.ipv6_count_);
1033 }
1034 };
1035
1036 class LoopbackNetworkManager {
1037 public:
1038 LoopbackNetworkManager(WebRtcSessionTest* session,
1039 const LoopbackNetworkConfiguration& config)
1040 : config_(config) {
1041 session->AddInterface(
1042 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1043 if (config_.test_extra_ipv4_network_) {
1044 session->AddInterface(
1045 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1046 }
1047 if (config_.test_ipv6_network_) {
1048 session->AddInterface(
1049 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1050 }
1051 }
1052
1053 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1054 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1055 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1056 if (config_.test_extra_ipv4_network_) {
1057 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1058 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1059 }
1060 if (config_.test_ipv6_network_) {
1061 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1062 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1063 }
1064 }
1065
1066 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1067
1068 private:
1069 LoopbackNetworkConfiguration config_;
1070 };
1071
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001072 // The method sets up a call from the session to itself, in a loopback
1073 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001074 // disconnection, and then a permanent disconnection.
1075 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001076 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1077 // While running the call, this method also checks if the session goes through
1078 // the correct sequence of ICE states when a connection is established,
1079 // broken, and re-established.
1080 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001081 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1082 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001083 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001084
1085 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1086 LoopbackNetworkManager loopback_network_manager(this, config);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001087 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001088 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001089 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001090
1091 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1092 observer_.ice_gathering_state_);
1093 SetLocalDescriptionWithoutError(offer);
1094 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1095 observer_.ice_connection_state_);
1096 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
1097 observer_.ice_gathering_state_,
1098 kIceCandidatesTimeout);
1099 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1100 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
1101 observer_.ice_gathering_state_,
1102 kIceCandidatesTimeout);
1103
1104 std::string sdp;
1105 offer->ToString(&sdp);
1106 SessionDescriptionInterface* desc =
1107 webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer, sdp);
1108 ASSERT_TRUE(desc != NULL);
1109 SetRemoteDescriptionWithoutError(desc);
1110
1111 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
1112 observer_.ice_connection_state_,
1113 kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001114
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001115 // The ice connection state is "Connected" too briefly to catch in a test.
1116 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001117 observer_.ice_connection_state_,
1118 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001119
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001120 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001121 // Adding firewall rule to block ping requests, which should cause
1122 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001123
1124 loopback_network_manager.ApplyFirewallRules(fss_.get());
1125
1126 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001127 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1128 observer_.ice_connection_state_,
1129 kIceCandidatesTimeout);
1130
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001131 metrics_observer_.Reset();
1132
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001133 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001134 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001135 // Session is automatically calling OnSignalingReady after creation of
1136 // new portallocator session which will allocate new set of candidates.
1137
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001138 LOG(LS_INFO) << "Firewall Rules cleared";
1139
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001140 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001141 observer_.ice_connection_state_,
1142 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001143
1144 // Now we block ping requests and wait until the ICE connection transitions
1145 // to the Failed state. This will take at least 30 seconds because it must
1146 // wait for the Port to timeout.
1147 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001148
1149 loopback_network_manager.ApplyFirewallRules(fss_.get());
1150 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001151 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001152 observer_.ice_connection_state_,
1153 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001154 }
1155
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001156 void TestLoopbackCall() {
1157 LoopbackNetworkConfiguration config;
1158 TestLoopbackCall(config);
1159 }
1160
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001161 void VerifyTransportType(const std::string& content_name,
1162 cricket::TransportProtocol protocol) {
1163 const cricket::Transport* transport = session_->GetTransport(content_name);
1164 ASSERT_TRUE(transport != NULL);
1165 EXPECT_EQ(protocol, transport->protocol());
1166 }
1167
1168 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1169 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001170 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1171 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1172
1173 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001174 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1175 codecs.push_back(kCNCodec1);
1176 codecs.push_back(kCNCodec2);
1177 media_engine_->SetAudioCodecs(codecs);
1178 desc_factory_->set_audio_codecs(codecs);
1179 }
1180
1181 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1182 const cricket::ContentDescription* description = content->description;
1183 ASSERT(description != NULL);
1184 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001185 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001186 ASSERT(audio_content_desc != NULL);
1187 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1188 if (audio_content_desc->codecs()[i].name == "CN")
1189 return false;
1190 }
1191 return true;
1192 }
1193
1194 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001195 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001196 dci.reliable = false;
1197 session_->CreateDataChannel("datachannel", &dci);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001198 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001199 SetLocalDescriptionWithoutError(offer);
1200 }
1201
wu@webrtc.org91053e72013-08-10 07:18:04 +00001202 void VerifyMultipleAsyncCreateDescription(
1203 bool success, CreateSessionDescriptionRequest::Type type) {
henrike@webrtc.org7666db72013-08-22 14:45:42 +00001204 InitWithDtls(!success);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001205 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001206 if (type == CreateSessionDescriptionRequest::kAnswer) {
1207 cricket::MediaSessionOptions options;
1208 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001209 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001210 ASSERT_TRUE(offer.get() != NULL);
1211 SetRemoteDescriptionWithoutError(offer.release());
1212 }
1213
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001214 PeerConnectionInterface::RTCOfferAnswerOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001215 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001216 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001217 observers[kNumber];
1218 for (int i = 0; i < kNumber; ++i) {
1219 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1220 if (type == CreateSessionDescriptionRequest::kOffer) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001221 session_->CreateOffer(observers[i], options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001222 } else {
1223 session_->CreateAnswer(observers[i], NULL);
1224 }
1225 }
1226
1227 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1228 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1229 WebRtcSessionCreateSDPObserverForTest::kFailed;
1230
1231 for (int i = 0; i < kNumber; ++i) {
1232 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1233 if (success) {
1234 EXPECT_TRUE(observers[i]->description() != NULL);
1235 } else {
1236 EXPECT_TRUE(observers[i]->description() == NULL);
1237 }
1238 }
1239 }
1240
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001241 void ConfigureAllocatorWithTurn() {
1242 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1243 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
1244 relay_server.credentials = credentials;
1245 relay_server.ports.push_back(cricket::ProtocolAddress(
1246 kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1247 allocator_->AddRelay(relay_server);
1248 allocator_->set_step_delay(cricket::kMinimumStepDelay);
1249 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
jiayl@webrtc.orgdacdd942015-01-23 17:33:34 +00001250 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001251 }
1252
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001253 cricket::FakeMediaEngine* media_engine_;
1254 cricket::FakeDataEngine* data_engine_;
1255 cricket::FakeDeviceManager* device_manager_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001256 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
1257 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1258 rtc::scoped_ptr<rtc::SSLIdentity> identity_;
1259 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1260 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1261 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1262 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1263 rtc::SocketServerScope ss_scope_;
1264 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001265 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001266 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001267 rtc::FakeNetworkManager network_manager_;
1268 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001269 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001270 rtc::scoped_ptr<FakeConstraints> constraints_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001271 FakeMediaStreamSignaling mediastream_signaling_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001272 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001273 MockIceObserver observer_;
1274 cricket::FakeVideoMediaChannel* video_channel_;
1275 cricket::FakeVoiceMediaChannel* voice_channel_;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001276 FakeMetricsObserver metrics_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001277};
1278
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001279TEST_F(WebRtcSessionTest, TestInitializeWithDtls) {
1280 InitWithDtls();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001281 // SDES is disabled when DTLS is on.
1282 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001283}
1284
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001285TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001286 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001287 // SDES is required if DTLS is off.
1288 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001289}
1290
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001291TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1292 TestSessionCandidatesWithBundleRtcpMux(false, false);
1293}
1294
1295// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1296// with rtcp-mux and/or bundle.
1297TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1298 TestSessionCandidatesWithBundleRtcpMux(false, true);
1299}
1300
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001301TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1302 TestSessionCandidatesWithBundleRtcpMux(true, true);
1303}
1304
1305TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001306 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1307 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001308 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001309 mediastream_signaling_.SendAudioVideoStream1();
1310 InitiateCall();
1311 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1312 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1313 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1314}
1315
1316TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001317 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1318 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001319 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001320 rtc::FP_UDP,
1321 rtc::FD_ANY,
1322 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001323 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324 mediastream_signaling_.SendAudioVideoStream1();
1325 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001326 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001327 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1328 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1329 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1330}
1331
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001332// Test session delivers no candidates gathered when constraint set to "none".
1333TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1334 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001335 InitWithIceTransport(PeerConnectionInterface::kNone);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001336 mediastream_signaling_.SendAudioVideoStream1();
1337 InitiateCall();
1338 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1339 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1340 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1341}
1342
1343// Test session delivers only relay candidates gathered when constaint set to
1344// "relay".
1345TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1346 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1347 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001348 InitWithIceTransport(PeerConnectionInterface::kRelay);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001349 mediastream_signaling_.SendAudioVideoStream1();
1350 InitiateCall();
1351 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1352 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1353 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1354 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1355 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1356 observer_.mline_0_candidates_[i].type());
1357 }
1358 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1359 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1360 observer_.mline_1_candidates_[i].type());
1361 }
1362}
1363
1364// Test session delivers all candidates gathered when constaint set to "all".
1365TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1366 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001367 InitWithIceTransport(PeerConnectionInterface::kAll);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001368 mediastream_signaling_.SendAudioVideoStream1();
1369 InitiateCall();
1370 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1371 // Host + STUN. By default allocator is disabled to gather relay candidates.
1372 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1373 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1374}
1375
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001376TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001377 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001378 SessionDescriptionInterface* offer = NULL;
1379 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1380 std::string unknown_action;
1381 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1382 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1383}
1384
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001385// Test creating offers and receive answers and make sure the
1386// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001387TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001388 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001389 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001390 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001391 const std::string session_id_orig = offer->session_id();
1392 const std::string session_version_orig = offer->session_version();
1393 SetLocalDescriptionWithoutError(offer);
1394
1395 mediastream_signaling_.SendAudioVideoStream2();
1396 SessionDescriptionInterface* answer =
1397 CreateRemoteAnswer(session_->local_description());
1398 SetRemoteDescriptionWithoutError(answer);
1399
1400 video_channel_ = media_engine_->GetVideoChannel(0);
1401 voice_channel_ = media_engine_->GetVoiceChannel(0);
1402
1403 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1404 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1405
1406 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1407 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1408
1409 ASSERT_EQ(1u, video_channel_->send_streams().size());
1410 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1411 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1412 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1413
1414 // Create new offer without send streams.
1415 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001416 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001417
1418 // Verify the session id is the same and the session version is
1419 // increased.
1420 EXPECT_EQ(session_id_orig, offer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001421 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1422 rtc::FromString<uint64>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001423
1424 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001425 EXPECT_EQ(0u, video_channel_->send_streams().size());
1426 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001427
1428 mediastream_signaling_.SendAudioVideoStream2();
1429 answer = CreateRemoteAnswer(session_->local_description());
1430 SetRemoteDescriptionWithoutError(answer);
1431
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001432 // Make sure the receive streams have not changed.
1433 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1434 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1435 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1436 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1437}
1438
1439// Test receiving offers and creating answers and make sure the
1440// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001441TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001442 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001443 mediastream_signaling_.SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001444 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001445 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001446 SetRemoteDescriptionWithoutError(offer);
1447
1448 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001449 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001450 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001451 SetLocalDescriptionWithoutError(answer);
1452
1453 const std::string session_id_orig = answer->session_id();
1454 const std::string session_version_orig = answer->session_version();
1455
1456 video_channel_ = media_engine_->GetVideoChannel(0);
1457 voice_channel_ = media_engine_->GetVoiceChannel(0);
1458
1459 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1460 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1461
1462 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1463 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1464
1465 ASSERT_EQ(1u, video_channel_->send_streams().size());
1466 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1467 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1468 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1469
1470 mediastream_signaling_.SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001471 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001472 SetRemoteDescriptionWithoutError(offer);
1473
1474 // Answer by turning off all send streams.
1475 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001476 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001477
1478 // Verify the session id is the same and the session version is
1479 // increased.
1480 EXPECT_EQ(session_id_orig, answer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001481 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1482 rtc::FromString<uint64>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001483 SetLocalDescriptionWithoutError(answer);
1484
1485 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1486 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1487 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1488 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1489 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1490 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1491
1492 // Make sure we have no send streams.
1493 EXPECT_EQ(0u, video_channel_->send_streams().size());
1494 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1495}
1496
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001497TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001498 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001499 media_engine_->set_fail_create_channel(true);
1500
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001501 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001502 ASSERT_TRUE(offer != NULL);
1503 // SetRemoteDescription and SetLocalDescription will take the ownership of
1504 // the offer.
1505 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001506 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001507 ASSERT_TRUE(offer != NULL);
1508 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1509}
1510
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001511//
1512// Tests for creating/setting SDP under different SDES/DTLS polices:
1513//
1514// --DTLS off and SDES on
1515// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1516// set local/remote offer/answer with crypto --> success
1517// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1518// failure
1519// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1520// failure
1521// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1522// failure
1523//
1524// --DTLS on and SDES off
1525// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1526// set local/remote offer/answer with DTLS fingerprint --> success
1527// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1528// fingerprint --> failure
1529// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1530// --> failure
1531// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1532// --> failure
1533//
1534// --Encryption disabled: DTLS off and SDES off
1535// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1536// answer without SDES or DTLS --> success
1537// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1538// answer without SDES or DTLS --> success
1539//
1540
1541// Test that we return a failure when applying a remote/local offer that doesn't
1542// have cryptos enabled when DTLS is off.
1543TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001544 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001545 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001546 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001547 JsepSessionDescription* offer = CreateRemoteOffer(
1548 options, cricket::SEC_DISABLED);
1549 ASSERT_TRUE(offer != NULL);
1550 VerifyNoCryptoParams(offer->description(), false);
1551 // SetRemoteDescription and SetLocalDescription will take the ownership of
1552 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001553 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001554 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1555 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001556 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001557}
1558
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001559// Test that we return a failure when applying a local answer that doesn't have
1560// cryptos enabled when DTLS is off.
1561TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001562 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001563 SessionDescriptionInterface* offer = NULL;
1564 SessionDescriptionInterface* answer = NULL;
1565 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1566 // SetRemoteDescription and SetLocalDescription will take the ownership of
1567 // the offer.
1568 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001569 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001570}
1571
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001572// Test we will return fail when apply an remote answer that doesn't have
1573// crypto enabled when DTLS is off.
1574TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001575 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001576 SessionDescriptionInterface* offer = NULL;
1577 SessionDescriptionInterface* answer = NULL;
1578 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1579 // SetRemoteDescription and SetLocalDescription will take the ownership of
1580 // the offer.
1581 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001582 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001583}
1584
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001585// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1586// and that we return an answer with a DTLS fingerprint.
1587TEST_F(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001588 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001589 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001590 InitWithDtls();
1591 SetFactoryDtlsSrtp();
1592 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001593 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001594 JsepSessionDescription* offer =
1595 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001596 ASSERT_TRUE(offer != NULL);
1597 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001598 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001599
1600 // SetRemoteDescription will take the ownership of the offer.
1601 SetRemoteDescriptionWithoutError(offer);
1602
1603 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001604 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001605 ASSERT_TRUE(answer != NULL);
1606 VerifyFingerprintStatus(answer->description(), true);
1607 // Check that we don't have an a=crypto line in the answer.
1608 VerifyNoCryptoParams(answer->description(), true);
1609
1610 // Now set the local description, which should work, even without a=crypto.
1611 SetLocalDescriptionWithoutError(answer);
1612}
1613
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001614// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1615// and then we accept a remote answer with a DTLS fingerprint successfully.
1616TEST_F(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001617 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001618 mediastream_signaling_.SendAudioVideoStream1();
1619 InitWithDtls();
1620 SetFactoryDtlsSrtp();
1621
1622 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001623 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001624 ASSERT_TRUE(offer != NULL);
1625 VerifyFingerprintStatus(offer->description(), true);
1626 // Check that we don't have an a=crypto line in the offer.
1627 VerifyNoCryptoParams(offer->description(), true);
1628
1629 // Now set the local description, which should work, even without a=crypto.
1630 SetLocalDescriptionWithoutError(offer);
1631
1632 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001633 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001634 JsepSessionDescription* answer =
1635 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1636 ASSERT_TRUE(answer != NULL);
1637 VerifyFingerprintStatus(answer->description(), true);
1638 VerifyNoCryptoParams(answer->description(), true);
1639
1640 // SetRemoteDescription will take the ownership of the answer.
1641 SetRemoteDescriptionWithoutError(answer);
1642}
1643
1644// Test that if we support DTLS and the other side didn't offer a fingerprint,
1645// we will fail to set the remote description.
1646TEST_F(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001647 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001648 InitWithDtls();
1649 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001650 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001651 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001652 JsepSessionDescription* offer = CreateRemoteOffer(
1653 options, cricket::SEC_REQUIRED);
1654 ASSERT_TRUE(offer != NULL);
1655 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001656 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001657
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001658 // SetRemoteDescription will take the ownership of the offer.
1659 SetRemoteDescriptionOfferExpectError(
1660 kSdpWithoutDtlsFingerprint, offer);
1661
1662 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1663 // SetLocalDescription will take the ownership of the offer.
1664 SetLocalDescriptionOfferExpectError(
1665 kSdpWithoutDtlsFingerprint, offer);
1666}
1667
1668// Test that we return a failure when applying a local answer that doesn't have
1669// a DTLS fingerprint when DTLS is required.
1670TEST_F(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001671 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001672 InitWithDtls();
1673 SessionDescriptionInterface* offer = NULL;
1674 SessionDescriptionInterface* answer = NULL;
1675 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1676
1677 // SetRemoteDescription and SetLocalDescription will take the ownership of
1678 // the offer and answer.
1679 SetRemoteDescriptionWithoutError(offer);
1680 SetLocalDescriptionAnswerExpectError(
1681 kSdpWithoutDtlsFingerprint, answer);
1682}
1683
1684// Test that we return a failure when applying a remote answer that doesn't have
1685// a DTLS fingerprint when DTLS is required.
1686TEST_F(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001687 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001688 InitWithDtls();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001689 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001690 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001691 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001692 JsepSessionDescription* answer =
1693 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
1694
1695 // SetRemoteDescription and SetLocalDescription will take the ownership of
1696 // the offer and answer.
1697 SetLocalDescriptionWithoutError(offer);
1698 SetRemoteDescriptionAnswerExpectError(
1699 kSdpWithoutDtlsFingerprint, answer);
1700}
1701
1702// Test that we create a local offer without SDES or DTLS and accept a remote
1703// answer without SDES or DTLS when encryption is disabled.
1704TEST_F(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
1705 mediastream_signaling_.SendAudioVideoStream1();
1706 options_.disable_encryption = true;
1707 InitWithDtls();
1708
1709 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001710 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001711 ASSERT_TRUE(offer != NULL);
1712 VerifyFingerprintStatus(offer->description(), false);
1713 // Check that we don't have an a=crypto line in the offer.
1714 VerifyNoCryptoParams(offer->description(), false);
1715
1716 // Now set the local description, which should work, even without a=crypto.
1717 SetLocalDescriptionWithoutError(offer);
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* answer =
1722 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1723 ASSERT_TRUE(answer != NULL);
1724 VerifyFingerprintStatus(answer->description(), false);
1725 VerifyNoCryptoParams(answer->description(), false);
1726
1727 // SetRemoteDescription will take the ownership of the answer.
1728 SetRemoteDescriptionWithoutError(answer);
1729}
1730
1731// Test that we create a local answer without SDES or DTLS and accept a remote
1732// offer without SDES or DTLS when encryption is disabled.
1733TEST_F(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
1734 options_.disable_encryption = true;
1735 InitWithDtls();
1736
1737 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001738 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001739 JsepSessionDescription* offer =
1740 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1741 ASSERT_TRUE(offer != NULL);
1742 VerifyFingerprintStatus(offer->description(), false);
1743 VerifyNoCryptoParams(offer->description(), false);
1744
1745 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001746 SetRemoteDescriptionWithoutError(offer);
1747
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001748 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001749 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001750 ASSERT_TRUE(answer != NULL);
1751 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001752 // Check that we don't have an a=crypto line in the answer.
1753 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001754
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001755 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001756 SetLocalDescriptionWithoutError(answer);
1757}
1758
1759TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001760 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001761 mediastream_signaling_.SendNothing();
1762 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001763 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001764 SetLocalDescriptionWithoutError(offer);
1765
1766 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001767 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768 SetLocalDescriptionWithoutError(offer2);
1769}
1770
1771TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001772 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001773 mediastream_signaling_.SendNothing();
1774 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001775 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776 SetRemoteDescriptionWithoutError(offer);
1777
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001778 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001779 SetRemoteDescriptionWithoutError(offer2);
1780}
1781
1782TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001783 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001784 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001785 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001787 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001788 SetRemoteDescriptionOfferExpectError(
1789 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001790}
1791
1792TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001793 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001794 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001795 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001796 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001797 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001798 SetLocalDescriptionOfferExpectError(
1799 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001800}
1801
1802TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001803 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001804 mediastream_signaling_.SendNothing();
1805 SessionDescriptionInterface* offer = CreateRemoteOffer();
1806 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1807
1808 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001809 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1811 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1812
1813 mediastream_signaling_.SendAudioVideoStream1();
1814 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001815 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001816 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1817
1818 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1819
1820 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001821 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001822 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1823}
1824
1825TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001826 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001827 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001828 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001829 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1830
1831 JsepSessionDescription* pranswer =
1832 CreateRemoteAnswer(session_->local_description());
1833 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1834
1835 SetRemoteDescriptionExpectState(pranswer,
1836 BaseSession::STATE_RECEIVEDPRACCEPT);
1837
1838 mediastream_signaling_.SendAudioVideoStream1();
1839 JsepSessionDescription* pranswer2 =
1840 CreateRemoteAnswer(session_->local_description());
1841 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1842
1843 SetRemoteDescriptionExpectState(pranswer2,
1844 BaseSession::STATE_RECEIVEDPRACCEPT);
1845
1846 mediastream_signaling_.SendAudioVideoStream2();
1847 SessionDescriptionInterface* answer =
1848 CreateRemoteAnswer(session_->local_description());
1849 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1850}
1851
1852TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001853 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001854 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001855 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1856
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857 SessionDescriptionInterface* answer =
1858 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001859 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1860 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001861}
1862
1863TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001864 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001865 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001866 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1867
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001868 SessionDescriptionInterface* answer =
1869 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001870 SetRemoteDescriptionAnswerExpectError(
1871 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001872}
1873
1874TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001875 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001876 mediastream_signaling_.SendAudioVideoStream1();
1877
1878 cricket::Candidate candidate;
1879 candidate.set_component(1);
1880 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1881
1882 // Fail since we have not set a offer description.
1883 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1884
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001885 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001886 SetLocalDescriptionWithoutError(offer);
1887 // Candidate should be allowed to add before remote description.
1888 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1889 candidate.set_component(2);
1890 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1891 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1892
1893 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1894 session_->local_description());
1895 SetRemoteDescriptionWithoutError(answer);
1896
1897 // Verifying the candidates are copied properly from internal vector.
1898 const SessionDescriptionInterface* remote_desc =
1899 session_->remote_description();
1900 ASSERT_TRUE(remote_desc != NULL);
1901 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1902 const IceCandidateCollection* candidates =
1903 remote_desc->candidates(kMediaContentIndex0);
1904 ASSERT_EQ(2u, candidates->count());
1905 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1906 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1907 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1908 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1909
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001910 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1911 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001912 candidate.set_component(2);
1913 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1914 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001915 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001916
1917 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1918 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1919}
1920
1921// Test that a remote candidate is added to the remote session description and
1922// that it is retained if the remote session description is changed.
1923TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001924 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001925 cricket::Candidate candidate1;
1926 candidate1.set_component(1);
1927 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1928 candidate1);
1929 mediastream_signaling_.SendAudioVideoStream1();
1930 CreateAndSetRemoteOfferAndLocalAnswer();
1931
1932 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1933 const SessionDescriptionInterface* remote_desc =
1934 session_->remote_description();
1935 ASSERT_TRUE(remote_desc != NULL);
1936 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1937 const IceCandidateCollection* candidates =
1938 remote_desc->candidates(kMediaContentIndex0);
1939 ASSERT_EQ(1u, candidates->count());
1940 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1941
1942 // Update the RemoteSessionDescription with a new session description and
1943 // a candidate and check that the new remote session description contains both
1944 // candidates.
1945 SessionDescriptionInterface* offer = CreateRemoteOffer();
1946 cricket::Candidate candidate2;
1947 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1948 candidate2);
1949 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1950 SetRemoteDescriptionWithoutError(offer);
1951
1952 remote_desc = session_->remote_description();
1953 ASSERT_TRUE(remote_desc != NULL);
1954 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1955 candidates = remote_desc->candidates(kMediaContentIndex0);
1956 ASSERT_EQ(2u, candidates->count());
1957 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1958 // Username and password have be updated with the TransportInfo of the
1959 // SessionDescription, won't be equal to the original one.
1960 candidate2.set_username(candidates->at(0)->candidate().username());
1961 candidate2.set_password(candidates->at(0)->candidate().password());
1962 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
1963 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
1964 // No need to verify the username and password.
1965 candidate1.set_username(candidates->at(1)->candidate().username());
1966 candidate1.set_password(candidates->at(1)->candidate().password());
1967 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
1968
1969 // Test that the candidate is ignored if we can add the same candidate again.
1970 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1971}
1972
1973// Test that local candidates are added to the local session description and
1974// that they are retained if the local session description is changed.
1975TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001976 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001977 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001978 mediastream_signaling_.SendAudioVideoStream1();
1979 CreateAndSetRemoteOfferAndLocalAnswer();
1980
1981 const SessionDescriptionInterface* local_desc = session_->local_description();
1982 const IceCandidateCollection* candidates =
1983 local_desc->candidates(kMediaContentIndex0);
1984 ASSERT_TRUE(candidates != NULL);
1985 EXPECT_EQ(0u, candidates->count());
1986
1987 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1988
1989 local_desc = session_->local_description();
1990 candidates = local_desc->candidates(kMediaContentIndex0);
1991 ASSERT_TRUE(candidates != NULL);
1992 EXPECT_LT(0u, candidates->count());
1993 candidates = local_desc->candidates(1);
1994 ASSERT_TRUE(candidates != NULL);
1995 EXPECT_LT(0u, candidates->count());
1996
1997 // Update the session descriptions.
1998 mediastream_signaling_.SendAudioVideoStream1();
1999 CreateAndSetRemoteOfferAndLocalAnswer();
2000
2001 local_desc = session_->local_description();
2002 candidates = local_desc->candidates(kMediaContentIndex0);
2003 ASSERT_TRUE(candidates != NULL);
2004 EXPECT_LT(0u, candidates->count());
2005 candidates = local_desc->candidates(1);
2006 ASSERT_TRUE(candidates != NULL);
2007 EXPECT_LT(0u, candidates->count());
2008}
2009
2010// Test that we can set a remote session description with remote candidates.
2011TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002012 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002013
2014 cricket::Candidate candidate1;
2015 candidate1.set_component(1);
2016 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2017 candidate1);
2018 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002019 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020
2021 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2022 SetRemoteDescriptionWithoutError(offer);
2023
2024 const SessionDescriptionInterface* remote_desc =
2025 session_->remote_description();
2026 ASSERT_TRUE(remote_desc != NULL);
2027 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2028 const IceCandidateCollection* candidates =
2029 remote_desc->candidates(kMediaContentIndex0);
2030 ASSERT_EQ(1u, candidates->count());
2031 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2032
wu@webrtc.org91053e72013-08-10 07:18:04 +00002033 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002034 SetLocalDescriptionWithoutError(answer);
2035}
2036
2037// Test that offers and answers contains ice candidates when Ice candidates have
2038// been gathered.
2039TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002040 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002041 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002042 mediastream_signaling_.SendAudioVideoStream1();
2043 // Ice is started but candidates are not provided until SetLocalDescription
2044 // is called.
2045 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2046 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2047 CreateAndSetRemoteOfferAndLocalAnswer();
2048 // Wait until at least one local candidate has been collected.
2049 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2050 kIceCandidatesTimeout);
2051 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
2052 kIceCandidatesTimeout);
2053
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002054 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2055
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002056 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2057 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
2058 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
2059 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
2060
2061 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2062 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002063 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002064 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2065 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
2066 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
2067 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
2068 SetLocalDescriptionWithoutError(answer);
2069}
2070
2071// Verifies TransportProxy and media channels are created with content names
2072// present in the SessionDescription.
2073TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002074 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002075 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002076 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002077
2078 // CreateOffer creates session description with the content names "audio" and
2079 // "video". Goal is to modify these content names and verify transport channel
2080 // proxy in the BaseSession, as proxies are created with the content names
2081 // present in SDP.
2082 std::string sdp;
2083 EXPECT_TRUE(offer->ToString(&sdp));
2084 const std::string kAudioMid = "a=mid:audio";
2085 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2086 const std::string kVideoMid = "a=mid:video";
2087 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2088
2089 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002090 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091 kAudioMidReplaceStr.c_str(),
2092 kAudioMidReplaceStr.length(),
2093 &sdp);
2094 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002095 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002096 kVideoMidReplaceStr.c_str(),
2097 kVideoMidReplaceStr.length(),
2098 &sdp);
2099
2100 SessionDescriptionInterface* modified_offer =
2101 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2102
2103 SetRemoteDescriptionWithoutError(modified_offer);
2104
2105 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002106 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107 SetLocalDescriptionWithoutError(answer);
2108
2109 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
2110 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
2111 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2112 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2113}
2114
2115// Test that an offer contains the correct media content descriptions based on
2116// the send streams when no constraints have been set.
2117TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002118 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002119 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2120
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002121 ASSERT_TRUE(offer != NULL);
2122 const cricket::ContentInfo* content =
2123 cricket::GetFirstAudioContent(offer->description());
2124 EXPECT_TRUE(content != NULL);
2125 content = cricket::GetFirstVideoContent(offer->description());
2126 EXPECT_TRUE(content == NULL);
2127}
2128
2129// Test that an offer contains the correct media content descriptions based on
2130// the send streams when no constraints have been set.
2131TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002132 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133 // Test Audio only offer.
2134 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002135 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2136
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137 const cricket::ContentInfo* content =
2138 cricket::GetFirstAudioContent(offer->description());
2139 EXPECT_TRUE(content != NULL);
2140 content = cricket::GetFirstVideoContent(offer->description());
2141 EXPECT_TRUE(content == NULL);
2142
2143 // Test Audio / Video offer.
2144 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002145 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002146 content = cricket::GetFirstAudioContent(offer->description());
2147 EXPECT_TRUE(content != NULL);
2148 content = cricket::GetFirstVideoContent(offer->description());
2149 EXPECT_TRUE(content != NULL);
2150}
2151
2152// Test that an offer contains no media content descriptions if
2153// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2154TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002155 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002156 PeerConnectionInterface::RTCOfferAnswerOptions options;
2157 options.offer_to_receive_audio = 0;
2158 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002159
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002160 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002161 CreateOffer(options));
2162
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163 ASSERT_TRUE(offer != NULL);
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 only audio media content descriptions if
2172// kOfferToReceiveAudio constraints are set to true.
2173TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002174 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002175 PeerConnectionInterface::RTCOfferAnswerOptions options;
2176 options.offer_to_receive_audio =
2177 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2178
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002179 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002180 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002181
2182 const cricket::ContentInfo* content =
2183 cricket::GetFirstAudioContent(offer->description());
2184 EXPECT_TRUE(content != NULL);
2185 content = cricket::GetFirstVideoContent(offer->description());
2186 EXPECT_TRUE(content == NULL);
2187}
2188
2189// Test that an offer contains audio and video media content descriptions if
2190// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2191TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002192 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002193 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002194 PeerConnectionInterface::RTCOfferAnswerOptions options;
2195 options.offer_to_receive_audio =
2196 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2197 options.offer_to_receive_video =
2198 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2199
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002200 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002201 CreateOffer(options));
2202
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002203 const cricket::ContentInfo* content =
2204 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002205 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002206
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002207 content = cricket::GetFirstVideoContent(offer->description());
2208 EXPECT_TRUE(content != NULL);
2209
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002210 // Sets constraints to false and verifies that audio/video contents are
2211 // removed.
2212 options.offer_to_receive_audio = 0;
2213 options.offer_to_receive_video = 0;
2214 offer.reset(CreateOffer(options));
2215
2216 content = cricket::GetFirstAudioContent(offer->description());
2217 EXPECT_TRUE(content == NULL);
2218 content = cricket::GetFirstVideoContent(offer->description());
2219 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002220}
2221
2222// Test that an answer can not be created if the last remote description is not
2223// an offer.
2224TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002225 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002226 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002227 SetLocalDescriptionWithoutError(offer);
2228 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2229 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002230 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002231}
2232
2233// Test that an answer contains the correct media content descriptions when no
2234// constraints have been set.
2235TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002236 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002237 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002238 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002239 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002240 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002241 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002242 const cricket::ContentInfo* content =
2243 cricket::GetFirstAudioContent(answer->description());
2244 ASSERT_TRUE(content != NULL);
2245 EXPECT_FALSE(content->rejected);
2246
2247 content = cricket::GetFirstVideoContent(answer->description());
2248 ASSERT_TRUE(content != NULL);
2249 EXPECT_FALSE(content->rejected);
2250}
2251
2252// Test that an answer contains the correct media content descriptions when no
2253// constraints have been set and the offer only contain audio.
2254TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002255 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002256 // Create a remote offer with audio only.
2257 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002258
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002259 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002260 CreateRemoteOffer(options));
2261 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2262 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2263
2264 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002265 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002266 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002267 const cricket::ContentInfo* content =
2268 cricket::GetFirstAudioContent(answer->description());
2269 ASSERT_TRUE(content != NULL);
2270 EXPECT_FALSE(content->rejected);
2271
2272 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2273}
2274
2275// Test that an answer contains the correct media content descriptions when no
2276// constraints have been set.
2277TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002278 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002279 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002280 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002281 SetRemoteDescriptionWithoutError(offer.release());
2282 // Test with a stream with tracks.
2283 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002284 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002285 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002286 const cricket::ContentInfo* content =
2287 cricket::GetFirstAudioContent(answer->description());
2288 ASSERT_TRUE(content != NULL);
2289 EXPECT_FALSE(content->rejected);
2290
2291 content = cricket::GetFirstVideoContent(answer->description());
2292 ASSERT_TRUE(content != NULL);
2293 EXPECT_FALSE(content->rejected);
2294}
2295
2296// Test that an answer contains the correct media content descriptions when
2297// constraints have been set but no stream is sent.
2298TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002299 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002300 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002301 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002302 SetRemoteDescriptionWithoutError(offer.release());
2303
2304 webrtc::FakeConstraints constraints_no_receive;
2305 constraints_no_receive.SetMandatoryReceiveAudio(false);
2306 constraints_no_receive.SetMandatoryReceiveVideo(false);
2307
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002308 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002309 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002310 const cricket::ContentInfo* content =
2311 cricket::GetFirstAudioContent(answer->description());
2312 ASSERT_TRUE(content != NULL);
2313 EXPECT_TRUE(content->rejected);
2314
2315 content = cricket::GetFirstVideoContent(answer->description());
2316 ASSERT_TRUE(content != NULL);
2317 EXPECT_TRUE(content->rejected);
2318}
2319
2320// Test that an answer contains the correct media content descriptions when
2321// constraints have been set and streams are sent.
2322TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002323 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002324 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002325 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326 SetRemoteDescriptionWithoutError(offer.release());
2327
2328 webrtc::FakeConstraints constraints_no_receive;
2329 constraints_no_receive.SetMandatoryReceiveAudio(false);
2330 constraints_no_receive.SetMandatoryReceiveVideo(false);
2331
2332 // Test with a stream with tracks.
2333 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002334 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002335 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002336
2337 // TODO(perkj): Should the direction be set to SEND_ONLY?
2338 const cricket::ContentInfo* content =
2339 cricket::GetFirstAudioContent(answer->description());
2340 ASSERT_TRUE(content != NULL);
2341 EXPECT_FALSE(content->rejected);
2342
2343 // TODO(perkj): Should the direction be set to SEND_ONLY?
2344 content = cricket::GetFirstVideoContent(answer->description());
2345 ASSERT_TRUE(content != NULL);
2346 EXPECT_FALSE(content->rejected);
2347}
2348
2349TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2350 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002351 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002352 PeerConnectionInterface::RTCOfferAnswerOptions options;
2353 options.offer_to_receive_audio =
2354 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2355 options.voice_activity_detection = false;
2356
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002357 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002358 CreateOffer(options));
2359
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002360 const cricket::ContentInfo* content =
2361 cricket::GetFirstAudioContent(offer->description());
2362 EXPECT_TRUE(content != NULL);
2363 EXPECT_TRUE(VerifyNoCNCodecs(content));
2364}
2365
2366TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2367 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002368 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002369 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002370 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002371 SetRemoteDescriptionWithoutError(offer.release());
2372
2373 webrtc::FakeConstraints constraints;
2374 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002375 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002376 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002377 const cricket::ContentInfo* content =
2378 cricket::GetFirstAudioContent(answer->description());
2379 ASSERT_TRUE(content != NULL);
2380 EXPECT_TRUE(VerifyNoCNCodecs(content));
2381}
2382
2383// This test verifies the call setup when remote answer with audio only and
2384// later updates with video.
2385TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002386 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002387 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2388 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2389
2390 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002391 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002392
2393 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002394 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2395
2396 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2397 // and answer;
2398 SetLocalDescriptionWithoutError(offer);
2399 SetRemoteDescriptionWithoutError(answer);
2400
2401 video_channel_ = media_engine_->GetVideoChannel(0);
2402 voice_channel_ = media_engine_->GetVoiceChannel(0);
2403
2404 ASSERT_TRUE(video_channel_ == NULL);
2405
2406 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2407 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2408 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2409
2410 // Let the remote end update the session descriptions, with Audio and Video.
2411 mediastream_signaling_.SendAudioVideoStream2();
2412 CreateAndSetRemoteOfferAndLocalAnswer();
2413
2414 video_channel_ = media_engine_->GetVideoChannel(0);
2415 voice_channel_ = media_engine_->GetVoiceChannel(0);
2416
2417 ASSERT_TRUE(video_channel_ != NULL);
2418 ASSERT_TRUE(voice_channel_ != NULL);
2419
2420 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2421 ASSERT_EQ(1u, video_channel_->send_streams().size());
2422 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2423 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2424 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2425 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2426 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2427 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2428
2429 // Change session back to audio only.
2430 mediastream_signaling_.UseOptionsAudioOnly();
2431 CreateAndSetRemoteOfferAndLocalAnswer();
2432
2433 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2434 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2435 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2436 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2437 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2438}
2439
2440// This test verifies the call setup when remote answer with video only and
2441// later updates with audio.
2442TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002443 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002444 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2445 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2446 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002447 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002448
2449 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002450 options.recv_audio = false;
2451 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002452 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2453 offer, options, cricket::SEC_ENABLED);
2454
2455 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2456 // and answer.
2457 SetLocalDescriptionWithoutError(offer);
2458 SetRemoteDescriptionWithoutError(answer);
2459
2460 video_channel_ = media_engine_->GetVideoChannel(0);
2461 voice_channel_ = media_engine_->GetVoiceChannel(0);
2462
2463 ASSERT_TRUE(voice_channel_ == NULL);
2464 ASSERT_TRUE(video_channel_ != NULL);
2465
2466 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2467 ASSERT_EQ(1u, video_channel_->send_streams().size());
2468 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2469
2470 // Update the session descriptions, with Audio and Video.
2471 mediastream_signaling_.SendAudioVideoStream2();
2472 CreateAndSetRemoteOfferAndLocalAnswer();
2473
2474 voice_channel_ = media_engine_->GetVoiceChannel(0);
2475 ASSERT_TRUE(voice_channel_ != NULL);
2476
2477 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2478 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2479 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2480 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2481
2482 // Change session back to video only.
2483 mediastream_signaling_.UseOptionsVideoOnly();
2484 CreateAndSetRemoteOfferAndLocalAnswer();
2485
2486 video_channel_ = media_engine_->GetVideoChannel(0);
2487 voice_channel_ = media_engine_->GetVoiceChannel(0);
2488
2489 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2490 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2491 ASSERT_EQ(1u, video_channel_->send_streams().size());
2492 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2493}
2494
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002495TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002496 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002497 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002498 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002499 VerifyCryptoParams(offer->description());
2500 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002501 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002502 VerifyCryptoParams(answer->description());
2503}
2504
2505TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002506 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002507 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002508 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002509 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002510 VerifyNoCryptoParams(offer->description(), false);
2511}
2512
2513TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002514 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002515 VerifyAnswerFromNonCryptoOffer();
2516}
2517
2518TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002519 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002520 VerifyAnswerFromCryptoOffer();
2521}
2522
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002523// This test verifies that setLocalDescription fails if
2524// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2525TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002526 Init();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002527 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002528 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2529
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002530 std::string sdp;
2531 RemoveIceUfragPwdLines(offer.get(), &sdp);
2532 SessionDescriptionInterface* modified_offer =
2533 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002534 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002535}
2536
2537// This test verifies that setRemoteDescription fails if
2538// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2539TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002540 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002541 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002542 std::string sdp;
2543 RemoveIceUfragPwdLines(offer.get(), &sdp);
2544 SessionDescriptionInterface* modified_offer =
2545 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002546 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002547}
2548
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002549// This test verifies that setLocalDescription fails if local offer has
2550// too short ice ufrag and pwd strings.
2551TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002552 Init();
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002553 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
2554 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002555 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2556
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002557 std::string sdp;
2558 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2559 // recommended values of 4 and 22 bytes respectively.
2560 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2561 SessionDescriptionInterface* modified_offer =
2562 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2563 std::string error;
2564 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2565
2566 // Test with string greater than 256.
2567 sdp.clear();
2568 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2569 &sdp);
2570 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2571 NULL);
2572 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2573}
2574
2575// This test verifies that setRemoteDescription fails if remote offer has
2576// too short ice ufrag and pwd strings.
2577TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002578 Init();
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002579 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002580 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002581 std::string sdp;
2582 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2583 // recommended values of 4 and 22 bytes respectively.
2584 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2585 SessionDescriptionInterface* modified_offer =
2586 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2587 std::string error;
2588 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2589
2590 sdp.clear();
2591 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2592 &sdp);
2593 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2594 NULL);
2595 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2596}
2597
Donald Curtis0e209b02015-03-24 09:29:54 -07002598// kBundlePolicyBalanced bundle policy with and answer contains BUNDLE.
2599TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
2600 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002601 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002602
2603 PeerConnectionInterface::RTCOfferAnswerOptions options;
2604 options.use_rtp_mux = true;
2605
2606 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002607 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07002608
2609 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2610 session_->GetTransportProxy("video")->impl());
2611
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002612 mediastream_signaling_.SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002613 SessionDescriptionInterface* answer =
2614 CreateRemoteAnswer(session_->local_description());
2615 SetRemoteDescriptionWithoutError(answer);
2616
2617 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2618 session_->GetTransportProxy("video")->impl());
2619}
2620
2621// kBundlePolicyBalanced bundle policy but no BUNDLE in the answer.
2622TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
2623 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2624 mediastream_signaling_.SendAudioVideoStream1();
2625 PeerConnectionInterface::RTCOfferAnswerOptions options;
2626 options.use_rtp_mux = true;
2627
2628 SessionDescriptionInterface* offer = CreateOffer(options);
2629 SetLocalDescriptionWithoutError(offer);
2630
2631 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2632 session_->GetTransportProxy("video")->impl());
2633
2634 mediastream_signaling_.SendAudioVideoStream2();
2635
2636 // Remove BUNDLE from the answer.
2637 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2638 CreateRemoteAnswer(session_->local_description()));
2639 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2640 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2641 JsepSessionDescription* modified_answer =
2642 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2643 modified_answer->Initialize(answer_copy, "1", "1");
2644 SetRemoteDescriptionWithoutError(modified_answer); //
2645
2646 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2647 session_->GetTransportProxy("video")->impl());
2648}
2649
2650// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
2651TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
2652 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2653 mediastream_signaling_.SendAudioVideoStream1();
2654
2655 PeerConnectionInterface::RTCOfferAnswerOptions options;
2656 options.use_rtp_mux = true;
2657
2658 SessionDescriptionInterface* offer = CreateOffer(options);
2659 SetLocalDescriptionWithoutError(offer);
2660
2661 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2662 session_->GetTransportProxy("video")->impl());
2663
2664 mediastream_signaling_.SendAudioVideoStream2();
2665 SessionDescriptionInterface* answer =
2666 CreateRemoteAnswer(session_->local_description());
2667 SetRemoteDescriptionWithoutError(answer);
2668
2669 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2670 session_->GetTransportProxy("video")->impl());
2671}
2672
2673// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
2674TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
2675 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2676 mediastream_signaling_.SendAudioVideoStream1();
2677 PeerConnectionInterface::RTCOfferAnswerOptions options;
2678 options.use_rtp_mux = true;
2679
2680 SessionDescriptionInterface* offer = CreateOffer(options);
2681 SetLocalDescriptionWithoutError(offer);
2682
2683 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2684 session_->GetTransportProxy("video")->impl());
2685
2686 mediastream_signaling_.SendAudioVideoStream2();
2687
2688 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002689 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002690 CreateRemoteAnswer(session_->local_description()));
2691 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2692 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2693 JsepSessionDescription* modified_answer =
2694 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2695 modified_answer->Initialize(answer_copy, "1", "1");
2696 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002697
Donald Curtis0e209b02015-03-24 09:29:54 -07002698 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2699 session_->GetTransportProxy("video")->impl());
2700}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002701
Donald Curtis0e209b02015-03-24 09:29:54 -07002702// kBundlePolicyMaxCompat bundle policy with and answer contains BUNDLE.
2703TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
2704 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2705 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002706
Donald Curtis0e209b02015-03-24 09:29:54 -07002707 PeerConnectionInterface::RTCOfferAnswerOptions options;
2708 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002709
Donald Curtis0e209b02015-03-24 09:29:54 -07002710 SessionDescriptionInterface* offer = CreateOffer(options);
2711 SetLocalDescriptionWithoutError(offer);
2712
2713 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2714 session_->GetTransportProxy("video")->impl());
2715
2716 mediastream_signaling_.SendAudioVideoStream2();
2717 SessionDescriptionInterface* answer =
2718 CreateRemoteAnswer(session_->local_description());
2719 SetRemoteDescriptionWithoutError(answer);
2720
2721 // This should lead to an audio-only call but isn't implemented
2722 // correctly yet.
2723 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2724 session_->GetTransportProxy("video")->impl());
2725}
2726
2727// kBundlePolicyMaxCompat bundle policy but no BUNDLE in the answer.
2728TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
2729 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2730 mediastream_signaling_.SendAudioVideoStream1();
2731 PeerConnectionInterface::RTCOfferAnswerOptions options;
2732 options.use_rtp_mux = true;
2733
2734 SessionDescriptionInterface* offer = CreateOffer(options);
2735 SetLocalDescriptionWithoutError(offer);
2736
2737 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2738 session_->GetTransportProxy("video")->impl());
2739
2740 mediastream_signaling_.SendAudioVideoStream2();
2741
2742 // Remove BUNDLE from the answer.
2743 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2744 CreateRemoteAnswer(session_->local_description()));
2745 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2746 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2747 JsepSessionDescription* modified_answer =
2748 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2749 modified_answer->Initialize(answer_copy, "1", "1");
2750 SetRemoteDescriptionWithoutError(modified_answer); //
2751
2752 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2753 session_->GetTransportProxy("video")->impl());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002754}
2755
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002756// This test verifies that SetLocalDescription and SetRemoteDescription fails
2757// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2758TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002759 Init();
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002760 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002761
2762 PeerConnectionInterface::RTCOfferAnswerOptions options;
2763 options.use_rtp_mux = true;
2764
2765 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002766 std::string offer_str;
2767 offer->ToString(&offer_str);
2768 // Disable rtcp-mux
2769 const std::string rtcp_mux = "rtcp-mux";
2770 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002771 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002772 xrtcp_mux.c_str(), xrtcp_mux.length(),
2773 &offer_str);
2774 JsepSessionDescription *local_offer =
2775 new JsepSessionDescription(JsepSessionDescription::kOffer);
2776 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002777 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002778 JsepSessionDescription *remote_offer =
2779 new JsepSessionDescription(JsepSessionDescription::kOffer);
2780 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002781 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002782 // Trying unmodified SDP.
2783 SetLocalDescriptionWithoutError(offer);
2784}
2785
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002786TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002787 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002788 mediastream_signaling_.SendAudioVideoStream1();
2789 CreateAndSetRemoteOfferAndLocalAnswer();
2790 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2791 ASSERT_TRUE(channel != NULL);
2792 ASSERT_EQ(1u, channel->recv_streams().size());
2793 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2794 double left_vol, right_vol;
2795 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2796 EXPECT_EQ(1, left_vol);
2797 EXPECT_EQ(1, right_vol);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002798 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002799 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002800 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2801 EXPECT_EQ(0, left_vol);
2802 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002803 EXPECT_EQ(0, renderer->channel_id());
2804 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002805 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2806 EXPECT_EQ(1, left_vol);
2807 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002808 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002809}
2810
2811TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002812 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002813 mediastream_signaling_.SendAudioVideoStream1();
2814 CreateAndSetRemoteOfferAndLocalAnswer();
2815 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2816 ASSERT_TRUE(channel != NULL);
2817 ASSERT_EQ(1u, channel->send_streams().size());
2818 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2819 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2820
2821 cricket::AudioOptions options;
2822 options.echo_cancellation.Set(true);
2823
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002824 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002825 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002826 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2827 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002828 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002829 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002830
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002831 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002832 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002833 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2834 bool value;
2835 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
2836 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002837 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002838 EXPECT_TRUE(renderer->sink() == NULL);
2839}
2840
2841TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002842 Init();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002843 mediastream_signaling_.SendAudioVideoStream1();
2844 CreateAndSetRemoteOfferAndLocalAnswer();
2845 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2846 ASSERT_TRUE(channel != NULL);
2847 ASSERT_EQ(1u, channel->send_streams().size());
2848 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2849
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002850 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002851 cricket::AudioOptions options;
2852 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
2853 EXPECT_TRUE(renderer->sink() != NULL);
2854
2855 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
2856 // will invalidate the |renderer_| pointer in the sink and prevent getting a
2857 // SetSink(NULL) callback afterwards.
2858 renderer.reset();
2859
2860 // This will trigger SetSink(NULL) if no OnClose() callback.
2861 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002862}
2863
2864TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002865 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002866 mediastream_signaling_.SendAudioVideoStream1();
2867 CreateAndSetRemoteOfferAndLocalAnswer();
2868 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2869 ASSERT_TRUE(channel != NULL);
2870 ASSERT_LT(0u, channel->renderers().size());
2871 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2872 ASSERT_EQ(1u, channel->recv_streams().size());
2873 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2874 cricket::FakeVideoRenderer renderer;
2875 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
2876 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
2877 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
2878 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2879}
2880
2881TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002882 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002883 mediastream_signaling_.SendAudioVideoStream1();
2884 CreateAndSetRemoteOfferAndLocalAnswer();
2885 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2886 ASSERT_TRUE(channel != NULL);
2887 ASSERT_EQ(1u, channel->send_streams().size());
2888 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2889 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2890 cricket::VideoOptions* options = NULL;
2891 session_->SetVideoSend(send_ssrc, false, options);
2892 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2893 session_->SetVideoSend(send_ssrc, true, options);
2894 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2895}
2896
2897TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
2898 TestCanInsertDtmf(false);
2899}
2900
2901TEST_F(WebRtcSessionTest, CanInsertDtmf) {
2902 TestCanInsertDtmf(true);
2903}
2904
2905TEST_F(WebRtcSessionTest, InsertDtmf) {
2906 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002907 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002908 mediastream_signaling_.SendAudioVideoStream1();
2909 CreateAndSetRemoteOfferAndLocalAnswer();
2910 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2911 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
2912
2913 // Insert DTMF
2914 const int expected_flags = DF_SEND;
2915 const int expected_duration = 90;
2916 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
2917 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
2918 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
2919
2920 // Verify
2921 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
2922 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2923 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
2924 expected_duration, expected_flags));
2925 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
2926 expected_duration, expected_flags));
2927 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
2928 expected_duration, expected_flags));
2929}
2930
2931// This test verifies the |initiator| flag when session initiates the call.
2932TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002933 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002934 EXPECT_FALSE(session_->initiator());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002935 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002936 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2937 SetLocalDescriptionWithoutError(offer);
2938 EXPECT_TRUE(session_->initiator());
2939 SetRemoteDescriptionWithoutError(answer);
2940 EXPECT_TRUE(session_->initiator());
2941}
2942
2943// This test verifies the |initiator| flag when session receives the call.
2944TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002945 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002946 EXPECT_FALSE(session_->initiator());
2947 SessionDescriptionInterface* offer = CreateRemoteOffer();
2948 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002949 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002950
2951 EXPECT_FALSE(session_->initiator());
2952 SetLocalDescriptionWithoutError(answer);
2953 EXPECT_FALSE(session_->initiator());
2954}
2955
2956// This test verifies the ice protocol type at initiator of the call
2957// if |a=ice-options:google-ice| is present in answer.
2958TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002959 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002960 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002961 SessionDescriptionInterface* offer = CreateOffer();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002962 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002963 CreateRemoteAnswer(offer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002964 SetLocalDescriptionWithoutError(offer);
2965 std::string sdp;
2966 EXPECT_TRUE(answer->ToString(&sdp));
2967 // Adding ice-options to the session level.
2968 InjectAfter("t=0 0\r\n",
2969 "a=ice-options:google-ice\r\n",
2970 &sdp);
2971 SessionDescriptionInterface* answer_with_gice =
2972 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00002973 // Default offer is ICEPROTO_RFC5245, so we expect responder with
2974 // only gice to fail.
2975 SetRemoteDescriptionAnswerExpectError(kPushDownTDFailed, answer_with_gice);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002976}
2977
2978// This test verifies the ice protocol type at initiator of the call
2979// if ICE RFC5245 is supported in answer.
2980TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002981 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002982 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002983 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002984 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2985 SetLocalDescriptionWithoutError(offer);
2986
2987 SetRemoteDescriptionWithoutError(answer);
2988 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2989 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2990}
2991
2992// This test verifies the ice protocol type at receiver side of the call if
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002993// receiver decides to use ice RFC 5245.
2994TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002995 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002996 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002997 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002998 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002999 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003000 SetLocalDescriptionWithoutError(answer);
3001 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
3002 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
3003}
3004
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003005// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3006TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003007 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003008 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003009 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003010 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003011 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003012 CreateRemoteAnswer(session_->local_description()));
3013
3014 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3015 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003016 JsepSessionDescription* modified_answer =
3017 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003018
3019 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3020 answer->session_id(),
3021 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003022 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003023
wu@webrtc.org4e393072014-04-07 17:04:35 +00003024 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003025 std::string sdp;
3026 EXPECT_TRUE(answer->ToString(&sdp));
3027 const std::string kAudioMid = "a=mid:audio";
3028 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003029 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003030 kAudioMidReplaceStr.c_str(),
3031 kAudioMidReplaceStr.length(),
3032 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003033 SessionDescriptionInterface* modified_answer1 =
3034 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003035 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003036
wu@webrtc.org4e393072014-04-07 17:04:35 +00003037 // Different media types.
3038 EXPECT_TRUE(answer->ToString(&sdp));
3039 const std::string kAudioMline = "m=audio";
3040 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003041 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003042 kAudioMlineReplaceStr.c_str(),
3043 kAudioMlineReplaceStr.length(),
3044 &sdp);
3045 SessionDescriptionInterface* modified_answer2 =
3046 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3047 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3048
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003049 SetRemoteDescriptionWithoutError(answer.release());
3050}
3051
3052// Verifying remote offer and local answer have matching m-lines as per
3053// RFC 3264.
3054TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003055 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003056 mediastream_signaling_.SendAudioVideoStream1();
3057 SessionDescriptionInterface* offer = CreateRemoteOffer();
3058 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003059 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003060
3061 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3062 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003063 JsepSessionDescription* modified_answer =
3064 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003065
3066 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3067 answer->session_id(),
3068 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003069 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003070 SetLocalDescriptionWithoutError(answer);
3071}
3072
3073// This test verifies that WebRtcSession does not start candidate allocation
3074// before SetLocalDescription is called.
3075TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003076 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003077 mediastream_signaling_.SendAudioVideoStream1();
3078 SessionDescriptionInterface* offer = CreateRemoteOffer();
3079 cricket::Candidate candidate;
3080 candidate.set_component(1);
3081 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3082 candidate);
3083 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3084 cricket::Candidate candidate1;
3085 candidate1.set_component(1);
3086 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3087 candidate1);
3088 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3089 SetRemoteDescriptionWithoutError(offer);
3090 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
3091 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
3092
3093 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003094 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003095 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3096 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3097
wu@webrtc.org91053e72013-08-10 07:18:04 +00003098 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003099 SetLocalDescriptionWithoutError(answer);
3100 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
3101 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
3102 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3103}
3104
3105// This test verifies that crypto parameter is updated in local session
3106// description as per security policy set in MediaSessionDescriptionFactory.
3107TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003108 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003109 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003110 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003111
3112 // Making sure SetLocalDescription correctly sets crypto value in
3113 // SessionDescription object after de-serialization of sdp string. The value
3114 // will be set as per MediaSessionDescriptionFactory.
3115 std::string offer_str;
3116 offer->ToString(&offer_str);
3117 SessionDescriptionInterface* jsep_offer_str =
3118 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3119 SetLocalDescriptionWithoutError(jsep_offer_str);
3120 EXPECT_TRUE(session_->voice_channel()->secure_required());
3121 EXPECT_TRUE(session_->video_channel()->secure_required());
3122}
3123
3124// This test verifies the crypto parameter when security is disabled.
3125TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003126 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003127 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003128 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003129 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003130
3131 // Making sure SetLocalDescription correctly sets crypto value in
3132 // SessionDescription object after de-serialization of sdp string. The value
3133 // will be set as per MediaSessionDescriptionFactory.
3134 std::string offer_str;
3135 offer->ToString(&offer_str);
3136 SessionDescriptionInterface *jsep_offer_str =
3137 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3138 SetLocalDescriptionWithoutError(jsep_offer_str);
3139 EXPECT_FALSE(session_->voice_channel()->secure_required());
3140 EXPECT_FALSE(session_->video_channel()->secure_required());
3141}
3142
3143// This test verifies that an answer contains new ufrag and password if an offer
3144// with new ufrag and password is received.
3145TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003146 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003147 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003148 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003149 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003150 CreateRemoteOffer(options));
3151 SetRemoteDescriptionWithoutError(offer.release());
3152
3153 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003154 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003155 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003156 SetLocalDescriptionWithoutError(answer.release());
3157
3158 // Receive an offer with new ufrag and password.
3159 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003160 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003161 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003162 SetRemoteDescriptionWithoutError(updated_offer1.release());
3163
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003164 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003165 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003166
3167 CompareIceUfragAndPassword(updated_answer1->description(),
3168 session_->local_description()->description(),
3169 false);
3170
3171 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003172}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003173
wu@webrtc.org91053e72013-08-10 07:18:04 +00003174// This test verifies that an answer contains old ufrag and password if an offer
3175// with old ufrag and password is received.
3176TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003177 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003178 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003179 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003180 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003181 CreateRemoteOffer(options));
3182 SetRemoteDescriptionWithoutError(offer.release());
3183
3184 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003185 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003186 CreateAnswer(NULL));
3187 SetLocalDescriptionWithoutError(answer.release());
3188
3189 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003190 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003191 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003192 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003193 SetRemoteDescriptionWithoutError(updated_offer2.release());
3194
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003195 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003196 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003197
3198 CompareIceUfragAndPassword(updated_answer2->description(),
3199 session_->local_description()->description(),
3200 true);
3201
3202 SetLocalDescriptionWithoutError(updated_answer2.release());
3203}
3204
3205TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003206 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003207 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003208 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003209 const std::string session_id_orig = offer->session_id();
3210 const std::string session_version_orig = offer->session_version();
3211 SetLocalDescriptionWithoutError(offer);
3212
3213 video_channel_ = media_engine_->GetVideoChannel(0);
3214 video_channel_->set_fail_set_send_codecs(true);
3215
3216 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003217 SessionDescriptionInterface* answer =
3218 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003219 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003220}
3221
3222// Runs the loopback call test with BUNDLE and STUN disabled.
3223TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3224 // Lets try with only UDP ports.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00003225 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003226 cricket::PORTALLOCATOR_DISABLE_TCP |
3227 cricket::PORTALLOCATOR_DISABLE_STUN |
3228 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003229 TestLoopbackCall();
3230}
3231
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003232TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
3233 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
3234 cricket::PORTALLOCATOR_DISABLE_TCP |
3235 cricket::PORTALLOCATOR_DISABLE_STUN |
3236 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3237 cricket::PORTALLOCATOR_DISABLE_RELAY);
3238
3239 // best connection is IPv6 since it has higher network preference.
3240 LoopbackNetworkConfiguration config;
3241 config.test_ipv6_network_ = true;
3242 config.best_connection_after_initial_ice_converged_ =
3243 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3244
3245 TestLoopbackCall(config);
3246}
3247
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003248// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003249TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00003250 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003251 cricket::PORTALLOCATOR_DISABLE_TCP |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003252 cricket::PORTALLOCATOR_DISABLE_RELAY);
3253 TestLoopbackCall();
3254}
3255
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003256TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003257 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003258 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003259 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003260
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003261 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
3262 std::string error_code_str = "ERROR_CONTENT";
3263 std::string error_desc = "Fake session error description.";
3264 session_->SetError(error_code, error_desc);
3265
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003266 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
3267 SessionDescriptionInterface* answer =
3268 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003269
3270 std::string action;
3271 std::ostringstream session_error_msg;
3272 session_error_msg << kSessionError << error_code_str << ". ";
3273 session_error_msg << kSessionErrorDesc << error_desc << ".";
3274 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
3275 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003276}
3277
3278TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3279 constraints_.reset(new FakeConstraints());
3280 constraints_->AddOptional(
3281 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003282 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003283
3284 SetLocalDescriptionWithDataChannel();
3285 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3286}
3287
3288TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003289 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003290
3291 constraints_.reset(new FakeConstraints());
3292 constraints_->AddOptional(
3293 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003294 options_.disable_sctp_data_channels = false;
3295
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003296 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003297
3298 SetLocalDescriptionWithDataChannel();
3299 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3300}
3301
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003302TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003303 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003304
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003305 InitWithDtls();
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003306
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003307 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003308 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003309 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3310}
3311
3312TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003313 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003314 SetFactoryDtlsSrtp();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003315 InitWithDtls();
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003316
3317 // Create remote offer with SCTP.
3318 cricket::MediaSessionOptions options;
3319 options.data_channel_type = cricket::DCT_SCTP;
3320 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003321 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003322 SetRemoteDescriptionWithoutError(offer);
3323
3324 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003325 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003326 EXPECT_TRUE(answer != NULL);
3327 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3328 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003329}
3330
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003331TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
3332 constraints_.reset(new FakeConstraints());
3333 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003334 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003335 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003336
3337 SetLocalDescriptionWithDataChannel();
3338 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3339}
3340
3341TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003342 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003343
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003344 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003345
3346 SetLocalDescriptionWithDataChannel();
3347 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3348}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003349
wu@webrtc.org97077a32013-10-25 21:18:33 +00003350TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003351 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003352 options_.disable_sctp_data_channels = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003353 InitWithDtls();
wu@webrtc.org97077a32013-10-25 21:18:33 +00003354
3355 SetLocalDescriptionWithDataChannel();
3356 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3357}
3358
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003359TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003360 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003361 const int new_send_port = 9998;
3362 const int new_recv_port = 7775;
3363
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003364 InitWithDtls();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003365 SetFactoryDtlsSrtp();
3366
3367 // By default, don't actually add the codecs to desc_factory_; they don't
3368 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3369 // let the session description get parsed. That'll get the proper codecs
3370 // into the stream.
3371 cricket::MediaSessionOptions options;
3372 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3373 "stream1", new_send_port, options);
3374
3375 // SetRemoteDescription will take the ownership of the offer.
3376 SetRemoteDescriptionWithoutError(offer);
3377
3378 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3379 new_recv_port, CreateAnswer(NULL));
3380 ASSERT_TRUE(answer != NULL);
3381
3382 // Now set the local description, which'll take ownership of the answer.
3383 SetLocalDescriptionWithoutError(answer);
3384
3385 // TEST PLAN: Set the port number to something new, set it in the SDP,
3386 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003387 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003388 dci.reliable = true;
3389 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003390 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003391 session_->CreateDataChannel("datachannel", &dci);
3392
3393 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3394 int portnum = -1;
3395 ASSERT_TRUE(ch != NULL);
3396 ASSERT_EQ(1UL, ch->send_codecs().size());
3397 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
3398 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3399 ch->send_codecs()[0].name.c_str()));
3400 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3401 &portnum));
3402 EXPECT_EQ(new_send_port, portnum);
3403
3404 ASSERT_EQ(1UL, ch->recv_codecs().size());
3405 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
3406 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3407 ch->recv_codecs()[0].name.c_str()));
3408 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3409 &portnum));
3410 EXPECT_EQ(new_recv_port, portnum);
3411}
3412
wu@webrtc.org91053e72013-08-10 07:18:04 +00003413// Verifies that CreateOffer succeeds when CreateOffer is called before async
3414// identity generation is finished.
3415TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003416 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003417 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003418
3419 EXPECT_TRUE(session_->waiting_for_identity());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003420 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003421 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3422
wu@webrtc.org91053e72013-08-10 07:18:04 +00003423 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003424 VerifyNoCryptoParams(offer->description(), true);
3425 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003426}
3427
3428// Verifies that CreateAnswer succeeds when CreateOffer is called before async
3429// identity generation is finished.
3430TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003431 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003432 InitWithDtls();
3433 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003434
3435 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003436 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003437 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003438 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003439 ASSERT_TRUE(offer.get() != NULL);
3440 SetRemoteDescriptionWithoutError(offer.release());
3441
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003442 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003443 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003444 VerifyNoCryptoParams(answer->description(), true);
3445 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003446}
3447
3448// Verifies that CreateOffer succeeds when CreateOffer is called after async
3449// identity generation is finished.
3450TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003451 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003452 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003453
3454 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003455
3456 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003457 EXPECT_TRUE(offer != NULL);
3458}
3459
3460// Verifies that CreateOffer fails when CreateOffer is called after async
3461// identity generation fails.
3462TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003463 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00003464 InitWithDtls(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003465
3466 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003467
3468 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003469 EXPECT_TRUE(offer == NULL);
3470}
3471
3472// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3473// before async identity generation is finished.
3474TEST_F(WebRtcSessionTest,
3475 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003476 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003477 VerifyMultipleAsyncCreateDescription(
3478 true, CreateSessionDescriptionRequest::kOffer);
3479}
3480
3481// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3482// before async identity generation fails.
3483TEST_F(WebRtcSessionTest,
3484 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003485 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003486 VerifyMultipleAsyncCreateDescription(
3487 false, CreateSessionDescriptionRequest::kOffer);
3488}
3489
3490// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3491// before async identity generation is finished.
3492TEST_F(WebRtcSessionTest,
3493 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003494 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003495 VerifyMultipleAsyncCreateDescription(
3496 true, CreateSessionDescriptionRequest::kAnswer);
3497}
3498
3499// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3500// before async identity generation fails.
3501TEST_F(WebRtcSessionTest,
3502 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003503 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003504 VerifyMultipleAsyncCreateDescription(
3505 false, CreateSessionDescriptionRequest::kAnswer);
3506}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003507
3508// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3509// offer has no SDES crypto but only DTLS fingerprint.
3510TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3511 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003512 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003513 // Create a remote offer with secured transport disabled.
3514 cricket::MediaSessionOptions options;
3515 JsepSessionDescription* offer(CreateRemoteOffer(
3516 options, cricket::SEC_DISABLED));
3517 // Adds a DTLS fingerprint to the remote offer.
3518 cricket::SessionDescription* sdp = offer->description();
3519 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3520 ASSERT_TRUE(audio != NULL);
3521 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3522 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003523 rtc::SSLFingerprint::CreateFromRfc4572(
3524 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003525 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003526 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003527}
3528
wu@webrtc.orgde305012013-10-31 15:40:38 +00003529// This test verifies DSCP is properly applied on the media channels.
3530TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3531 constraints_.reset(new FakeConstraints());
3532 constraints_->AddOptional(
3533 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003534 Init();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003535 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003536 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003537
3538 SetLocalDescriptionWithoutError(offer);
3539
3540 video_channel_ = media_engine_->GetVideoChannel(0);
3541 voice_channel_ = media_engine_->GetVoiceChannel(0);
3542
3543 ASSERT_TRUE(video_channel_ != NULL);
3544 ASSERT_TRUE(voice_channel_ != NULL);
3545 cricket::AudioOptions audio_options;
3546 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3547 cricket::VideoOptions video_options;
3548 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3549 EXPECT_TRUE(audio_options.dscp.IsSet());
3550 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3551 EXPECT_TRUE(video_options.dscp.IsSet());
3552 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3553}
3554
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003555TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3556 constraints_.reset(new FakeConstraints());
3557 constraints_->AddOptional(
3558 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3559 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003560 Init();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003561 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003562 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003563
3564 SetLocalDescriptionWithoutError(offer);
3565
3566 video_channel_ = media_engine_->GetVideoChannel(0);
3567
3568 ASSERT_TRUE(video_channel_ != NULL);
3569 cricket::VideoOptions video_options;
3570 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3571 EXPECT_TRUE(
3572 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3573}
3574
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00003575TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
3576 // Number of unsignalled receiving streams should be between 0 and
3577 // kMaxUnsignalledRecvStreams.
3578 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
3579 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
3580 kMaxUnsignalledRecvStreams);
3581 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
3582}
3583
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003584TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
3585 constraints_.reset(new FakeConstraints());
3586 constraints_->AddOptional(
3587 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
3588 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003589 Init();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003590 mediastream_signaling_.SendAudioVideoStream1();
3591 SessionDescriptionInterface* offer = CreateOffer();
3592
3593 SetLocalDescriptionWithoutError(offer);
3594
3595 voice_channel_ = media_engine_->GetVoiceChannel(0);
3596
3597 ASSERT_TRUE(voice_channel_ != NULL);
3598 cricket::AudioOptions audio_options;
3599 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3600 EXPECT_TRUE(
3601 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
3602}
3603
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003604// Tests that we can renegotiate new media content with ICE candidates in the
3605// new remote SDP.
3606TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003607 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003608 InitWithDtls();
3609 SetFactoryDtlsSrtp();
3610
3611 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003612 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003613 SetLocalDescriptionWithoutError(offer);
3614
3615 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3616 SetRemoteDescriptionWithoutError(answer);
3617
3618 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003619 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003620 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3621
3622 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003623 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003624 candidate1.set_component(1);
3625 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3626 candidate1);
3627 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3628 SetRemoteDescriptionWithoutError(offer);
3629
3630 answer = CreateAnswer(NULL);
3631 SetLocalDescriptionWithoutError(answer);
3632}
3633
3634// Tests that we can renegotiate new media content with ICE candidates separated
3635// from the remote SDP.
3636TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003637 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003638 InitWithDtls();
3639 SetFactoryDtlsSrtp();
3640
3641 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003642 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003643 SetLocalDescriptionWithoutError(offer);
3644
3645 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3646 SetRemoteDescriptionWithoutError(answer);
3647
3648 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003649 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003650 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3651 SetRemoteDescriptionWithoutError(offer);
3652
3653 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003654 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003655 candidate1.set_component(1);
3656 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3657 candidate1);
3658 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3659
3660 answer = CreateAnswer(NULL);
3661 SetLocalDescriptionWithoutError(answer);
3662}
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00003663// Tests that RTX codec is removed from the answer when it isn't supported
3664// by local side.
3665TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
3666 Init();
3667 mediastream_signaling_.SendAudioVideoStream1();
3668 std::string offer_sdp(kSdpWithRtx);
3669
3670 SessionDescriptionInterface* offer =
3671 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
3672 EXPECT_TRUE(offer->ToString(&offer_sdp));
3673
3674 // Offer SDP contains the RTX codec.
3675 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
3676 SetRemoteDescriptionWithoutError(offer);
3677
3678 SessionDescriptionInterface* answer = CreateAnswer(NULL);
3679 std::string answer_sdp;
3680 answer->ToString(&answer_sdp);
3681 // Answer SDP removes the unsupported RTX codec.
3682 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
3683 SetLocalDescriptionWithoutError(answer);
3684}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003685
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003686// This verifies that the voice channel after bundle has both options from video
3687// and voice channels.
3688TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
3689 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
3690 mediastream_signaling_.SendAudioVideoStream1();
3691
3692 PeerConnectionInterface::RTCOfferAnswerOptions options;
3693 options.use_rtp_mux = true;
3694
3695 SessionDescriptionInterface* offer = CreateOffer(options);
3696 SetLocalDescriptionWithoutError(offer);
3697
3698 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3699 rtc::Socket::Option::OPT_SNDBUF, 4000);
3700
3701 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3702 rtc::Socket::Option::OPT_RCVBUF, 8000);
3703
3704 int option_val;
3705 EXPECT_TRUE(session_->video_channel()->transport_channel()->GetOption(
3706 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3707 EXPECT_EQ(4000, option_val);
3708 EXPECT_FALSE(session_->voice_channel()->transport_channel()->GetOption(
3709 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3710
3711 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3712 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3713 EXPECT_EQ(8000, option_val);
3714 EXPECT_FALSE(session_->video_channel()->transport_channel()->GetOption(
3715 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3716
3717 EXPECT_NE(session_->voice_channel()->transport_channel(),
3718 session_->video_channel()->transport_channel());
3719
3720 mediastream_signaling_.SendAudioVideoStream2();
3721 SessionDescriptionInterface* answer =
3722 CreateRemoteAnswer(session_->local_description());
3723 SetRemoteDescriptionWithoutError(answer);
3724
3725 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3726 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3727 EXPECT_EQ(4000, option_val);
3728
3729 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3730 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3731 EXPECT_EQ(8000, option_val);
3732}
3733
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003734// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
3735// currently fails because upon disconnection and reconnection OnIceComplete is
3736// called more than once without returning to IceGatheringGathering.