blob: 388fff7786f2d7612055878ad89eec00debc533d [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
3 * Copyright 2012, Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include "talk/app/webrtc/audiotrack.h"
29#include "talk/app/webrtc/jsepicecandidate.h"
30#include "talk/app/webrtc/jsepsessiondescription.h"
31#include "talk/app/webrtc/mediastreamsignaling.h"
32#include "talk/app/webrtc/streamcollection.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033#include "talk/app/webrtc/test/fakeconstraints.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000034#include "talk/app/webrtc/test/fakedtlsidentityservice.h"
35#include "talk/app/webrtc/test/fakemediastreamsignaling.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000036#include "talk/app/webrtc/videotrack.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037#include "talk/app/webrtc/webrtcsession.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000038#include "talk/app/webrtc/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000039#include "talk/media/base/fakemediaengine.h"
40#include "talk/media/base/fakevideorenderer.h"
41#include "talk/media/base/mediachannel.h"
42#include "talk/media/devices/fakedevicemanager.h"
43#include "talk/p2p/base/stunserver.h"
44#include "talk/p2p/base/teststunserver.h"
45#include "talk/p2p/base/testturnserver.h"
46#include "talk/p2p/client/basicportallocator.h"
47#include "talk/session/media/channelmanager.h"
48#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000049#include "webrtc/base/fakenetwork.h"
50#include "webrtc/base/firewallsocketserver.h"
51#include "webrtc/base/gunit.h"
52#include "webrtc/base/logging.h"
53#include "webrtc/base/network.h"
54#include "webrtc/base/physicalsocketserver.h"
55#include "webrtc/base/ssladapter.h"
56#include "webrtc/base/sslstreamadapter.h"
57#include "webrtc/base/stringutils.h"
58#include "webrtc/base/thread.h"
59#include "webrtc/base/virtualsocketserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060
61#define MAYBE_SKIP_TEST(feature) \
62 if (!(feature())) { \
63 LOG(LS_INFO) << "Feature disabled... skipping"; \
64 return; \
65 }
66
67using cricket::BaseSession;
68using cricket::DF_PLAY;
69using cricket::DF_SEND;
70using cricket::FakeVoiceMediaChannel;
71using cricket::NS_GINGLE_P2P;
72using cricket::NS_JINGLE_ICE_UDP;
73using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000074using rtc::SocketAddress;
75using rtc::scoped_ptr;
76using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000078using webrtc::CreateSessionDescriptionObserver;
79using webrtc::CreateSessionDescriptionRequest;
80using webrtc::DTLSIdentityRequestObserver;
81using webrtc::DTLSIdentityServiceInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082using webrtc::FakeConstraints;
83using webrtc::IceCandidateCollection;
84using webrtc::JsepIceCandidate;
85using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000086using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087using webrtc::PeerConnectionInterface;
88using webrtc::SessionDescriptionInterface;
89using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000090using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000091using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000092using webrtc::kCreateChannelFailed;
93using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000095using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000096using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000097using webrtc::kSdpWithoutDtlsFingerprint;
98using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000100using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000101using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000103typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
104
wu@webrtc.org364f2042013-11-20 21:49:41 +0000105static const int kClientAddrPort = 0;
106static const char kClientAddrHost1[] = "11.11.11.11";
107static const char kClientAddrHost2[] = "22.22.22.22";
108static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000109static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
110static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000111static const char kTurnUsername[] = "test";
112static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000113
114static const char kSessionVersion[] = "1";
115
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116// Media index of candidates belonging to the first media content.
117static const int kMediaContentIndex0 = 0;
118static const char kMediaContentName0[] = "audio";
119
120// Media index of candidates belonging to the second media content.
121static const int kMediaContentIndex1 = 1;
122static const char kMediaContentName1[] = "video";
123
124static const int kIceCandidatesTimeout = 10000;
125
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000126static const char kFakeDtlsFingerprint[] =
127 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
128 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
129
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000130static const char kTooLongIceUfragPwd[] =
131 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
132 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
133 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
134 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
135
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000136// Add some extra |newlines| to the |message| after |line|.
137static void InjectAfter(const std::string& line,
138 const std::string& newlines,
139 std::string* message) {
140 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000141 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000142 tmp.c_str(), tmp.length(), message);
143}
144
145class MockIceObserver : public webrtc::IceObserver {
146 public:
147 MockIceObserver()
148 : oncandidatesready_(false),
149 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
150 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
151 }
152
153 virtual void OnIceConnectionChange(
154 PeerConnectionInterface::IceConnectionState new_state) {
155 ice_connection_state_ = new_state;
156 }
157 virtual void OnIceGatheringChange(
158 PeerConnectionInterface::IceGatheringState new_state) {
159 // We can never transition back to "new".
160 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
161 ice_gathering_state_ = new_state;
162
163 // oncandidatesready_ really means "ICE gathering is complete".
164 // This if statement ensures that this value remains correct when we
165 // transition from kIceGatheringComplete to kIceGatheringGathering.
166 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
167 oncandidatesready_ = false;
168 }
169 }
170
171 // Found a new candidate.
172 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000173 switch (candidate->sdp_mline_index()) {
174 case kMediaContentIndex0:
175 mline_0_candidates_.push_back(candidate->candidate());
176 break;
177 case kMediaContentIndex1:
178 mline_1_candidates_.push_back(candidate->candidate());
179 break;
180 default:
181 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000182 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000183
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184 // The ICE gathering state should always be Gathering when a candidate is
185 // received (or possibly Completed in the case of the final candidate).
186 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
187 }
188
189 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
190 virtual void OnIceComplete() {
191 EXPECT_FALSE(oncandidatesready_);
192 oncandidatesready_ = true;
193
194 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
195 // be called approximately simultaneously. For ease of testing, this
196 // check additionally requires that they be called in the above order.
197 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
198 ice_gathering_state_);
199 }
200
201 bool oncandidatesready_;
202 std::vector<cricket::Candidate> mline_0_candidates_;
203 std::vector<cricket::Candidate> mline_1_candidates_;
204 PeerConnectionInterface::IceConnectionState ice_connection_state_;
205 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
206};
207
208class WebRtcSessionForTest : public webrtc::WebRtcSession {
209 public:
210 WebRtcSessionForTest(cricket::ChannelManager* cmgr,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000211 rtc::Thread* signaling_thread,
212 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 cricket::PortAllocator* port_allocator,
214 webrtc::IceObserver* ice_observer,
215 webrtc::MediaStreamSignaling* mediastream_signaling)
216 : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator,
217 mediastream_signaling) {
218 RegisterIceObserver(ice_observer);
219 }
220 virtual ~WebRtcSessionForTest() {}
221
222 using cricket::BaseSession::GetTransportProxy;
223 using webrtc::WebRtcSession::SetAudioPlayout;
224 using webrtc::WebRtcSession::SetAudioSend;
225 using webrtc::WebRtcSession::SetCaptureDevice;
226 using webrtc::WebRtcSession::SetVideoPlayout;
227 using webrtc::WebRtcSession::SetVideoSend;
228};
229
wu@webrtc.org91053e72013-08-10 07:18:04 +0000230class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000231 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000233 enum State {
234 kInit,
235 kFailed,
236 kSucceeded,
237 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000238 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000239
240 // CreateSessionDescriptionObserver implementation.
241 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000242 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000243 state_ = kSucceeded;
244 }
245 virtual void OnFailure(const std::string& error) {
246 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000247 }
248
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000249 SessionDescriptionInterface* description() { return description_.get(); }
250
251 SessionDescriptionInterface* ReleaseDescription() {
252 return description_.release();
253 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000254
wu@webrtc.org91053e72013-08-10 07:18:04 +0000255 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256
wu@webrtc.org91053e72013-08-10 07:18:04 +0000257 protected:
258 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259
260 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000261 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000262 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000263};
264
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000265class FakeAudioRenderer : public cricket::AudioRenderer {
266 public:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000267 FakeAudioRenderer() : channel_id_(-1), sink_(NULL) {}
268 virtual ~FakeAudioRenderer() {
269 if (sink_)
270 sink_->OnClose();
271 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000272
273 virtual void AddChannel(int channel_id) OVERRIDE {
274 ASSERT(channel_id_ == -1);
275 channel_id_ = channel_id;
276 }
277 virtual void RemoveChannel(int channel_id) OVERRIDE {
278 ASSERT(channel_id == channel_id_);
279 channel_id_ = -1;
280 }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000281 virtual void SetSink(Sink* sink) OVERRIDE {
282 sink_ = sink;
283 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000284
285 int channel_id() const { return channel_id_; }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000286 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000287 private:
288 int channel_id_;
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000289 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000290};
291
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000292class WebRtcSessionTest : public testing::Test {
293 protected:
294 // TODO Investigate why ChannelManager crashes, if it's created
295 // after stun_server.
296 WebRtcSessionTest()
297 : media_engine_(new cricket::FakeMediaEngine()),
298 data_engine_(new cricket::FakeDataEngine()),
299 device_manager_(new cricket::FakeDeviceManager()),
300 channel_manager_(new cricket::ChannelManager(
301 media_engine_, data_engine_, device_manager_,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000302 new cricket::CaptureManager(), rtc::Thread::Current())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000303 tdesc_factory_(new cricket::TransportDescriptionFactory()),
304 desc_factory_(new cricket::MediaSessionDescriptionFactory(
305 channel_manager_.get(), tdesc_factory_.get())),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000306 pss_(new rtc::PhysicalSocketServer),
307 vss_(new rtc::VirtualSocketServer(pss_.get())),
308 fss_(new rtc::FirewallSocketServer(vss_.get())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309 ss_scope_(fss_.get()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000310 stun_socket_addr_(rtc::SocketAddress(kStunAddrHost,
wu@webrtc.org364f2042013-11-20 21:49:41 +0000311 cricket::STUN_SERVER_PORT)),
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +0000312 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
313 stun_socket_addr_)),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000314 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000315 mediastream_signaling_(channel_manager_.get()),
316 ice_type_(PeerConnectionInterface::kAll) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000317 tdesc_factory_->set_protocol(cricket::ICEPROTO_HYBRID);
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000318
319 cricket::ServerAddresses stun_servers;
320 stun_servers.insert(stun_socket_addr_);
321 allocator_.reset(new cricket::BasicPortAllocator(
322 &network_manager_,
323 stun_servers,
324 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000325 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326 cricket::PORTALLOCATOR_DISABLE_RELAY |
327 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
328 EXPECT_TRUE(channel_manager_->Init());
329 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000330 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000331 }
332
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000333 static void SetUpTestCase() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000334 rtc::InitializeSSL();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000335 }
336
337 static void TearDownTestCase() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000338 rtc::CleanupSSL();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000339 }
340
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000341 void AddInterface(const SocketAddress& addr) {
342 network_manager_.AddInterface(addr);
343 }
344
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000345 void SetIceTransportType(PeerConnectionInterface::IceTransportsType type) {
346 ice_type_ = type;
347 }
348
wu@webrtc.org91053e72013-08-10 07:18:04 +0000349 void Init(DTLSIdentityServiceInterface* identity_service) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000350 ASSERT_TRUE(session_.get() == NULL);
351 session_.reset(new WebRtcSessionForTest(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000352 channel_manager_.get(), rtc::Thread::Current(),
353 rtc::Thread::Current(), allocator_.get(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000354 &observer_,
355 &mediastream_signaling_));
356
357 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
358 observer_.ice_connection_state_);
359 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
360 observer_.ice_gathering_state_);
361
wu@webrtc.org97077a32013-10-25 21:18:33 +0000362 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000363 identity_service, ice_type_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000364 }
365
366 void InitWithDtmfCodec() {
367 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000368 const cricket::AudioCodec kTelephoneEventCodec(
369 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000370 std::vector<cricket::AudioCodec> codecs;
371 codecs.push_back(kTelephoneEventCodec);
372 media_engine_->SetAudioCodecs(codecs);
373 desc_factory_->set_audio_codecs(codecs);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000374 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000375 }
376
henrike@webrtc.org7666db72013-08-22 14:45:42 +0000377 void InitWithDtls(bool identity_request_should_fail = false) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000378 FakeIdentityService* identity_service = new FakeIdentityService();
379 identity_service->set_should_fail(identity_request_should_fail);
380 Init(identity_service);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000381 }
382
383 // Creates a local offer and applies it. Starts ice.
384 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
385 // to decide which streams to create.
386 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000387 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000388 SetLocalDescriptionWithoutError(offer);
389 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
390 observer_.ice_gathering_state_,
391 kIceCandidatesTimeout);
392 }
393
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000394 SessionDescriptionInterface* CreateOffer() {
395 PeerConnectionInterface::RTCOfferAnswerOptions options;
396 options.offer_to_receive_audio =
397 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
398
399 return CreateOffer(options);
400 }
401
wu@webrtc.org91053e72013-08-10 07:18:04 +0000402 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000403 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000404 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000405 observer = new WebRtcSessionCreateSDPObserverForTest();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000406 session_->CreateOffer(observer, options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000407 EXPECT_TRUE_WAIT(
408 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000409 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000410 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000411 }
412
413 SessionDescriptionInterface* CreateAnswer(
414 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000415 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000416 = new WebRtcSessionCreateSDPObserverForTest();
417 session_->CreateAnswer(observer, constraints);
418 EXPECT_TRUE_WAIT(
419 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000420 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000421 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000422 }
423
wu@webrtc.org364f2042013-11-20 21:49:41 +0000424 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000425 return (session_->voice_channel() != NULL &&
426 session_->video_channel() != NULL);
427 }
428
wu@webrtc.org364f2042013-11-20 21:49:41 +0000429 void CheckTransportChannels() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000430 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 1) != NULL);
431 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 2) != NULL);
432 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 1) != NULL);
433 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 2) != NULL);
434 }
435
436 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
437 ASSERT_TRUE(session_.get() != NULL);
438 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
439 ASSERT_TRUE(content != NULL);
440 const cricket::AudioContentDescription* audio_content =
441 static_cast<const cricket::AudioContentDescription*>(
442 content->description);
443 ASSERT_TRUE(audio_content != NULL);
444 ASSERT_EQ(1U, audio_content->cryptos().size());
445 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
446 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
447 audio_content->cryptos()[0].cipher_suite);
448 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
449 audio_content->protocol());
450
451 content = cricket::GetFirstVideoContent(sdp);
452 ASSERT_TRUE(content != NULL);
453 const cricket::VideoContentDescription* video_content =
454 static_cast<const cricket::VideoContentDescription*>(
455 content->description);
456 ASSERT_TRUE(video_content != NULL);
457 ASSERT_EQ(1U, video_content->cryptos().size());
458 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
459 video_content->cryptos()[0].cipher_suite);
460 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
461 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
462 video_content->protocol());
463 }
464
465 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
466 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
467 ASSERT_TRUE(content != NULL);
468 const cricket::AudioContentDescription* audio_content =
469 static_cast<const cricket::AudioContentDescription*>(
470 content->description);
471 ASSERT_TRUE(audio_content != NULL);
472 ASSERT_EQ(0U, audio_content->cryptos().size());
473
474 content = cricket::GetFirstVideoContent(sdp);
475 ASSERT_TRUE(content != NULL);
476 const cricket::VideoContentDescription* video_content =
477 static_cast<const cricket::VideoContentDescription*>(
478 content->description);
479 ASSERT_TRUE(video_content != NULL);
480 ASSERT_EQ(0U, video_content->cryptos().size());
481
482 if (dtls) {
483 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
484 audio_content->protocol());
485 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
486 video_content->protocol());
487 } else {
488 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
489 audio_content->protocol());
490 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
491 video_content->protocol());
492 }
493 }
494
495 // Set the internal fake description factories to do DTLS-SRTP.
496 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000497 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000498 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000499 rtc::ToString(rtc::CreateRandomId());
500 identity_.reset(rtc::SSLIdentity::Generate(identity_name));
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000501 tdesc_factory_->set_identity(identity_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000502 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
503 }
504
505 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
506 bool expected) {
507 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
508 ASSERT_TRUE(audio != NULL);
509 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000510 const TransportInfo* video = sdp->GetTransportInfoByName("video");
511 ASSERT_TRUE(video != NULL);
512 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000513 }
514
515 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000516 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000517 cricket::MediaSessionOptions options;
518 options.has_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000519 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000520 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000521 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000522 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000523 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
524 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000525 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000526 // Answer should be NULL as no crypto params in offer.
527 ASSERT_TRUE(answer == NULL);
528 }
529
530 void VerifyAnswerFromCryptoOffer() {
531 cricket::MediaSessionOptions options;
532 options.has_video = true;
533 options.bundle_enabled = true;
534 scoped_ptr<JsepSessionDescription> offer(
535 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
536 ASSERT_TRUE(offer.get() != NULL);
537 VerifyCryptoParams(offer->description());
538 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000539 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000540 ASSERT_TRUE(answer.get() != NULL);
541 VerifyCryptoParams(answer->description());
542 }
543
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000544 void SetAndVerifyNumUnsignalledRecvStreams(
545 int value_set, int value_expected) {
546 constraints_.reset(new FakeConstraints());
547 constraints_->AddOptional(
548 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
549 value_set);
550 session_.reset();
551 Init(NULL);
552 mediastream_signaling_.SendAudioVideoStream1();
553 SessionDescriptionInterface* offer = CreateOffer();
554
555 SetLocalDescriptionWithoutError(offer);
556
557 video_channel_ = media_engine_->GetVideoChannel(0);
558
559 ASSERT_TRUE(video_channel_ != NULL);
560 cricket::VideoOptions video_options;
561 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
562 EXPECT_EQ(value_expected,
563 video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1));
564 }
565
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000566 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
567 const cricket::SessionDescription* desc2,
568 bool expect_equal) {
569 if (desc1->contents().size() != desc2->contents().size()) {
570 EXPECT_FALSE(expect_equal);
571 return;
572 }
573
574 const cricket::ContentInfos& contents = desc1->contents();
575 cricket::ContentInfos::const_iterator it = contents.begin();
576
577 for (; it != contents.end(); ++it) {
578 const cricket::TransportDescription* transport_desc1 =
579 desc1->GetTransportDescriptionByName(it->name);
580 const cricket::TransportDescription* transport_desc2 =
581 desc2->GetTransportDescriptionByName(it->name);
582 if (!transport_desc1 || !transport_desc2) {
583 EXPECT_FALSE(expect_equal);
584 return;
585 }
586 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
587 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
588 EXPECT_FALSE(expect_equal);
589 return;
590 }
591 }
592 EXPECT_TRUE(expect_equal);
593 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000594
595 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
596 std::string *sdp) {
597 const cricket::SessionDescription* desc = current_desc->description();
598 EXPECT_TRUE(current_desc->ToString(sdp));
599
600 const cricket::ContentInfos& contents = desc->contents();
601 cricket::ContentInfos::const_iterator it = contents.begin();
602 // Replace ufrag and pwd lines with empty strings.
603 for (; it != contents.end(); ++it) {
604 const cricket::TransportDescription* transport_desc =
605 desc->GetTransportDescriptionByName(it->name);
606 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
607 + "\r\n";
608 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
609 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000610 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000611 "", 0,
612 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000613 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000614 "", 0,
615 sdp);
616 }
617 }
618
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000619 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
620 const std::string& modified_ice_ufrag,
621 const std::string& modified_ice_pwd,
622 std::string* sdp) {
623 const cricket::SessionDescription* desc = current_desc->description();
624 EXPECT_TRUE(current_desc->ToString(sdp));
625
626 const cricket::ContentInfos& contents = desc->contents();
627 cricket::ContentInfos::const_iterator it = contents.begin();
628 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
629 // |modified_ice_pwd| strings.
630 for (; it != contents.end(); ++it) {
631 const cricket::TransportDescription* transport_desc =
632 desc->GetTransportDescriptionByName(it->name);
633 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
634 + "\r\n";
635 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
636 + "\r\n";
637 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
638 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000639 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000640 mod_ufrag.c_str(), mod_ufrag.length(),
641 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000642 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000643 mod_pwd.c_str(), mod_pwd.length(),
644 sdp);
645 }
646 }
647
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000648 // Creates a remote offer and and applies it as a remote description,
649 // creates a local answer and applies is as a local description.
650 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
651 // to decide which local and remote streams to create.
652 void CreateAndSetRemoteOfferAndLocalAnswer() {
653 SessionDescriptionInterface* offer = CreateRemoteOffer();
654 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000655 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000656 SetLocalDescriptionWithoutError(answer);
657 }
658 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
659 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
660 }
661 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
662 BaseSession::State expected_state) {
663 SetLocalDescriptionWithoutError(desc);
664 EXPECT_EQ(expected_state, session_->state());
665 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000666 void SetLocalDescriptionExpectError(const std::string& action,
667 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000668 SessionDescriptionInterface* desc) {
669 std::string error;
670 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000671 std::string sdp_type = "local ";
672 sdp_type.append(action);
673 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000674 EXPECT_NE(std::string::npos, error.find(expected_error));
675 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000676 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
677 SessionDescriptionInterface* desc) {
678 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
679 expected_error, desc);
680 }
681 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
682 SessionDescriptionInterface* desc) {
683 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
684 expected_error, desc);
685 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000686 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
687 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
688 }
689 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
690 BaseSession::State expected_state) {
691 SetRemoteDescriptionWithoutError(desc);
692 EXPECT_EQ(expected_state, session_->state());
693 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000694 void SetRemoteDescriptionExpectError(const std::string& action,
695 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000696 SessionDescriptionInterface* desc) {
697 std::string error;
698 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000699 std::string sdp_type = "remote ";
700 sdp_type.append(action);
701 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000702 EXPECT_NE(std::string::npos, error.find(expected_error));
703 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000704 void SetRemoteDescriptionOfferExpectError(
705 const std::string& expected_error, SessionDescriptionInterface* desc) {
706 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
707 expected_error, desc);
708 }
709 void SetRemoteDescriptionPranswerExpectError(
710 const std::string& expected_error, SessionDescriptionInterface* desc) {
711 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
712 expected_error, desc);
713 }
714 void SetRemoteDescriptionAnswerExpectError(
715 const std::string& expected_error, SessionDescriptionInterface* desc) {
716 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
717 expected_error, desc);
718 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000719
720 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
721 SessionDescriptionInterface** nocrypto_answer) {
722 // Create a SDP without Crypto.
723 cricket::MediaSessionOptions options;
724 options.has_video = true;
725 options.bundle_enabled = true;
726 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
727 ASSERT_TRUE(*offer != NULL);
728 VerifyCryptoParams((*offer)->description());
729
730 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
731 cricket::SEC_DISABLED);
732 EXPECT_TRUE(*nocrypto_answer != NULL);
733 }
734
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000735 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
736 SessionDescriptionInterface** nodtls_answer) {
737 cricket::MediaSessionOptions options;
738 options.has_video = true;
739 options.bundle_enabled = true;
740
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000741 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000742 CreateRemoteOffer(options, cricket::SEC_ENABLED));
743
744 *nodtls_answer =
745 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
746 EXPECT_TRUE(*nodtls_answer != NULL);
747 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
748 VerifyCryptoParams((*nodtls_answer)->description());
749
750 SetFactoryDtlsSrtp();
751 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
752 ASSERT_TRUE(*offer != NULL);
753 VerifyFingerprintStatus((*offer)->description(), true);
754 VerifyCryptoParams((*offer)->description());
755 }
756
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000757 JsepSessionDescription* CreateRemoteOfferWithVersion(
758 cricket::MediaSessionOptions options,
759 cricket::SecurePolicy secure_policy,
760 const std::string& session_version,
761 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000762 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763 const cricket::SessionDescription* cricket_desc = NULL;
764 if (current_desc) {
765 cricket_desc = current_desc->description();
766 session_id = current_desc->session_id();
767 }
768
769 desc_factory_->set_secure(secure_policy);
770 JsepSessionDescription* offer(
771 new JsepSessionDescription(JsepSessionDescription::kOffer));
772 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
773 session_id, session_version)) {
774 delete offer;
775 offer = NULL;
776 }
777 return offer;
778 }
779 JsepSessionDescription* CreateRemoteOffer(
780 cricket::MediaSessionOptions options) {
781 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
782 kSessionVersion, NULL);
783 }
784 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000785 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
786 return CreateRemoteOfferWithVersion(
787 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000788 }
789 JsepSessionDescription* CreateRemoteOffer(
790 cricket::MediaSessionOptions options,
791 const SessionDescriptionInterface* current_desc) {
792 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
793 kSessionVersion, current_desc);
794 }
795
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000796 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
797 const char* sctp_stream_name, int new_port,
798 cricket::MediaSessionOptions options) {
799 options.data_channel_type = cricket::DCT_SCTP;
800 options.AddStream(cricket::MEDIA_TYPE_DATA, "datachannel",
801 sctp_stream_name);
802 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
803 }
804
805 // Takes ownership of offer_basis (and deletes it).
806 JsepSessionDescription* ChangeSDPSctpPort(
807 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
808 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
809 // SessionDescription from the mutated string.
810 const char* default_port_str = "5000";
811 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000812 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000813 std::string offer_str;
814 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000815 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000816 new_port_str, strlen(new_port_str),
817 &offer_str);
818 JsepSessionDescription* offer = new JsepSessionDescription(
819 offer_basis->type());
820 delete offer_basis;
821 offer->Initialize(offer_str, NULL);
822 return offer;
823 }
824
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000825 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
826 // before this function to decide which streams to create.
827 JsepSessionDescription* CreateRemoteOffer() {
828 cricket::MediaSessionOptions options;
829 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
830 return CreateRemoteOffer(options, session_->remote_description());
831 }
832
833 JsepSessionDescription* CreateRemoteAnswer(
834 const SessionDescriptionInterface* offer,
835 cricket::MediaSessionOptions options,
836 cricket::SecurePolicy policy) {
837 desc_factory_->set_secure(policy);
838 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000839 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000840 JsepSessionDescription* answer(
841 new JsepSessionDescription(JsepSessionDescription::kAnswer));
842 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
843 options, NULL),
844 session_id, kSessionVersion)) {
845 delete answer;
846 answer = NULL;
847 }
848 return answer;
849 }
850
851 JsepSessionDescription* CreateRemoteAnswer(
852 const SessionDescriptionInterface* offer,
853 cricket::MediaSessionOptions options) {
854 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
855 }
856
857 // Creates an answer session description with streams based on
858 // |mediastream_signaling_|. Call
859 // mediastream_signaling_.UseOptionsWithStreamX() before this function
860 // to decide which streams to create.
861 JsepSessionDescription* CreateRemoteAnswer(
862 const SessionDescriptionInterface* offer) {
863 cricket::MediaSessionOptions options;
864 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
865 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
866 }
867
868 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000869 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +0000870 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000871 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000872
873 PeerConnectionInterface::RTCOfferAnswerOptions options;
874 options.use_rtp_mux = bundle;
875
876 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000877 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
878 // and answer.
879 SetLocalDescriptionWithoutError(offer);
880
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000881 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000882 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 std::string sdp;
884 EXPECT_TRUE(answer->ToString(&sdp));
885
886 size_t expected_candidate_num = 2;
887 if (!rtcp_mux) {
888 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
889 // for rtp and rtcp.
890 expected_candidate_num = 4;
891 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000892 const std::string kRtcpMux = "a=rtcp-mux";
893 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000894 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000895 kXRtcpMux.c_str(), kXRtcpMux.length(),
896 &sdp);
897 }
898
899 SessionDescriptionInterface* new_answer = CreateSessionDescription(
900 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000901
902 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000903 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000904 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
905 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
906 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
907 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
908 cricket::Candidate c0 = observer_.mline_0_candidates_[i];
909 cricket::Candidate c1 = observer_.mline_1_candidates_[i];
910 if (bundle) {
911 EXPECT_TRUE(c0.IsEquivalent(c1));
912 } else {
913 EXPECT_FALSE(c0.IsEquivalent(c1));
914 }
915 }
916 }
917 // Tests that we can only send DTMF when the dtmf codec is supported.
918 void TestCanInsertDtmf(bool can) {
919 if (can) {
920 InitWithDtmfCodec();
921 } else {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000922 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000923 }
924 mediastream_signaling_.SendAudioVideoStream1();
925 CreateAndSetRemoteOfferAndLocalAnswer();
926 EXPECT_FALSE(session_->CanInsertDtmf(""));
927 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
928 }
929
930 // The method sets up a call from the session to itself, in a loopback
931 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000932 // disconnection, and then a permanent disconnection.
933 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000934 // by multiple tests with different allocators (e.g. with and without BUNDLE).
935 // While running the call, this method also checks if the session goes through
936 // the correct sequence of ICE states when a connection is established,
937 // broken, and re-established.
938 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000939 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
940 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000941 // The Gathering state should go: New -> Gathering -> Completed.
942 void TestLoopbackCall() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000943 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +0000944 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000946 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947
948 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
949 observer_.ice_gathering_state_);
950 SetLocalDescriptionWithoutError(offer);
951 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
952 observer_.ice_connection_state_);
953 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
954 observer_.ice_gathering_state_,
955 kIceCandidatesTimeout);
956 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
957 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
958 observer_.ice_gathering_state_,
959 kIceCandidatesTimeout);
960
961 std::string sdp;
962 offer->ToString(&sdp);
963 SessionDescriptionInterface* desc =
964 webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer, sdp);
965 ASSERT_TRUE(desc != NULL);
966 SetRemoteDescriptionWithoutError(desc);
967
968 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
969 observer_.ice_connection_state_,
970 kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +0000971
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000972 // The ice connection state is "Connected" too briefly to catch in a test.
973 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000974 observer_.ice_connection_state_,
975 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000976
977 // Adding firewall rule to block ping requests, which should cause
978 // transport channel failure.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000979 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000980 rtc::FP_ANY,
981 rtc::FD_ANY,
982 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000983 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
984 observer_.ice_connection_state_,
985 kIceCandidatesTimeout);
986
987 // Clearing the rules, session should move back to completed state.
988 fss_->ClearRules();
989 // Session is automatically calling OnSignalingReady after creation of
990 // new portallocator session which will allocate new set of candidates.
991
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000992 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000993 observer_.ice_connection_state_,
994 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000995
996 // Now we block ping requests and wait until the ICE connection transitions
997 // to the Failed state. This will take at least 30 seconds because it must
998 // wait for the Port to timeout.
999 int port_timeout = 30000;
1000 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001001 rtc::FP_ANY,
1002 rtc::FD_ANY,
1003 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001004 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionFailed,
1005 observer_.ice_connection_state_,
1006 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001007 }
1008
1009 void VerifyTransportType(const std::string& content_name,
1010 cricket::TransportProtocol protocol) {
1011 const cricket::Transport* transport = session_->GetTransport(content_name);
1012 ASSERT_TRUE(transport != NULL);
1013 EXPECT_EQ(protocol, transport->protocol());
1014 }
1015
1016 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1017 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001018 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1019 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1020
1021 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001022 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1023 codecs.push_back(kCNCodec1);
1024 codecs.push_back(kCNCodec2);
1025 media_engine_->SetAudioCodecs(codecs);
1026 desc_factory_->set_audio_codecs(codecs);
1027 }
1028
1029 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1030 const cricket::ContentDescription* description = content->description;
1031 ASSERT(description != NULL);
1032 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001033 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001034 ASSERT(audio_content_desc != NULL);
1035 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1036 if (audio_content_desc->codecs()[i].name == "CN")
1037 return false;
1038 }
1039 return true;
1040 }
1041
1042 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001043 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001044 dci.reliable = false;
1045 session_->CreateDataChannel("datachannel", &dci);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001046 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001047 SetLocalDescriptionWithoutError(offer);
1048 }
1049
wu@webrtc.org91053e72013-08-10 07:18:04 +00001050 void VerifyMultipleAsyncCreateDescription(
1051 bool success, CreateSessionDescriptionRequest::Type type) {
henrike@webrtc.org7666db72013-08-22 14:45:42 +00001052 InitWithDtls(!success);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001053 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001054 if (type == CreateSessionDescriptionRequest::kAnswer) {
1055 cricket::MediaSessionOptions options;
1056 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001057 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001058 ASSERT_TRUE(offer.get() != NULL);
1059 SetRemoteDescriptionWithoutError(offer.release());
1060 }
1061
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001062 PeerConnectionInterface::RTCOfferAnswerOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001063 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001064 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001065 observers[kNumber];
1066 for (int i = 0; i < kNumber; ++i) {
1067 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1068 if (type == CreateSessionDescriptionRequest::kOffer) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001069 session_->CreateOffer(observers[i], options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001070 } else {
1071 session_->CreateAnswer(observers[i], NULL);
1072 }
1073 }
1074
1075 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1076 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1077 WebRtcSessionCreateSDPObserverForTest::kFailed;
1078
1079 for (int i = 0; i < kNumber; ++i) {
1080 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1081 if (success) {
1082 EXPECT_TRUE(observers[i]->description() != NULL);
1083 } else {
1084 EXPECT_TRUE(observers[i]->description() == NULL);
1085 }
1086 }
1087 }
1088
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001089 void ConfigureAllocatorWithTurn() {
1090 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1091 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
1092 relay_server.credentials = credentials;
1093 relay_server.ports.push_back(cricket::ProtocolAddress(
1094 kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1095 allocator_->AddRelay(relay_server);
1096 allocator_->set_step_delay(cricket::kMinimumStepDelay);
1097 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
1098 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
1099 }
1100
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001101 cricket::FakeMediaEngine* media_engine_;
1102 cricket::FakeDataEngine* data_engine_;
1103 cricket::FakeDeviceManager* device_manager_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001104 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
1105 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1106 rtc::scoped_ptr<rtc::SSLIdentity> identity_;
1107 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1108 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1109 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1110 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1111 rtc::SocketServerScope ss_scope_;
1112 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001113 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001114 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001115 rtc::FakeNetworkManager network_manager_;
1116 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001117 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001118 rtc::scoped_ptr<FakeConstraints> constraints_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001119 FakeMediaStreamSignaling mediastream_signaling_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001120 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001121 MockIceObserver observer_;
1122 cricket::FakeVideoMediaChannel* video_channel_;
1123 cricket::FakeVoiceMediaChannel* voice_channel_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001124 PeerConnectionInterface::IceTransportsType ice_type_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001125};
1126
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001127TEST_F(WebRtcSessionTest, TestInitializeWithDtls) {
1128 InitWithDtls();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001129 // SDES is disabled when DTLS is on.
1130 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001131}
1132
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001133TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001134 Init(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001135 // SDES is required if DTLS is off.
1136 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001137}
1138
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001139TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1140 TestSessionCandidatesWithBundleRtcpMux(false, false);
1141}
1142
1143// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1144// with rtcp-mux and/or bundle.
1145TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1146 TestSessionCandidatesWithBundleRtcpMux(false, true);
1147}
1148
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001149TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1150 TestSessionCandidatesWithBundleRtcpMux(true, true);
1151}
1152
1153TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001154 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1155 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001156 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001157 mediastream_signaling_.SendAudioVideoStream1();
1158 InitiateCall();
1159 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1160 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1161 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1162}
1163
1164TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001165 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1166 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001167 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001168 rtc::FP_UDP,
1169 rtc::FD_ANY,
1170 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001171 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001172 mediastream_signaling_.SendAudioVideoStream1();
1173 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001174 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001175 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1176 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1177 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1178}
1179
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001180// Test session delivers no candidates gathered when constraint set to "none".
1181TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1182 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1183 SetIceTransportType(PeerConnectionInterface::kNone);
1184 Init(NULL);
1185 mediastream_signaling_.SendAudioVideoStream1();
1186 InitiateCall();
1187 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1188 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1189 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1190}
1191
1192// Test session delivers only relay candidates gathered when constaint set to
1193// "relay".
1194TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1195 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1196 ConfigureAllocatorWithTurn();
1197 SetIceTransportType(PeerConnectionInterface::kRelay);
1198 Init(NULL);
1199 mediastream_signaling_.SendAudioVideoStream1();
1200 InitiateCall();
1201 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1202 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1203 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1204 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1205 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1206 observer_.mline_0_candidates_[i].type());
1207 }
1208 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1209 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1210 observer_.mline_1_candidates_[i].type());
1211 }
1212}
1213
1214// Test session delivers all candidates gathered when constaint set to "all".
1215TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1216 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1217 SetIceTransportType(PeerConnectionInterface::kAll);
1218 Init(NULL);
1219 mediastream_signaling_.SendAudioVideoStream1();
1220 InitiateCall();
1221 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1222 // Host + STUN. By default allocator is disabled to gather relay candidates.
1223 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1224 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1225}
1226
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001227TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
1228 Init(NULL);
1229 SessionDescriptionInterface* offer = NULL;
1230 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1231 std::string unknown_action;
1232 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1233 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1234}
1235
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001236// Test creating offers and receive answers and make sure the
1237// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001238TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001239 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001240 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001241 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001242 const std::string session_id_orig = offer->session_id();
1243 const std::string session_version_orig = offer->session_version();
1244 SetLocalDescriptionWithoutError(offer);
1245
1246 mediastream_signaling_.SendAudioVideoStream2();
1247 SessionDescriptionInterface* answer =
1248 CreateRemoteAnswer(session_->local_description());
1249 SetRemoteDescriptionWithoutError(answer);
1250
1251 video_channel_ = media_engine_->GetVideoChannel(0);
1252 voice_channel_ = media_engine_->GetVoiceChannel(0);
1253
1254 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1255 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1256
1257 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1258 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1259
1260 ASSERT_EQ(1u, video_channel_->send_streams().size());
1261 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1262 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1263 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1264
1265 // Create new offer without send streams.
1266 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001267 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001268
1269 // Verify the session id is the same and the session version is
1270 // increased.
1271 EXPECT_EQ(session_id_orig, offer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001272 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1273 rtc::FromString<uint64>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001274
1275 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001276 EXPECT_EQ(0u, video_channel_->send_streams().size());
1277 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001278
1279 mediastream_signaling_.SendAudioVideoStream2();
1280 answer = CreateRemoteAnswer(session_->local_description());
1281 SetRemoteDescriptionWithoutError(answer);
1282
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001283 // Make sure the receive streams have not changed.
1284 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1285 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1286 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1287 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1288}
1289
1290// Test receiving offers and creating answers and make sure the
1291// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001292TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001293 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001294 mediastream_signaling_.SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001295 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001296 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001297 SetRemoteDescriptionWithoutError(offer);
1298
1299 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001300 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001301 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001302 SetLocalDescriptionWithoutError(answer);
1303
1304 const std::string session_id_orig = answer->session_id();
1305 const std::string session_version_orig = answer->session_version();
1306
1307 video_channel_ = media_engine_->GetVideoChannel(0);
1308 voice_channel_ = media_engine_->GetVoiceChannel(0);
1309
1310 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1311 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1312
1313 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1314 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1315
1316 ASSERT_EQ(1u, video_channel_->send_streams().size());
1317 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1318 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1319 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1320
1321 mediastream_signaling_.SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001322 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001323 SetRemoteDescriptionWithoutError(offer);
1324
1325 // Answer by turning off all send streams.
1326 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001327 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001328
1329 // Verify the session id is the same and the session version is
1330 // increased.
1331 EXPECT_EQ(session_id_orig, answer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001332 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1333 rtc::FromString<uint64>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001334 SetLocalDescriptionWithoutError(answer);
1335
1336 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1337 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1338 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1339 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1340 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1341 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1342
1343 // Make sure we have no send streams.
1344 EXPECT_EQ(0u, video_channel_->send_streams().size());
1345 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1346}
1347
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001348TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
1349 Init(NULL);
1350 media_engine_->set_fail_create_channel(true);
1351
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001352 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001353 ASSERT_TRUE(offer != NULL);
1354 // SetRemoteDescription and SetLocalDescription will take the ownership of
1355 // the offer.
1356 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001357 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001358 ASSERT_TRUE(offer != NULL);
1359 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1360}
1361
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001362//
1363// Tests for creating/setting SDP under different SDES/DTLS polices:
1364//
1365// --DTLS off and SDES on
1366// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1367// set local/remote offer/answer with crypto --> success
1368// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1369// failure
1370// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1371// failure
1372// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1373// failure
1374//
1375// --DTLS on and SDES off
1376// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1377// set local/remote offer/answer with DTLS fingerprint --> success
1378// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1379// fingerprint --> failure
1380// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1381// --> failure
1382// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1383// --> failure
1384//
1385// --Encryption disabled: DTLS off and SDES off
1386// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1387// answer without SDES or DTLS --> success
1388// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1389// answer without SDES or DTLS --> success
1390//
1391
1392// Test that we return a failure when applying a remote/local offer that doesn't
1393// have cryptos enabled when DTLS is off.
1394TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001395 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001396 cricket::MediaSessionOptions options;
1397 options.has_video = true;
1398 JsepSessionDescription* offer = CreateRemoteOffer(
1399 options, cricket::SEC_DISABLED);
1400 ASSERT_TRUE(offer != NULL);
1401 VerifyNoCryptoParams(offer->description(), false);
1402 // SetRemoteDescription and SetLocalDescription will take the ownership of
1403 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001404 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001405 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1406 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001407 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001408}
1409
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001410// Test that we return a failure when applying a local answer that doesn't have
1411// cryptos enabled when DTLS is off.
1412TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001413 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001414 SessionDescriptionInterface* offer = NULL;
1415 SessionDescriptionInterface* answer = NULL;
1416 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1417 // SetRemoteDescription and SetLocalDescription will take the ownership of
1418 // the offer.
1419 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001420 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001421}
1422
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001423// Test we will return fail when apply an remote answer that doesn't have
1424// crypto enabled when DTLS is off.
1425TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001426 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001427 SessionDescriptionInterface* offer = NULL;
1428 SessionDescriptionInterface* answer = NULL;
1429 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1430 // SetRemoteDescription and SetLocalDescription will take the ownership of
1431 // the offer.
1432 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001433 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001434}
1435
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001436// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1437// and that we return an answer with a DTLS fingerprint.
1438TEST_F(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001439 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001440 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001441 InitWithDtls();
1442 SetFactoryDtlsSrtp();
1443 cricket::MediaSessionOptions options;
1444 options.has_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001445 JsepSessionDescription* offer =
1446 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001447 ASSERT_TRUE(offer != NULL);
1448 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001449 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001450
1451 // SetRemoteDescription will take the ownership of the offer.
1452 SetRemoteDescriptionWithoutError(offer);
1453
1454 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001455 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001456 ASSERT_TRUE(answer != NULL);
1457 VerifyFingerprintStatus(answer->description(), true);
1458 // Check that we don't have an a=crypto line in the answer.
1459 VerifyNoCryptoParams(answer->description(), true);
1460
1461 // Now set the local description, which should work, even without a=crypto.
1462 SetLocalDescriptionWithoutError(answer);
1463}
1464
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001465// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1466// and then we accept a remote answer with a DTLS fingerprint successfully.
1467TEST_F(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001468 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001469 mediastream_signaling_.SendAudioVideoStream1();
1470 InitWithDtls();
1471 SetFactoryDtlsSrtp();
1472
1473 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001474 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001475 ASSERT_TRUE(offer != NULL);
1476 VerifyFingerprintStatus(offer->description(), true);
1477 // Check that we don't have an a=crypto line in the offer.
1478 VerifyNoCryptoParams(offer->description(), true);
1479
1480 // Now set the local description, which should work, even without a=crypto.
1481 SetLocalDescriptionWithoutError(offer);
1482
1483 cricket::MediaSessionOptions options;
1484 options.has_video = true;
1485 JsepSessionDescription* answer =
1486 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1487 ASSERT_TRUE(answer != NULL);
1488 VerifyFingerprintStatus(answer->description(), true);
1489 VerifyNoCryptoParams(answer->description(), true);
1490
1491 // SetRemoteDescription will take the ownership of the answer.
1492 SetRemoteDescriptionWithoutError(answer);
1493}
1494
1495// Test that if we support DTLS and the other side didn't offer a fingerprint,
1496// we will fail to set the remote description.
1497TEST_F(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001498 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001499 InitWithDtls();
1500 cricket::MediaSessionOptions options;
1501 options.has_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001502 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001503 JsepSessionDescription* offer = CreateRemoteOffer(
1504 options, cricket::SEC_REQUIRED);
1505 ASSERT_TRUE(offer != NULL);
1506 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001507 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001508
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001509 // SetRemoteDescription will take the ownership of the offer.
1510 SetRemoteDescriptionOfferExpectError(
1511 kSdpWithoutDtlsFingerprint, offer);
1512
1513 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1514 // SetLocalDescription will take the ownership of the offer.
1515 SetLocalDescriptionOfferExpectError(
1516 kSdpWithoutDtlsFingerprint, offer);
1517}
1518
1519// Test that we return a failure when applying a local answer that doesn't have
1520// a DTLS fingerprint when DTLS is required.
1521TEST_F(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001522 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001523 InitWithDtls();
1524 SessionDescriptionInterface* offer = NULL;
1525 SessionDescriptionInterface* answer = NULL;
1526 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1527
1528 // SetRemoteDescription and SetLocalDescription will take the ownership of
1529 // the offer and answer.
1530 SetRemoteDescriptionWithoutError(offer);
1531 SetLocalDescriptionAnswerExpectError(
1532 kSdpWithoutDtlsFingerprint, answer);
1533}
1534
1535// Test that we return a failure when applying a remote answer that doesn't have
1536// a DTLS fingerprint when DTLS is required.
1537TEST_F(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001538 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001539 InitWithDtls();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001540 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001541 cricket::MediaSessionOptions options;
1542 options.has_video = true;
1543 JsepSessionDescription* answer =
1544 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
1545
1546 // SetRemoteDescription and SetLocalDescription will take the ownership of
1547 // the offer and answer.
1548 SetLocalDescriptionWithoutError(offer);
1549 SetRemoteDescriptionAnswerExpectError(
1550 kSdpWithoutDtlsFingerprint, answer);
1551}
1552
1553// Test that we create a local offer without SDES or DTLS and accept a remote
1554// answer without SDES or DTLS when encryption is disabled.
1555TEST_F(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
1556 mediastream_signaling_.SendAudioVideoStream1();
1557 options_.disable_encryption = true;
1558 InitWithDtls();
1559
1560 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001561 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001562 ASSERT_TRUE(offer != NULL);
1563 VerifyFingerprintStatus(offer->description(), false);
1564 // Check that we don't have an a=crypto line in the offer.
1565 VerifyNoCryptoParams(offer->description(), false);
1566
1567 // Now set the local description, which should work, even without a=crypto.
1568 SetLocalDescriptionWithoutError(offer);
1569
1570 cricket::MediaSessionOptions options;
1571 options.has_video = true;
1572 JsepSessionDescription* answer =
1573 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1574 ASSERT_TRUE(answer != NULL);
1575 VerifyFingerprintStatus(answer->description(), false);
1576 VerifyNoCryptoParams(answer->description(), false);
1577
1578 // SetRemoteDescription will take the ownership of the answer.
1579 SetRemoteDescriptionWithoutError(answer);
1580}
1581
1582// Test that we create a local answer without SDES or DTLS and accept a remote
1583// offer without SDES or DTLS when encryption is disabled.
1584TEST_F(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
1585 options_.disable_encryption = true;
1586 InitWithDtls();
1587
1588 cricket::MediaSessionOptions options;
1589 options.has_video = true;
1590 JsepSessionDescription* offer =
1591 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1592 ASSERT_TRUE(offer != NULL);
1593 VerifyFingerprintStatus(offer->description(), false);
1594 VerifyNoCryptoParams(offer->description(), false);
1595
1596 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001597 SetRemoteDescriptionWithoutError(offer);
1598
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001599 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001600 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001601 ASSERT_TRUE(answer != NULL);
1602 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001603 // Check that we don't have an a=crypto line in the answer.
1604 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001605
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001606 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607 SetLocalDescriptionWithoutError(answer);
1608}
1609
1610TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001611 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001612 mediastream_signaling_.SendNothing();
1613 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001614 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001615 SetLocalDescriptionWithoutError(offer);
1616
1617 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001618 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619 SetLocalDescriptionWithoutError(offer2);
1620}
1621
1622TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001623 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001624 mediastream_signaling_.SendNothing();
1625 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001626 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001627 SetRemoteDescriptionWithoutError(offer);
1628
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001629 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001630 SetRemoteDescriptionWithoutError(offer2);
1631}
1632
1633TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001634 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001635 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001636 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001637 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001638 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001639 SetRemoteDescriptionOfferExpectError(
1640 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001641}
1642
1643TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001644 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001645 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001646 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001647 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001648 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001649 SetLocalDescriptionOfferExpectError(
1650 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001651}
1652
1653TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001654 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001655 mediastream_signaling_.SendNothing();
1656 SessionDescriptionInterface* offer = CreateRemoteOffer();
1657 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1658
1659 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001660 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001661 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1662 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1663
1664 mediastream_signaling_.SendAudioVideoStream1();
1665 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001666 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001667 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1668
1669 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1670
1671 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001672 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001673 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1674}
1675
1676TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001677 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001678 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001679 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001680 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1681
1682 JsepSessionDescription* pranswer =
1683 CreateRemoteAnswer(session_->local_description());
1684 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1685
1686 SetRemoteDescriptionExpectState(pranswer,
1687 BaseSession::STATE_RECEIVEDPRACCEPT);
1688
1689 mediastream_signaling_.SendAudioVideoStream1();
1690 JsepSessionDescription* pranswer2 =
1691 CreateRemoteAnswer(session_->local_description());
1692 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1693
1694 SetRemoteDescriptionExpectState(pranswer2,
1695 BaseSession::STATE_RECEIVEDPRACCEPT);
1696
1697 mediastream_signaling_.SendAudioVideoStream2();
1698 SessionDescriptionInterface* answer =
1699 CreateRemoteAnswer(session_->local_description());
1700 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1701}
1702
1703TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001704 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001705 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001706 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1707
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708 SessionDescriptionInterface* answer =
1709 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001710 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1711 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001712}
1713
1714TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001715 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001716 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001717 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1718
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001719 SessionDescriptionInterface* answer =
1720 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001721 SetRemoteDescriptionAnswerExpectError(
1722 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001723}
1724
1725TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001726 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001727 mediastream_signaling_.SendAudioVideoStream1();
1728
1729 cricket::Candidate candidate;
1730 candidate.set_component(1);
1731 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1732
1733 // Fail since we have not set a offer description.
1734 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1735
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001736 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001737 SetLocalDescriptionWithoutError(offer);
1738 // Candidate should be allowed to add before remote description.
1739 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1740 candidate.set_component(2);
1741 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1742 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1743
1744 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1745 session_->local_description());
1746 SetRemoteDescriptionWithoutError(answer);
1747
1748 // Verifying the candidates are copied properly from internal vector.
1749 const SessionDescriptionInterface* remote_desc =
1750 session_->remote_description();
1751 ASSERT_TRUE(remote_desc != NULL);
1752 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1753 const IceCandidateCollection* candidates =
1754 remote_desc->candidates(kMediaContentIndex0);
1755 ASSERT_EQ(2u, candidates->count());
1756 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1757 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1758 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1759 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1760
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001761 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1762 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001763 candidate.set_component(2);
1764 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1765 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001766 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001767
1768 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1769 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1770}
1771
1772// Test that a remote candidate is added to the remote session description and
1773// that it is retained if the remote session description is changed.
1774TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001775 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776 cricket::Candidate candidate1;
1777 candidate1.set_component(1);
1778 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1779 candidate1);
1780 mediastream_signaling_.SendAudioVideoStream1();
1781 CreateAndSetRemoteOfferAndLocalAnswer();
1782
1783 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1784 const SessionDescriptionInterface* remote_desc =
1785 session_->remote_description();
1786 ASSERT_TRUE(remote_desc != NULL);
1787 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1788 const IceCandidateCollection* candidates =
1789 remote_desc->candidates(kMediaContentIndex0);
1790 ASSERT_EQ(1u, candidates->count());
1791 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1792
1793 // Update the RemoteSessionDescription with a new session description and
1794 // a candidate and check that the new remote session description contains both
1795 // candidates.
1796 SessionDescriptionInterface* offer = CreateRemoteOffer();
1797 cricket::Candidate candidate2;
1798 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1799 candidate2);
1800 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1801 SetRemoteDescriptionWithoutError(offer);
1802
1803 remote_desc = session_->remote_description();
1804 ASSERT_TRUE(remote_desc != NULL);
1805 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1806 candidates = remote_desc->candidates(kMediaContentIndex0);
1807 ASSERT_EQ(2u, candidates->count());
1808 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1809 // Username and password have be updated with the TransportInfo of the
1810 // SessionDescription, won't be equal to the original one.
1811 candidate2.set_username(candidates->at(0)->candidate().username());
1812 candidate2.set_password(candidates->at(0)->candidate().password());
1813 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
1814 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
1815 // No need to verify the username and password.
1816 candidate1.set_username(candidates->at(1)->candidate().username());
1817 candidate1.set_password(candidates->at(1)->candidate().password());
1818 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
1819
1820 // Test that the candidate is ignored if we can add the same candidate again.
1821 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1822}
1823
1824// Test that local candidates are added to the local session description and
1825// that they are retained if the local session description is changed.
1826TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001827 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001828 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001829 mediastream_signaling_.SendAudioVideoStream1();
1830 CreateAndSetRemoteOfferAndLocalAnswer();
1831
1832 const SessionDescriptionInterface* local_desc = session_->local_description();
1833 const IceCandidateCollection* candidates =
1834 local_desc->candidates(kMediaContentIndex0);
1835 ASSERT_TRUE(candidates != NULL);
1836 EXPECT_EQ(0u, candidates->count());
1837
1838 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1839
1840 local_desc = session_->local_description();
1841 candidates = local_desc->candidates(kMediaContentIndex0);
1842 ASSERT_TRUE(candidates != NULL);
1843 EXPECT_LT(0u, candidates->count());
1844 candidates = local_desc->candidates(1);
1845 ASSERT_TRUE(candidates != NULL);
1846 EXPECT_LT(0u, candidates->count());
1847
1848 // Update the session descriptions.
1849 mediastream_signaling_.SendAudioVideoStream1();
1850 CreateAndSetRemoteOfferAndLocalAnswer();
1851
1852 local_desc = session_->local_description();
1853 candidates = local_desc->candidates(kMediaContentIndex0);
1854 ASSERT_TRUE(candidates != NULL);
1855 EXPECT_LT(0u, candidates->count());
1856 candidates = local_desc->candidates(1);
1857 ASSERT_TRUE(candidates != NULL);
1858 EXPECT_LT(0u, candidates->count());
1859}
1860
1861// Test that we can set a remote session description with remote candidates.
1862TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001863 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001864
1865 cricket::Candidate candidate1;
1866 candidate1.set_component(1);
1867 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
1868 candidate1);
1869 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001870 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001871
1872 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
1873 SetRemoteDescriptionWithoutError(offer);
1874
1875 const SessionDescriptionInterface* remote_desc =
1876 session_->remote_description();
1877 ASSERT_TRUE(remote_desc != NULL);
1878 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1879 const IceCandidateCollection* candidates =
1880 remote_desc->candidates(kMediaContentIndex0);
1881 ASSERT_EQ(1u, candidates->count());
1882 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1883
wu@webrtc.org91053e72013-08-10 07:18:04 +00001884 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001885 SetLocalDescriptionWithoutError(answer);
1886}
1887
1888// Test that offers and answers contains ice candidates when Ice candidates have
1889// been gathered.
1890TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001891 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001892 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001893 mediastream_signaling_.SendAudioVideoStream1();
1894 // Ice is started but candidates are not provided until SetLocalDescription
1895 // is called.
1896 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1897 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1898 CreateAndSetRemoteOfferAndLocalAnswer();
1899 // Wait until at least one local candidate has been collected.
1900 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
1901 kIceCandidatesTimeout);
1902 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
1903 kIceCandidatesTimeout);
1904
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001905 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
1906
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
1908 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
1909 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
1910 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
1911
1912 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
1913 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001914 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001915 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
1916 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
1917 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
1918 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
1919 SetLocalDescriptionWithoutError(answer);
1920}
1921
1922// Verifies TransportProxy and media channels are created with content names
1923// present in the SessionDescription.
1924TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001925 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001926 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001927 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001928
1929 // CreateOffer creates session description with the content names "audio" and
1930 // "video". Goal is to modify these content names and verify transport channel
1931 // proxy in the BaseSession, as proxies are created with the content names
1932 // present in SDP.
1933 std::string sdp;
1934 EXPECT_TRUE(offer->ToString(&sdp));
1935 const std::string kAudioMid = "a=mid:audio";
1936 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
1937 const std::string kVideoMid = "a=mid:video";
1938 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
1939
1940 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001941 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001942 kAudioMidReplaceStr.c_str(),
1943 kAudioMidReplaceStr.length(),
1944 &sdp);
1945 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001946 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001947 kVideoMidReplaceStr.c_str(),
1948 kVideoMidReplaceStr.length(),
1949 &sdp);
1950
1951 SessionDescriptionInterface* modified_offer =
1952 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
1953
1954 SetRemoteDescriptionWithoutError(modified_offer);
1955
1956 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00001957 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001958 SetLocalDescriptionWithoutError(answer);
1959
1960 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
1961 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
1962 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
1963 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
1964}
1965
1966// Test that an offer contains the correct media content descriptions based on
1967// the send streams when no constraints have been set.
1968TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001969 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001970 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1971
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001972 ASSERT_TRUE(offer != NULL);
1973 const cricket::ContentInfo* content =
1974 cricket::GetFirstAudioContent(offer->description());
1975 EXPECT_TRUE(content != NULL);
1976 content = cricket::GetFirstVideoContent(offer->description());
1977 EXPECT_TRUE(content == NULL);
1978}
1979
1980// Test that an offer contains the correct media content descriptions based on
1981// the send streams when no constraints have been set.
1982TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001983 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001984 // Test Audio only offer.
1985 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001986 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1987
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001988 const cricket::ContentInfo* content =
1989 cricket::GetFirstAudioContent(offer->description());
1990 EXPECT_TRUE(content != NULL);
1991 content = cricket::GetFirstVideoContent(offer->description());
1992 EXPECT_TRUE(content == NULL);
1993
1994 // Test Audio / Video offer.
1995 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001996 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001997 content = cricket::GetFirstAudioContent(offer->description());
1998 EXPECT_TRUE(content != NULL);
1999 content = cricket::GetFirstVideoContent(offer->description());
2000 EXPECT_TRUE(content != NULL);
2001}
2002
2003// Test that an offer contains no media content descriptions if
2004// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2005TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002006 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002007 PeerConnectionInterface::RTCOfferAnswerOptions options;
2008 options.offer_to_receive_audio = 0;
2009 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002010
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002011 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002012 CreateOffer(options));
2013
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002014 ASSERT_TRUE(offer != NULL);
2015 const cricket::ContentInfo* content =
2016 cricket::GetFirstAudioContent(offer->description());
2017 EXPECT_TRUE(content == NULL);
2018 content = cricket::GetFirstVideoContent(offer->description());
2019 EXPECT_TRUE(content == NULL);
2020}
2021
2022// Test that an offer contains only audio media content descriptions if
2023// kOfferToReceiveAudio constraints are set to true.
2024TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002025 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002026 PeerConnectionInterface::RTCOfferAnswerOptions options;
2027 options.offer_to_receive_audio =
2028 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2029
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002030 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002031 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002032
2033 const cricket::ContentInfo* content =
2034 cricket::GetFirstAudioContent(offer->description());
2035 EXPECT_TRUE(content != NULL);
2036 content = cricket::GetFirstVideoContent(offer->description());
2037 EXPECT_TRUE(content == NULL);
2038}
2039
2040// Test that an offer contains audio and video media content descriptions if
2041// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2042TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002043 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002044 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002045 PeerConnectionInterface::RTCOfferAnswerOptions options;
2046 options.offer_to_receive_audio =
2047 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2048 options.offer_to_receive_video =
2049 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2050
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002051 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002052 CreateOffer(options));
2053
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002054 const cricket::ContentInfo* content =
2055 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002056 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002057
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058 content = cricket::GetFirstVideoContent(offer->description());
2059 EXPECT_TRUE(content != NULL);
2060
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002061 // Sets constraints to false and verifies that audio/video contents are
2062 // removed.
2063 options.offer_to_receive_audio = 0;
2064 options.offer_to_receive_video = 0;
2065 offer.reset(CreateOffer(options));
2066
2067 content = cricket::GetFirstAudioContent(offer->description());
2068 EXPECT_TRUE(content == NULL);
2069 content = cricket::GetFirstVideoContent(offer->description());
2070 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002071}
2072
2073// Test that an answer can not be created if the last remote description is not
2074// an offer.
2075TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002076 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002077 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002078 SetLocalDescriptionWithoutError(offer);
2079 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2080 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002081 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002082}
2083
2084// Test that an answer contains the correct media content descriptions when no
2085// constraints have been set.
2086TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002087 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002088 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002089 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002090 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002091 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002092 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093 const cricket::ContentInfo* content =
2094 cricket::GetFirstAudioContent(answer->description());
2095 ASSERT_TRUE(content != NULL);
2096 EXPECT_FALSE(content->rejected);
2097
2098 content = cricket::GetFirstVideoContent(answer->description());
2099 ASSERT_TRUE(content != NULL);
2100 EXPECT_FALSE(content->rejected);
2101}
2102
2103// Test that an answer contains the correct media content descriptions when no
2104// constraints have been set and the offer only contain audio.
2105TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002106 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002107 // Create a remote offer with audio only.
2108 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002109
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002110 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002111 CreateRemoteOffer(options));
2112 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2113 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2114
2115 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002116 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002117 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118 const cricket::ContentInfo* content =
2119 cricket::GetFirstAudioContent(answer->description());
2120 ASSERT_TRUE(content != NULL);
2121 EXPECT_FALSE(content->rejected);
2122
2123 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2124}
2125
2126// Test that an answer contains the correct media content descriptions when no
2127// constraints have been set.
2128TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002129 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002130 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002131 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002132 SetRemoteDescriptionWithoutError(offer.release());
2133 // Test with a stream with tracks.
2134 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002135 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002136 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137 const cricket::ContentInfo* content =
2138 cricket::GetFirstAudioContent(answer->description());
2139 ASSERT_TRUE(content != NULL);
2140 EXPECT_FALSE(content->rejected);
2141
2142 content = cricket::GetFirstVideoContent(answer->description());
2143 ASSERT_TRUE(content != NULL);
2144 EXPECT_FALSE(content->rejected);
2145}
2146
2147// Test that an answer contains the correct media content descriptions when
2148// constraints have been set but no stream is sent.
2149TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002150 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002151 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002152 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002153 SetRemoteDescriptionWithoutError(offer.release());
2154
2155 webrtc::FakeConstraints constraints_no_receive;
2156 constraints_no_receive.SetMandatoryReceiveAudio(false);
2157 constraints_no_receive.SetMandatoryReceiveVideo(false);
2158
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002159 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002160 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002161 const cricket::ContentInfo* content =
2162 cricket::GetFirstAudioContent(answer->description());
2163 ASSERT_TRUE(content != NULL);
2164 EXPECT_TRUE(content->rejected);
2165
2166 content = cricket::GetFirstVideoContent(answer->description());
2167 ASSERT_TRUE(content != NULL);
2168 EXPECT_TRUE(content->rejected);
2169}
2170
2171// Test that an answer contains the correct media content descriptions when
2172// constraints have been set and streams are sent.
2173TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002174 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002175 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002176 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002177 SetRemoteDescriptionWithoutError(offer.release());
2178
2179 webrtc::FakeConstraints constraints_no_receive;
2180 constraints_no_receive.SetMandatoryReceiveAudio(false);
2181 constraints_no_receive.SetMandatoryReceiveVideo(false);
2182
2183 // Test with a stream with tracks.
2184 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002185 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002186 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002187
2188 // TODO(perkj): Should the direction be set to SEND_ONLY?
2189 const cricket::ContentInfo* content =
2190 cricket::GetFirstAudioContent(answer->description());
2191 ASSERT_TRUE(content != NULL);
2192 EXPECT_FALSE(content->rejected);
2193
2194 // TODO(perkj): Should the direction be set to SEND_ONLY?
2195 content = cricket::GetFirstVideoContent(answer->description());
2196 ASSERT_TRUE(content != NULL);
2197 EXPECT_FALSE(content->rejected);
2198}
2199
2200TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2201 AddCNCodecs();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002202 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002203 PeerConnectionInterface::RTCOfferAnswerOptions options;
2204 options.offer_to_receive_audio =
2205 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2206 options.voice_activity_detection = false;
2207
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002208 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002209 CreateOffer(options));
2210
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002211 const cricket::ContentInfo* content =
2212 cricket::GetFirstAudioContent(offer->description());
2213 EXPECT_TRUE(content != NULL);
2214 EXPECT_TRUE(VerifyNoCNCodecs(content));
2215}
2216
2217TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2218 AddCNCodecs();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002219 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002220 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002221 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002222 SetRemoteDescriptionWithoutError(offer.release());
2223
2224 webrtc::FakeConstraints constraints;
2225 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002226 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002227 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002228 const cricket::ContentInfo* content =
2229 cricket::GetFirstAudioContent(answer->description());
2230 ASSERT_TRUE(content != NULL);
2231 EXPECT_TRUE(VerifyNoCNCodecs(content));
2232}
2233
2234// This test verifies the call setup when remote answer with audio only and
2235// later updates with video.
2236TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002237 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002238 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2239 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2240
2241 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002242 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002243
2244 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002245 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2246
2247 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2248 // and answer;
2249 SetLocalDescriptionWithoutError(offer);
2250 SetRemoteDescriptionWithoutError(answer);
2251
2252 video_channel_ = media_engine_->GetVideoChannel(0);
2253 voice_channel_ = media_engine_->GetVoiceChannel(0);
2254
2255 ASSERT_TRUE(video_channel_ == NULL);
2256
2257 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2258 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2259 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2260
2261 // Let the remote end update the session descriptions, with Audio and Video.
2262 mediastream_signaling_.SendAudioVideoStream2();
2263 CreateAndSetRemoteOfferAndLocalAnswer();
2264
2265 video_channel_ = media_engine_->GetVideoChannel(0);
2266 voice_channel_ = media_engine_->GetVoiceChannel(0);
2267
2268 ASSERT_TRUE(video_channel_ != NULL);
2269 ASSERT_TRUE(voice_channel_ != NULL);
2270
2271 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2272 ASSERT_EQ(1u, video_channel_->send_streams().size());
2273 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2274 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2275 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2276 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2277 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2278 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2279
2280 // Change session back to audio only.
2281 mediastream_signaling_.UseOptionsAudioOnly();
2282 CreateAndSetRemoteOfferAndLocalAnswer();
2283
2284 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2285 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2286 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2287 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2288 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2289}
2290
2291// This test verifies the call setup when remote answer with video only and
2292// later updates with audio.
2293TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002294 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002295 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2296 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2297 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002298 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002299
2300 cricket::MediaSessionOptions options;
2301 options.has_audio = false;
2302 options.has_video = true;
2303 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2304 offer, options, cricket::SEC_ENABLED);
2305
2306 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2307 // and answer.
2308 SetLocalDescriptionWithoutError(offer);
2309 SetRemoteDescriptionWithoutError(answer);
2310
2311 video_channel_ = media_engine_->GetVideoChannel(0);
2312 voice_channel_ = media_engine_->GetVoiceChannel(0);
2313
2314 ASSERT_TRUE(voice_channel_ == NULL);
2315 ASSERT_TRUE(video_channel_ != NULL);
2316
2317 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2318 ASSERT_EQ(1u, video_channel_->send_streams().size());
2319 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2320
2321 // Update the session descriptions, with Audio and Video.
2322 mediastream_signaling_.SendAudioVideoStream2();
2323 CreateAndSetRemoteOfferAndLocalAnswer();
2324
2325 voice_channel_ = media_engine_->GetVoiceChannel(0);
2326 ASSERT_TRUE(voice_channel_ != NULL);
2327
2328 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2329 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2330 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2331 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2332
2333 // Change session back to video only.
2334 mediastream_signaling_.UseOptionsVideoOnly();
2335 CreateAndSetRemoteOfferAndLocalAnswer();
2336
2337 video_channel_ = media_engine_->GetVideoChannel(0);
2338 voice_channel_ = media_engine_->GetVoiceChannel(0);
2339
2340 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2341 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2342 ASSERT_EQ(1u, video_channel_->send_streams().size());
2343 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2344}
2345
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002346TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002347 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002348 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002349 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002350 VerifyCryptoParams(offer->description());
2351 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002352 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002353 VerifyCryptoParams(answer->description());
2354}
2355
2356TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002357 options_.disable_encryption = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00002358 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002360 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002361 VerifyNoCryptoParams(offer->description(), false);
2362}
2363
2364TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002365 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002366 VerifyAnswerFromNonCryptoOffer();
2367}
2368
2369TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002370 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002371 VerifyAnswerFromCryptoOffer();
2372}
2373
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002374// This test verifies that setLocalDescription fails if
2375// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2376TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
2377 Init(NULL);
2378 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002379 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2380
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002381 std::string sdp;
2382 RemoveIceUfragPwdLines(offer.get(), &sdp);
2383 SessionDescriptionInterface* modified_offer =
2384 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002385 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002386}
2387
2388// This test verifies that setRemoteDescription fails if
2389// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2390TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
2391 Init(NULL);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002392 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002393 std::string sdp;
2394 RemoveIceUfragPwdLines(offer.get(), &sdp);
2395 SessionDescriptionInterface* modified_offer =
2396 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002397 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002398}
2399
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002400// This test verifies that setLocalDescription fails if local offer has
2401// too short ice ufrag and pwd strings.
2402TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
2403 Init(NULL);
2404 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
2405 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002406 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2407
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002408 std::string sdp;
2409 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2410 // recommended values of 4 and 22 bytes respectively.
2411 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2412 SessionDescriptionInterface* modified_offer =
2413 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2414 std::string error;
2415 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2416
2417 // Test with string greater than 256.
2418 sdp.clear();
2419 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2420 &sdp);
2421 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2422 NULL);
2423 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2424}
2425
2426// This test verifies that setRemoteDescription fails if remote offer has
2427// too short ice ufrag and pwd strings.
2428TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
2429 Init(NULL);
2430 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002431 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002432 std::string sdp;
2433 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2434 // recommended values of 4 and 22 bytes respectively.
2435 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2436 SessionDescriptionInterface* modified_offer =
2437 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2438 std::string error;
2439 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2440
2441 sdp.clear();
2442 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2443 &sdp);
2444 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2445 NULL);
2446 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2447}
2448
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002449TEST_F(WebRtcSessionTest, VerifyBundleFlagInPA) {
2450 // This test verifies BUNDLE flag in PortAllocator, if BUNDLE information in
2451 // local description is removed by the application, BUNDLE flag should be
2452 // disabled in PortAllocator. By default BUNDLE is enabled in the WebRtc.
wu@webrtc.org91053e72013-08-10 07:18:04 +00002453 Init(NULL);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002454 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2455 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002456 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2457
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002458 cricket::SessionDescription* offer_copy =
2459 offer->description()->Copy();
2460 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2461 JsepSessionDescription* modified_offer =
2462 new JsepSessionDescription(JsepSessionDescription::kOffer);
2463 modified_offer->Initialize(offer_copy, "1", "1");
2464
2465 SetLocalDescriptionWithoutError(modified_offer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002466 EXPECT_FALSE(allocator_->flags() & cricket::PORTALLOCATOR_ENABLE_BUNDLE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002467}
2468
2469TEST_F(WebRtcSessionTest, TestDisabledBundleInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002470 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002471 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002472 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2473 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002474
2475 PeerConnectionInterface::RTCOfferAnswerOptions options;
2476 options.use_rtp_mux = true;
2477
2478 SessionDescriptionInterface* offer = CreateOffer(options);
2479
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002480 SetLocalDescriptionWithoutError(offer);
2481 mediastream_signaling_.SendAudioVideoStream2();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002482 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002483 CreateRemoteAnswer(session_->local_description()));
2484 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2485 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2486 JsepSessionDescription* modified_answer =
2487 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2488 modified_answer->Initialize(answer_copy, "1", "1");
2489 SetRemoteDescriptionWithoutError(modified_answer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002490 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2491 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002492
2493 video_channel_ = media_engine_->GetVideoChannel(0);
2494 voice_channel_ = media_engine_->GetVoiceChannel(0);
2495
2496 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2497 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
2498
2499 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2500 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
2501
2502 ASSERT_EQ(1u, video_channel_->send_streams().size());
2503 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
2504 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2505 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
2506}
2507
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002508// This test verifies that SetLocalDescription and SetRemoteDescription fails
2509// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2510TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002511 WebRtcSessionTest::Init(NULL);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002512 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002513 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2514 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002515
2516 PeerConnectionInterface::RTCOfferAnswerOptions options;
2517 options.use_rtp_mux = true;
2518
2519 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002520 std::string offer_str;
2521 offer->ToString(&offer_str);
2522 // Disable rtcp-mux
2523 const std::string rtcp_mux = "rtcp-mux";
2524 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002525 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002526 xrtcp_mux.c_str(), xrtcp_mux.length(),
2527 &offer_str);
2528 JsepSessionDescription *local_offer =
2529 new JsepSessionDescription(JsepSessionDescription::kOffer);
2530 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002531 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002532 JsepSessionDescription *remote_offer =
2533 new JsepSessionDescription(JsepSessionDescription::kOffer);
2534 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002535 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002536 // Trying unmodified SDP.
2537 SetLocalDescriptionWithoutError(offer);
2538}
2539
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002540TEST_F(WebRtcSessionTest, SetAudioPlayout) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002541 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002542 mediastream_signaling_.SendAudioVideoStream1();
2543 CreateAndSetRemoteOfferAndLocalAnswer();
2544 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2545 ASSERT_TRUE(channel != NULL);
2546 ASSERT_EQ(1u, channel->recv_streams().size());
2547 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2548 double left_vol, right_vol;
2549 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2550 EXPECT_EQ(1, left_vol);
2551 EXPECT_EQ(1, right_vol);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002552 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002553 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002554 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2555 EXPECT_EQ(0, left_vol);
2556 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002557 EXPECT_EQ(0, renderer->channel_id());
2558 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002559 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2560 EXPECT_EQ(1, left_vol);
2561 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002562 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002563}
2564
2565TEST_F(WebRtcSessionTest, SetAudioSend) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002566 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002567 mediastream_signaling_.SendAudioVideoStream1();
2568 CreateAndSetRemoteOfferAndLocalAnswer();
2569 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2570 ASSERT_TRUE(channel != NULL);
2571 ASSERT_EQ(1u, channel->send_streams().size());
2572 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2573 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2574
2575 cricket::AudioOptions options;
2576 options.echo_cancellation.Set(true);
2577
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002578 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002579 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002580 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2581 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002582 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002583 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002584
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002585 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002586 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002587 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2588 bool value;
2589 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
2590 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002591 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002592 EXPECT_TRUE(renderer->sink() == NULL);
2593}
2594
2595TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
2596 Init(NULL);
2597 mediastream_signaling_.SendAudioVideoStream1();
2598 CreateAndSetRemoteOfferAndLocalAnswer();
2599 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2600 ASSERT_TRUE(channel != NULL);
2601 ASSERT_EQ(1u, channel->send_streams().size());
2602 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2603
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002604 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002605 cricket::AudioOptions options;
2606 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
2607 EXPECT_TRUE(renderer->sink() != NULL);
2608
2609 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
2610 // will invalidate the |renderer_| pointer in the sink and prevent getting a
2611 // SetSink(NULL) callback afterwards.
2612 renderer.reset();
2613
2614 // This will trigger SetSink(NULL) if no OnClose() callback.
2615 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002616}
2617
2618TEST_F(WebRtcSessionTest, SetVideoPlayout) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002619 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002620 mediastream_signaling_.SendAudioVideoStream1();
2621 CreateAndSetRemoteOfferAndLocalAnswer();
2622 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2623 ASSERT_TRUE(channel != NULL);
2624 ASSERT_LT(0u, channel->renderers().size());
2625 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2626 ASSERT_EQ(1u, channel->recv_streams().size());
2627 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2628 cricket::FakeVideoRenderer renderer;
2629 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
2630 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
2631 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
2632 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2633}
2634
2635TEST_F(WebRtcSessionTest, SetVideoSend) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002636 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002637 mediastream_signaling_.SendAudioVideoStream1();
2638 CreateAndSetRemoteOfferAndLocalAnswer();
2639 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2640 ASSERT_TRUE(channel != NULL);
2641 ASSERT_EQ(1u, channel->send_streams().size());
2642 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2643 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2644 cricket::VideoOptions* options = NULL;
2645 session_->SetVideoSend(send_ssrc, false, options);
2646 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2647 session_->SetVideoSend(send_ssrc, true, options);
2648 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2649}
2650
2651TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
2652 TestCanInsertDtmf(false);
2653}
2654
2655TEST_F(WebRtcSessionTest, CanInsertDtmf) {
2656 TestCanInsertDtmf(true);
2657}
2658
2659TEST_F(WebRtcSessionTest, InsertDtmf) {
2660 // Setup
wu@webrtc.org91053e72013-08-10 07:18:04 +00002661 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002662 mediastream_signaling_.SendAudioVideoStream1();
2663 CreateAndSetRemoteOfferAndLocalAnswer();
2664 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2665 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
2666
2667 // Insert DTMF
2668 const int expected_flags = DF_SEND;
2669 const int expected_duration = 90;
2670 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
2671 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
2672 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
2673
2674 // Verify
2675 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
2676 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2677 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
2678 expected_duration, expected_flags));
2679 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
2680 expected_duration, expected_flags));
2681 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
2682 expected_duration, expected_flags));
2683}
2684
2685// This test verifies the |initiator| flag when session initiates the call.
2686TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002687 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002688 EXPECT_FALSE(session_->initiator());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002689 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002690 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2691 SetLocalDescriptionWithoutError(offer);
2692 EXPECT_TRUE(session_->initiator());
2693 SetRemoteDescriptionWithoutError(answer);
2694 EXPECT_TRUE(session_->initiator());
2695}
2696
2697// This test verifies the |initiator| flag when session receives the call.
2698TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002699 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002700 EXPECT_FALSE(session_->initiator());
2701 SessionDescriptionInterface* offer = CreateRemoteOffer();
2702 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002703 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002704
2705 EXPECT_FALSE(session_->initiator());
2706 SetLocalDescriptionWithoutError(answer);
2707 EXPECT_FALSE(session_->initiator());
2708}
2709
2710// This test verifies the ice protocol type at initiator of the call
2711// if |a=ice-options:google-ice| is present in answer.
2712TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002713 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002714 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002715 SessionDescriptionInterface* offer = CreateOffer();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002716 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002717 CreateRemoteAnswer(offer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002718 SetLocalDescriptionWithoutError(offer);
2719 std::string sdp;
2720 EXPECT_TRUE(answer->ToString(&sdp));
2721 // Adding ice-options to the session level.
2722 InjectAfter("t=0 0\r\n",
2723 "a=ice-options:google-ice\r\n",
2724 &sdp);
2725 SessionDescriptionInterface* answer_with_gice =
2726 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2727 SetRemoteDescriptionWithoutError(answer_with_gice);
2728 VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE);
2729 VerifyTransportType("video", cricket::ICEPROTO_GOOGLE);
2730}
2731
2732// This test verifies the ice protocol type at initiator of the call
2733// if ICE RFC5245 is supported in answer.
2734TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002735 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002736 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002737 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002738 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2739 SetLocalDescriptionWithoutError(offer);
2740
2741 SetRemoteDescriptionWithoutError(answer);
2742 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2743 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2744}
2745
2746// This test verifies the ice protocol type at receiver side of the call if
2747// receiver decides to use google-ice.
2748TEST_F(WebRtcSessionTest, TestReceiverGIceInOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002749 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002750 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002751 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002752 SetRemoteDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002753 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002754 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002755 std::string sdp;
2756 EXPECT_TRUE(answer->ToString(&sdp));
2757 // Adding ice-options to the session level.
2758 InjectAfter("t=0 0\r\n",
2759 "a=ice-options:google-ice\r\n",
2760 &sdp);
2761 SessionDescriptionInterface* answer_with_gice =
2762 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2763 SetLocalDescriptionWithoutError(answer_with_gice);
2764 VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE);
2765 VerifyTransportType("video", cricket::ICEPROTO_GOOGLE);
2766}
2767
2768// This test verifies the ice protocol type at receiver side of the call if
2769// receiver decides to use ice RFC 5245.
2770TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002771 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002772 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002773 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002774 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002775 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002776 SetLocalDescriptionWithoutError(answer);
2777 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2778 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2779}
2780
2781// This test verifies the session state when ICE RFC5245 in offer and
2782// ICE google-ice in answer.
2783TEST_F(WebRtcSessionTest, TestIceOfferGIceOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002784 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002785 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002786 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2787
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002788 std::string offer_str;
2789 offer->ToString(&offer_str);
2790 // Disable google-ice
2791 const std::string gice_option = "google-ice";
2792 const std::string xgoogle_xice = "xgoogle-xice";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002793 rtc::replace_substrs(gice_option.c_str(), gice_option.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002794 xgoogle_xice.c_str(), xgoogle_xice.length(),
2795 &offer_str);
2796 JsepSessionDescription *ice_only_offer =
2797 new JsepSessionDescription(JsepSessionDescription::kOffer);
2798 EXPECT_TRUE((ice_only_offer)->Initialize(offer_str, NULL));
2799 SetLocalDescriptionWithoutError(ice_only_offer);
2800 std::string original_offer_sdp;
2801 EXPECT_TRUE(offer->ToString(&original_offer_sdp));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002802 SessionDescriptionInterface* pranswer_with_gice =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002803 CreateSessionDescription(JsepSessionDescription::kPrAnswer,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002804 original_offer_sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002805 SetRemoteDescriptionPranswerExpectError(kPushDownTDFailed,
2806 pranswer_with_gice);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002807 SessionDescriptionInterface* answer_with_gice =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002808 CreateSessionDescription(JsepSessionDescription::kAnswer,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002809 original_offer_sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002810 SetRemoteDescriptionAnswerExpectError(kPushDownTDFailed,
2811 answer_with_gice);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002812}
2813
2814// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
2815TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002816 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002817 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002818 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002819 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002820 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002821 CreateRemoteAnswer(session_->local_description()));
2822
2823 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2824 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002825 JsepSessionDescription* modified_answer =
2826 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002827
2828 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2829 answer->session_id(),
2830 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002831 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002832
wu@webrtc.org4e393072014-04-07 17:04:35 +00002833 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002834 std::string sdp;
2835 EXPECT_TRUE(answer->ToString(&sdp));
2836 const std::string kAudioMid = "a=mid:audio";
2837 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002838 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002839 kAudioMidReplaceStr.c_str(),
2840 kAudioMidReplaceStr.length(),
2841 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002842 SessionDescriptionInterface* modified_answer1 =
2843 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002844 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002845
wu@webrtc.org4e393072014-04-07 17:04:35 +00002846 // Different media types.
2847 EXPECT_TRUE(answer->ToString(&sdp));
2848 const std::string kAudioMline = "m=audio";
2849 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002850 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00002851 kAudioMlineReplaceStr.c_str(),
2852 kAudioMlineReplaceStr.length(),
2853 &sdp);
2854 SessionDescriptionInterface* modified_answer2 =
2855 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2856 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
2857
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002858 SetRemoteDescriptionWithoutError(answer.release());
2859}
2860
2861// Verifying remote offer and local answer have matching m-lines as per
2862// RFC 3264.
2863TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002864 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002865 mediastream_signaling_.SendAudioVideoStream1();
2866 SessionDescriptionInterface* offer = CreateRemoteOffer();
2867 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002868 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002869
2870 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2871 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002872 JsepSessionDescription* modified_answer =
2873 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002874
2875 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2876 answer->session_id(),
2877 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002878 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002879 SetLocalDescriptionWithoutError(answer);
2880}
2881
2882// This test verifies that WebRtcSession does not start candidate allocation
2883// before SetLocalDescription is called.
2884TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002885 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002886 mediastream_signaling_.SendAudioVideoStream1();
2887 SessionDescriptionInterface* offer = CreateRemoteOffer();
2888 cricket::Candidate candidate;
2889 candidate.set_component(1);
2890 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2891 candidate);
2892 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2893 cricket::Candidate candidate1;
2894 candidate1.set_component(1);
2895 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2896 candidate1);
2897 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2898 SetRemoteDescriptionWithoutError(offer);
2899 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
2900 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
2901
2902 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002903 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002904 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
2905 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
2906
wu@webrtc.org91053e72013-08-10 07:18:04 +00002907 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002908 SetLocalDescriptionWithoutError(answer);
2909 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
2910 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
2911 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2912}
2913
2914// This test verifies that crypto parameter is updated in local session
2915// description as per security policy set in MediaSessionDescriptionFactory.
2916TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002917 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002918 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002919 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002920
2921 // Making sure SetLocalDescription correctly sets crypto value in
2922 // SessionDescription object after de-serialization of sdp string. The value
2923 // will be set as per MediaSessionDescriptionFactory.
2924 std::string offer_str;
2925 offer->ToString(&offer_str);
2926 SessionDescriptionInterface* jsep_offer_str =
2927 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
2928 SetLocalDescriptionWithoutError(jsep_offer_str);
2929 EXPECT_TRUE(session_->voice_channel()->secure_required());
2930 EXPECT_TRUE(session_->video_channel()->secure_required());
2931}
2932
2933// This test verifies the crypto parameter when security is disabled.
2934TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002935 options_.disable_encryption = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00002936 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002937 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002938 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002939
2940 // Making sure SetLocalDescription correctly sets crypto value in
2941 // SessionDescription object after de-serialization of sdp string. The value
2942 // will be set as per MediaSessionDescriptionFactory.
2943 std::string offer_str;
2944 offer->ToString(&offer_str);
2945 SessionDescriptionInterface *jsep_offer_str =
2946 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
2947 SetLocalDescriptionWithoutError(jsep_offer_str);
2948 EXPECT_FALSE(session_->voice_channel()->secure_required());
2949 EXPECT_FALSE(session_->video_channel()->secure_required());
2950}
2951
2952// This test verifies that an answer contains new ufrag and password if an offer
2953// with new ufrag and password is received.
2954TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002955 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002956 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002957 options.has_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002958 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002959 CreateRemoteOffer(options));
2960 SetRemoteDescriptionWithoutError(offer.release());
2961
2962 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002963 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002964 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002965 SetLocalDescriptionWithoutError(answer.release());
2966
2967 // Receive an offer with new ufrag and password.
2968 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002969 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002970 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002971 SetRemoteDescriptionWithoutError(updated_offer1.release());
2972
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002973 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002974 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002975
2976 CompareIceUfragAndPassword(updated_answer1->description(),
2977 session_->local_description()->description(),
2978 false);
2979
2980 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002981}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002982
wu@webrtc.org91053e72013-08-10 07:18:04 +00002983// This test verifies that an answer contains old ufrag and password if an offer
2984// with old ufrag and password is received.
2985TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
2986 Init(NULL);
2987 cricket::MediaSessionOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00002988 options.has_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002989 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002990 CreateRemoteOffer(options));
2991 SetRemoteDescriptionWithoutError(offer.release());
2992
2993 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002994 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002995 CreateAnswer(NULL));
2996 SetLocalDescriptionWithoutError(answer.release());
2997
2998 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002999 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003000 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003001 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003002 SetRemoteDescriptionWithoutError(updated_offer2.release());
3003
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003004 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003005 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003006
3007 CompareIceUfragAndPassword(updated_answer2->description(),
3008 session_->local_description()->description(),
3009 true);
3010
3011 SetLocalDescriptionWithoutError(updated_answer2.release());
3012}
3013
3014TEST_F(WebRtcSessionTest, TestSessionContentError) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00003015 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003016 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003017 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003018 const std::string session_id_orig = offer->session_id();
3019 const std::string session_version_orig = offer->session_version();
3020 SetLocalDescriptionWithoutError(offer);
3021
3022 video_channel_ = media_engine_->GetVideoChannel(0);
3023 video_channel_->set_fail_set_send_codecs(true);
3024
3025 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003026 SessionDescriptionInterface* answer =
3027 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003028 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003029}
3030
3031// Runs the loopback call test with BUNDLE and STUN disabled.
3032TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3033 // Lets try with only UDP ports.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00003034 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003035 cricket::PORTALLOCATOR_DISABLE_TCP |
3036 cricket::PORTALLOCATOR_DISABLE_STUN |
3037 cricket::PORTALLOCATOR_DISABLE_RELAY);
3038 TestLoopbackCall();
3039}
3040
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003041// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003042TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00003043 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003044 cricket::PORTALLOCATOR_ENABLE_BUNDLE |
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003045 cricket::PORTALLOCATOR_DISABLE_TCP |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003046 cricket::PORTALLOCATOR_DISABLE_RELAY);
3047 TestLoopbackCall();
3048}
3049
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003050TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00003051 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003052 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003053 options.has_video = true;
3054
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003055 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
3056 std::string error_code_str = "ERROR_CONTENT";
3057 std::string error_desc = "Fake session error description.";
3058 session_->SetError(error_code, error_desc);
3059
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003060 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
3061 SessionDescriptionInterface* answer =
3062 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003063
3064 std::string action;
3065 std::ostringstream session_error_msg;
3066 session_error_msg << kSessionError << error_code_str << ". ";
3067 session_error_msg << kSessionErrorDesc << error_desc << ".";
3068 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
3069 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003070}
3071
3072TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3073 constraints_.reset(new FakeConstraints());
3074 constraints_->AddOptional(
3075 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003076 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003077
3078 SetLocalDescriptionWithDataChannel();
3079 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3080}
3081
3082TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003083 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003084
3085 constraints_.reset(new FakeConstraints());
3086 constraints_->AddOptional(
3087 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003088 options_.disable_sctp_data_channels = false;
3089
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003090 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003091
3092 SetLocalDescriptionWithDataChannel();
3093 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3094}
3095
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003096TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003097 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003098
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003099 InitWithDtls();
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003100
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003101 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003102 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003103 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3104}
3105
3106TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003107 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003108 SetFactoryDtlsSrtp();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003109 InitWithDtls();
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003110
3111 // Create remote offer with SCTP.
3112 cricket::MediaSessionOptions options;
3113 options.data_channel_type = cricket::DCT_SCTP;
3114 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003115 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003116 SetRemoteDescriptionWithoutError(offer);
3117
3118 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003119 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003120 EXPECT_TRUE(answer != NULL);
3121 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3122 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003123}
3124
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003125TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
3126 constraints_.reset(new FakeConstraints());
3127 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003128 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003129 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003130
3131 SetLocalDescriptionWithDataChannel();
3132 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3133}
3134
3135TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003136 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003137
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003138 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003139
3140 SetLocalDescriptionWithDataChannel();
3141 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3142}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003143
wu@webrtc.org97077a32013-10-25 21:18:33 +00003144TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003145 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003146 options_.disable_sctp_data_channels = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003147 InitWithDtls();
wu@webrtc.org97077a32013-10-25 21:18:33 +00003148
3149 SetLocalDescriptionWithDataChannel();
3150 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3151}
3152
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003153TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003154 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003155 const int new_send_port = 9998;
3156 const int new_recv_port = 7775;
3157
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003158 InitWithDtls();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003159 SetFactoryDtlsSrtp();
3160
3161 // By default, don't actually add the codecs to desc_factory_; they don't
3162 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3163 // let the session description get parsed. That'll get the proper codecs
3164 // into the stream.
3165 cricket::MediaSessionOptions options;
3166 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3167 "stream1", new_send_port, options);
3168
3169 // SetRemoteDescription will take the ownership of the offer.
3170 SetRemoteDescriptionWithoutError(offer);
3171
3172 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3173 new_recv_port, CreateAnswer(NULL));
3174 ASSERT_TRUE(answer != NULL);
3175
3176 // Now set the local description, which'll take ownership of the answer.
3177 SetLocalDescriptionWithoutError(answer);
3178
3179 // TEST PLAN: Set the port number to something new, set it in the SDP,
3180 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003181 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003182 dci.reliable = true;
3183 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003184 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003185 session_->CreateDataChannel("datachannel", &dci);
3186
3187 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3188 int portnum = -1;
3189 ASSERT_TRUE(ch != NULL);
3190 ASSERT_EQ(1UL, ch->send_codecs().size());
3191 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
3192 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3193 ch->send_codecs()[0].name.c_str()));
3194 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3195 &portnum));
3196 EXPECT_EQ(new_send_port, portnum);
3197
3198 ASSERT_EQ(1UL, ch->recv_codecs().size());
3199 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
3200 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3201 ch->recv_codecs()[0].name.c_str()));
3202 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3203 &portnum));
3204 EXPECT_EQ(new_recv_port, portnum);
3205}
3206
wu@webrtc.org91053e72013-08-10 07:18:04 +00003207// Verifies that CreateOffer succeeds when CreateOffer is called before async
3208// identity generation is finished.
3209TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003210 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003211 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003212
3213 EXPECT_TRUE(session_->waiting_for_identity());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003214 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003215 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3216
wu@webrtc.org91053e72013-08-10 07:18:04 +00003217 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003218 VerifyNoCryptoParams(offer->description(), true);
3219 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003220}
3221
3222// Verifies that CreateAnswer succeeds when CreateOffer is called before async
3223// identity generation is finished.
3224TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003225 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003226 InitWithDtls();
3227 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003228
3229 cricket::MediaSessionOptions options;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003230 options.has_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003231 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003232 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003233 ASSERT_TRUE(offer.get() != NULL);
3234 SetRemoteDescriptionWithoutError(offer.release());
3235
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003236 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003237 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003238 VerifyNoCryptoParams(answer->description(), true);
3239 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003240}
3241
3242// Verifies that CreateOffer succeeds when CreateOffer is called after async
3243// identity generation is finished.
3244TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003245 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003246 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003247
3248 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003249
3250 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003251 EXPECT_TRUE(offer != NULL);
3252}
3253
3254// Verifies that CreateOffer fails when CreateOffer is called after async
3255// identity generation fails.
3256TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003257 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00003258 InitWithDtls(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003259
3260 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003261
3262 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003263 EXPECT_TRUE(offer == NULL);
3264}
3265
3266// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3267// before async identity generation is finished.
3268TEST_F(WebRtcSessionTest,
3269 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003270 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003271 VerifyMultipleAsyncCreateDescription(
3272 true, CreateSessionDescriptionRequest::kOffer);
3273}
3274
3275// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3276// before async identity generation fails.
3277TEST_F(WebRtcSessionTest,
3278 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003279 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003280 VerifyMultipleAsyncCreateDescription(
3281 false, CreateSessionDescriptionRequest::kOffer);
3282}
3283
3284// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3285// before async identity generation is finished.
3286TEST_F(WebRtcSessionTest,
3287 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003288 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003289 VerifyMultipleAsyncCreateDescription(
3290 true, CreateSessionDescriptionRequest::kAnswer);
3291}
3292
3293// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3294// before async identity generation fails.
3295TEST_F(WebRtcSessionTest,
3296 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003297 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003298 VerifyMultipleAsyncCreateDescription(
3299 false, CreateSessionDescriptionRequest::kAnswer);
3300}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003301
3302// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3303// offer has no SDES crypto but only DTLS fingerprint.
3304TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3305 // Init without DTLS.
3306 Init(NULL);
3307 // Create a remote offer with secured transport disabled.
3308 cricket::MediaSessionOptions options;
3309 JsepSessionDescription* offer(CreateRemoteOffer(
3310 options, cricket::SEC_DISABLED));
3311 // Adds a DTLS fingerprint to the remote offer.
3312 cricket::SessionDescription* sdp = offer->description();
3313 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3314 ASSERT_TRUE(audio != NULL);
3315 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3316 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003317 rtc::SSLFingerprint::CreateFromRfc4572(
3318 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003319 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003320 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003321}
3322
wu@webrtc.orgde305012013-10-31 15:40:38 +00003323// This test verifies DSCP is properly applied on the media channels.
3324TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3325 constraints_.reset(new FakeConstraints());
3326 constraints_->AddOptional(
3327 webrtc::MediaConstraintsInterface::kEnableDscp, true);
3328 Init(NULL);
3329 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003330 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003331
3332 SetLocalDescriptionWithoutError(offer);
3333
3334 video_channel_ = media_engine_->GetVideoChannel(0);
3335 voice_channel_ = media_engine_->GetVoiceChannel(0);
3336
3337 ASSERT_TRUE(video_channel_ != NULL);
3338 ASSERT_TRUE(voice_channel_ != NULL);
3339 cricket::AudioOptions audio_options;
3340 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3341 cricket::VideoOptions video_options;
3342 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3343 EXPECT_TRUE(audio_options.dscp.IsSet());
3344 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3345 EXPECT_TRUE(video_options.dscp.IsSet());
3346 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3347}
3348
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003349TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3350 constraints_.reset(new FakeConstraints());
3351 constraints_->AddOptional(
3352 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3353 true);
3354 Init(NULL);
3355 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003356 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003357
3358 SetLocalDescriptionWithoutError(offer);
3359
3360 video_channel_ = media_engine_->GetVideoChannel(0);
3361
3362 ASSERT_TRUE(video_channel_ != NULL);
3363 cricket::VideoOptions video_options;
3364 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3365 EXPECT_TRUE(
3366 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3367}
3368
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00003369TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
3370 // Number of unsignalled receiving streams should be between 0 and
3371 // kMaxUnsignalledRecvStreams.
3372 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
3373 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
3374 kMaxUnsignalledRecvStreams);
3375 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
3376}
3377
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003378TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
3379 constraints_.reset(new FakeConstraints());
3380 constraints_->AddOptional(
3381 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
3382 true);
3383 Init(NULL);
3384 mediastream_signaling_.SendAudioVideoStream1();
3385 SessionDescriptionInterface* offer = CreateOffer();
3386
3387 SetLocalDescriptionWithoutError(offer);
3388
3389 voice_channel_ = media_engine_->GetVoiceChannel(0);
3390
3391 ASSERT_TRUE(voice_channel_ != NULL);
3392 cricket::AudioOptions audio_options;
3393 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3394 EXPECT_TRUE(
3395 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
3396}
3397
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003398// Tests that we can renegotiate new media content with ICE candidates in the
3399// new remote SDP.
3400TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003401 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003402 InitWithDtls();
3403 SetFactoryDtlsSrtp();
3404
3405 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003406 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003407 SetLocalDescriptionWithoutError(offer);
3408
3409 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3410 SetRemoteDescriptionWithoutError(answer);
3411
3412 cricket::MediaSessionOptions options;
3413 options.has_video = true;
3414 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3415
3416 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003417 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003418 candidate1.set_component(1);
3419 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3420 candidate1);
3421 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3422 SetRemoteDescriptionWithoutError(offer);
3423
3424 answer = CreateAnswer(NULL);
3425 SetLocalDescriptionWithoutError(answer);
3426}
3427
3428// Tests that we can renegotiate new media content with ICE candidates separated
3429// from the remote SDP.
3430TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003431 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003432 InitWithDtls();
3433 SetFactoryDtlsSrtp();
3434
3435 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003436 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003437 SetLocalDescriptionWithoutError(offer);
3438
3439 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3440 SetRemoteDescriptionWithoutError(answer);
3441
3442 cricket::MediaSessionOptions options;
3443 options.has_video = true;
3444 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3445 SetRemoteDescriptionWithoutError(offer);
3446
3447 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003448 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003449 candidate1.set_component(1);
3450 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3451 candidate1);
3452 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3453
3454 answer = CreateAnswer(NULL);
3455 SetLocalDescriptionWithoutError(answer);
3456}
3457
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003458// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
3459// currently fails because upon disconnection and reconnection OnIceComplete is
3460// called more than once without returning to IceGatheringGathering.