blob: c0938d11eaa207b291d4208439c9253acb529e46 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2012 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include "talk/app/webrtc/audiotrack.h"
jbauchac8869e2015-07-03 01:36:14 -070029#include "talk/app/webrtc/fakemetricsobserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030#include "talk/app/webrtc/jsepicecandidate.h"
31#include "talk/app/webrtc/jsepsessiondescription.h"
32#include "talk/app/webrtc/mediastreamsignaling.h"
33#include "talk/app/webrtc/streamcollection.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000034#include "talk/app/webrtc/test/fakeconstraints.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000035#include "talk/app/webrtc/test/fakedtlsidentityservice.h"
36#include "talk/app/webrtc/test/fakemediastreamsignaling.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000037#include "talk/app/webrtc/videotrack.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038#include "talk/app/webrtc/webrtcsession.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000039#include "talk/app/webrtc/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000040#include "talk/media/base/fakemediaengine.h"
41#include "talk/media/base/fakevideorenderer.h"
42#include "talk/media/base/mediachannel.h"
43#include "talk/media/devices/fakedevicemanager.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000044#include "webrtc/p2p/base/stunserver.h"
45#include "webrtc/p2p/base/teststunserver.h"
46#include "webrtc/p2p/base/testturnserver.h"
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +000047#include "webrtc/p2p/base/transportchannel.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000048#include "webrtc/p2p/client/basicportallocator.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000049#include "talk/session/media/channelmanager.h"
50#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000051#include "webrtc/base/fakenetwork.h"
52#include "webrtc/base/firewallsocketserver.h"
53#include "webrtc/base/gunit.h"
54#include "webrtc/base/logging.h"
55#include "webrtc/base/network.h"
56#include "webrtc/base/physicalsocketserver.h"
57#include "webrtc/base/ssladapter.h"
58#include "webrtc/base/sslstreamadapter.h"
59#include "webrtc/base/stringutils.h"
60#include "webrtc/base/thread.h"
61#include "webrtc/base/virtualsocketserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062
63#define MAYBE_SKIP_TEST(feature) \
64 if (!(feature())) { \
65 LOG(LS_INFO) << "Feature disabled... skipping"; \
66 return; \
67 }
68
69using cricket::BaseSession;
70using cricket::DF_PLAY;
71using cricket::DF_SEND;
72using cricket::FakeVoiceMediaChannel;
73using cricket::NS_GINGLE_P2P;
74using cricket::NS_JINGLE_ICE_UDP;
75using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000076using rtc::SocketAddress;
77using rtc::scoped_ptr;
78using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000080using webrtc::CreateSessionDescriptionObserver;
81using webrtc::CreateSessionDescriptionRequest;
82using webrtc::DTLSIdentityRequestObserver;
83using webrtc::DTLSIdentityServiceInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084using webrtc::FakeConstraints;
jbauchac8869e2015-07-03 01:36:14 -070085using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086using webrtc::IceCandidateCollection;
87using webrtc::JsepIceCandidate;
88using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000089using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090using webrtc::PeerConnectionInterface;
91using webrtc::SessionDescriptionInterface;
92using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000093using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000094using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000095using webrtc::kCreateChannelFailed;
96using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000097using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000098using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000099using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000100using webrtc::kSdpWithoutDtlsFingerprint;
101using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000103using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000104using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000106typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
107
wu@webrtc.org364f2042013-11-20 21:49:41 +0000108static const int kClientAddrPort = 0;
109static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000110static const char kClientIPv6AddrHost1[] =
111 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +0000112static const char kClientAddrHost2[] = "22.22.22.22";
113static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000114static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
115static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000116static const char kTurnUsername[] = "test";
117static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000118
119static const char kSessionVersion[] = "1";
120
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121// Media index of candidates belonging to the first media content.
122static const int kMediaContentIndex0 = 0;
123static const char kMediaContentName0[] = "audio";
124
125// Media index of candidates belonging to the second media content.
126static const int kMediaContentIndex1 = 1;
127static const char kMediaContentName1[] = "video";
128
129static const int kIceCandidatesTimeout = 10000;
130
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000131static const char kFakeDtlsFingerprint[] =
132 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
133 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
134
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000135static const char kTooLongIceUfragPwd[] =
136 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
137 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
138 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
139 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
140
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000141static const char kSdpWithRtx[] =
142 "v=0\r\n"
143 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
144 "s=-\r\n"
145 "t=0 0\r\n"
146 "a=msid-semantic: WMS stream1\r\n"
147 "m=video 9 RTP/SAVPF 0 96\r\n"
148 "c=IN IP4 0.0.0.0\r\n"
149 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
150 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
151 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
152 "a=mid:video\r\n"
153 "a=sendrecv\r\n"
154 "a=rtcp-mux\r\n"
155 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
156 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
157 "a=rtpmap:0 fake_video_codec/90000\r\n"
158 "a=rtpmap:96 rtx/90000\r\n"
159 "a=fmtp:96 apt=0\r\n";
160
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161// Add some extra |newlines| to the |message| after |line|.
162static void InjectAfter(const std::string& line,
163 const std::string& newlines,
164 std::string* message) {
165 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000166 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000167 tmp.c_str(), tmp.length(), message);
168}
169
170class MockIceObserver : public webrtc::IceObserver {
171 public:
172 MockIceObserver()
173 : oncandidatesready_(false),
174 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
175 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
176 }
177
178 virtual void OnIceConnectionChange(
179 PeerConnectionInterface::IceConnectionState new_state) {
180 ice_connection_state_ = new_state;
181 }
182 virtual void OnIceGatheringChange(
183 PeerConnectionInterface::IceGatheringState new_state) {
184 // We can never transition back to "new".
185 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
186 ice_gathering_state_ = new_state;
187
188 // oncandidatesready_ really means "ICE gathering is complete".
189 // This if statement ensures that this value remains correct when we
190 // transition from kIceGatheringComplete to kIceGatheringGathering.
191 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
192 oncandidatesready_ = false;
193 }
194 }
195
196 // Found a new candidate.
197 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000198 switch (candidate->sdp_mline_index()) {
199 case kMediaContentIndex0:
200 mline_0_candidates_.push_back(candidate->candidate());
201 break;
202 case kMediaContentIndex1:
203 mline_1_candidates_.push_back(candidate->candidate());
204 break;
205 default:
206 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000208
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209 // The ICE gathering state should always be Gathering when a candidate is
210 // received (or possibly Completed in the case of the final candidate).
211 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
212 }
213
214 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
215 virtual void OnIceComplete() {
216 EXPECT_FALSE(oncandidatesready_);
217 oncandidatesready_ = true;
218
219 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
220 // be called approximately simultaneously. For ease of testing, this
221 // check additionally requires that they be called in the above order.
222 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
223 ice_gathering_state_);
224 }
225
226 bool oncandidatesready_;
227 std::vector<cricket::Candidate> mline_0_candidates_;
228 std::vector<cricket::Candidate> mline_1_candidates_;
229 PeerConnectionInterface::IceConnectionState ice_connection_state_;
230 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
231};
232
233class WebRtcSessionForTest : public webrtc::WebRtcSession {
234 public:
235 WebRtcSessionForTest(cricket::ChannelManager* cmgr,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000236 rtc::Thread* signaling_thread,
237 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000238 cricket::PortAllocator* port_allocator,
239 webrtc::IceObserver* ice_observer,
240 webrtc::MediaStreamSignaling* mediastream_signaling)
241 : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator,
242 mediastream_signaling) {
243 RegisterIceObserver(ice_observer);
244 }
245 virtual ~WebRtcSessionForTest() {}
246
247 using cricket::BaseSession::GetTransportProxy;
248 using webrtc::WebRtcSession::SetAudioPlayout;
249 using webrtc::WebRtcSession::SetAudioSend;
250 using webrtc::WebRtcSession::SetCaptureDevice;
251 using webrtc::WebRtcSession::SetVideoPlayout;
252 using webrtc::WebRtcSession::SetVideoSend;
253};
254
wu@webrtc.org91053e72013-08-10 07:18:04 +0000255class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000256 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000258 enum State {
259 kInit,
260 kFailed,
261 kSucceeded,
262 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000263 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000264
265 // CreateSessionDescriptionObserver implementation.
266 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000267 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000268 state_ = kSucceeded;
269 }
270 virtual void OnFailure(const std::string& error) {
271 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000272 }
273
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000274 SessionDescriptionInterface* description() { return description_.get(); }
275
276 SessionDescriptionInterface* ReleaseDescription() {
277 return description_.release();
278 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279
wu@webrtc.org91053e72013-08-10 07:18:04 +0000280 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000281
wu@webrtc.org91053e72013-08-10 07:18:04 +0000282 protected:
283 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000284
285 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000286 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000287 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288};
289
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000290class FakeAudioRenderer : public cricket::AudioRenderer {
291 public:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000292 FakeAudioRenderer() : channel_id_(-1), sink_(NULL) {}
293 virtual ~FakeAudioRenderer() {
294 if (sink_)
295 sink_->OnClose();
296 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000297
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000298 void AddChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000299 ASSERT(channel_id_ == -1);
300 channel_id_ = channel_id;
301 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000302 void RemoveChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000303 ASSERT(channel_id == channel_id_);
304 channel_id_ = -1;
305 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000306 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000307
308 int channel_id() const { return channel_id_; }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000309 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000310 private:
311 int channel_id_;
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000312 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000313};
314
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000315class WebRtcSessionTest : public testing::Test {
316 protected:
317 // TODO Investigate why ChannelManager crashes, if it's created
318 // after stun_server.
319 WebRtcSessionTest()
320 : media_engine_(new cricket::FakeMediaEngine()),
321 data_engine_(new cricket::FakeDataEngine()),
322 device_manager_(new cricket::FakeDeviceManager()),
323 channel_manager_(new cricket::ChannelManager(
324 media_engine_, data_engine_, device_manager_,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000325 new cricket::CaptureManager(), rtc::Thread::Current())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326 tdesc_factory_(new cricket::TransportDescriptionFactory()),
327 desc_factory_(new cricket::MediaSessionDescriptionFactory(
328 channel_manager_.get(), tdesc_factory_.get())),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000329 pss_(new rtc::PhysicalSocketServer),
330 vss_(new rtc::VirtualSocketServer(pss_.get())),
331 fss_(new rtc::FirewallSocketServer(vss_.get())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000332 ss_scope_(fss_.get()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000333 stun_socket_addr_(rtc::SocketAddress(kStunAddrHost,
wu@webrtc.org364f2042013-11-20 21:49:41 +0000334 cricket::STUN_SERVER_PORT)),
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +0000335 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
336 stun_socket_addr_)),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000337 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
jbauchac8869e2015-07-03 01:36:14 -0700338 mediastream_signaling_(channel_manager_.get()),
339 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000340 tdesc_factory_->set_protocol(cricket::ICEPROTO_HYBRID);
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000341
342 cricket::ServerAddresses stun_servers;
343 stun_servers.insert(stun_socket_addr_);
344 allocator_.reset(new cricket::BasicPortAllocator(
345 &network_manager_,
346 stun_servers,
347 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000348 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349 cricket::PORTALLOCATOR_DISABLE_RELAY |
jiayl@webrtc.orgdacdd942015-01-23 17:33:34 +0000350 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351 EXPECT_TRUE(channel_manager_->Init());
352 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000353 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000354 }
355
356 void AddInterface(const SocketAddress& addr) {
357 network_manager_.AddInterface(addr);
358 }
359
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000360 void Init(
361 DTLSIdentityServiceInterface* identity_service,
Henrik Lundin64dad832015-05-11 12:44:23 +0200362 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000363 ASSERT_TRUE(session_.get() == NULL);
364 session_.reset(new WebRtcSessionForTest(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000365 channel_manager_.get(), rtc::Thread::Current(),
366 rtc::Thread::Current(), allocator_.get(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000367 &observer_,
368 &mediastream_signaling_));
369
370 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
371 observer_.ice_connection_state_);
372 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
373 observer_.ice_gathering_state_);
374
wu@webrtc.org97077a32013-10-25 21:18:33 +0000375 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
Henrik Lundin64dad832015-05-11 12:44:23 +0200376 identity_service, rtc_configuration));
jbauchac8869e2015-07-03 01:36:14 -0700377 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000378 }
379
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000380 void Init() {
Henrik Lundin64dad832015-05-11 12:44:23 +0200381 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Lundin64dad832015-05-11 12:44:23 +0200382 Init(NULL, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000383 }
384
385 void InitWithIceTransport(
386 PeerConnectionInterface::IceTransportsType ice_transport_type) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200387 PeerConnectionInterface::RTCConfiguration configuration;
388 configuration.type = ice_transport_type;
Henrik Lundin64dad832015-05-11 12:44:23 +0200389 Init(NULL, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000390 }
391
392 void InitWithBundlePolicy(
393 PeerConnectionInterface::BundlePolicy bundle_policy) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200394 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Lundin64dad832015-05-11 12:44:23 +0200395 configuration.bundle_policy = bundle_policy;
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700396 Init(NULL, configuration);
397 }
398
399 void InitWithRtcpMuxPolicy(
400 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
401 PeerConnectionInterface::RTCConfiguration configuration;
402 configuration.rtcp_mux_policy = rtcp_mux_policy;
Henrik Lundin64dad832015-05-11 12:44:23 +0200403 Init(NULL, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000404 }
405
406 void InitWithDtls(bool identity_request_should_fail = false) {
407 FakeIdentityService* identity_service = new FakeIdentityService();
408 identity_service->set_should_fail(identity_request_should_fail);
Henrik Lundin64dad832015-05-11 12:44:23 +0200409 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Lundin64dad832015-05-11 12:44:23 +0200410 Init(identity_service, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000411 }
412
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000413 void InitWithDtmfCodec() {
414 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000415 const cricket::AudioCodec kTelephoneEventCodec(
416 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000417 std::vector<cricket::AudioCodec> codecs;
418 codecs.push_back(kTelephoneEventCodec);
419 media_engine_->SetAudioCodecs(codecs);
420 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000421 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000422 }
423
424 // Creates a local offer and applies it. Starts ice.
425 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
426 // to decide which streams to create.
427 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000428 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000429 SetLocalDescriptionWithoutError(offer);
430 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
431 observer_.ice_gathering_state_,
432 kIceCandidatesTimeout);
433 }
434
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000435 SessionDescriptionInterface* CreateOffer() {
436 PeerConnectionInterface::RTCOfferAnswerOptions options;
437 options.offer_to_receive_audio =
438 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
439
440 return CreateOffer(options);
441 }
442
wu@webrtc.org91053e72013-08-10 07:18:04 +0000443 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000444 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000445 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000446 observer = new WebRtcSessionCreateSDPObserverForTest();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000447 session_->CreateOffer(observer, options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000448 EXPECT_TRUE_WAIT(
449 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000450 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000451 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000452 }
453
454 SessionDescriptionInterface* CreateAnswer(
455 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000456 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000457 = new WebRtcSessionCreateSDPObserverForTest();
458 session_->CreateAnswer(observer, constraints);
459 EXPECT_TRUE_WAIT(
460 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000461 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000462 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000463 }
464
wu@webrtc.org364f2042013-11-20 21:49:41 +0000465 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000466 return (session_->voice_channel() != NULL &&
467 session_->video_channel() != NULL);
468 }
469
wu@webrtc.org364f2042013-11-20 21:49:41 +0000470 void CheckTransportChannels() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000471 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 1) != NULL);
472 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 2) != NULL);
473 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 1) != NULL);
474 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 2) != NULL);
475 }
476
477 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
478 ASSERT_TRUE(session_.get() != NULL);
479 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
480 ASSERT_TRUE(content != NULL);
481 const cricket::AudioContentDescription* audio_content =
482 static_cast<const cricket::AudioContentDescription*>(
483 content->description);
484 ASSERT_TRUE(audio_content != NULL);
485 ASSERT_EQ(1U, audio_content->cryptos().size());
486 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
487 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
488 audio_content->cryptos()[0].cipher_suite);
489 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
490 audio_content->protocol());
491
492 content = cricket::GetFirstVideoContent(sdp);
493 ASSERT_TRUE(content != NULL);
494 const cricket::VideoContentDescription* video_content =
495 static_cast<const cricket::VideoContentDescription*>(
496 content->description);
497 ASSERT_TRUE(video_content != NULL);
498 ASSERT_EQ(1U, video_content->cryptos().size());
499 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
500 video_content->cryptos()[0].cipher_suite);
501 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
502 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
503 video_content->protocol());
504 }
505
506 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
507 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
508 ASSERT_TRUE(content != NULL);
509 const cricket::AudioContentDescription* audio_content =
510 static_cast<const cricket::AudioContentDescription*>(
511 content->description);
512 ASSERT_TRUE(audio_content != NULL);
513 ASSERT_EQ(0U, audio_content->cryptos().size());
514
515 content = cricket::GetFirstVideoContent(sdp);
516 ASSERT_TRUE(content != NULL);
517 const cricket::VideoContentDescription* video_content =
518 static_cast<const cricket::VideoContentDescription*>(
519 content->description);
520 ASSERT_TRUE(video_content != NULL);
521 ASSERT_EQ(0U, video_content->cryptos().size());
522
523 if (dtls) {
524 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
525 audio_content->protocol());
526 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
527 video_content->protocol());
528 } else {
529 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
530 audio_content->protocol());
531 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
532 video_content->protocol());
533 }
534 }
535
536 // Set the internal fake description factories to do DTLS-SRTP.
537 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000538 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000539 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000540 rtc::ToString(rtc::CreateRandomId());
541 identity_.reset(rtc::SSLIdentity::Generate(identity_name));
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000542 tdesc_factory_->set_identity(identity_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000543 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
544 }
545
546 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
547 bool expected) {
548 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
549 ASSERT_TRUE(audio != NULL);
550 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000551 const TransportInfo* video = sdp->GetTransportInfoByName("video");
552 ASSERT_TRUE(video != NULL);
553 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000554 }
555
556 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000557 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000558 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000559 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000560 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000561 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000562 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000563 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000564 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
565 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000566 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000567 // Answer should be NULL as no crypto params in offer.
568 ASSERT_TRUE(answer == NULL);
569 }
570
571 void VerifyAnswerFromCryptoOffer() {
572 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000573 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000574 options.bundle_enabled = true;
575 scoped_ptr<JsepSessionDescription> offer(
576 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
577 ASSERT_TRUE(offer.get() != NULL);
578 VerifyCryptoParams(offer->description());
579 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000580 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000581 ASSERT_TRUE(answer.get() != NULL);
582 VerifyCryptoParams(answer->description());
583 }
584
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000585 void SetAndVerifyNumUnsignalledRecvStreams(
586 int value_set, int value_expected) {
587 constraints_.reset(new FakeConstraints());
588 constraints_->AddOptional(
589 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
590 value_set);
591 session_.reset();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000592 Init();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000593 mediastream_signaling_.SendAudioVideoStream1();
594 SessionDescriptionInterface* offer = CreateOffer();
595
596 SetLocalDescriptionWithoutError(offer);
597
598 video_channel_ = media_engine_->GetVideoChannel(0);
599
600 ASSERT_TRUE(video_channel_ != NULL);
601 cricket::VideoOptions video_options;
602 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
603 EXPECT_EQ(value_expected,
604 video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1));
605 }
606
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000607 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
608 const cricket::SessionDescription* desc2,
609 bool expect_equal) {
610 if (desc1->contents().size() != desc2->contents().size()) {
611 EXPECT_FALSE(expect_equal);
612 return;
613 }
614
615 const cricket::ContentInfos& contents = desc1->contents();
616 cricket::ContentInfos::const_iterator it = contents.begin();
617
618 for (; it != contents.end(); ++it) {
619 const cricket::TransportDescription* transport_desc1 =
620 desc1->GetTransportDescriptionByName(it->name);
621 const cricket::TransportDescription* transport_desc2 =
622 desc2->GetTransportDescriptionByName(it->name);
623 if (!transport_desc1 || !transport_desc2) {
624 EXPECT_FALSE(expect_equal);
625 return;
626 }
627 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
628 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
629 EXPECT_FALSE(expect_equal);
630 return;
631 }
632 }
633 EXPECT_TRUE(expect_equal);
634 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000635
636 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
637 std::string *sdp) {
638 const cricket::SessionDescription* desc = current_desc->description();
639 EXPECT_TRUE(current_desc->ToString(sdp));
640
641 const cricket::ContentInfos& contents = desc->contents();
642 cricket::ContentInfos::const_iterator it = contents.begin();
643 // Replace ufrag and pwd lines with empty strings.
644 for (; it != contents.end(); ++it) {
645 const cricket::TransportDescription* transport_desc =
646 desc->GetTransportDescriptionByName(it->name);
647 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
648 + "\r\n";
649 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
650 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000651 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000652 "", 0,
653 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000654 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000655 "", 0,
656 sdp);
657 }
658 }
659
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000660 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
661 const std::string& modified_ice_ufrag,
662 const std::string& modified_ice_pwd,
663 std::string* sdp) {
664 const cricket::SessionDescription* desc = current_desc->description();
665 EXPECT_TRUE(current_desc->ToString(sdp));
666
667 const cricket::ContentInfos& contents = desc->contents();
668 cricket::ContentInfos::const_iterator it = contents.begin();
669 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
670 // |modified_ice_pwd| strings.
671 for (; it != contents.end(); ++it) {
672 const cricket::TransportDescription* transport_desc =
673 desc->GetTransportDescriptionByName(it->name);
674 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
675 + "\r\n";
676 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
677 + "\r\n";
678 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
679 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000680 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000681 mod_ufrag.c_str(), mod_ufrag.length(),
682 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000683 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000684 mod_pwd.c_str(), mod_pwd.length(),
685 sdp);
686 }
687 }
688
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000689 // Creates a remote offer and and applies it as a remote description,
690 // creates a local answer and applies is as a local description.
691 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
692 // to decide which local and remote streams to create.
693 void CreateAndSetRemoteOfferAndLocalAnswer() {
694 SessionDescriptionInterface* offer = CreateRemoteOffer();
695 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000696 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000697 SetLocalDescriptionWithoutError(answer);
698 }
699 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
700 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
701 }
702 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
703 BaseSession::State expected_state) {
704 SetLocalDescriptionWithoutError(desc);
705 EXPECT_EQ(expected_state, session_->state());
706 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000707 void SetLocalDescriptionExpectError(const std::string& action,
708 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000709 SessionDescriptionInterface* desc) {
710 std::string error;
711 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000712 std::string sdp_type = "local ";
713 sdp_type.append(action);
714 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000715 EXPECT_NE(std::string::npos, error.find(expected_error));
716 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000717 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
718 SessionDescriptionInterface* desc) {
719 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
720 expected_error, desc);
721 }
722 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
723 SessionDescriptionInterface* desc) {
724 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
725 expected_error, desc);
726 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000727 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
728 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
729 }
730 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
731 BaseSession::State expected_state) {
732 SetRemoteDescriptionWithoutError(desc);
733 EXPECT_EQ(expected_state, session_->state());
734 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000735 void SetRemoteDescriptionExpectError(const std::string& action,
736 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000737 SessionDescriptionInterface* desc) {
738 std::string error;
739 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000740 std::string sdp_type = "remote ";
741 sdp_type.append(action);
742 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000743 EXPECT_NE(std::string::npos, error.find(expected_error));
744 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000745 void SetRemoteDescriptionOfferExpectError(
746 const std::string& expected_error, SessionDescriptionInterface* desc) {
747 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
748 expected_error, desc);
749 }
750 void SetRemoteDescriptionPranswerExpectError(
751 const std::string& expected_error, SessionDescriptionInterface* desc) {
752 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
753 expected_error, desc);
754 }
755 void SetRemoteDescriptionAnswerExpectError(
756 const std::string& expected_error, SessionDescriptionInterface* desc) {
757 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
758 expected_error, desc);
759 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760
761 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
762 SessionDescriptionInterface** nocrypto_answer) {
763 // Create a SDP without Crypto.
764 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000765 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000766 options.bundle_enabled = true;
767 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
768 ASSERT_TRUE(*offer != NULL);
769 VerifyCryptoParams((*offer)->description());
770
771 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
772 cricket::SEC_DISABLED);
773 EXPECT_TRUE(*nocrypto_answer != NULL);
774 }
775
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000776 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
777 SessionDescriptionInterface** nodtls_answer) {
778 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000779 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000780 options.bundle_enabled = true;
781
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000782 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000783 CreateRemoteOffer(options, cricket::SEC_ENABLED));
784
785 *nodtls_answer =
786 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
787 EXPECT_TRUE(*nodtls_answer != NULL);
788 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
789 VerifyCryptoParams((*nodtls_answer)->description());
790
791 SetFactoryDtlsSrtp();
792 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
793 ASSERT_TRUE(*offer != NULL);
794 VerifyFingerprintStatus((*offer)->description(), true);
795 VerifyCryptoParams((*offer)->description());
796 }
797
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000798 JsepSessionDescription* CreateRemoteOfferWithVersion(
799 cricket::MediaSessionOptions options,
800 cricket::SecurePolicy secure_policy,
801 const std::string& session_version,
802 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000803 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 const cricket::SessionDescription* cricket_desc = NULL;
805 if (current_desc) {
806 cricket_desc = current_desc->description();
807 session_id = current_desc->session_id();
808 }
809
810 desc_factory_->set_secure(secure_policy);
811 JsepSessionDescription* offer(
812 new JsepSessionDescription(JsepSessionDescription::kOffer));
813 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
814 session_id, session_version)) {
815 delete offer;
816 offer = NULL;
817 }
818 return offer;
819 }
820 JsepSessionDescription* CreateRemoteOffer(
821 cricket::MediaSessionOptions options) {
822 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
823 kSessionVersion, NULL);
824 }
825 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000826 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
827 return CreateRemoteOfferWithVersion(
828 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000829 }
830 JsepSessionDescription* CreateRemoteOffer(
831 cricket::MediaSessionOptions options,
832 const SessionDescriptionInterface* current_desc) {
833 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
834 kSessionVersion, current_desc);
835 }
836
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000837 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
838 const char* sctp_stream_name, int new_port,
839 cricket::MediaSessionOptions options) {
840 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000841 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
842 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000843 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
844 }
845
846 // Takes ownership of offer_basis (and deletes it).
847 JsepSessionDescription* ChangeSDPSctpPort(
848 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
849 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
850 // SessionDescription from the mutated string.
851 const char* default_port_str = "5000";
852 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000853 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000854 std::string offer_str;
855 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000856 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000857 new_port_str, strlen(new_port_str),
858 &offer_str);
859 JsepSessionDescription* offer = new JsepSessionDescription(
860 offer_basis->type());
861 delete offer_basis;
862 offer->Initialize(offer_str, NULL);
863 return offer;
864 }
865
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
867 // before this function to decide which streams to create.
868 JsepSessionDescription* CreateRemoteOffer() {
869 cricket::MediaSessionOptions options;
870 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
871 return CreateRemoteOffer(options, session_->remote_description());
872 }
873
874 JsepSessionDescription* CreateRemoteAnswer(
875 const SessionDescriptionInterface* offer,
876 cricket::MediaSessionOptions options,
877 cricket::SecurePolicy policy) {
878 desc_factory_->set_secure(policy);
879 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000880 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000881 JsepSessionDescription* answer(
882 new JsepSessionDescription(JsepSessionDescription::kAnswer));
883 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
884 options, NULL),
885 session_id, kSessionVersion)) {
886 delete answer;
887 answer = NULL;
888 }
889 return answer;
890 }
891
892 JsepSessionDescription* CreateRemoteAnswer(
893 const SessionDescriptionInterface* offer,
894 cricket::MediaSessionOptions options) {
895 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
896 }
897
898 // Creates an answer session description with streams based on
899 // |mediastream_signaling_|. Call
900 // mediastream_signaling_.UseOptionsWithStreamX() before this function
901 // to decide which streams to create.
902 JsepSessionDescription* CreateRemoteAnswer(
903 const SessionDescriptionInterface* offer) {
904 cricket::MediaSessionOptions options;
905 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
906 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
907 }
908
909 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000910 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000911 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000912 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000913
914 PeerConnectionInterface::RTCOfferAnswerOptions options;
915 options.use_rtp_mux = bundle;
916
917 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000918 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
919 // and answer.
920 SetLocalDescriptionWithoutError(offer);
921
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000922 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000923 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000924 std::string sdp;
925 EXPECT_TRUE(answer->ToString(&sdp));
926
927 size_t expected_candidate_num = 2;
928 if (!rtcp_mux) {
929 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
930 // for rtp and rtcp.
931 expected_candidate_num = 4;
932 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 const std::string kRtcpMux = "a=rtcp-mux";
934 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000935 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000936 kXRtcpMux.c_str(), kXRtcpMux.length(),
937 &sdp);
938 }
939
940 SessionDescriptionInterface* new_answer = CreateSessionDescription(
941 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000942
943 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000944 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
946 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
947 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
948 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
949 cricket::Candidate c0 = observer_.mline_0_candidates_[i];
950 cricket::Candidate c1 = observer_.mline_1_candidates_[i];
951 if (bundle) {
952 EXPECT_TRUE(c0.IsEquivalent(c1));
953 } else {
954 EXPECT_FALSE(c0.IsEquivalent(c1));
955 }
956 }
957 }
958 // Tests that we can only send DTMF when the dtmf codec is supported.
959 void TestCanInsertDtmf(bool can) {
960 if (can) {
961 InitWithDtmfCodec();
962 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000963 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000964 }
965 mediastream_signaling_.SendAudioVideoStream1();
966 CreateAndSetRemoteOfferAndLocalAnswer();
967 EXPECT_FALSE(session_->CanInsertDtmf(""));
968 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
969 }
970
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000971 // Helper class to configure loopback network and verify Best
972 // Connection using right IP protocol for TestLoopbackCall
973 // method. LoopbackNetworkManager applies firewall rules to block
974 // all ping traffic once ICE completed, and remove them to observe
975 // ICE reconnected again. This LoopbackNetworkConfiguration struct
976 // verifies the best connection is using the right IP protocol after
977 // initial ICE convergences.
978
979 class LoopbackNetworkConfiguration {
980 public:
981 LoopbackNetworkConfiguration()
982 : test_ipv6_network_(false),
983 test_extra_ipv4_network_(false),
984 best_connection_after_initial_ice_converged_(1, 0) {}
985
986 // Used to track the expected best connection count in each IP protocol.
987 struct ExpectedBestConnection {
988 ExpectedBestConnection(int ipv4_count, int ipv6_count)
989 : ipv4_count_(ipv4_count),
990 ipv6_count_(ipv6_count) {}
991
992 int ipv4_count_;
993 int ipv6_count_;
994 };
995
996 bool test_ipv6_network_;
997 bool test_extra_ipv4_network_;
998 ExpectedBestConnection best_connection_after_initial_ice_converged_;
999
1000 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001001 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001002 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1003 }
1004
1005 private:
jbauchac8869e2015-07-03 01:36:14 -07001006 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001007 const ExpectedBestConnection& expected) const {
1008 EXPECT_EQ(
jbauchac8869e2015-07-03 01:36:14 -07001009 metrics_observer->GetCounter(webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001010 expected.ipv4_count_);
1011 EXPECT_EQ(
jbauchac8869e2015-07-03 01:36:14 -07001012 metrics_observer->GetCounter(webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001013 expected.ipv6_count_);
1014 }
1015 };
1016
1017 class LoopbackNetworkManager {
1018 public:
1019 LoopbackNetworkManager(WebRtcSessionTest* session,
1020 const LoopbackNetworkConfiguration& config)
1021 : config_(config) {
1022 session->AddInterface(
1023 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1024 if (config_.test_extra_ipv4_network_) {
1025 session->AddInterface(
1026 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1027 }
1028 if (config_.test_ipv6_network_) {
1029 session->AddInterface(
1030 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1031 }
1032 }
1033
1034 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1035 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1036 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1037 if (config_.test_extra_ipv4_network_) {
1038 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1039 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1040 }
1041 if (config_.test_ipv6_network_) {
1042 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1043 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1044 }
1045 }
1046
1047 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1048
1049 private:
1050 LoopbackNetworkConfiguration config_;
1051 };
1052
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001053 // The method sets up a call from the session to itself, in a loopback
1054 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001055 // disconnection, and then a permanent disconnection.
1056 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001057 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1058 // While running the call, this method also checks if the session goes through
1059 // the correct sequence of ICE states when a connection is established,
1060 // broken, and re-established.
1061 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001062 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1063 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001064 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001065
1066 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1067 LoopbackNetworkManager loopback_network_manager(this, config);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001068 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001069 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001070 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001071
1072 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1073 observer_.ice_gathering_state_);
1074 SetLocalDescriptionWithoutError(offer);
1075 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1076 observer_.ice_connection_state_);
1077 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
1078 observer_.ice_gathering_state_,
1079 kIceCandidatesTimeout);
1080 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1081 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
1082 observer_.ice_gathering_state_,
1083 kIceCandidatesTimeout);
1084
1085 std::string sdp;
1086 offer->ToString(&sdp);
1087 SessionDescriptionInterface* desc =
1088 webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer, sdp);
1089 ASSERT_TRUE(desc != NULL);
1090 SetRemoteDescriptionWithoutError(desc);
1091
1092 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
1093 observer_.ice_connection_state_,
1094 kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001095
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001096 // The ice connection state is "Connected" too briefly to catch in a test.
1097 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001098 observer_.ice_connection_state_,
1099 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001100
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001101 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001102 // Adding firewall rule to block ping requests, which should cause
1103 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001104
1105 loopback_network_manager.ApplyFirewallRules(fss_.get());
1106
1107 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001108 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1109 observer_.ice_connection_state_,
1110 kIceCandidatesTimeout);
1111
jbauchac8869e2015-07-03 01:36:14 -07001112 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001113
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001114 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001115 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001116 // Session is automatically calling OnSignalingReady after creation of
1117 // new portallocator session which will allocate new set of candidates.
1118
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001119 LOG(LS_INFO) << "Firewall Rules cleared";
1120
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001121 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001122 observer_.ice_connection_state_,
1123 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001124
1125 // Now we block ping requests and wait until the ICE connection transitions
1126 // to the Failed state. This will take at least 30 seconds because it must
1127 // wait for the Port to timeout.
1128 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001129
1130 loopback_network_manager.ApplyFirewallRules(fss_.get());
1131 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001132 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001133 observer_.ice_connection_state_,
1134 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001135 }
1136
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001137 void TestLoopbackCall() {
1138 LoopbackNetworkConfiguration config;
1139 TestLoopbackCall(config);
1140 }
1141
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001142 void VerifyTransportType(const std::string& content_name,
1143 cricket::TransportProtocol protocol) {
1144 const cricket::Transport* transport = session_->GetTransport(content_name);
1145 ASSERT_TRUE(transport != NULL);
1146 EXPECT_EQ(protocol, transport->protocol());
1147 }
1148
1149 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1150 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001151 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1152 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1153
1154 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001155 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1156 codecs.push_back(kCNCodec1);
1157 codecs.push_back(kCNCodec2);
1158 media_engine_->SetAudioCodecs(codecs);
1159 desc_factory_->set_audio_codecs(codecs);
1160 }
1161
1162 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1163 const cricket::ContentDescription* description = content->description;
1164 ASSERT(description != NULL);
1165 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001166 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001167 ASSERT(audio_content_desc != NULL);
1168 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1169 if (audio_content_desc->codecs()[i].name == "CN")
1170 return false;
1171 }
1172 return true;
1173 }
1174
1175 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001176 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001177 dci.reliable = false;
1178 session_->CreateDataChannel("datachannel", &dci);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001179 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001180 SetLocalDescriptionWithoutError(offer);
1181 }
1182
wu@webrtc.org91053e72013-08-10 07:18:04 +00001183 void VerifyMultipleAsyncCreateDescription(
1184 bool success, CreateSessionDescriptionRequest::Type type) {
henrike@webrtc.org7666db72013-08-22 14:45:42 +00001185 InitWithDtls(!success);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001186 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001187 if (type == CreateSessionDescriptionRequest::kAnswer) {
1188 cricket::MediaSessionOptions options;
1189 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001190 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001191 ASSERT_TRUE(offer.get() != NULL);
1192 SetRemoteDescriptionWithoutError(offer.release());
1193 }
1194
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001195 PeerConnectionInterface::RTCOfferAnswerOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001196 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001197 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001198 observers[kNumber];
1199 for (int i = 0; i < kNumber; ++i) {
1200 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1201 if (type == CreateSessionDescriptionRequest::kOffer) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001202 session_->CreateOffer(observers[i], options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001203 } else {
1204 session_->CreateAnswer(observers[i], NULL);
1205 }
1206 }
1207
1208 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1209 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1210 WebRtcSessionCreateSDPObserverForTest::kFailed;
1211
1212 for (int i = 0; i < kNumber; ++i) {
1213 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1214 if (success) {
1215 EXPECT_TRUE(observers[i]->description() != NULL);
1216 } else {
1217 EXPECT_TRUE(observers[i]->description() == NULL);
1218 }
1219 }
1220 }
1221
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001222 void ConfigureAllocatorWithTurn() {
1223 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1224 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
1225 relay_server.credentials = credentials;
1226 relay_server.ports.push_back(cricket::ProtocolAddress(
1227 kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1228 allocator_->AddRelay(relay_server);
1229 allocator_->set_step_delay(cricket::kMinimumStepDelay);
1230 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
jiayl@webrtc.orgdacdd942015-01-23 17:33:34 +00001231 cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001232 }
1233
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001234 cricket::FakeMediaEngine* media_engine_;
1235 cricket::FakeDataEngine* data_engine_;
1236 cricket::FakeDeviceManager* device_manager_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001237 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
1238 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1239 rtc::scoped_ptr<rtc::SSLIdentity> identity_;
1240 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1241 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1242 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1243 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1244 rtc::SocketServerScope ss_scope_;
1245 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001246 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001247 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001248 rtc::FakeNetworkManager network_manager_;
1249 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001250 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001251 rtc::scoped_ptr<FakeConstraints> constraints_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001252 FakeMediaStreamSignaling mediastream_signaling_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001253 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001254 MockIceObserver observer_;
1255 cricket::FakeVideoMediaChannel* video_channel_;
1256 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001257 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001258};
1259
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001260TEST_F(WebRtcSessionTest, TestInitializeWithDtls) {
1261 InitWithDtls();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001262 // SDES is disabled when DTLS is on.
1263 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001264}
1265
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001266TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001267 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001268 // SDES is required if DTLS is off.
1269 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001270}
1271
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001272TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1273 TestSessionCandidatesWithBundleRtcpMux(false, false);
1274}
1275
1276// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1277// with rtcp-mux and/or bundle.
1278TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1279 TestSessionCandidatesWithBundleRtcpMux(false, true);
1280}
1281
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001282TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1283 TestSessionCandidatesWithBundleRtcpMux(true, true);
1284}
1285
1286TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001287 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1288 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001289 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290 mediastream_signaling_.SendAudioVideoStream1();
1291 InitiateCall();
1292 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1293 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1294 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1295}
1296
1297TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001298 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1299 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001300 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001301 rtc::FP_UDP,
1302 rtc::FD_ANY,
1303 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001304 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001305 mediastream_signaling_.SendAudioVideoStream1();
1306 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001307 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001308 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1309 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1310 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1311}
1312
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001313// Test session delivers no candidates gathered when constraint set to "none".
1314TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1315 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001316 InitWithIceTransport(PeerConnectionInterface::kNone);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001317 mediastream_signaling_.SendAudioVideoStream1();
1318 InitiateCall();
1319 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1320 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1321 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1322}
1323
1324// Test session delivers only relay candidates gathered when constaint set to
1325// "relay".
1326TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1327 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1328 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001329 InitWithIceTransport(PeerConnectionInterface::kRelay);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001330 mediastream_signaling_.SendAudioVideoStream1();
1331 InitiateCall();
1332 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1333 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1334 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1335 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1336 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1337 observer_.mline_0_candidates_[i].type());
1338 }
1339 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1340 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1341 observer_.mline_1_candidates_[i].type());
1342 }
1343}
1344
1345// Test session delivers all candidates gathered when constaint set to "all".
1346TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1347 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001348 InitWithIceTransport(PeerConnectionInterface::kAll);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001349 mediastream_signaling_.SendAudioVideoStream1();
1350 InitiateCall();
1351 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1352 // Host + STUN. By default allocator is disabled to gather relay candidates.
1353 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1354 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1355}
1356
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001357TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001358 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001359 SessionDescriptionInterface* offer = NULL;
1360 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1361 std::string unknown_action;
1362 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1363 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1364}
1365
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001366// Test creating offers and receive answers and make sure the
1367// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001368TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001369 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001370 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001371 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001372 const std::string session_id_orig = offer->session_id();
1373 const std::string session_version_orig = offer->session_version();
1374 SetLocalDescriptionWithoutError(offer);
1375
1376 mediastream_signaling_.SendAudioVideoStream2();
1377 SessionDescriptionInterface* answer =
1378 CreateRemoteAnswer(session_->local_description());
1379 SetRemoteDescriptionWithoutError(answer);
1380
1381 video_channel_ = media_engine_->GetVideoChannel(0);
1382 voice_channel_ = media_engine_->GetVoiceChannel(0);
1383
1384 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1385 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1386
1387 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1388 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1389
1390 ASSERT_EQ(1u, video_channel_->send_streams().size());
1391 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1392 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1393 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1394
1395 // Create new offer without send streams.
1396 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001397 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001398
1399 // Verify the session id is the same and the session version is
1400 // increased.
1401 EXPECT_EQ(session_id_orig, offer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001402 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1403 rtc::FromString<uint64>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001404
1405 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001406 EXPECT_EQ(0u, video_channel_->send_streams().size());
1407 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001408
1409 mediastream_signaling_.SendAudioVideoStream2();
1410 answer = CreateRemoteAnswer(session_->local_description());
1411 SetRemoteDescriptionWithoutError(answer);
1412
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001413 // Make sure the receive streams have not changed.
1414 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1415 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1416 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1417 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1418}
1419
1420// Test receiving offers and creating answers and make sure the
1421// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001422TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001423 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001424 mediastream_signaling_.SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001425 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001426 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001427 SetRemoteDescriptionWithoutError(offer);
1428
1429 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001430 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001431 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001432 SetLocalDescriptionWithoutError(answer);
1433
1434 const std::string session_id_orig = answer->session_id();
1435 const std::string session_version_orig = answer->session_version();
1436
1437 video_channel_ = media_engine_->GetVideoChannel(0);
1438 voice_channel_ = media_engine_->GetVoiceChannel(0);
1439
1440 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1441 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1442
1443 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1444 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1445
1446 ASSERT_EQ(1u, video_channel_->send_streams().size());
1447 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1448 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1449 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1450
1451 mediastream_signaling_.SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001452 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001453 SetRemoteDescriptionWithoutError(offer);
1454
1455 // Answer by turning off all send streams.
1456 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001457 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001458
1459 // Verify the session id is the same and the session version is
1460 // increased.
1461 EXPECT_EQ(session_id_orig, answer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001462 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1463 rtc::FromString<uint64>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001464 SetLocalDescriptionWithoutError(answer);
1465
1466 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1467 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1468 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1469 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1470 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1471 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1472
1473 // Make sure we have no send streams.
1474 EXPECT_EQ(0u, video_channel_->send_streams().size());
1475 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1476}
1477
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001478TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001479 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001480 media_engine_->set_fail_create_channel(true);
1481
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001482 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001483 ASSERT_TRUE(offer != NULL);
1484 // SetRemoteDescription and SetLocalDescription will take the ownership of
1485 // the offer.
1486 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001487 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001488 ASSERT_TRUE(offer != NULL);
1489 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1490}
1491
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001492//
1493// Tests for creating/setting SDP under different SDES/DTLS polices:
1494//
1495// --DTLS off and SDES on
1496// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1497// set local/remote offer/answer with crypto --> success
1498// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1499// failure
1500// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1501// failure
1502// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1503// failure
1504//
1505// --DTLS on and SDES off
1506// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1507// set local/remote offer/answer with DTLS fingerprint --> success
1508// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1509// fingerprint --> failure
1510// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1511// --> failure
1512// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1513// --> failure
1514//
1515// --Encryption disabled: DTLS off and SDES off
1516// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1517// answer without SDES or DTLS --> success
1518// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1519// answer without SDES or DTLS --> success
1520//
1521
1522// Test that we return a failure when applying a remote/local offer that doesn't
1523// have cryptos enabled when DTLS is off.
1524TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001525 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001526 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001527 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001528 JsepSessionDescription* offer = CreateRemoteOffer(
1529 options, cricket::SEC_DISABLED);
1530 ASSERT_TRUE(offer != NULL);
1531 VerifyNoCryptoParams(offer->description(), false);
1532 // SetRemoteDescription and SetLocalDescription will take the ownership of
1533 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001534 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001535 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1536 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001537 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001538}
1539
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001540// Test that we return a failure when applying a local answer that doesn't have
1541// cryptos enabled when DTLS is off.
1542TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001543 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001544 SessionDescriptionInterface* offer = NULL;
1545 SessionDescriptionInterface* answer = NULL;
1546 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1547 // SetRemoteDescription and SetLocalDescription will take the ownership of
1548 // the offer.
1549 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001550 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001551}
1552
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001553// Test we will return fail when apply an remote answer that doesn't have
1554// crypto enabled when DTLS is off.
1555TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001556 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001557 SessionDescriptionInterface* offer = NULL;
1558 SessionDescriptionInterface* answer = NULL;
1559 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1560 // SetRemoteDescription and SetLocalDescription will take the ownership of
1561 // the offer.
1562 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001563 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001564}
1565
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001566// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1567// and that we return an answer with a DTLS fingerprint.
1568TEST_F(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001569 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001570 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001571 InitWithDtls();
1572 SetFactoryDtlsSrtp();
1573 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001574 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001575 JsepSessionDescription* offer =
1576 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001577 ASSERT_TRUE(offer != NULL);
1578 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001579 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001580
1581 // SetRemoteDescription will take the ownership of the offer.
1582 SetRemoteDescriptionWithoutError(offer);
1583
1584 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001585 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001586 ASSERT_TRUE(answer != NULL);
1587 VerifyFingerprintStatus(answer->description(), true);
1588 // Check that we don't have an a=crypto line in the answer.
1589 VerifyNoCryptoParams(answer->description(), true);
1590
1591 // Now set the local description, which should work, even without a=crypto.
1592 SetLocalDescriptionWithoutError(answer);
1593}
1594
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001595// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1596// and then we accept a remote answer with a DTLS fingerprint successfully.
1597TEST_F(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001598 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001599 mediastream_signaling_.SendAudioVideoStream1();
1600 InitWithDtls();
1601 SetFactoryDtlsSrtp();
1602
1603 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001604 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001605 ASSERT_TRUE(offer != NULL);
1606 VerifyFingerprintStatus(offer->description(), true);
1607 // Check that we don't have an a=crypto line in the offer.
1608 VerifyNoCryptoParams(offer->description(), true);
1609
1610 // Now set the local description, which should work, even without a=crypto.
1611 SetLocalDescriptionWithoutError(offer);
1612
1613 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001614 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001615 JsepSessionDescription* answer =
1616 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1617 ASSERT_TRUE(answer != NULL);
1618 VerifyFingerprintStatus(answer->description(), true);
1619 VerifyNoCryptoParams(answer->description(), true);
1620
1621 // SetRemoteDescription will take the ownership of the answer.
1622 SetRemoteDescriptionWithoutError(answer);
1623}
1624
1625// Test that if we support DTLS and the other side didn't offer a fingerprint,
1626// we will fail to set the remote description.
1627TEST_F(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001628 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001629 InitWithDtls();
1630 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001631 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001632 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001633 JsepSessionDescription* offer = CreateRemoteOffer(
1634 options, cricket::SEC_REQUIRED);
1635 ASSERT_TRUE(offer != NULL);
1636 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001637 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001638
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001639 // SetRemoteDescription will take the ownership of the offer.
1640 SetRemoteDescriptionOfferExpectError(
1641 kSdpWithoutDtlsFingerprint, offer);
1642
1643 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1644 // SetLocalDescription will take the ownership of the offer.
1645 SetLocalDescriptionOfferExpectError(
1646 kSdpWithoutDtlsFingerprint, offer);
1647}
1648
1649// Test that we return a failure when applying a local answer that doesn't have
1650// a DTLS fingerprint when DTLS is required.
1651TEST_F(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001652 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001653 InitWithDtls();
1654 SessionDescriptionInterface* offer = NULL;
1655 SessionDescriptionInterface* answer = NULL;
1656 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1657
1658 // SetRemoteDescription and SetLocalDescription will take the ownership of
1659 // the offer and answer.
1660 SetRemoteDescriptionWithoutError(offer);
1661 SetLocalDescriptionAnswerExpectError(
1662 kSdpWithoutDtlsFingerprint, answer);
1663}
1664
1665// Test that we return a failure when applying a remote answer that doesn't have
1666// a DTLS fingerprint when DTLS is required.
1667TEST_F(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001668 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001669 InitWithDtls();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001670 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001671 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001672 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001673 JsepSessionDescription* answer =
1674 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
1675
1676 // SetRemoteDescription and SetLocalDescription will take the ownership of
1677 // the offer and answer.
1678 SetLocalDescriptionWithoutError(offer);
1679 SetRemoteDescriptionAnswerExpectError(
1680 kSdpWithoutDtlsFingerprint, answer);
1681}
1682
1683// Test that we create a local offer without SDES or DTLS and accept a remote
1684// answer without SDES or DTLS when encryption is disabled.
1685TEST_F(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
1686 mediastream_signaling_.SendAudioVideoStream1();
1687 options_.disable_encryption = true;
1688 InitWithDtls();
1689
1690 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001691 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001692 ASSERT_TRUE(offer != NULL);
1693 VerifyFingerprintStatus(offer->description(), false);
1694 // Check that we don't have an a=crypto line in the offer.
1695 VerifyNoCryptoParams(offer->description(), false);
1696
1697 // Now set the local description, which should work, even without a=crypto.
1698 SetLocalDescriptionWithoutError(offer);
1699
1700 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001701 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001702 JsepSessionDescription* answer =
1703 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1704 ASSERT_TRUE(answer != NULL);
1705 VerifyFingerprintStatus(answer->description(), false);
1706 VerifyNoCryptoParams(answer->description(), false);
1707
1708 // SetRemoteDescription will take the ownership of the answer.
1709 SetRemoteDescriptionWithoutError(answer);
1710}
1711
1712// Test that we create a local answer without SDES or DTLS and accept a remote
1713// offer without SDES or DTLS when encryption is disabled.
1714TEST_F(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
1715 options_.disable_encryption = true;
1716 InitWithDtls();
1717
1718 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001719 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001720 JsepSessionDescription* offer =
1721 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1722 ASSERT_TRUE(offer != NULL);
1723 VerifyFingerprintStatus(offer->description(), false);
1724 VerifyNoCryptoParams(offer->description(), false);
1725
1726 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001727 SetRemoteDescriptionWithoutError(offer);
1728
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001729 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001730 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001731 ASSERT_TRUE(answer != NULL);
1732 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001733 // Check that we don't have an a=crypto line in the answer.
1734 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001735
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001736 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001737 SetLocalDescriptionWithoutError(answer);
1738}
1739
1740TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001741 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001742 mediastream_signaling_.SendNothing();
1743 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001744 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745 SetLocalDescriptionWithoutError(offer);
1746
1747 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001748 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001749 SetLocalDescriptionWithoutError(offer2);
1750}
1751
1752TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001753 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001754 mediastream_signaling_.SendNothing();
1755 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001756 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001757 SetRemoteDescriptionWithoutError(offer);
1758
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001759 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001760 SetRemoteDescriptionWithoutError(offer2);
1761}
1762
1763TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001764 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001766 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001767 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001768 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001769 SetRemoteDescriptionOfferExpectError(
1770 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001771}
1772
1773TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001774 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001776 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001777 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001778 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001779 SetLocalDescriptionOfferExpectError(
1780 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001781}
1782
1783TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001784 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001785 mediastream_signaling_.SendNothing();
1786 SessionDescriptionInterface* offer = CreateRemoteOffer();
1787 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1788
1789 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001790 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001791 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1792 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1793
1794 mediastream_signaling_.SendAudioVideoStream1();
1795 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001796 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001797 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1798
1799 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1800
1801 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001802 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001803 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1804}
1805
1806TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001807 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001808 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001809 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1811
1812 JsepSessionDescription* pranswer =
1813 CreateRemoteAnswer(session_->local_description());
1814 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1815
1816 SetRemoteDescriptionExpectState(pranswer,
1817 BaseSession::STATE_RECEIVEDPRACCEPT);
1818
1819 mediastream_signaling_.SendAudioVideoStream1();
1820 JsepSessionDescription* pranswer2 =
1821 CreateRemoteAnswer(session_->local_description());
1822 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1823
1824 SetRemoteDescriptionExpectState(pranswer2,
1825 BaseSession::STATE_RECEIVEDPRACCEPT);
1826
1827 mediastream_signaling_.SendAudioVideoStream2();
1828 SessionDescriptionInterface* answer =
1829 CreateRemoteAnswer(session_->local_description());
1830 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1831}
1832
1833TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001834 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001835 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001836 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1837
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001838 SessionDescriptionInterface* answer =
1839 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001840 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1841 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001842}
1843
1844TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001845 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001846 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001847 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1848
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001849 SessionDescriptionInterface* answer =
1850 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001851 SetRemoteDescriptionAnswerExpectError(
1852 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001853}
1854
1855TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001856 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857 mediastream_signaling_.SendAudioVideoStream1();
1858
1859 cricket::Candidate candidate;
1860 candidate.set_component(1);
1861 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1862
1863 // Fail since we have not set a offer description.
1864 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1865
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001866 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001867 SetLocalDescriptionWithoutError(offer);
1868 // Candidate should be allowed to add before remote description.
1869 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1870 candidate.set_component(2);
1871 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1872 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1873
1874 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1875 session_->local_description());
1876 SetRemoteDescriptionWithoutError(answer);
1877
1878 // Verifying the candidates are copied properly from internal vector.
1879 const SessionDescriptionInterface* remote_desc =
1880 session_->remote_description();
1881 ASSERT_TRUE(remote_desc != NULL);
1882 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1883 const IceCandidateCollection* candidates =
1884 remote_desc->candidates(kMediaContentIndex0);
1885 ASSERT_EQ(2u, candidates->count());
1886 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1887 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1888 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1889 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1890
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001891 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1892 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001893 candidate.set_component(2);
1894 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1895 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001896 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001897
1898 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1899 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1900}
1901
1902// Test that a remote candidate is added to the remote session description and
1903// that it is retained if the remote session description is changed.
1904TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001905 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001906 cricket::Candidate candidate1;
1907 candidate1.set_component(1);
1908 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1909 candidate1);
1910 mediastream_signaling_.SendAudioVideoStream1();
1911 CreateAndSetRemoteOfferAndLocalAnswer();
1912
1913 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1914 const SessionDescriptionInterface* remote_desc =
1915 session_->remote_description();
1916 ASSERT_TRUE(remote_desc != NULL);
1917 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1918 const IceCandidateCollection* candidates =
1919 remote_desc->candidates(kMediaContentIndex0);
1920 ASSERT_EQ(1u, candidates->count());
1921 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1922
1923 // Update the RemoteSessionDescription with a new session description and
1924 // a candidate and check that the new remote session description contains both
1925 // candidates.
1926 SessionDescriptionInterface* offer = CreateRemoteOffer();
1927 cricket::Candidate candidate2;
1928 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1929 candidate2);
1930 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1931 SetRemoteDescriptionWithoutError(offer);
1932
1933 remote_desc = session_->remote_description();
1934 ASSERT_TRUE(remote_desc != NULL);
1935 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1936 candidates = remote_desc->candidates(kMediaContentIndex0);
1937 ASSERT_EQ(2u, candidates->count());
1938 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1939 // Username and password have be updated with the TransportInfo of the
1940 // SessionDescription, won't be equal to the original one.
1941 candidate2.set_username(candidates->at(0)->candidate().username());
1942 candidate2.set_password(candidates->at(0)->candidate().password());
1943 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
1944 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
1945 // No need to verify the username and password.
1946 candidate1.set_username(candidates->at(1)->candidate().username());
1947 candidate1.set_password(candidates->at(1)->candidate().password());
1948 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
1949
1950 // Test that the candidate is ignored if we can add the same candidate again.
1951 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1952}
1953
1954// Test that local candidates are added to the local session description and
1955// that they are retained if the local session description is changed.
1956TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001957 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001958 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001959 mediastream_signaling_.SendAudioVideoStream1();
1960 CreateAndSetRemoteOfferAndLocalAnswer();
1961
1962 const SessionDescriptionInterface* local_desc = session_->local_description();
1963 const IceCandidateCollection* candidates =
1964 local_desc->candidates(kMediaContentIndex0);
1965 ASSERT_TRUE(candidates != NULL);
1966 EXPECT_EQ(0u, candidates->count());
1967
1968 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1969
1970 local_desc = session_->local_description();
1971 candidates = local_desc->candidates(kMediaContentIndex0);
1972 ASSERT_TRUE(candidates != NULL);
1973 EXPECT_LT(0u, candidates->count());
1974 candidates = local_desc->candidates(1);
1975 ASSERT_TRUE(candidates != NULL);
1976 EXPECT_LT(0u, candidates->count());
1977
1978 // Update the session descriptions.
1979 mediastream_signaling_.SendAudioVideoStream1();
1980 CreateAndSetRemoteOfferAndLocalAnswer();
1981
1982 local_desc = session_->local_description();
1983 candidates = local_desc->candidates(kMediaContentIndex0);
1984 ASSERT_TRUE(candidates != NULL);
1985 EXPECT_LT(0u, candidates->count());
1986 candidates = local_desc->candidates(1);
1987 ASSERT_TRUE(candidates != NULL);
1988 EXPECT_LT(0u, candidates->count());
1989}
1990
1991// Test that we can set a remote session description with remote candidates.
1992TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001993 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001994
1995 cricket::Candidate candidate1;
1996 candidate1.set_component(1);
1997 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
1998 candidate1);
1999 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002000 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001
2002 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2003 SetRemoteDescriptionWithoutError(offer);
2004
2005 const SessionDescriptionInterface* remote_desc =
2006 session_->remote_description();
2007 ASSERT_TRUE(remote_desc != NULL);
2008 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2009 const IceCandidateCollection* candidates =
2010 remote_desc->candidates(kMediaContentIndex0);
2011 ASSERT_EQ(1u, candidates->count());
2012 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2013
wu@webrtc.org91053e72013-08-10 07:18:04 +00002014 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002015 SetLocalDescriptionWithoutError(answer);
2016}
2017
2018// Test that offers and answers contains ice candidates when Ice candidates have
2019// been gathered.
2020TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002021 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002022 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002023 mediastream_signaling_.SendAudioVideoStream1();
2024 // Ice is started but candidates are not provided until SetLocalDescription
2025 // is called.
2026 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2027 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2028 CreateAndSetRemoteOfferAndLocalAnswer();
2029 // Wait until at least one local candidate has been collected.
2030 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2031 kIceCandidatesTimeout);
2032 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
2033 kIceCandidatesTimeout);
2034
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002035 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2036
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002037 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2038 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
2039 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
2040 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
2041
2042 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2043 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002044 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002045 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2046 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
2047 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
2048 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
2049 SetLocalDescriptionWithoutError(answer);
2050}
2051
2052// Verifies TransportProxy and media channels are created with content names
2053// present in the SessionDescription.
2054TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002055 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002056 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002057 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058
2059 // CreateOffer creates session description with the content names "audio" and
2060 // "video". Goal is to modify these content names and verify transport channel
2061 // proxy in the BaseSession, as proxies are created with the content names
2062 // present in SDP.
2063 std::string sdp;
2064 EXPECT_TRUE(offer->ToString(&sdp));
2065 const std::string kAudioMid = "a=mid:audio";
2066 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2067 const std::string kVideoMid = "a=mid:video";
2068 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2069
2070 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002071 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002072 kAudioMidReplaceStr.c_str(),
2073 kAudioMidReplaceStr.length(),
2074 &sdp);
2075 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002076 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002077 kVideoMidReplaceStr.c_str(),
2078 kVideoMidReplaceStr.length(),
2079 &sdp);
2080
2081 SessionDescriptionInterface* modified_offer =
2082 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2083
2084 SetRemoteDescriptionWithoutError(modified_offer);
2085
2086 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002087 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002088 SetLocalDescriptionWithoutError(answer);
2089
2090 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
2091 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
2092 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2093 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2094}
2095
2096// Test that an offer contains the correct media content descriptions based on
2097// the send streams when no constraints have been set.
2098TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002099 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002100 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2101
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002102 ASSERT_TRUE(offer != NULL);
2103 const cricket::ContentInfo* content =
2104 cricket::GetFirstAudioContent(offer->description());
2105 EXPECT_TRUE(content != NULL);
2106 content = cricket::GetFirstVideoContent(offer->description());
2107 EXPECT_TRUE(content == NULL);
2108}
2109
2110// Test that an offer contains the correct media content descriptions based on
2111// the send streams when no constraints have been set.
2112TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002113 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002114 // Test Audio only offer.
2115 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002116 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2117
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118 const cricket::ContentInfo* content =
2119 cricket::GetFirstAudioContent(offer->description());
2120 EXPECT_TRUE(content != NULL);
2121 content = cricket::GetFirstVideoContent(offer->description());
2122 EXPECT_TRUE(content == NULL);
2123
2124 // Test Audio / Video offer.
2125 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002126 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002127 content = cricket::GetFirstAudioContent(offer->description());
2128 EXPECT_TRUE(content != NULL);
2129 content = cricket::GetFirstVideoContent(offer->description());
2130 EXPECT_TRUE(content != NULL);
2131}
2132
2133// Test that an offer contains no media content descriptions if
2134// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2135TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002136 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002137 PeerConnectionInterface::RTCOfferAnswerOptions options;
2138 options.offer_to_receive_audio = 0;
2139 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002140
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002141 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002142 CreateOffer(options));
2143
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002144 ASSERT_TRUE(offer != NULL);
2145 const cricket::ContentInfo* content =
2146 cricket::GetFirstAudioContent(offer->description());
2147 EXPECT_TRUE(content == NULL);
2148 content = cricket::GetFirstVideoContent(offer->description());
2149 EXPECT_TRUE(content == NULL);
2150}
2151
2152// Test that an offer contains only audio media content descriptions if
2153// kOfferToReceiveAudio constraints are set to true.
2154TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002155 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002156 PeerConnectionInterface::RTCOfferAnswerOptions options;
2157 options.offer_to_receive_audio =
2158 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2159
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002160 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002161 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002162
2163 const cricket::ContentInfo* content =
2164 cricket::GetFirstAudioContent(offer->description());
2165 EXPECT_TRUE(content != NULL);
2166 content = cricket::GetFirstVideoContent(offer->description());
2167 EXPECT_TRUE(content == NULL);
2168}
2169
2170// Test that an offer contains audio and video media content descriptions if
2171// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2172TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002173 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002174 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002175 PeerConnectionInterface::RTCOfferAnswerOptions options;
2176 options.offer_to_receive_audio =
2177 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2178 options.offer_to_receive_video =
2179 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2180
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002181 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002182 CreateOffer(options));
2183
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002184 const cricket::ContentInfo* content =
2185 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002186 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002187
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002188 content = cricket::GetFirstVideoContent(offer->description());
2189 EXPECT_TRUE(content != NULL);
2190
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002191 // Sets constraints to false and verifies that audio/video contents are
2192 // removed.
2193 options.offer_to_receive_audio = 0;
2194 options.offer_to_receive_video = 0;
2195 offer.reset(CreateOffer(options));
2196
2197 content = cricket::GetFirstAudioContent(offer->description());
2198 EXPECT_TRUE(content == NULL);
2199 content = cricket::GetFirstVideoContent(offer->description());
2200 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002201}
2202
2203// Test that an answer can not be created if the last remote description is not
2204// an offer.
2205TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002206 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002207 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002208 SetLocalDescriptionWithoutError(offer);
2209 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2210 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002211 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002212}
2213
2214// Test that an answer contains the correct media content descriptions when no
2215// constraints have been set.
2216TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002217 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002218 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002219 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002220 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002221 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002222 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002223 const cricket::ContentInfo* content =
2224 cricket::GetFirstAudioContent(answer->description());
2225 ASSERT_TRUE(content != NULL);
2226 EXPECT_FALSE(content->rejected);
2227
2228 content = cricket::GetFirstVideoContent(answer->description());
2229 ASSERT_TRUE(content != NULL);
2230 EXPECT_FALSE(content->rejected);
2231}
2232
2233// Test that an answer contains the correct media content descriptions when no
2234// constraints have been set and the offer only contain audio.
2235TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002236 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002237 // Create a remote offer with audio only.
2238 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002239
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002240 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002241 CreateRemoteOffer(options));
2242 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2243 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2244
2245 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002246 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002247 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002248 const cricket::ContentInfo* content =
2249 cricket::GetFirstAudioContent(answer->description());
2250 ASSERT_TRUE(content != NULL);
2251 EXPECT_FALSE(content->rejected);
2252
2253 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2254}
2255
2256// Test that an answer contains the correct media content descriptions when no
2257// constraints have been set.
2258TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002259 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002260 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002261 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002262 SetRemoteDescriptionWithoutError(offer.release());
2263 // Test with a stream with tracks.
2264 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002265 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002266 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002267 const cricket::ContentInfo* content =
2268 cricket::GetFirstAudioContent(answer->description());
2269 ASSERT_TRUE(content != NULL);
2270 EXPECT_FALSE(content->rejected);
2271
2272 content = cricket::GetFirstVideoContent(answer->description());
2273 ASSERT_TRUE(content != NULL);
2274 EXPECT_FALSE(content->rejected);
2275}
2276
2277// Test that an answer contains the correct media content descriptions when
2278// constraints have been set but no stream is sent.
2279TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002280 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002281 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002282 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002283 SetRemoteDescriptionWithoutError(offer.release());
2284
2285 webrtc::FakeConstraints constraints_no_receive;
2286 constraints_no_receive.SetMandatoryReceiveAudio(false);
2287 constraints_no_receive.SetMandatoryReceiveVideo(false);
2288
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002289 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002290 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002291 const cricket::ContentInfo* content =
2292 cricket::GetFirstAudioContent(answer->description());
2293 ASSERT_TRUE(content != NULL);
2294 EXPECT_TRUE(content->rejected);
2295
2296 content = cricket::GetFirstVideoContent(answer->description());
2297 ASSERT_TRUE(content != NULL);
2298 EXPECT_TRUE(content->rejected);
2299}
2300
2301// Test that an answer contains the correct media content descriptions when
2302// constraints have been set and streams are sent.
2303TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002304 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002305 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002306 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002307 SetRemoteDescriptionWithoutError(offer.release());
2308
2309 webrtc::FakeConstraints constraints_no_receive;
2310 constraints_no_receive.SetMandatoryReceiveAudio(false);
2311 constraints_no_receive.SetMandatoryReceiveVideo(false);
2312
2313 // Test with a stream with tracks.
2314 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002315 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002316 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002317
2318 // TODO(perkj): Should the direction be set to SEND_ONLY?
2319 const cricket::ContentInfo* content =
2320 cricket::GetFirstAudioContent(answer->description());
2321 ASSERT_TRUE(content != NULL);
2322 EXPECT_FALSE(content->rejected);
2323
2324 // TODO(perkj): Should the direction be set to SEND_ONLY?
2325 content = cricket::GetFirstVideoContent(answer->description());
2326 ASSERT_TRUE(content != NULL);
2327 EXPECT_FALSE(content->rejected);
2328}
2329
2330TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2331 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002332 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002333 PeerConnectionInterface::RTCOfferAnswerOptions options;
2334 options.offer_to_receive_audio =
2335 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2336 options.voice_activity_detection = false;
2337
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002338 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002339 CreateOffer(options));
2340
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002341 const cricket::ContentInfo* content =
2342 cricket::GetFirstAudioContent(offer->description());
2343 EXPECT_TRUE(content != NULL);
2344 EXPECT_TRUE(VerifyNoCNCodecs(content));
2345}
2346
2347TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2348 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002349 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002350 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002351 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002352 SetRemoteDescriptionWithoutError(offer.release());
2353
2354 webrtc::FakeConstraints constraints;
2355 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002356 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002357 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002358 const cricket::ContentInfo* content =
2359 cricket::GetFirstAudioContent(answer->description());
2360 ASSERT_TRUE(content != NULL);
2361 EXPECT_TRUE(VerifyNoCNCodecs(content));
2362}
2363
2364// This test verifies the call setup when remote answer with audio only and
2365// later updates with video.
2366TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002367 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002368 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2369 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2370
2371 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002372 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002373
2374 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002375 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2376
2377 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2378 // and answer;
2379 SetLocalDescriptionWithoutError(offer);
2380 SetRemoteDescriptionWithoutError(answer);
2381
2382 video_channel_ = media_engine_->GetVideoChannel(0);
2383 voice_channel_ = media_engine_->GetVoiceChannel(0);
2384
2385 ASSERT_TRUE(video_channel_ == NULL);
2386
2387 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2388 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2389 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2390
2391 // Let the remote end update the session descriptions, with Audio and Video.
2392 mediastream_signaling_.SendAudioVideoStream2();
2393 CreateAndSetRemoteOfferAndLocalAnswer();
2394
2395 video_channel_ = media_engine_->GetVideoChannel(0);
2396 voice_channel_ = media_engine_->GetVoiceChannel(0);
2397
2398 ASSERT_TRUE(video_channel_ != NULL);
2399 ASSERT_TRUE(voice_channel_ != NULL);
2400
2401 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2402 ASSERT_EQ(1u, video_channel_->send_streams().size());
2403 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2404 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2405 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2406 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2407 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2408 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2409
2410 // Change session back to audio only.
2411 mediastream_signaling_.UseOptionsAudioOnly();
2412 CreateAndSetRemoteOfferAndLocalAnswer();
2413
2414 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2415 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2416 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2417 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2418 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2419}
2420
2421// This test verifies the call setup when remote answer with video only and
2422// later updates with audio.
2423TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002424 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002425 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2426 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2427 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002428 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002429
2430 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002431 options.recv_audio = false;
2432 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002433 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2434 offer, options, cricket::SEC_ENABLED);
2435
2436 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2437 // and answer.
2438 SetLocalDescriptionWithoutError(offer);
2439 SetRemoteDescriptionWithoutError(answer);
2440
2441 video_channel_ = media_engine_->GetVideoChannel(0);
2442 voice_channel_ = media_engine_->GetVoiceChannel(0);
2443
2444 ASSERT_TRUE(voice_channel_ == NULL);
2445 ASSERT_TRUE(video_channel_ != NULL);
2446
2447 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2448 ASSERT_EQ(1u, video_channel_->send_streams().size());
2449 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2450
2451 // Update the session descriptions, with Audio and Video.
2452 mediastream_signaling_.SendAudioVideoStream2();
2453 CreateAndSetRemoteOfferAndLocalAnswer();
2454
2455 voice_channel_ = media_engine_->GetVoiceChannel(0);
2456 ASSERT_TRUE(voice_channel_ != NULL);
2457
2458 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2459 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2460 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2461 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2462
2463 // Change session back to video only.
2464 mediastream_signaling_.UseOptionsVideoOnly();
2465 CreateAndSetRemoteOfferAndLocalAnswer();
2466
2467 video_channel_ = media_engine_->GetVideoChannel(0);
2468 voice_channel_ = media_engine_->GetVoiceChannel(0);
2469
2470 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2471 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2472 ASSERT_EQ(1u, video_channel_->send_streams().size());
2473 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2474}
2475
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002476TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002477 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002478 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002479 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002480 VerifyCryptoParams(offer->description());
2481 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002482 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002483 VerifyCryptoParams(answer->description());
2484}
2485
2486TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002487 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002488 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002489 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002490 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002491 VerifyNoCryptoParams(offer->description(), false);
2492}
2493
2494TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002495 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002496 VerifyAnswerFromNonCryptoOffer();
2497}
2498
2499TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002500 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002501 VerifyAnswerFromCryptoOffer();
2502}
2503
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002504// This test verifies that setLocalDescription fails if
2505// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2506TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002507 Init();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002508 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002509 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2510
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002511 std::string sdp;
2512 RemoveIceUfragPwdLines(offer.get(), &sdp);
2513 SessionDescriptionInterface* modified_offer =
2514 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002515 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002516}
2517
2518// This test verifies that setRemoteDescription fails if
2519// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2520TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002521 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002522 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002523 std::string sdp;
2524 RemoveIceUfragPwdLines(offer.get(), &sdp);
2525 SessionDescriptionInterface* modified_offer =
2526 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002527 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002528}
2529
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002530// This test verifies that setLocalDescription fails if local offer has
2531// too short ice ufrag and pwd strings.
2532TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002533 Init();
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002534 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
2535 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002536 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2537
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002538 std::string sdp;
2539 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2540 // recommended values of 4 and 22 bytes respectively.
2541 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2542 SessionDescriptionInterface* modified_offer =
2543 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2544 std::string error;
2545 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2546
2547 // Test with string greater than 256.
2548 sdp.clear();
2549 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2550 &sdp);
2551 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2552 NULL);
2553 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2554}
2555
2556// This test verifies that setRemoteDescription fails if remote offer has
2557// too short ice ufrag and pwd strings.
2558TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002559 Init();
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002560 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002561 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002562 std::string sdp;
2563 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2564 // recommended values of 4 and 22 bytes respectively.
2565 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2566 SessionDescriptionInterface* modified_offer =
2567 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2568 std::string error;
2569 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2570
2571 sdp.clear();
2572 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2573 &sdp);
2574 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2575 NULL);
2576 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2577}
2578
Donald Curtisd4f769d2015-05-28 09:48:21 -07002579// Test that candidates sent to the "video" transport do not get pushed down to
2580// the "audio" transport channel when bundling using TransportProxy.
2581TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2582 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2583
2584 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2585 mediastream_signaling_.SendAudioVideoStream1();
2586
2587 PeerConnectionInterface::RTCOfferAnswerOptions options;
2588 options.use_rtp_mux = true;
2589
2590 SessionDescriptionInterface* offer = CreateRemoteOffer();
2591 SetRemoteDescriptionWithoutError(offer);
2592
2593 SessionDescriptionInterface* answer = CreateAnswer(NULL);
2594 SetLocalDescriptionWithoutError(answer);
2595
2596 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2597 session_->GetTransportProxy("video")->impl());
2598
2599 cricket::Transport* t = session_->GetTransport("audio");
2600
2601 // Checks if one of the transport channels contains a connection using a given
2602 // port.
2603 auto connection_with_remote_port = [t](int port) {
2604 cricket::TransportStats stats;
2605 t->GetStats(&stats);
2606 for (auto& chan_stat : stats.channel_stats) {
2607 for (auto& conn_info : chan_stat.connection_infos) {
2608 if (conn_info.remote_candidate.address().port() == port) {
2609 return true;
2610 }
2611 }
2612 }
2613 return false;
2614 };
2615
2616 EXPECT_FALSE(connection_with_remote_port(5000));
2617 EXPECT_FALSE(connection_with_remote_port(5001));
2618 EXPECT_FALSE(connection_with_remote_port(6000));
2619
2620 // The way the *_WAIT checks work is they only wait if the condition fails,
2621 // which does not help in the case where state is not changing. This is
2622 // problematic in this test since we want to verify that adding a video
2623 // candidate does _not_ change state. So we interleave candidates and assume
2624 // that messages are executed in the order they were posted.
2625
2626 // First audio candidate.
2627 cricket::Candidate candidate0;
2628 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2629 candidate0.set_component(1);
2630 candidate0.set_protocol("udp");
2631 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2632 candidate0);
2633 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2634
2635 // Video candidate.
2636 cricket::Candidate candidate1;
2637 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2638 candidate1.set_component(1);
2639 candidate1.set_protocol("udp");
2640 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2641 candidate1);
2642 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2643
2644 // Second audio candidate.
2645 cricket::Candidate candidate2;
2646 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
2647 candidate2.set_component(1);
2648 candidate2.set_protocol("udp");
2649 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2650 candidate2);
2651 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2652
2653 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
2654 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
2655
2656 // No need here for a _WAIT check since we are checking that state hasn't
2657 // changed: if this is false we would be doing waits for nothing and if this
2658 // is true then there will be no messages processed anyways.
2659 EXPECT_FALSE(connection_with_remote_port(6000));
2660}
2661
Peter Thatcher4eddf182015-04-30 10:55:59 -07002662// kBundlePolicyBalanced bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002663TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
2664 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002665 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002666
2667 PeerConnectionInterface::RTCOfferAnswerOptions options;
2668 options.use_rtp_mux = true;
2669
2670 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002671 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07002672
2673 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2674 session_->GetTransportProxy("video")->impl());
2675
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002676 mediastream_signaling_.SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002677 SessionDescriptionInterface* answer =
2678 CreateRemoteAnswer(session_->local_description());
2679 SetRemoteDescriptionWithoutError(answer);
2680
2681 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2682 session_->GetTransportProxy("video")->impl());
2683}
2684
2685// kBundlePolicyBalanced bundle policy but no BUNDLE in the answer.
2686TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
2687 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2688 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002689
Donald Curtis0e209b02015-03-24 09:29:54 -07002690 PeerConnectionInterface::RTCOfferAnswerOptions options;
2691 options.use_rtp_mux = true;
2692
2693 SessionDescriptionInterface* offer = CreateOffer(options);
2694 SetLocalDescriptionWithoutError(offer);
2695
2696 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2697 session_->GetTransportProxy("video")->impl());
2698
2699 mediastream_signaling_.SendAudioVideoStream2();
2700
2701 // Remove BUNDLE from the answer.
2702 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2703 CreateRemoteAnswer(session_->local_description()));
2704 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2705 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2706 JsepSessionDescription* modified_answer =
2707 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2708 modified_answer->Initialize(answer_copy, "1", "1");
2709 SetRemoteDescriptionWithoutError(modified_answer); //
2710
2711 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2712 session_->GetTransportProxy("video")->impl());
2713}
2714
2715// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
2716TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
2717 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2718 mediastream_signaling_.SendAudioVideoStream1();
2719
2720 PeerConnectionInterface::RTCOfferAnswerOptions options;
2721 options.use_rtp_mux = true;
2722
2723 SessionDescriptionInterface* offer = CreateOffer(options);
2724 SetLocalDescriptionWithoutError(offer);
2725
2726 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2727 session_->GetTransportProxy("video")->impl());
2728
2729 mediastream_signaling_.SendAudioVideoStream2();
2730 SessionDescriptionInterface* answer =
2731 CreateRemoteAnswer(session_->local_description());
2732 SetRemoteDescriptionWithoutError(answer);
2733
2734 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2735 session_->GetTransportProxy("video")->impl());
2736}
2737
2738// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
2739TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
2740 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2741 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002742
Donald Curtis0e209b02015-03-24 09:29:54 -07002743 PeerConnectionInterface::RTCOfferAnswerOptions options;
2744 options.use_rtp_mux = true;
2745
2746 SessionDescriptionInterface* offer = CreateOffer(options);
2747 SetLocalDescriptionWithoutError(offer);
2748
2749 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2750 session_->GetTransportProxy("video")->impl());
2751
2752 mediastream_signaling_.SendAudioVideoStream2();
2753
2754 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002755 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002756 CreateRemoteAnswer(session_->local_description()));
2757 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2758 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2759 JsepSessionDescription* modified_answer =
2760 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2761 modified_answer->Initialize(answer_copy, "1", "1");
2762 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002763
Donald Curtis0e209b02015-03-24 09:29:54 -07002764 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2765 session_->GetTransportProxy("video")->impl());
2766}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002767
Peter Thatcher4eddf182015-04-30 10:55:59 -07002768// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002769TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
2770 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2771 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002772
Donald Curtis0e209b02015-03-24 09:29:54 -07002773 PeerConnectionInterface::RTCOfferAnswerOptions options;
2774 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002775
Donald Curtis0e209b02015-03-24 09:29:54 -07002776 SessionDescriptionInterface* offer = CreateOffer(options);
2777 SetLocalDescriptionWithoutError(offer);
2778
2779 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2780 session_->GetTransportProxy("video")->impl());
2781
2782 mediastream_signaling_.SendAudioVideoStream2();
2783 SessionDescriptionInterface* answer =
2784 CreateRemoteAnswer(session_->local_description());
2785 SetRemoteDescriptionWithoutError(answer);
2786
2787 // This should lead to an audio-only call but isn't implemented
2788 // correctly yet.
2789 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2790 session_->GetTransportProxy("video")->impl());
2791}
2792
2793// kBundlePolicyMaxCompat bundle policy but no BUNDLE in the answer.
2794TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
2795 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2796 mediastream_signaling_.SendAudioVideoStream1();
2797 PeerConnectionInterface::RTCOfferAnswerOptions options;
2798 options.use_rtp_mux = true;
2799
2800 SessionDescriptionInterface* offer = CreateOffer(options);
2801 SetLocalDescriptionWithoutError(offer);
2802
2803 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2804 session_->GetTransportProxy("video")->impl());
2805
2806 mediastream_signaling_.SendAudioVideoStream2();
2807
2808 // Remove BUNDLE from the answer.
2809 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2810 CreateRemoteAnswer(session_->local_description()));
2811 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2812 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2813 JsepSessionDescription* modified_answer =
2814 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2815 modified_answer->Initialize(answer_copy, "1", "1");
2816 SetRemoteDescriptionWithoutError(modified_answer); //
2817
2818 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2819 session_->GetTransportProxy("video")->impl());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002820}
2821
Peter Thatcher4eddf182015-04-30 10:55:59 -07002822// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
2823TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
2824 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2825 mediastream_signaling_.SendAudioVideoStream1();
2826
2827 PeerConnectionInterface::RTCOfferAnswerOptions options;
2828 options.use_rtp_mux = true;
2829
2830 SessionDescriptionInterface* offer = CreateOffer(options);
2831 SetRemoteDescriptionWithoutError(offer);
2832
2833 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2834 session_->GetTransportProxy("video")->impl());
2835}
2836
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002837TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
2838 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
2839 mediastream_signaling_.SendAudioVideoStream1();
2840
2841 PeerConnectionInterface::RTCOfferAnswerOptions options;
2842 SessionDescriptionInterface* offer = CreateOffer(options);
2843 SetLocalDescriptionWithoutError(offer);
2844
2845 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2846 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2847
2848 mediastream_signaling_.SendAudioVideoStream2();
2849 SessionDescriptionInterface* answer =
2850 CreateRemoteAnswer(session_->local_description());
2851 SetRemoteDescriptionWithoutError(answer);
2852
2853 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2854 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2855}
2856
2857TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
2858 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
2859 mediastream_signaling_.SendAudioVideoStream1();
2860
2861 PeerConnectionInterface::RTCOfferAnswerOptions options;
2862 SessionDescriptionInterface* offer = CreateOffer(options);
2863 SetLocalDescriptionWithoutError(offer);
2864
2865 EXPECT_TRUE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2866 EXPECT_TRUE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2867
2868 mediastream_signaling_.SendAudioVideoStream2();
2869 SessionDescriptionInterface* answer =
2870 CreateRemoteAnswer(session_->local_description());
2871 SetRemoteDescriptionWithoutError(answer);
2872
2873 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2874 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2875}
2876
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002877// This test verifies that SetLocalDescription and SetRemoteDescription fails
2878// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2879TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002880 Init();
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002881 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002882
2883 PeerConnectionInterface::RTCOfferAnswerOptions options;
2884 options.use_rtp_mux = true;
2885
2886 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002887 std::string offer_str;
2888 offer->ToString(&offer_str);
2889 // Disable rtcp-mux
2890 const std::string rtcp_mux = "rtcp-mux";
2891 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002892 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002893 xrtcp_mux.c_str(), xrtcp_mux.length(),
2894 &offer_str);
2895 JsepSessionDescription *local_offer =
2896 new JsepSessionDescription(JsepSessionDescription::kOffer);
2897 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002898 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002899 JsepSessionDescription *remote_offer =
2900 new JsepSessionDescription(JsepSessionDescription::kOffer);
2901 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002902 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002903 // Trying unmodified SDP.
2904 SetLocalDescriptionWithoutError(offer);
2905}
2906
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002907TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002908 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002909 mediastream_signaling_.SendAudioVideoStream1();
2910 CreateAndSetRemoteOfferAndLocalAnswer();
2911 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2912 ASSERT_TRUE(channel != NULL);
2913 ASSERT_EQ(1u, channel->recv_streams().size());
2914 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2915 double left_vol, right_vol;
2916 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2917 EXPECT_EQ(1, left_vol);
2918 EXPECT_EQ(1, right_vol);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002919 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002920 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002921 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2922 EXPECT_EQ(0, left_vol);
2923 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002924 EXPECT_EQ(0, renderer->channel_id());
2925 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002926 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2927 EXPECT_EQ(1, left_vol);
2928 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002929 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002930}
2931
2932TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002933 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002934 mediastream_signaling_.SendAudioVideoStream1();
2935 CreateAndSetRemoteOfferAndLocalAnswer();
2936 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2937 ASSERT_TRUE(channel != NULL);
2938 ASSERT_EQ(1u, channel->send_streams().size());
2939 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2940 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2941
2942 cricket::AudioOptions options;
2943 options.echo_cancellation.Set(true);
2944
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002945 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002946 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002947 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2948 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002949 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002950 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002951
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002952 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002953 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002954 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2955 bool value;
2956 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
2957 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002958 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002959 EXPECT_TRUE(renderer->sink() == NULL);
2960}
2961
2962TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002963 Init();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002964 mediastream_signaling_.SendAudioVideoStream1();
2965 CreateAndSetRemoteOfferAndLocalAnswer();
2966 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2967 ASSERT_TRUE(channel != NULL);
2968 ASSERT_EQ(1u, channel->send_streams().size());
2969 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2970
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002971 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002972 cricket::AudioOptions options;
2973 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
2974 EXPECT_TRUE(renderer->sink() != NULL);
2975
2976 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
2977 // will invalidate the |renderer_| pointer in the sink and prevent getting a
2978 // SetSink(NULL) callback afterwards.
2979 renderer.reset();
2980
2981 // This will trigger SetSink(NULL) if no OnClose() callback.
2982 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002983}
2984
2985TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002986 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002987 mediastream_signaling_.SendAudioVideoStream1();
2988 CreateAndSetRemoteOfferAndLocalAnswer();
2989 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2990 ASSERT_TRUE(channel != NULL);
2991 ASSERT_LT(0u, channel->renderers().size());
2992 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2993 ASSERT_EQ(1u, channel->recv_streams().size());
2994 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2995 cricket::FakeVideoRenderer renderer;
2996 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
2997 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
2998 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
2999 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3000}
3001
3002TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003003 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003004 mediastream_signaling_.SendAudioVideoStream1();
3005 CreateAndSetRemoteOfferAndLocalAnswer();
3006 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3007 ASSERT_TRUE(channel != NULL);
3008 ASSERT_EQ(1u, channel->send_streams().size());
3009 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3010 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3011 cricket::VideoOptions* options = NULL;
3012 session_->SetVideoSend(send_ssrc, false, options);
3013 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3014 session_->SetVideoSend(send_ssrc, true, options);
3015 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3016}
3017
3018TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3019 TestCanInsertDtmf(false);
3020}
3021
3022TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3023 TestCanInsertDtmf(true);
3024}
3025
3026TEST_F(WebRtcSessionTest, InsertDtmf) {
3027 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003028 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003029 mediastream_signaling_.SendAudioVideoStream1();
3030 CreateAndSetRemoteOfferAndLocalAnswer();
3031 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3032 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3033
3034 // Insert DTMF
3035 const int expected_flags = DF_SEND;
3036 const int expected_duration = 90;
3037 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3038 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3039 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3040
3041 // Verify
3042 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
3043 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3044 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
3045 expected_duration, expected_flags));
3046 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
3047 expected_duration, expected_flags));
3048 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
3049 expected_duration, expected_flags));
3050}
3051
3052// This test verifies the |initiator| flag when session initiates the call.
3053TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003054 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003055 EXPECT_FALSE(session_->initiator());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003056 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003057 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3058 SetLocalDescriptionWithoutError(offer);
3059 EXPECT_TRUE(session_->initiator());
3060 SetRemoteDescriptionWithoutError(answer);
3061 EXPECT_TRUE(session_->initiator());
3062}
3063
3064// This test verifies the |initiator| flag when session receives the call.
3065TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003066 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003067 EXPECT_FALSE(session_->initiator());
3068 SessionDescriptionInterface* offer = CreateRemoteOffer();
3069 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003070 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003071
3072 EXPECT_FALSE(session_->initiator());
3073 SetLocalDescriptionWithoutError(answer);
3074 EXPECT_FALSE(session_->initiator());
3075}
3076
3077// This test verifies the ice protocol type at initiator of the call
3078// if |a=ice-options:google-ice| is present in answer.
3079TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003080 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003081 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003082 SessionDescriptionInterface* offer = CreateOffer();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003083 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003084 CreateRemoteAnswer(offer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003085 SetLocalDescriptionWithoutError(offer);
3086 std::string sdp;
3087 EXPECT_TRUE(answer->ToString(&sdp));
3088 // Adding ice-options to the session level.
3089 InjectAfter("t=0 0\r\n",
3090 "a=ice-options:google-ice\r\n",
3091 &sdp);
3092 SessionDescriptionInterface* answer_with_gice =
3093 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00003094 // Default offer is ICEPROTO_RFC5245, so we expect responder with
3095 // only gice to fail.
3096 SetRemoteDescriptionAnswerExpectError(kPushDownTDFailed, answer_with_gice);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003097}
3098
3099// This test verifies the ice protocol type at initiator of the call
3100// if ICE RFC5245 is supported in answer.
3101TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003102 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003103 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003104 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003105 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3106 SetLocalDescriptionWithoutError(offer);
3107
3108 SetRemoteDescriptionWithoutError(answer);
3109 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
3110 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
3111}
3112
3113// This test verifies the ice protocol type at receiver side of the call if
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003114// receiver decides to use ice RFC 5245.
3115TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003116 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003117 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003118 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003119 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003120 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003121 SetLocalDescriptionWithoutError(answer);
3122 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
3123 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
3124}
3125
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003126// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3127TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003128 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003129 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003130 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003131 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003132 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003133 CreateRemoteAnswer(session_->local_description()));
3134
3135 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3136 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003137 JsepSessionDescription* modified_answer =
3138 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003139
3140 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3141 answer->session_id(),
3142 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003143 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003144
wu@webrtc.org4e393072014-04-07 17:04:35 +00003145 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003146 std::string sdp;
3147 EXPECT_TRUE(answer->ToString(&sdp));
3148 const std::string kAudioMid = "a=mid:audio";
3149 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003150 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003151 kAudioMidReplaceStr.c_str(),
3152 kAudioMidReplaceStr.length(),
3153 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003154 SessionDescriptionInterface* modified_answer1 =
3155 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003156 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003157
wu@webrtc.org4e393072014-04-07 17:04:35 +00003158 // Different media types.
3159 EXPECT_TRUE(answer->ToString(&sdp));
3160 const std::string kAudioMline = "m=audio";
3161 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003162 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003163 kAudioMlineReplaceStr.c_str(),
3164 kAudioMlineReplaceStr.length(),
3165 &sdp);
3166 SessionDescriptionInterface* modified_answer2 =
3167 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3168 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3169
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003170 SetRemoteDescriptionWithoutError(answer.release());
3171}
3172
3173// Verifying remote offer and local answer have matching m-lines as per
3174// RFC 3264.
3175TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003176 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003177 mediastream_signaling_.SendAudioVideoStream1();
3178 SessionDescriptionInterface* offer = CreateRemoteOffer();
3179 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003180 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003181
3182 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3183 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003184 JsepSessionDescription* modified_answer =
3185 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003186
3187 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3188 answer->session_id(),
3189 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003190 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003191 SetLocalDescriptionWithoutError(answer);
3192}
3193
3194// This test verifies that WebRtcSession does not start candidate allocation
3195// before SetLocalDescription is called.
3196TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003197 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003198 mediastream_signaling_.SendAudioVideoStream1();
3199 SessionDescriptionInterface* offer = CreateRemoteOffer();
3200 cricket::Candidate candidate;
3201 candidate.set_component(1);
3202 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3203 candidate);
3204 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3205 cricket::Candidate candidate1;
3206 candidate1.set_component(1);
3207 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3208 candidate1);
3209 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3210 SetRemoteDescriptionWithoutError(offer);
3211 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
3212 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
3213
3214 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003215 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003216 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3217 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3218
wu@webrtc.org91053e72013-08-10 07:18:04 +00003219 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003220 SetLocalDescriptionWithoutError(answer);
3221 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
3222 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
3223 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3224}
3225
3226// This test verifies that crypto parameter is updated in local session
3227// description as per security policy set in MediaSessionDescriptionFactory.
3228TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003229 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003230 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003231 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003232
3233 // Making sure SetLocalDescription correctly sets crypto value in
3234 // SessionDescription object after de-serialization of sdp string. The value
3235 // will be set as per MediaSessionDescriptionFactory.
3236 std::string offer_str;
3237 offer->ToString(&offer_str);
3238 SessionDescriptionInterface* jsep_offer_str =
3239 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3240 SetLocalDescriptionWithoutError(jsep_offer_str);
3241 EXPECT_TRUE(session_->voice_channel()->secure_required());
3242 EXPECT_TRUE(session_->video_channel()->secure_required());
3243}
3244
3245// This test verifies the crypto parameter when security is disabled.
3246TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003247 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003248 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003249 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003250 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003251
3252 // Making sure SetLocalDescription correctly sets crypto value in
3253 // SessionDescription object after de-serialization of sdp string. The value
3254 // will be set as per MediaSessionDescriptionFactory.
3255 std::string offer_str;
3256 offer->ToString(&offer_str);
3257 SessionDescriptionInterface *jsep_offer_str =
3258 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3259 SetLocalDescriptionWithoutError(jsep_offer_str);
3260 EXPECT_FALSE(session_->voice_channel()->secure_required());
3261 EXPECT_FALSE(session_->video_channel()->secure_required());
3262}
3263
3264// This test verifies that an answer contains new ufrag and password if an offer
3265// with new ufrag and password is received.
3266TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003267 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003268 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003269 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003270 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003271 CreateRemoteOffer(options));
3272 SetRemoteDescriptionWithoutError(offer.release());
3273
3274 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003275 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003276 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003277 SetLocalDescriptionWithoutError(answer.release());
3278
3279 // Receive an offer with new ufrag and password.
3280 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003281 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003282 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003283 SetRemoteDescriptionWithoutError(updated_offer1.release());
3284
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003285 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003286 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003287
3288 CompareIceUfragAndPassword(updated_answer1->description(),
3289 session_->local_description()->description(),
3290 false);
3291
3292 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003293}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003294
wu@webrtc.org91053e72013-08-10 07:18:04 +00003295// This test verifies that an answer contains old ufrag and password if an offer
3296// with old ufrag and password is received.
3297TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003298 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003299 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003300 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003301 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003302 CreateRemoteOffer(options));
3303 SetRemoteDescriptionWithoutError(offer.release());
3304
3305 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003306 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003307 CreateAnswer(NULL));
3308 SetLocalDescriptionWithoutError(answer.release());
3309
3310 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003311 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003312 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003313 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003314 SetRemoteDescriptionWithoutError(updated_offer2.release());
3315
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003316 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003317 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003318
3319 CompareIceUfragAndPassword(updated_answer2->description(),
3320 session_->local_description()->description(),
3321 true);
3322
3323 SetLocalDescriptionWithoutError(updated_answer2.release());
3324}
3325
3326TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003327 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003328 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003329 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003330 const std::string session_id_orig = offer->session_id();
3331 const std::string session_version_orig = offer->session_version();
3332 SetLocalDescriptionWithoutError(offer);
3333
3334 video_channel_ = media_engine_->GetVideoChannel(0);
3335 video_channel_->set_fail_set_send_codecs(true);
3336
3337 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003338 SessionDescriptionInterface* answer =
3339 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003340 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003341}
3342
3343// Runs the loopback call test with BUNDLE and STUN disabled.
3344TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3345 // Lets try with only UDP ports.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00003346 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003347 cricket::PORTALLOCATOR_DISABLE_TCP |
3348 cricket::PORTALLOCATOR_DISABLE_STUN |
3349 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003350 TestLoopbackCall();
3351}
3352
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003353TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
3354 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
3355 cricket::PORTALLOCATOR_DISABLE_TCP |
3356 cricket::PORTALLOCATOR_DISABLE_STUN |
3357 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3358 cricket::PORTALLOCATOR_DISABLE_RELAY);
3359
3360 // best connection is IPv6 since it has higher network preference.
3361 LoopbackNetworkConfiguration config;
3362 config.test_ipv6_network_ = true;
3363 config.best_connection_after_initial_ice_converged_ =
3364 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3365
3366 TestLoopbackCall(config);
3367}
3368
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003369// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003370TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00003371 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003372 cricket::PORTALLOCATOR_DISABLE_TCP |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003373 cricket::PORTALLOCATOR_DISABLE_RELAY);
3374 TestLoopbackCall();
3375}
3376
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003377TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003378 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003379 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003380 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003381
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003382 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
3383 std::string error_code_str = "ERROR_CONTENT";
3384 std::string error_desc = "Fake session error description.";
3385 session_->SetError(error_code, error_desc);
3386
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003387 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
3388 SessionDescriptionInterface* answer =
3389 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003390
3391 std::string action;
3392 std::ostringstream session_error_msg;
3393 session_error_msg << kSessionError << error_code_str << ". ";
3394 session_error_msg << kSessionErrorDesc << error_desc << ".";
3395 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
3396 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003397}
3398
3399TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3400 constraints_.reset(new FakeConstraints());
3401 constraints_->AddOptional(
3402 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003403 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003404
3405 SetLocalDescriptionWithDataChannel();
3406 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3407}
3408
3409TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003410 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003411
3412 constraints_.reset(new FakeConstraints());
3413 constraints_->AddOptional(
3414 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003415 options_.disable_sctp_data_channels = false;
3416
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003417 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003418
3419 SetLocalDescriptionWithDataChannel();
3420 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3421}
3422
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003423TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003424 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003425
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003426 InitWithDtls();
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003427
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003428 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003429 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003430 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3431}
3432
3433TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003434 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003435 SetFactoryDtlsSrtp();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003436 InitWithDtls();
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003437
3438 // Create remote offer with SCTP.
3439 cricket::MediaSessionOptions options;
3440 options.data_channel_type = cricket::DCT_SCTP;
3441 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003442 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003443 SetRemoteDescriptionWithoutError(offer);
3444
3445 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003446 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003447 EXPECT_TRUE(answer != NULL);
3448 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3449 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003450}
3451
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003452TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
3453 constraints_.reset(new FakeConstraints());
3454 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003455 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003456 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003457
3458 SetLocalDescriptionWithDataChannel();
3459 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3460}
3461
3462TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003463 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003464
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003465 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003466
3467 SetLocalDescriptionWithDataChannel();
3468 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3469}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003470
wu@webrtc.org97077a32013-10-25 21:18:33 +00003471TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003472 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003473 options_.disable_sctp_data_channels = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003474 InitWithDtls();
wu@webrtc.org97077a32013-10-25 21:18:33 +00003475
3476 SetLocalDescriptionWithDataChannel();
3477 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3478}
3479
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003480TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003481 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003482 const int new_send_port = 9998;
3483 const int new_recv_port = 7775;
3484
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003485 InitWithDtls();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003486 SetFactoryDtlsSrtp();
3487
3488 // By default, don't actually add the codecs to desc_factory_; they don't
3489 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3490 // let the session description get parsed. That'll get the proper codecs
3491 // into the stream.
3492 cricket::MediaSessionOptions options;
3493 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3494 "stream1", new_send_port, options);
3495
3496 // SetRemoteDescription will take the ownership of the offer.
3497 SetRemoteDescriptionWithoutError(offer);
3498
3499 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3500 new_recv_port, CreateAnswer(NULL));
3501 ASSERT_TRUE(answer != NULL);
3502
3503 // Now set the local description, which'll take ownership of the answer.
3504 SetLocalDescriptionWithoutError(answer);
3505
3506 // TEST PLAN: Set the port number to something new, set it in the SDP,
3507 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003508 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003509 dci.reliable = true;
3510 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003511 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003512 session_->CreateDataChannel("datachannel", &dci);
3513
3514 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3515 int portnum = -1;
3516 ASSERT_TRUE(ch != NULL);
3517 ASSERT_EQ(1UL, ch->send_codecs().size());
3518 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003519 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003520 ch->send_codecs()[0].name.c_str()));
3521 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3522 &portnum));
3523 EXPECT_EQ(new_send_port, portnum);
3524
3525 ASSERT_EQ(1UL, ch->recv_codecs().size());
3526 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003527 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003528 ch->recv_codecs()[0].name.c_str()));
3529 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3530 &portnum));
3531 EXPECT_EQ(new_recv_port, portnum);
3532}
3533
wu@webrtc.org91053e72013-08-10 07:18:04 +00003534// Verifies that CreateOffer succeeds when CreateOffer is called before async
3535// identity generation is finished.
3536TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003537 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003538 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003539
3540 EXPECT_TRUE(session_->waiting_for_identity());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003541 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003542 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3543
wu@webrtc.org91053e72013-08-10 07:18:04 +00003544 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003545 VerifyNoCryptoParams(offer->description(), true);
3546 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003547}
3548
3549// Verifies that CreateAnswer succeeds when CreateOffer is called before async
3550// identity generation is finished.
3551TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003552 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003553 InitWithDtls();
3554 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003555
3556 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003557 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003558 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003559 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003560 ASSERT_TRUE(offer.get() != NULL);
3561 SetRemoteDescriptionWithoutError(offer.release());
3562
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003563 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003564 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003565 VerifyNoCryptoParams(answer->description(), true);
3566 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003567}
3568
3569// Verifies that CreateOffer succeeds when CreateOffer is called after async
3570// identity generation is finished.
3571TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003572 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003573 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003574
3575 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003576
3577 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003578 EXPECT_TRUE(offer != NULL);
3579}
3580
3581// Verifies that CreateOffer fails when CreateOffer is called after async
3582// identity generation fails.
3583TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003584 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00003585 InitWithDtls(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003586
3587 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003588
3589 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003590 EXPECT_TRUE(offer == NULL);
3591}
3592
3593// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3594// before async identity generation is finished.
3595TEST_F(WebRtcSessionTest,
3596 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003597 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003598 VerifyMultipleAsyncCreateDescription(
3599 true, CreateSessionDescriptionRequest::kOffer);
3600}
3601
3602// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3603// before async identity generation fails.
3604TEST_F(WebRtcSessionTest,
3605 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003606 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003607 VerifyMultipleAsyncCreateDescription(
3608 false, CreateSessionDescriptionRequest::kOffer);
3609}
3610
3611// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3612// before async identity generation is finished.
3613TEST_F(WebRtcSessionTest,
3614 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003615 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003616 VerifyMultipleAsyncCreateDescription(
3617 true, CreateSessionDescriptionRequest::kAnswer);
3618}
3619
3620// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3621// before async identity generation fails.
3622TEST_F(WebRtcSessionTest,
3623 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003624 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003625 VerifyMultipleAsyncCreateDescription(
3626 false, CreateSessionDescriptionRequest::kAnswer);
3627}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003628
3629// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3630// offer has no SDES crypto but only DTLS fingerprint.
3631TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3632 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003633 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003634 // Create a remote offer with secured transport disabled.
3635 cricket::MediaSessionOptions options;
3636 JsepSessionDescription* offer(CreateRemoteOffer(
3637 options, cricket::SEC_DISABLED));
3638 // Adds a DTLS fingerprint to the remote offer.
3639 cricket::SessionDescription* sdp = offer->description();
3640 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3641 ASSERT_TRUE(audio != NULL);
3642 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3643 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003644 rtc::SSLFingerprint::CreateFromRfc4572(
3645 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003646 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003647 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003648}
3649
wu@webrtc.orgde305012013-10-31 15:40:38 +00003650// This test verifies DSCP is properly applied on the media channels.
3651TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3652 constraints_.reset(new FakeConstraints());
3653 constraints_->AddOptional(
3654 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003655 Init();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003656 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003657 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003658
3659 SetLocalDescriptionWithoutError(offer);
3660
3661 video_channel_ = media_engine_->GetVideoChannel(0);
3662 voice_channel_ = media_engine_->GetVoiceChannel(0);
3663
3664 ASSERT_TRUE(video_channel_ != NULL);
3665 ASSERT_TRUE(voice_channel_ != NULL);
3666 cricket::AudioOptions audio_options;
3667 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3668 cricket::VideoOptions video_options;
3669 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3670 EXPECT_TRUE(audio_options.dscp.IsSet());
3671 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3672 EXPECT_TRUE(video_options.dscp.IsSet());
3673 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3674}
3675
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003676TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3677 constraints_.reset(new FakeConstraints());
3678 constraints_->AddOptional(
3679 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3680 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003681 Init();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003682 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003683 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003684
3685 SetLocalDescriptionWithoutError(offer);
3686
3687 video_channel_ = media_engine_->GetVideoChannel(0);
3688
3689 ASSERT_TRUE(video_channel_ != NULL);
3690 cricket::VideoOptions video_options;
3691 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3692 EXPECT_TRUE(
3693 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3694}
3695
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00003696TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
3697 // Number of unsignalled receiving streams should be between 0 and
3698 // kMaxUnsignalledRecvStreams.
3699 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
3700 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
3701 kMaxUnsignalledRecvStreams);
3702 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
3703}
3704
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003705TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
3706 constraints_.reset(new FakeConstraints());
3707 constraints_->AddOptional(
3708 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
3709 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003710 Init();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003711 mediastream_signaling_.SendAudioVideoStream1();
3712 SessionDescriptionInterface* offer = CreateOffer();
3713
3714 SetLocalDescriptionWithoutError(offer);
3715
3716 voice_channel_ = media_engine_->GetVoiceChannel(0);
3717
3718 ASSERT_TRUE(voice_channel_ != NULL);
3719 cricket::AudioOptions audio_options;
3720 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3721 EXPECT_TRUE(
3722 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
3723}
3724
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003725// Tests that we can renegotiate new media content with ICE candidates in the
3726// new remote SDP.
3727TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003728 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003729 InitWithDtls();
3730 SetFactoryDtlsSrtp();
3731
3732 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003733 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003734 SetLocalDescriptionWithoutError(offer);
3735
3736 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3737 SetRemoteDescriptionWithoutError(answer);
3738
3739 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003740 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003741 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3742
3743 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003744 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003745 candidate1.set_component(1);
3746 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3747 candidate1);
3748 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3749 SetRemoteDescriptionWithoutError(offer);
3750
3751 answer = CreateAnswer(NULL);
3752 SetLocalDescriptionWithoutError(answer);
3753}
3754
3755// Tests that we can renegotiate new media content with ICE candidates separated
3756// from the remote SDP.
3757TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003758 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003759 InitWithDtls();
3760 SetFactoryDtlsSrtp();
3761
3762 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003763 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003764 SetLocalDescriptionWithoutError(offer);
3765
3766 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3767 SetRemoteDescriptionWithoutError(answer);
3768
3769 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003770 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003771 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3772 SetRemoteDescriptionWithoutError(offer);
3773
3774 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003775 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003776 candidate1.set_component(1);
3777 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3778 candidate1);
3779 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3780
3781 answer = CreateAnswer(NULL);
3782 SetLocalDescriptionWithoutError(answer);
3783}
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00003784// Tests that RTX codec is removed from the answer when it isn't supported
3785// by local side.
3786TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
3787 Init();
3788 mediastream_signaling_.SendAudioVideoStream1();
3789 std::string offer_sdp(kSdpWithRtx);
3790
3791 SessionDescriptionInterface* offer =
3792 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
3793 EXPECT_TRUE(offer->ToString(&offer_sdp));
3794
3795 // Offer SDP contains the RTX codec.
3796 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
3797 SetRemoteDescriptionWithoutError(offer);
3798
3799 SessionDescriptionInterface* answer = CreateAnswer(NULL);
3800 std::string answer_sdp;
3801 answer->ToString(&answer_sdp);
3802 // Answer SDP removes the unsupported RTX codec.
3803 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
3804 SetLocalDescriptionWithoutError(answer);
3805}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003806
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003807// This verifies that the voice channel after bundle has both options from video
3808// and voice channels.
3809TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
3810 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
3811 mediastream_signaling_.SendAudioVideoStream1();
3812
3813 PeerConnectionInterface::RTCOfferAnswerOptions options;
3814 options.use_rtp_mux = true;
3815
3816 SessionDescriptionInterface* offer = CreateOffer(options);
3817 SetLocalDescriptionWithoutError(offer);
3818
3819 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3820 rtc::Socket::Option::OPT_SNDBUF, 4000);
3821
3822 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3823 rtc::Socket::Option::OPT_RCVBUF, 8000);
3824
3825 int option_val;
3826 EXPECT_TRUE(session_->video_channel()->transport_channel()->GetOption(
3827 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3828 EXPECT_EQ(4000, option_val);
3829 EXPECT_FALSE(session_->voice_channel()->transport_channel()->GetOption(
3830 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3831
3832 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3833 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3834 EXPECT_EQ(8000, option_val);
3835 EXPECT_FALSE(session_->video_channel()->transport_channel()->GetOption(
3836 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3837
3838 EXPECT_NE(session_->voice_channel()->transport_channel(),
3839 session_->video_channel()->transport_channel());
3840
3841 mediastream_signaling_.SendAudioVideoStream2();
3842 SessionDescriptionInterface* answer =
3843 CreateRemoteAnswer(session_->local_description());
3844 SetRemoteDescriptionWithoutError(answer);
3845
3846 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3847 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3848 EXPECT_EQ(4000, option_val);
3849
3850 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3851 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3852 EXPECT_EQ(8000, option_val);
3853}
3854
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003855// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
3856// currently fails because upon disconnection and reconnection OnIceComplete is
3857// called more than once without returning to IceGatheringGathering.