blob: 2cf422b88c92ca957b48861765ad769fec08d727 [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.org7256d312014-09-07 04:08:44 +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)),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000312 stun_server_(Thread::Current(), stun_socket_addr_),
313 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000314 mediastream_signaling_(channel_manager_.get()),
315 ice_type_(PeerConnectionInterface::kAll) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000316 tdesc_factory_->set_protocol(cricket::ICEPROTO_HYBRID);
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000317
318 cricket::ServerAddresses stun_servers;
319 stun_servers.insert(stun_socket_addr_);
320 allocator_.reset(new cricket::BasicPortAllocator(
321 &network_manager_,
322 stun_servers,
323 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000324 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325 cricket::PORTALLOCATOR_DISABLE_RELAY |
326 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
327 EXPECT_TRUE(channel_manager_->Init());
328 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000329 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000330 }
331
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000332 static void SetUpTestCase() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000333 rtc::InitializeSSL();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000334 }
335
336 static void TearDownTestCase() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000337 rtc::CleanupSSL();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000338 }
339
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000340 void AddInterface(const SocketAddress& addr) {
341 network_manager_.AddInterface(addr);
342 }
343
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000344 void SetIceTransportType(PeerConnectionInterface::IceTransportsType type) {
345 ice_type_ = type;
346 }
347
wu@webrtc.org91053e72013-08-10 07:18:04 +0000348 void Init(DTLSIdentityServiceInterface* identity_service) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349 ASSERT_TRUE(session_.get() == NULL);
350 session_.reset(new WebRtcSessionForTest(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000351 channel_manager_.get(), rtc::Thread::Current(),
352 rtc::Thread::Current(), allocator_.get(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000353 &observer_,
354 &mediastream_signaling_));
355
356 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
357 observer_.ice_connection_state_);
358 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
359 observer_.ice_gathering_state_);
360
wu@webrtc.org97077a32013-10-25 21:18:33 +0000361 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000362 identity_service, ice_type_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000363 }
364
365 void InitWithDtmfCodec() {
366 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000367 const cricket::AudioCodec kTelephoneEventCodec(
368 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369 std::vector<cricket::AudioCodec> codecs;
370 codecs.push_back(kTelephoneEventCodec);
371 media_engine_->SetAudioCodecs(codecs);
372 desc_factory_->set_audio_codecs(codecs);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000373 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000374 }
375
henrike@webrtc.org7666db72013-08-22 14:45:42 +0000376 void InitWithDtls(bool identity_request_should_fail = false) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000377 FakeIdentityService* identity_service = new FakeIdentityService();
378 identity_service->set_should_fail(identity_request_should_fail);
379 Init(identity_service);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000380 }
381
382 // Creates a local offer and applies it. Starts ice.
383 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
384 // to decide which streams to create.
385 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000386 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000387 SetLocalDescriptionWithoutError(offer);
388 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
389 observer_.ice_gathering_state_,
390 kIceCandidatesTimeout);
391 }
392
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000393 SessionDescriptionInterface* CreateOffer() {
394 PeerConnectionInterface::RTCOfferAnswerOptions options;
395 options.offer_to_receive_audio =
396 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
397
398 return CreateOffer(options);
399 }
400
wu@webrtc.org91053e72013-08-10 07:18:04 +0000401 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000402 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000403 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000404 observer = new WebRtcSessionCreateSDPObserverForTest();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000405 session_->CreateOffer(observer, options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000406 EXPECT_TRUE_WAIT(
407 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000408 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000409 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000410 }
411
412 SessionDescriptionInterface* CreateAnswer(
413 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000414 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000415 = new WebRtcSessionCreateSDPObserverForTest();
416 session_->CreateAnswer(observer, constraints);
417 EXPECT_TRUE_WAIT(
418 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000419 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000420 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000421 }
422
wu@webrtc.org364f2042013-11-20 21:49:41 +0000423 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000424 return (session_->voice_channel() != NULL &&
425 session_->video_channel() != NULL);
426 }
427
wu@webrtc.org364f2042013-11-20 21:49:41 +0000428 void CheckTransportChannels() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000429 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 1) != NULL);
430 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 2) != NULL);
431 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 1) != NULL);
432 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 2) != NULL);
433 }
434
435 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
436 ASSERT_TRUE(session_.get() != NULL);
437 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
438 ASSERT_TRUE(content != NULL);
439 const cricket::AudioContentDescription* audio_content =
440 static_cast<const cricket::AudioContentDescription*>(
441 content->description);
442 ASSERT_TRUE(audio_content != NULL);
443 ASSERT_EQ(1U, audio_content->cryptos().size());
444 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
445 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
446 audio_content->cryptos()[0].cipher_suite);
447 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
448 audio_content->protocol());
449
450 content = cricket::GetFirstVideoContent(sdp);
451 ASSERT_TRUE(content != NULL);
452 const cricket::VideoContentDescription* video_content =
453 static_cast<const cricket::VideoContentDescription*>(
454 content->description);
455 ASSERT_TRUE(video_content != NULL);
456 ASSERT_EQ(1U, video_content->cryptos().size());
457 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
458 video_content->cryptos()[0].cipher_suite);
459 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
460 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
461 video_content->protocol());
462 }
463
464 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
465 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
466 ASSERT_TRUE(content != NULL);
467 const cricket::AudioContentDescription* audio_content =
468 static_cast<const cricket::AudioContentDescription*>(
469 content->description);
470 ASSERT_TRUE(audio_content != NULL);
471 ASSERT_EQ(0U, audio_content->cryptos().size());
472
473 content = cricket::GetFirstVideoContent(sdp);
474 ASSERT_TRUE(content != NULL);
475 const cricket::VideoContentDescription* video_content =
476 static_cast<const cricket::VideoContentDescription*>(
477 content->description);
478 ASSERT_TRUE(video_content != NULL);
479 ASSERT_EQ(0U, video_content->cryptos().size());
480
481 if (dtls) {
482 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
483 audio_content->protocol());
484 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
485 video_content->protocol());
486 } else {
487 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
488 audio_content->protocol());
489 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
490 video_content->protocol());
491 }
492 }
493
494 // Set the internal fake description factories to do DTLS-SRTP.
495 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000496 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000497 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000498 rtc::ToString(rtc::CreateRandomId());
499 identity_.reset(rtc::SSLIdentity::Generate(identity_name));
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000500 tdesc_factory_->set_identity(identity_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000501 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
502 }
503
504 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
505 bool expected) {
506 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
507 ASSERT_TRUE(audio != NULL);
508 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000509 const TransportInfo* video = sdp->GetTransportInfoByName("video");
510 ASSERT_TRUE(video != NULL);
511 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000512 }
513
514 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +0000515 // Create a SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000516 cricket::MediaSessionOptions options;
517 options.has_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000518 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000519 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000520 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000521 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000522 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
523 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000524 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000525 // Answer should be NULL as no crypto params in offer.
526 ASSERT_TRUE(answer == NULL);
527 }
528
529 void VerifyAnswerFromCryptoOffer() {
530 cricket::MediaSessionOptions options;
531 options.has_video = true;
532 options.bundle_enabled = true;
533 scoped_ptr<JsepSessionDescription> offer(
534 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
535 ASSERT_TRUE(offer.get() != NULL);
536 VerifyCryptoParams(offer->description());
537 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000538 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000539 ASSERT_TRUE(answer.get() != NULL);
540 VerifyCryptoParams(answer->description());
541 }
542
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000543 void SetAndVerifyNumUnsignalledRecvStreams(
544 int value_set, int value_expected) {
545 constraints_.reset(new FakeConstraints());
546 constraints_->AddOptional(
547 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
548 value_set);
549 session_.reset();
550 Init(NULL);
551 mediastream_signaling_.SendAudioVideoStream1();
552 SessionDescriptionInterface* offer = CreateOffer();
553
554 SetLocalDescriptionWithoutError(offer);
555
556 video_channel_ = media_engine_->GetVideoChannel(0);
557
558 ASSERT_TRUE(video_channel_ != NULL);
559 cricket::VideoOptions video_options;
560 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
561 EXPECT_EQ(value_expected,
562 video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1));
563 }
564
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000565 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
566 const cricket::SessionDescription* desc2,
567 bool expect_equal) {
568 if (desc1->contents().size() != desc2->contents().size()) {
569 EXPECT_FALSE(expect_equal);
570 return;
571 }
572
573 const cricket::ContentInfos& contents = desc1->contents();
574 cricket::ContentInfos::const_iterator it = contents.begin();
575
576 for (; it != contents.end(); ++it) {
577 const cricket::TransportDescription* transport_desc1 =
578 desc1->GetTransportDescriptionByName(it->name);
579 const cricket::TransportDescription* transport_desc2 =
580 desc2->GetTransportDescriptionByName(it->name);
581 if (!transport_desc1 || !transport_desc2) {
582 EXPECT_FALSE(expect_equal);
583 return;
584 }
585 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
586 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
587 EXPECT_FALSE(expect_equal);
588 return;
589 }
590 }
591 EXPECT_TRUE(expect_equal);
592 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000593
594 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
595 std::string *sdp) {
596 const cricket::SessionDescription* desc = current_desc->description();
597 EXPECT_TRUE(current_desc->ToString(sdp));
598
599 const cricket::ContentInfos& contents = desc->contents();
600 cricket::ContentInfos::const_iterator it = contents.begin();
601 // Replace ufrag and pwd lines with empty strings.
602 for (; it != contents.end(); ++it) {
603 const cricket::TransportDescription* transport_desc =
604 desc->GetTransportDescriptionByName(it->name);
605 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
606 + "\r\n";
607 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
608 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000609 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000610 "", 0,
611 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000612 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000613 "", 0,
614 sdp);
615 }
616 }
617
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000618 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
619 const std::string& modified_ice_ufrag,
620 const std::string& modified_ice_pwd,
621 std::string* sdp) {
622 const cricket::SessionDescription* desc = current_desc->description();
623 EXPECT_TRUE(current_desc->ToString(sdp));
624
625 const cricket::ContentInfos& contents = desc->contents();
626 cricket::ContentInfos::const_iterator it = contents.begin();
627 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
628 // |modified_ice_pwd| strings.
629 for (; it != contents.end(); ++it) {
630 const cricket::TransportDescription* transport_desc =
631 desc->GetTransportDescriptionByName(it->name);
632 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
633 + "\r\n";
634 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
635 + "\r\n";
636 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
637 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000638 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000639 mod_ufrag.c_str(), mod_ufrag.length(),
640 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000641 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000642 mod_pwd.c_str(), mod_pwd.length(),
643 sdp);
644 }
645 }
646
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000647 // Creates a remote offer and and applies it as a remote description,
648 // creates a local answer and applies is as a local description.
649 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
650 // to decide which local and remote streams to create.
651 void CreateAndSetRemoteOfferAndLocalAnswer() {
652 SessionDescriptionInterface* offer = CreateRemoteOffer();
653 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000654 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000655 SetLocalDescriptionWithoutError(answer);
656 }
657 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
658 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
659 }
660 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
661 BaseSession::State expected_state) {
662 SetLocalDescriptionWithoutError(desc);
663 EXPECT_EQ(expected_state, session_->state());
664 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000665 void SetLocalDescriptionExpectError(const std::string& action,
666 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000667 SessionDescriptionInterface* desc) {
668 std::string error;
669 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000670 std::string sdp_type = "local ";
671 sdp_type.append(action);
672 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000673 EXPECT_NE(std::string::npos, error.find(expected_error));
674 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000675 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
676 SessionDescriptionInterface* desc) {
677 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
678 expected_error, desc);
679 }
680 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
681 SessionDescriptionInterface* desc) {
682 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
683 expected_error, desc);
684 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000685 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
686 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
687 }
688 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
689 BaseSession::State expected_state) {
690 SetRemoteDescriptionWithoutError(desc);
691 EXPECT_EQ(expected_state, session_->state());
692 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000693 void SetRemoteDescriptionExpectError(const std::string& action,
694 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000695 SessionDescriptionInterface* desc) {
696 std::string error;
697 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000698 std::string sdp_type = "remote ";
699 sdp_type.append(action);
700 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000701 EXPECT_NE(std::string::npos, error.find(expected_error));
702 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000703 void SetRemoteDescriptionOfferExpectError(
704 const std::string& expected_error, SessionDescriptionInterface* desc) {
705 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
706 expected_error, desc);
707 }
708 void SetRemoteDescriptionPranswerExpectError(
709 const std::string& expected_error, SessionDescriptionInterface* desc) {
710 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
711 expected_error, desc);
712 }
713 void SetRemoteDescriptionAnswerExpectError(
714 const std::string& expected_error, SessionDescriptionInterface* desc) {
715 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
716 expected_error, desc);
717 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000718
719 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
720 SessionDescriptionInterface** nocrypto_answer) {
721 // Create a SDP without Crypto.
722 cricket::MediaSessionOptions options;
723 options.has_video = true;
724 options.bundle_enabled = true;
725 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
726 ASSERT_TRUE(*offer != NULL);
727 VerifyCryptoParams((*offer)->description());
728
729 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
730 cricket::SEC_DISABLED);
731 EXPECT_TRUE(*nocrypto_answer != NULL);
732 }
733
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000734 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
735 SessionDescriptionInterface** nodtls_answer) {
736 cricket::MediaSessionOptions options;
737 options.has_video = true;
738 options.bundle_enabled = true;
739
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000740 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000741 CreateRemoteOffer(options, cricket::SEC_ENABLED));
742
743 *nodtls_answer =
744 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
745 EXPECT_TRUE(*nodtls_answer != NULL);
746 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
747 VerifyCryptoParams((*nodtls_answer)->description());
748
749 SetFactoryDtlsSrtp();
750 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
751 ASSERT_TRUE(*offer != NULL);
752 VerifyFingerprintStatus((*offer)->description(), true);
753 VerifyCryptoParams((*offer)->description());
754 }
755
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000756 JsepSessionDescription* CreateRemoteOfferWithVersion(
757 cricket::MediaSessionOptions options,
758 cricket::SecurePolicy secure_policy,
759 const std::string& session_version,
760 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000761 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762 const cricket::SessionDescription* cricket_desc = NULL;
763 if (current_desc) {
764 cricket_desc = current_desc->description();
765 session_id = current_desc->session_id();
766 }
767
768 desc_factory_->set_secure(secure_policy);
769 JsepSessionDescription* offer(
770 new JsepSessionDescription(JsepSessionDescription::kOffer));
771 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
772 session_id, session_version)) {
773 delete offer;
774 offer = NULL;
775 }
776 return offer;
777 }
778 JsepSessionDescription* CreateRemoteOffer(
779 cricket::MediaSessionOptions options) {
780 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
781 kSessionVersion, NULL);
782 }
783 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000784 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
785 return CreateRemoteOfferWithVersion(
786 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000787 }
788 JsepSessionDescription* CreateRemoteOffer(
789 cricket::MediaSessionOptions options,
790 const SessionDescriptionInterface* current_desc) {
791 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
792 kSessionVersion, current_desc);
793 }
794
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000795 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
796 const char* sctp_stream_name, int new_port,
797 cricket::MediaSessionOptions options) {
798 options.data_channel_type = cricket::DCT_SCTP;
799 options.AddStream(cricket::MEDIA_TYPE_DATA, "datachannel",
800 sctp_stream_name);
801 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
802 }
803
804 // Takes ownership of offer_basis (and deletes it).
805 JsepSessionDescription* ChangeSDPSctpPort(
806 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
807 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
808 // SessionDescription from the mutated string.
809 const char* default_port_str = "5000";
810 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000811 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000812 std::string offer_str;
813 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000814 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000815 new_port_str, strlen(new_port_str),
816 &offer_str);
817 JsepSessionDescription* offer = new JsepSessionDescription(
818 offer_basis->type());
819 delete offer_basis;
820 offer->Initialize(offer_str, NULL);
821 return offer;
822 }
823
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000824 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
825 // before this function to decide which streams to create.
826 JsepSessionDescription* CreateRemoteOffer() {
827 cricket::MediaSessionOptions options;
828 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
829 return CreateRemoteOffer(options, session_->remote_description());
830 }
831
832 JsepSessionDescription* CreateRemoteAnswer(
833 const SessionDescriptionInterface* offer,
834 cricket::MediaSessionOptions options,
835 cricket::SecurePolicy policy) {
836 desc_factory_->set_secure(policy);
837 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000838 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839 JsepSessionDescription* answer(
840 new JsepSessionDescription(JsepSessionDescription::kAnswer));
841 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
842 options, NULL),
843 session_id, kSessionVersion)) {
844 delete answer;
845 answer = NULL;
846 }
847 return answer;
848 }
849
850 JsepSessionDescription* CreateRemoteAnswer(
851 const SessionDescriptionInterface* offer,
852 cricket::MediaSessionOptions options) {
853 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
854 }
855
856 // Creates an answer session description with streams based on
857 // |mediastream_signaling_|. Call
858 // mediastream_signaling_.UseOptionsWithStreamX() before this function
859 // to decide which streams to create.
860 JsepSessionDescription* CreateRemoteAnswer(
861 const SessionDescriptionInterface* offer) {
862 cricket::MediaSessionOptions options;
863 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
864 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
865 }
866
867 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000868 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +0000869 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000870 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000871
872 PeerConnectionInterface::RTCOfferAnswerOptions options;
873 options.use_rtp_mux = bundle;
874
875 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000876 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
877 // and answer.
878 SetLocalDescriptionWithoutError(offer);
879
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000880 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000881 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882 std::string sdp;
883 EXPECT_TRUE(answer->ToString(&sdp));
884
885 size_t expected_candidate_num = 2;
886 if (!rtcp_mux) {
887 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
888 // for rtp and rtcp.
889 expected_candidate_num = 4;
890 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000891 const std::string kRtcpMux = "a=rtcp-mux";
892 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000893 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000894 kXRtcpMux.c_str(), kXRtcpMux.length(),
895 &sdp);
896 }
897
898 SessionDescriptionInterface* new_answer = CreateSessionDescription(
899 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000900
901 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000902 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
904 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
905 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
906 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
907 cricket::Candidate c0 = observer_.mline_0_candidates_[i];
908 cricket::Candidate c1 = observer_.mline_1_candidates_[i];
909 if (bundle) {
910 EXPECT_TRUE(c0.IsEquivalent(c1));
911 } else {
912 EXPECT_FALSE(c0.IsEquivalent(c1));
913 }
914 }
915 }
916 // Tests that we can only send DTMF when the dtmf codec is supported.
917 void TestCanInsertDtmf(bool can) {
918 if (can) {
919 InitWithDtmfCodec();
920 } else {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000921 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000922 }
923 mediastream_signaling_.SendAudioVideoStream1();
924 CreateAndSetRemoteOfferAndLocalAnswer();
925 EXPECT_FALSE(session_->CanInsertDtmf(""));
926 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
927 }
928
929 // The method sets up a call from the session to itself, in a loopback
930 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000931 // disconnection, and then a permanent disconnection.
932 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 // by multiple tests with different allocators (e.g. with and without BUNDLE).
934 // While running the call, this method also checks if the session goes through
935 // the correct sequence of ICE states when a connection is established,
936 // broken, and re-established.
937 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000938 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
939 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000940 // The Gathering state should go: New -> Gathering -> Completed.
941 void TestLoopbackCall() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000942 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +0000943 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000945 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000946
947 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
948 observer_.ice_gathering_state_);
949 SetLocalDescriptionWithoutError(offer);
950 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
951 observer_.ice_connection_state_);
952 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
953 observer_.ice_gathering_state_,
954 kIceCandidatesTimeout);
955 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
956 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
957 observer_.ice_gathering_state_,
958 kIceCandidatesTimeout);
959
960 std::string sdp;
961 offer->ToString(&sdp);
962 SessionDescriptionInterface* desc =
963 webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer, sdp);
964 ASSERT_TRUE(desc != NULL);
965 SetRemoteDescriptionWithoutError(desc);
966
967 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
968 observer_.ice_connection_state_,
969 kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +0000970
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000971 // The ice connection state is "Connected" too briefly to catch in a test.
972 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000973 observer_.ice_connection_state_,
974 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975
976 // Adding firewall rule to block ping requests, which should cause
977 // transport channel failure.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000978 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000979 rtc::FP_ANY,
980 rtc::FD_ANY,
981 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000982 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
983 observer_.ice_connection_state_,
984 kIceCandidatesTimeout);
985
986 // Clearing the rules, session should move back to completed state.
987 fss_->ClearRules();
988 // Session is automatically calling OnSignalingReady after creation of
989 // new portallocator session which will allocate new set of candidates.
990
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000991 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000992 observer_.ice_connection_state_,
993 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000994
995 // Now we block ping requests and wait until the ICE connection transitions
996 // to the Failed state. This will take at least 30 seconds because it must
997 // wait for the Port to timeout.
998 int port_timeout = 30000;
999 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001000 rtc::FP_ANY,
1001 rtc::FD_ANY,
1002 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001003 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionFailed,
1004 observer_.ice_connection_state_,
1005 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001006 }
1007
1008 void VerifyTransportType(const std::string& content_name,
1009 cricket::TransportProtocol protocol) {
1010 const cricket::Transport* transport = session_->GetTransport(content_name);
1011 ASSERT_TRUE(transport != NULL);
1012 EXPECT_EQ(protocol, transport->protocol());
1013 }
1014
1015 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1016 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001017 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1018 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1019
1020 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001021 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1022 codecs.push_back(kCNCodec1);
1023 codecs.push_back(kCNCodec2);
1024 media_engine_->SetAudioCodecs(codecs);
1025 desc_factory_->set_audio_codecs(codecs);
1026 }
1027
1028 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1029 const cricket::ContentDescription* description = content->description;
1030 ASSERT(description != NULL);
1031 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001032 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001033 ASSERT(audio_content_desc != NULL);
1034 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1035 if (audio_content_desc->codecs()[i].name == "CN")
1036 return false;
1037 }
1038 return true;
1039 }
1040
1041 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001042 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001043 dci.reliable = false;
1044 session_->CreateDataChannel("datachannel", &dci);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001045 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001046 SetLocalDescriptionWithoutError(offer);
1047 }
1048
wu@webrtc.org91053e72013-08-10 07:18:04 +00001049 void VerifyMultipleAsyncCreateDescription(
1050 bool success, CreateSessionDescriptionRequest::Type type) {
henrike@webrtc.org7666db72013-08-22 14:45:42 +00001051 InitWithDtls(!success);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001052 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001053 if (type == CreateSessionDescriptionRequest::kAnswer) {
1054 cricket::MediaSessionOptions options;
1055 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001056 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001057 ASSERT_TRUE(offer.get() != NULL);
1058 SetRemoteDescriptionWithoutError(offer.release());
1059 }
1060
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001061 PeerConnectionInterface::RTCOfferAnswerOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001062 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001063 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001064 observers[kNumber];
1065 for (int i = 0; i < kNumber; ++i) {
1066 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1067 if (type == CreateSessionDescriptionRequest::kOffer) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001068 session_->CreateOffer(observers[i], options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001069 } else {
1070 session_->CreateAnswer(observers[i], NULL);
1071 }
1072 }
1073
1074 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1075 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1076 WebRtcSessionCreateSDPObserverForTest::kFailed;
1077
1078 for (int i = 0; i < kNumber; ++i) {
1079 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1080 if (success) {
1081 EXPECT_TRUE(observers[i]->description() != NULL);
1082 } else {
1083 EXPECT_TRUE(observers[i]->description() == NULL);
1084 }
1085 }
1086 }
1087
mallinath@webrtc.org7256d312014-09-07 04:08:44 +00001088 void ConfigureAllocatorWithTurn() {
1089 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1090 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
1091 relay_server.credentials = credentials;
1092 relay_server.ports.push_back(cricket::ProtocolAddress(
1093 kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1094 allocator_->AddRelay(relay_server);
1095 allocator_->set_step_delay(cricket::kMinimumStepDelay);
1096 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
1097 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
1098 }
1099
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001100 cricket::FakeMediaEngine* media_engine_;
1101 cricket::FakeDataEngine* data_engine_;
1102 cricket::FakeDeviceManager* device_manager_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001103 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
1104 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1105 rtc::scoped_ptr<rtc::SSLIdentity> identity_;
1106 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1107 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1108 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1109 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1110 rtc::SocketServerScope ss_scope_;
1111 rtc::SocketAddress stun_socket_addr_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001112 cricket::TestStunServer stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001113 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001114 rtc::FakeNetworkManager network_manager_;
1115 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001116 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001117 rtc::scoped_ptr<FakeConstraints> constraints_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001118 FakeMediaStreamSignaling mediastream_signaling_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001119 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001120 MockIceObserver observer_;
1121 cricket::FakeVideoMediaChannel* video_channel_;
1122 cricket::FakeVoiceMediaChannel* voice_channel_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001123 PeerConnectionInterface::IceTransportsType ice_type_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001124};
1125
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001126TEST_F(WebRtcSessionTest, TestInitializeWithDtls) {
1127 InitWithDtls();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001128 // SDES is disabled when DTLS is on.
1129 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001130}
1131
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001132TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001133 Init(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001134 // SDES is required if DTLS is off.
1135 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001136}
1137
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001138TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1139 TestSessionCandidatesWithBundleRtcpMux(false, false);
1140}
1141
1142// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1143// with rtcp-mux and/or bundle.
1144TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1145 TestSessionCandidatesWithBundleRtcpMux(false, true);
1146}
1147
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001148TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1149 TestSessionCandidatesWithBundleRtcpMux(true, true);
1150}
1151
1152TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001153 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1154 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001155 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001156 mediastream_signaling_.SendAudioVideoStream1();
1157 InitiateCall();
1158 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1159 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1160 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1161}
1162
1163TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001164 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1165 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001166 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001167 rtc::FP_UDP,
1168 rtc::FD_ANY,
1169 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001170 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001171 mediastream_signaling_.SendAudioVideoStream1();
1172 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001173 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001174 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1175 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1176 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1177}
1178
mallinath@webrtc.org7256d312014-09-07 04:08:44 +00001179// Test session delivers no candidates gathered when constraint set to "none".
1180TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1181 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1182 SetIceTransportType(PeerConnectionInterface::kNone);
1183 Init(NULL);
1184 mediastream_signaling_.SendAudioVideoStream1();
1185 InitiateCall();
1186 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1187 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1188 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1189}
1190
1191// Test session delivers only relay candidates gathered when constaint set to
1192// "relay".
1193TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1194 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1195 ConfigureAllocatorWithTurn();
1196 SetIceTransportType(PeerConnectionInterface::kRelay);
1197 Init(NULL);
1198 mediastream_signaling_.SendAudioVideoStream1();
1199 InitiateCall();
1200 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1201 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1202 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1203 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1204 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1205 observer_.mline_0_candidates_[i].type());
1206 }
1207 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1208 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1209 observer_.mline_1_candidates_[i].type());
1210 }
1211}
1212
1213// Test session delivers all candidates gathered when constaint set to "all".
1214TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1215 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1216 SetIceTransportType(PeerConnectionInterface::kAll);
1217 Init(NULL);
1218 mediastream_signaling_.SendAudioVideoStream1();
1219 InitiateCall();
1220 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1221 // Host + STUN. By default allocator is disabled to gather relay candidates.
1222 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1223 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1224}
1225
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001226TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
1227 Init(NULL);
1228 SessionDescriptionInterface* offer = NULL;
1229 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1230 std::string unknown_action;
1231 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1232 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1233}
1234
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001235// Test creating offers and receive answers and make sure the
1236// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001237TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001238 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001239 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001240 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001241 const std::string session_id_orig = offer->session_id();
1242 const std::string session_version_orig = offer->session_version();
1243 SetLocalDescriptionWithoutError(offer);
1244
1245 mediastream_signaling_.SendAudioVideoStream2();
1246 SessionDescriptionInterface* answer =
1247 CreateRemoteAnswer(session_->local_description());
1248 SetRemoteDescriptionWithoutError(answer);
1249
1250 video_channel_ = media_engine_->GetVideoChannel(0);
1251 voice_channel_ = media_engine_->GetVoiceChannel(0);
1252
1253 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1254 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1255
1256 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1257 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1258
1259 ASSERT_EQ(1u, video_channel_->send_streams().size());
1260 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1261 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1262 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1263
1264 // Create new offer without send streams.
1265 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001266 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001267
1268 // Verify the session id is the same and the session version is
1269 // increased.
1270 EXPECT_EQ(session_id_orig, offer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001271 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1272 rtc::FromString<uint64>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001273
1274 SetLocalDescriptionWithoutError(offer);
1275
1276 mediastream_signaling_.SendAudioVideoStream2();
1277 answer = CreateRemoteAnswer(session_->local_description());
1278 SetRemoteDescriptionWithoutError(answer);
1279
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00001280 EXPECT_EQ(0u, video_channel_->send_streams().size());
1281 EXPECT_EQ(0u, voice_channel_->send_streams().size());
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.org52055a22014-09-04 17:12:25 +00002056
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002057 EXPECT_TRUE(content != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002058 content = cricket::GetFirstVideoContent(offer->description());
2059 EXPECT_TRUE(content != NULL);
2060
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002061 // TODO(perkj): Should the direction be set to SEND_ONLY if
2062 // The constraints is set to not receive audio or video but a track is added?
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002063}
2064
2065// Test that an answer can not be created if the last remote description is not
2066// an offer.
2067TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002068 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002069 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002070 SetLocalDescriptionWithoutError(offer);
2071 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2072 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002073 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074}
2075
2076// Test that an answer contains the correct media content descriptions when no
2077// constraints have been set.
2078TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002079 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002080 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002081 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002082 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002083 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002084 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002085 const cricket::ContentInfo* content =
2086 cricket::GetFirstAudioContent(answer->description());
2087 ASSERT_TRUE(content != NULL);
2088 EXPECT_FALSE(content->rejected);
2089
2090 content = cricket::GetFirstVideoContent(answer->description());
2091 ASSERT_TRUE(content != NULL);
2092 EXPECT_FALSE(content->rejected);
2093}
2094
2095// Test that an answer contains the correct media content descriptions when no
2096// constraints have been set and the offer only contain audio.
2097TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002098 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002099 // Create a remote offer with audio only.
2100 cricket::MediaSessionOptions options;
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002101 options.has_audio = true;
2102 options.has_video = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002103 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002104 CreateRemoteOffer(options));
2105 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2106 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2107
2108 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002109 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002110 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002111 const cricket::ContentInfo* content =
2112 cricket::GetFirstAudioContent(answer->description());
2113 ASSERT_TRUE(content != NULL);
2114 EXPECT_FALSE(content->rejected);
2115
2116 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2117}
2118
2119// Test that an answer contains the correct media content descriptions when no
2120// constraints have been set.
2121TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002122 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002123 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002124 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002125 SetRemoteDescriptionWithoutError(offer.release());
2126 // Test with a stream with tracks.
2127 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002128 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002129 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002130 const cricket::ContentInfo* content =
2131 cricket::GetFirstAudioContent(answer->description());
2132 ASSERT_TRUE(content != NULL);
2133 EXPECT_FALSE(content->rejected);
2134
2135 content = cricket::GetFirstVideoContent(answer->description());
2136 ASSERT_TRUE(content != NULL);
2137 EXPECT_FALSE(content->rejected);
2138}
2139
2140// Test that an answer contains the correct media content descriptions when
2141// constraints have been set but no stream is sent.
2142TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002143 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002144 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002145 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002146 SetRemoteDescriptionWithoutError(offer.release());
2147
2148 webrtc::FakeConstraints constraints_no_receive;
2149 constraints_no_receive.SetMandatoryReceiveAudio(false);
2150 constraints_no_receive.SetMandatoryReceiveVideo(false);
2151
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002152 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002153 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002154 const cricket::ContentInfo* content =
2155 cricket::GetFirstAudioContent(answer->description());
2156 ASSERT_TRUE(content != NULL);
2157 EXPECT_TRUE(content->rejected);
2158
2159 content = cricket::GetFirstVideoContent(answer->description());
2160 ASSERT_TRUE(content != NULL);
2161 EXPECT_TRUE(content->rejected);
2162}
2163
2164// Test that an answer contains the correct media content descriptions when
2165// constraints have been set and streams are sent.
2166TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002167 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002168 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002169 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002170 SetRemoteDescriptionWithoutError(offer.release());
2171
2172 webrtc::FakeConstraints constraints_no_receive;
2173 constraints_no_receive.SetMandatoryReceiveAudio(false);
2174 constraints_no_receive.SetMandatoryReceiveVideo(false);
2175
2176 // Test with a stream with tracks.
2177 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002178 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002179 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002180
2181 // TODO(perkj): Should the direction be set to SEND_ONLY?
2182 const cricket::ContentInfo* content =
2183 cricket::GetFirstAudioContent(answer->description());
2184 ASSERT_TRUE(content != NULL);
2185 EXPECT_FALSE(content->rejected);
2186
2187 // TODO(perkj): Should the direction be set to SEND_ONLY?
2188 content = cricket::GetFirstVideoContent(answer->description());
2189 ASSERT_TRUE(content != NULL);
2190 EXPECT_FALSE(content->rejected);
2191}
2192
2193TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2194 AddCNCodecs();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002195 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002196 PeerConnectionInterface::RTCOfferAnswerOptions options;
2197 options.offer_to_receive_audio =
2198 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2199 options.voice_activity_detection = false;
2200
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002201 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002202 CreateOffer(options));
2203
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002204 const cricket::ContentInfo* content =
2205 cricket::GetFirstAudioContent(offer->description());
2206 EXPECT_TRUE(content != NULL);
2207 EXPECT_TRUE(VerifyNoCNCodecs(content));
2208}
2209
2210TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2211 AddCNCodecs();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002212 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002213 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002214 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002215 SetRemoteDescriptionWithoutError(offer.release());
2216
2217 webrtc::FakeConstraints constraints;
2218 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002219 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002220 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002221 const cricket::ContentInfo* content =
2222 cricket::GetFirstAudioContent(answer->description());
2223 ASSERT_TRUE(content != NULL);
2224 EXPECT_TRUE(VerifyNoCNCodecs(content));
2225}
2226
2227// This test verifies the call setup when remote answer with audio only and
2228// later updates with video.
2229TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002230 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002231 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2232 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2233
2234 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002235 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002236
2237 cricket::MediaSessionOptions options;
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002238 options.has_video = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002239 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2240
2241 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2242 // and answer;
2243 SetLocalDescriptionWithoutError(offer);
2244 SetRemoteDescriptionWithoutError(answer);
2245
2246 video_channel_ = media_engine_->GetVideoChannel(0);
2247 voice_channel_ = media_engine_->GetVoiceChannel(0);
2248
2249 ASSERT_TRUE(video_channel_ == NULL);
2250
2251 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2252 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2253 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2254
2255 // Let the remote end update the session descriptions, with Audio and Video.
2256 mediastream_signaling_.SendAudioVideoStream2();
2257 CreateAndSetRemoteOfferAndLocalAnswer();
2258
2259 video_channel_ = media_engine_->GetVideoChannel(0);
2260 voice_channel_ = media_engine_->GetVoiceChannel(0);
2261
2262 ASSERT_TRUE(video_channel_ != NULL);
2263 ASSERT_TRUE(voice_channel_ != NULL);
2264
2265 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2266 ASSERT_EQ(1u, video_channel_->send_streams().size());
2267 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2268 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2269 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2270 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2271 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2272 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2273
2274 // Change session back to audio only.
2275 mediastream_signaling_.UseOptionsAudioOnly();
2276 CreateAndSetRemoteOfferAndLocalAnswer();
2277
2278 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2279 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2280 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2281 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2282 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2283}
2284
2285// This test verifies the call setup when remote answer with video only and
2286// later updates with audio.
2287TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002288 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002289 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2290 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2291 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002292 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002293
2294 cricket::MediaSessionOptions options;
2295 options.has_audio = false;
2296 options.has_video = true;
2297 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2298 offer, options, cricket::SEC_ENABLED);
2299
2300 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2301 // and answer.
2302 SetLocalDescriptionWithoutError(offer);
2303 SetRemoteDescriptionWithoutError(answer);
2304
2305 video_channel_ = media_engine_->GetVideoChannel(0);
2306 voice_channel_ = media_engine_->GetVoiceChannel(0);
2307
2308 ASSERT_TRUE(voice_channel_ == NULL);
2309 ASSERT_TRUE(video_channel_ != NULL);
2310
2311 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2312 ASSERT_EQ(1u, video_channel_->send_streams().size());
2313 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2314
2315 // Update the session descriptions, with Audio and Video.
2316 mediastream_signaling_.SendAudioVideoStream2();
2317 CreateAndSetRemoteOfferAndLocalAnswer();
2318
2319 voice_channel_ = media_engine_->GetVoiceChannel(0);
2320 ASSERT_TRUE(voice_channel_ != NULL);
2321
2322 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2323 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2324 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2325 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2326
2327 // Change session back to video only.
2328 mediastream_signaling_.UseOptionsVideoOnly();
2329 CreateAndSetRemoteOfferAndLocalAnswer();
2330
2331 video_channel_ = media_engine_->GetVideoChannel(0);
2332 voice_channel_ = media_engine_->GetVoiceChannel(0);
2333
2334 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2335 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2336 ASSERT_EQ(1u, video_channel_->send_streams().size());
2337 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2338}
2339
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002340TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002341 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002342 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002343 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002344 VerifyCryptoParams(offer->description());
2345 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002346 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002347 VerifyCryptoParams(answer->description());
2348}
2349
2350TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002351 options_.disable_encryption = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00002352 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002353 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002354 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002355 VerifyNoCryptoParams(offer->description(), false);
2356}
2357
2358TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002359 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002360 VerifyAnswerFromNonCryptoOffer();
2361}
2362
2363TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002364 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002365 VerifyAnswerFromCryptoOffer();
2366}
2367
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002368// This test verifies that setLocalDescription fails if
2369// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2370TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
2371 Init(NULL);
2372 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002373 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2374
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002375 std::string sdp;
2376 RemoveIceUfragPwdLines(offer.get(), &sdp);
2377 SessionDescriptionInterface* modified_offer =
2378 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002379 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002380}
2381
2382// This test verifies that setRemoteDescription fails if
2383// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2384TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
2385 Init(NULL);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002386 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002387 std::string sdp;
2388 RemoveIceUfragPwdLines(offer.get(), &sdp);
2389 SessionDescriptionInterface* modified_offer =
2390 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002391 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002392}
2393
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002394// This test verifies that setLocalDescription fails if local offer has
2395// too short ice ufrag and pwd strings.
2396TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
2397 Init(NULL);
2398 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
2399 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002400 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2401
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002402 std::string sdp;
2403 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2404 // recommended values of 4 and 22 bytes respectively.
2405 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2406 SessionDescriptionInterface* modified_offer =
2407 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2408 std::string error;
2409 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2410
2411 // Test with string greater than 256.
2412 sdp.clear();
2413 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2414 &sdp);
2415 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2416 NULL);
2417 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2418}
2419
2420// This test verifies that setRemoteDescription fails if remote offer has
2421// too short ice ufrag and pwd strings.
2422TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
2423 Init(NULL);
2424 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002425 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002426 std::string sdp;
2427 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2428 // recommended values of 4 and 22 bytes respectively.
2429 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2430 SessionDescriptionInterface* modified_offer =
2431 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2432 std::string error;
2433 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2434
2435 sdp.clear();
2436 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2437 &sdp);
2438 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2439 NULL);
2440 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2441}
2442
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002443TEST_F(WebRtcSessionTest, VerifyBundleFlagInPA) {
2444 // This test verifies BUNDLE flag in PortAllocator, if BUNDLE information in
2445 // local description is removed by the application, BUNDLE flag should be
2446 // disabled in PortAllocator. By default BUNDLE is enabled in the WebRtc.
wu@webrtc.org91053e72013-08-10 07:18:04 +00002447 Init(NULL);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002448 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2449 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002450 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2451
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002452 cricket::SessionDescription* offer_copy =
2453 offer->description()->Copy();
2454 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2455 JsepSessionDescription* modified_offer =
2456 new JsepSessionDescription(JsepSessionDescription::kOffer);
2457 modified_offer->Initialize(offer_copy, "1", "1");
2458
2459 SetLocalDescriptionWithoutError(modified_offer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002460 EXPECT_FALSE(allocator_->flags() & cricket::PORTALLOCATOR_ENABLE_BUNDLE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002461}
2462
2463TEST_F(WebRtcSessionTest, TestDisabledBundleInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002464 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002465 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002466 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2467 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002468
2469 PeerConnectionInterface::RTCOfferAnswerOptions options;
2470 options.use_rtp_mux = true;
2471
2472 SessionDescriptionInterface* offer = CreateOffer(options);
2473
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002474 SetLocalDescriptionWithoutError(offer);
2475 mediastream_signaling_.SendAudioVideoStream2();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002476 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002477 CreateRemoteAnswer(session_->local_description()));
2478 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2479 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2480 JsepSessionDescription* modified_answer =
2481 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2482 modified_answer->Initialize(answer_copy, "1", "1");
2483 SetRemoteDescriptionWithoutError(modified_answer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002484 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2485 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002486
2487 video_channel_ = media_engine_->GetVideoChannel(0);
2488 voice_channel_ = media_engine_->GetVoiceChannel(0);
2489
2490 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2491 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
2492
2493 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2494 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
2495
2496 ASSERT_EQ(1u, video_channel_->send_streams().size());
2497 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
2498 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2499 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
2500}
2501
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002502// This test verifies that SetLocalDescription and SetRemoteDescription fails
2503// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2504TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002505 WebRtcSessionTest::Init(NULL);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002506 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002507 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2508 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002509
2510 PeerConnectionInterface::RTCOfferAnswerOptions options;
2511 options.use_rtp_mux = true;
2512
2513 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002514 std::string offer_str;
2515 offer->ToString(&offer_str);
2516 // Disable rtcp-mux
2517 const std::string rtcp_mux = "rtcp-mux";
2518 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002519 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002520 xrtcp_mux.c_str(), xrtcp_mux.length(),
2521 &offer_str);
2522 JsepSessionDescription *local_offer =
2523 new JsepSessionDescription(JsepSessionDescription::kOffer);
2524 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002525 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002526 JsepSessionDescription *remote_offer =
2527 new JsepSessionDescription(JsepSessionDescription::kOffer);
2528 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002529 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002530 // Trying unmodified SDP.
2531 SetLocalDescriptionWithoutError(offer);
2532}
2533
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002534TEST_F(WebRtcSessionTest, SetAudioPlayout) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002535 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002536 mediastream_signaling_.SendAudioVideoStream1();
2537 CreateAndSetRemoteOfferAndLocalAnswer();
2538 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2539 ASSERT_TRUE(channel != NULL);
2540 ASSERT_EQ(1u, channel->recv_streams().size());
2541 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2542 double left_vol, right_vol;
2543 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2544 EXPECT_EQ(1, left_vol);
2545 EXPECT_EQ(1, right_vol);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002546 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002547 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002548 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2549 EXPECT_EQ(0, left_vol);
2550 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002551 EXPECT_EQ(0, renderer->channel_id());
2552 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002553 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2554 EXPECT_EQ(1, left_vol);
2555 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002556 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002557}
2558
2559TEST_F(WebRtcSessionTest, SetAudioSend) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002560 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002561 mediastream_signaling_.SendAudioVideoStream1();
2562 CreateAndSetRemoteOfferAndLocalAnswer();
2563 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2564 ASSERT_TRUE(channel != NULL);
2565 ASSERT_EQ(1u, channel->send_streams().size());
2566 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2567 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2568
2569 cricket::AudioOptions options;
2570 options.echo_cancellation.Set(true);
2571
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002572 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002573 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002574 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2575 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002576 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002577 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002578
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002579 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002580 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002581 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2582 bool value;
2583 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
2584 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002585 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002586 EXPECT_TRUE(renderer->sink() == NULL);
2587}
2588
2589TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
2590 Init(NULL);
2591 mediastream_signaling_.SendAudioVideoStream1();
2592 CreateAndSetRemoteOfferAndLocalAnswer();
2593 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2594 ASSERT_TRUE(channel != NULL);
2595 ASSERT_EQ(1u, channel->send_streams().size());
2596 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2597
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002598 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002599 cricket::AudioOptions options;
2600 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
2601 EXPECT_TRUE(renderer->sink() != NULL);
2602
2603 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
2604 // will invalidate the |renderer_| pointer in the sink and prevent getting a
2605 // SetSink(NULL) callback afterwards.
2606 renderer.reset();
2607
2608 // This will trigger SetSink(NULL) if no OnClose() callback.
2609 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002610}
2611
2612TEST_F(WebRtcSessionTest, SetVideoPlayout) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002613 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002614 mediastream_signaling_.SendAudioVideoStream1();
2615 CreateAndSetRemoteOfferAndLocalAnswer();
2616 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2617 ASSERT_TRUE(channel != NULL);
2618 ASSERT_LT(0u, channel->renderers().size());
2619 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2620 ASSERT_EQ(1u, channel->recv_streams().size());
2621 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2622 cricket::FakeVideoRenderer renderer;
2623 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
2624 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
2625 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
2626 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2627}
2628
2629TEST_F(WebRtcSessionTest, SetVideoSend) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002630 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002631 mediastream_signaling_.SendAudioVideoStream1();
2632 CreateAndSetRemoteOfferAndLocalAnswer();
2633 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2634 ASSERT_TRUE(channel != NULL);
2635 ASSERT_EQ(1u, channel->send_streams().size());
2636 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2637 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2638 cricket::VideoOptions* options = NULL;
2639 session_->SetVideoSend(send_ssrc, false, options);
2640 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2641 session_->SetVideoSend(send_ssrc, true, options);
2642 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2643}
2644
2645TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
2646 TestCanInsertDtmf(false);
2647}
2648
2649TEST_F(WebRtcSessionTest, CanInsertDtmf) {
2650 TestCanInsertDtmf(true);
2651}
2652
2653TEST_F(WebRtcSessionTest, InsertDtmf) {
2654 // Setup
wu@webrtc.org91053e72013-08-10 07:18:04 +00002655 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002656 mediastream_signaling_.SendAudioVideoStream1();
2657 CreateAndSetRemoteOfferAndLocalAnswer();
2658 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2659 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
2660
2661 // Insert DTMF
2662 const int expected_flags = DF_SEND;
2663 const int expected_duration = 90;
2664 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
2665 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
2666 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
2667
2668 // Verify
2669 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
2670 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2671 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
2672 expected_duration, expected_flags));
2673 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
2674 expected_duration, expected_flags));
2675 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
2676 expected_duration, expected_flags));
2677}
2678
2679// This test verifies the |initiator| flag when session initiates the call.
2680TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002681 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002682 EXPECT_FALSE(session_->initiator());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002683 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002684 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2685 SetLocalDescriptionWithoutError(offer);
2686 EXPECT_TRUE(session_->initiator());
2687 SetRemoteDescriptionWithoutError(answer);
2688 EXPECT_TRUE(session_->initiator());
2689}
2690
2691// This test verifies the |initiator| flag when session receives the call.
2692TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002693 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002694 EXPECT_FALSE(session_->initiator());
2695 SessionDescriptionInterface* offer = CreateRemoteOffer();
2696 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002697 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002698
2699 EXPECT_FALSE(session_->initiator());
2700 SetLocalDescriptionWithoutError(answer);
2701 EXPECT_FALSE(session_->initiator());
2702}
2703
2704// This test verifies the ice protocol type at initiator of the call
2705// if |a=ice-options:google-ice| is present in answer.
2706TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002707 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002708 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002709 SessionDescriptionInterface* offer = CreateOffer();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002710 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002711 CreateRemoteAnswer(offer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002712 SetLocalDescriptionWithoutError(offer);
2713 std::string sdp;
2714 EXPECT_TRUE(answer->ToString(&sdp));
2715 // Adding ice-options to the session level.
2716 InjectAfter("t=0 0\r\n",
2717 "a=ice-options:google-ice\r\n",
2718 &sdp);
2719 SessionDescriptionInterface* answer_with_gice =
2720 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2721 SetRemoteDescriptionWithoutError(answer_with_gice);
2722 VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE);
2723 VerifyTransportType("video", cricket::ICEPROTO_GOOGLE);
2724}
2725
2726// This test verifies the ice protocol type at initiator of the call
2727// if ICE RFC5245 is supported in answer.
2728TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002729 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002730 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002731 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002732 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2733 SetLocalDescriptionWithoutError(offer);
2734
2735 SetRemoteDescriptionWithoutError(answer);
2736 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2737 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2738}
2739
2740// This test verifies the ice protocol type at receiver side of the call if
2741// receiver decides to use google-ice.
2742TEST_F(WebRtcSessionTest, TestReceiverGIceInOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002743 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002744 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002745 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002746 SetRemoteDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002747 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002748 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002749 std::string sdp;
2750 EXPECT_TRUE(answer->ToString(&sdp));
2751 // Adding ice-options to the session level.
2752 InjectAfter("t=0 0\r\n",
2753 "a=ice-options:google-ice\r\n",
2754 &sdp);
2755 SessionDescriptionInterface* answer_with_gice =
2756 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2757 SetLocalDescriptionWithoutError(answer_with_gice);
2758 VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE);
2759 VerifyTransportType("video", cricket::ICEPROTO_GOOGLE);
2760}
2761
2762// This test verifies the ice protocol type at receiver side of the call if
2763// receiver decides to use ice RFC 5245.
2764TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002765 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002766 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002767 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002768 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002769 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002770 SetLocalDescriptionWithoutError(answer);
2771 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2772 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2773}
2774
2775// This test verifies the session state when ICE RFC5245 in offer and
2776// ICE google-ice in answer.
2777TEST_F(WebRtcSessionTest, TestIceOfferGIceOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002778 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002779 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002780 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2781
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002782 std::string offer_str;
2783 offer->ToString(&offer_str);
2784 // Disable google-ice
2785 const std::string gice_option = "google-ice";
2786 const std::string xgoogle_xice = "xgoogle-xice";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002787 rtc::replace_substrs(gice_option.c_str(), gice_option.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002788 xgoogle_xice.c_str(), xgoogle_xice.length(),
2789 &offer_str);
2790 JsepSessionDescription *ice_only_offer =
2791 new JsepSessionDescription(JsepSessionDescription::kOffer);
2792 EXPECT_TRUE((ice_only_offer)->Initialize(offer_str, NULL));
2793 SetLocalDescriptionWithoutError(ice_only_offer);
2794 std::string original_offer_sdp;
2795 EXPECT_TRUE(offer->ToString(&original_offer_sdp));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002796 SessionDescriptionInterface* pranswer_with_gice =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002797 CreateSessionDescription(JsepSessionDescription::kPrAnswer,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002798 original_offer_sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002799 SetRemoteDescriptionPranswerExpectError(kPushDownTDFailed,
2800 pranswer_with_gice);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002801 SessionDescriptionInterface* answer_with_gice =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002802 CreateSessionDescription(JsepSessionDescription::kAnswer,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002803 original_offer_sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002804 SetRemoteDescriptionAnswerExpectError(kPushDownTDFailed,
2805 answer_with_gice);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002806}
2807
2808// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
2809TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002810 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002811 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002812 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002813 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002814 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002815 CreateRemoteAnswer(session_->local_description()));
2816
2817 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2818 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002819 JsepSessionDescription* modified_answer =
2820 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002821
2822 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2823 answer->session_id(),
2824 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002825 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002826
wu@webrtc.org4e393072014-04-07 17:04:35 +00002827 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002828 std::string sdp;
2829 EXPECT_TRUE(answer->ToString(&sdp));
2830 const std::string kAudioMid = "a=mid:audio";
2831 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002832 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002833 kAudioMidReplaceStr.c_str(),
2834 kAudioMidReplaceStr.length(),
2835 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002836 SessionDescriptionInterface* modified_answer1 =
2837 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002838 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002839
wu@webrtc.org4e393072014-04-07 17:04:35 +00002840 // Different media types.
2841 EXPECT_TRUE(answer->ToString(&sdp));
2842 const std::string kAudioMline = "m=audio";
2843 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002844 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00002845 kAudioMlineReplaceStr.c_str(),
2846 kAudioMlineReplaceStr.length(),
2847 &sdp);
2848 SessionDescriptionInterface* modified_answer2 =
2849 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2850 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
2851
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002852 SetRemoteDescriptionWithoutError(answer.release());
2853}
2854
2855// Verifying remote offer and local answer have matching m-lines as per
2856// RFC 3264.
2857TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002858 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002859 mediastream_signaling_.SendAudioVideoStream1();
2860 SessionDescriptionInterface* offer = CreateRemoteOffer();
2861 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002862 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002863
2864 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2865 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002866 JsepSessionDescription* modified_answer =
2867 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002868
2869 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2870 answer->session_id(),
2871 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002872 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002873 SetLocalDescriptionWithoutError(answer);
2874}
2875
2876// This test verifies that WebRtcSession does not start candidate allocation
2877// before SetLocalDescription is called.
2878TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002879 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002880 mediastream_signaling_.SendAudioVideoStream1();
2881 SessionDescriptionInterface* offer = CreateRemoteOffer();
2882 cricket::Candidate candidate;
2883 candidate.set_component(1);
2884 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2885 candidate);
2886 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2887 cricket::Candidate candidate1;
2888 candidate1.set_component(1);
2889 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2890 candidate1);
2891 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2892 SetRemoteDescriptionWithoutError(offer);
2893 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
2894 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
2895
2896 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002897 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002898 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
2899 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
2900
wu@webrtc.org91053e72013-08-10 07:18:04 +00002901 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002902 SetLocalDescriptionWithoutError(answer);
2903 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
2904 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
2905 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2906}
2907
2908// This test verifies that crypto parameter is updated in local session
2909// description as per security policy set in MediaSessionDescriptionFactory.
2910TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002911 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002912 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002913 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002914
2915 // Making sure SetLocalDescription correctly sets crypto value in
2916 // SessionDescription object after de-serialization of sdp string. The value
2917 // will be set as per MediaSessionDescriptionFactory.
2918 std::string offer_str;
2919 offer->ToString(&offer_str);
2920 SessionDescriptionInterface* jsep_offer_str =
2921 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
2922 SetLocalDescriptionWithoutError(jsep_offer_str);
2923 EXPECT_TRUE(session_->voice_channel()->secure_required());
2924 EXPECT_TRUE(session_->video_channel()->secure_required());
2925}
2926
2927// This test verifies the crypto parameter when security is disabled.
2928TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002929 options_.disable_encryption = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00002930 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002931 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002932 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002933
2934 // Making sure SetLocalDescription correctly sets crypto value in
2935 // SessionDescription object after de-serialization of sdp string. The value
2936 // will be set as per MediaSessionDescriptionFactory.
2937 std::string offer_str;
2938 offer->ToString(&offer_str);
2939 SessionDescriptionInterface *jsep_offer_str =
2940 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
2941 SetLocalDescriptionWithoutError(jsep_offer_str);
2942 EXPECT_FALSE(session_->voice_channel()->secure_required());
2943 EXPECT_FALSE(session_->video_channel()->secure_required());
2944}
2945
2946// This test verifies that an answer contains new ufrag and password if an offer
2947// with new ufrag and password is received.
2948TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002949 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002950 cricket::MediaSessionOptions options;
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002951 options.has_audio = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002952 options.has_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002953 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002954 CreateRemoteOffer(options));
2955 SetRemoteDescriptionWithoutError(offer.release());
2956
2957 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002958 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002959 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002960 SetLocalDescriptionWithoutError(answer.release());
2961
2962 // Receive an offer with new ufrag and password.
2963 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002964 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002965 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002966 SetRemoteDescriptionWithoutError(updated_offer1.release());
2967
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002968 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002969 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002970
2971 CompareIceUfragAndPassword(updated_answer1->description(),
2972 session_->local_description()->description(),
2973 false);
2974
2975 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002976}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002977
wu@webrtc.org91053e72013-08-10 07:18:04 +00002978// This test verifies that an answer contains old ufrag and password if an offer
2979// with old ufrag and password is received.
2980TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
2981 Init(NULL);
2982 cricket::MediaSessionOptions options;
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002983 options.has_audio = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00002984 options.has_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002985 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002986 CreateRemoteOffer(options));
2987 SetRemoteDescriptionWithoutError(offer.release());
2988
2989 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002990 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002991 CreateAnswer(NULL));
2992 SetLocalDescriptionWithoutError(answer.release());
2993
2994 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002995 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002996 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002997 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002998 SetRemoteDescriptionWithoutError(updated_offer2.release());
2999
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003000 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003001 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003002
3003 CompareIceUfragAndPassword(updated_answer2->description(),
3004 session_->local_description()->description(),
3005 true);
3006
3007 SetLocalDescriptionWithoutError(updated_answer2.release());
3008}
3009
3010TEST_F(WebRtcSessionTest, TestSessionContentError) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00003011 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003012 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003013 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003014 const std::string session_id_orig = offer->session_id();
3015 const std::string session_version_orig = offer->session_version();
3016 SetLocalDescriptionWithoutError(offer);
3017
3018 video_channel_ = media_engine_->GetVideoChannel(0);
3019 video_channel_->set_fail_set_send_codecs(true);
3020
3021 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003022 SessionDescriptionInterface* answer =
3023 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003024 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003025}
3026
3027// Runs the loopback call test with BUNDLE and STUN disabled.
3028TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3029 // Lets try with only UDP ports.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00003030 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003031 cricket::PORTALLOCATOR_DISABLE_TCP |
3032 cricket::PORTALLOCATOR_DISABLE_STUN |
3033 cricket::PORTALLOCATOR_DISABLE_RELAY);
3034 TestLoopbackCall();
3035}
3036
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003037// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003038TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00003039 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003040 cricket::PORTALLOCATOR_ENABLE_BUNDLE |
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003041 cricket::PORTALLOCATOR_DISABLE_TCP |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003042 cricket::PORTALLOCATOR_DISABLE_RELAY);
3043 TestLoopbackCall();
3044}
3045
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003046TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00003047 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003048 cricket::MediaSessionOptions options;
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00003049 options.has_audio = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003050 options.has_video = true;
3051
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003052 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
3053 std::string error_code_str = "ERROR_CONTENT";
3054 std::string error_desc = "Fake session error description.";
3055 session_->SetError(error_code, error_desc);
3056
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003057 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
3058 SessionDescriptionInterface* answer =
3059 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003060
3061 std::string action;
3062 std::ostringstream session_error_msg;
3063 session_error_msg << kSessionError << error_code_str << ". ";
3064 session_error_msg << kSessionErrorDesc << error_desc << ".";
3065 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
3066 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003067}
3068
3069TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3070 constraints_.reset(new FakeConstraints());
3071 constraints_->AddOptional(
3072 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003073 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003074
3075 SetLocalDescriptionWithDataChannel();
3076 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3077}
3078
3079TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003080 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003081
3082 constraints_.reset(new FakeConstraints());
3083 constraints_->AddOptional(
3084 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003085 options_.disable_sctp_data_channels = false;
3086
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003087 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003088
3089 SetLocalDescriptionWithDataChannel();
3090 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3091}
3092
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003093TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003094 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003095
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003096 InitWithDtls();
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003097
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003098 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003099 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003100 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3101}
3102
3103TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003104 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003105 SetFactoryDtlsSrtp();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003106 InitWithDtls();
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003107
3108 // Create remote offer with SCTP.
3109 cricket::MediaSessionOptions options;
3110 options.data_channel_type = cricket::DCT_SCTP;
3111 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003112 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003113 SetRemoteDescriptionWithoutError(offer);
3114
3115 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003116 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003117 EXPECT_TRUE(answer != NULL);
3118 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3119 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003120}
3121
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003122TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
3123 constraints_.reset(new FakeConstraints());
3124 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003125 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003126 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003127
3128 SetLocalDescriptionWithDataChannel();
3129 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3130}
3131
3132TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003133 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003134
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003135 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003136
3137 SetLocalDescriptionWithDataChannel();
3138 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3139}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003140
wu@webrtc.org97077a32013-10-25 21:18:33 +00003141TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003142 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003143 options_.disable_sctp_data_channels = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003144 InitWithDtls();
wu@webrtc.org97077a32013-10-25 21:18:33 +00003145
3146 SetLocalDescriptionWithDataChannel();
3147 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3148}
3149
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003150TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003151 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003152 const int new_send_port = 9998;
3153 const int new_recv_port = 7775;
3154
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003155 InitWithDtls();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003156 SetFactoryDtlsSrtp();
3157
3158 // By default, don't actually add the codecs to desc_factory_; they don't
3159 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3160 // let the session description get parsed. That'll get the proper codecs
3161 // into the stream.
3162 cricket::MediaSessionOptions options;
3163 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3164 "stream1", new_send_port, options);
3165
3166 // SetRemoteDescription will take the ownership of the offer.
3167 SetRemoteDescriptionWithoutError(offer);
3168
3169 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3170 new_recv_port, CreateAnswer(NULL));
3171 ASSERT_TRUE(answer != NULL);
3172
3173 // Now set the local description, which'll take ownership of the answer.
3174 SetLocalDescriptionWithoutError(answer);
3175
3176 // TEST PLAN: Set the port number to something new, set it in the SDP,
3177 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003178 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003179 dci.reliable = true;
3180 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003181 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003182 session_->CreateDataChannel("datachannel", &dci);
3183
3184 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3185 int portnum = -1;
3186 ASSERT_TRUE(ch != NULL);
3187 ASSERT_EQ(1UL, ch->send_codecs().size());
3188 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
3189 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3190 ch->send_codecs()[0].name.c_str()));
3191 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3192 &portnum));
3193 EXPECT_EQ(new_send_port, portnum);
3194
3195 ASSERT_EQ(1UL, ch->recv_codecs().size());
3196 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
3197 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3198 ch->recv_codecs()[0].name.c_str()));
3199 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3200 &portnum));
3201 EXPECT_EQ(new_recv_port, portnum);
3202}
3203
wu@webrtc.org91053e72013-08-10 07:18:04 +00003204// Verifies that CreateOffer succeeds when CreateOffer is called before async
3205// identity generation is finished.
3206TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003207 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003208 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003209
3210 EXPECT_TRUE(session_->waiting_for_identity());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003211 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003212 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3213
wu@webrtc.org91053e72013-08-10 07:18:04 +00003214 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003215 VerifyNoCryptoParams(offer->description(), true);
3216 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003217}
3218
3219// Verifies that CreateAnswer succeeds when CreateOffer is called before async
3220// identity generation is finished.
3221TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003222 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003223 InitWithDtls();
3224 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003225
3226 cricket::MediaSessionOptions options;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003227 options.has_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003228 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003229 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003230 ASSERT_TRUE(offer.get() != NULL);
3231 SetRemoteDescriptionWithoutError(offer.release());
3232
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003233 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003234 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003235 VerifyNoCryptoParams(answer->description(), true);
3236 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003237}
3238
3239// Verifies that CreateOffer succeeds when CreateOffer is called after async
3240// identity generation is finished.
3241TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003242 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003243 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003244
3245 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003246
3247 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003248 EXPECT_TRUE(offer != NULL);
3249}
3250
3251// Verifies that CreateOffer fails when CreateOffer is called after async
3252// identity generation fails.
3253TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003254 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00003255 InitWithDtls(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003256
3257 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003258
3259 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003260 EXPECT_TRUE(offer == NULL);
3261}
3262
3263// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3264// before async identity generation is finished.
3265TEST_F(WebRtcSessionTest,
3266 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003267 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003268 VerifyMultipleAsyncCreateDescription(
3269 true, CreateSessionDescriptionRequest::kOffer);
3270}
3271
3272// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3273// before async identity generation fails.
3274TEST_F(WebRtcSessionTest,
3275 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003276 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003277 VerifyMultipleAsyncCreateDescription(
3278 false, CreateSessionDescriptionRequest::kOffer);
3279}
3280
3281// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3282// before async identity generation is finished.
3283TEST_F(WebRtcSessionTest,
3284 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003285 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003286 VerifyMultipleAsyncCreateDescription(
3287 true, CreateSessionDescriptionRequest::kAnswer);
3288}
3289
3290// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3291// before async identity generation fails.
3292TEST_F(WebRtcSessionTest,
3293 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003294 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003295 VerifyMultipleAsyncCreateDescription(
3296 false, CreateSessionDescriptionRequest::kAnswer);
3297}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003298
3299// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3300// offer has no SDES crypto but only DTLS fingerprint.
3301TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3302 // Init without DTLS.
3303 Init(NULL);
3304 // Create a remote offer with secured transport disabled.
3305 cricket::MediaSessionOptions options;
3306 JsepSessionDescription* offer(CreateRemoteOffer(
3307 options, cricket::SEC_DISABLED));
3308 // Adds a DTLS fingerprint to the remote offer.
3309 cricket::SessionDescription* sdp = offer->description();
3310 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3311 ASSERT_TRUE(audio != NULL);
3312 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3313 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003314 rtc::SSLFingerprint::CreateFromRfc4572(
3315 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003316 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003317 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003318}
3319
wu@webrtc.orgde305012013-10-31 15:40:38 +00003320// This test verifies DSCP is properly applied on the media channels.
3321TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3322 constraints_.reset(new FakeConstraints());
3323 constraints_->AddOptional(
3324 webrtc::MediaConstraintsInterface::kEnableDscp, true);
3325 Init(NULL);
3326 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003327 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003328
3329 SetLocalDescriptionWithoutError(offer);
3330
3331 video_channel_ = media_engine_->GetVideoChannel(0);
3332 voice_channel_ = media_engine_->GetVoiceChannel(0);
3333
3334 ASSERT_TRUE(video_channel_ != NULL);
3335 ASSERT_TRUE(voice_channel_ != NULL);
3336 cricket::AudioOptions audio_options;
3337 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3338 cricket::VideoOptions video_options;
3339 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3340 EXPECT_TRUE(audio_options.dscp.IsSet());
3341 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3342 EXPECT_TRUE(video_options.dscp.IsSet());
3343 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3344}
3345
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003346TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3347 constraints_.reset(new FakeConstraints());
3348 constraints_->AddOptional(
3349 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3350 true);
3351 Init(NULL);
3352 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003353 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003354
3355 SetLocalDescriptionWithoutError(offer);
3356
3357 video_channel_ = media_engine_->GetVideoChannel(0);
3358
3359 ASSERT_TRUE(video_channel_ != NULL);
3360 cricket::VideoOptions video_options;
3361 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3362 EXPECT_TRUE(
3363 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3364}
3365
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00003366TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
3367 // Number of unsignalled receiving streams should be between 0 and
3368 // kMaxUnsignalledRecvStreams.
3369 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
3370 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
3371 kMaxUnsignalledRecvStreams);
3372 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
3373}
3374
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003375TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
3376 constraints_.reset(new FakeConstraints());
3377 constraints_->AddOptional(
3378 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
3379 true);
3380 Init(NULL);
3381 mediastream_signaling_.SendAudioVideoStream1();
3382 SessionDescriptionInterface* offer = CreateOffer();
3383
3384 SetLocalDescriptionWithoutError(offer);
3385
3386 voice_channel_ = media_engine_->GetVoiceChannel(0);
3387
3388 ASSERT_TRUE(voice_channel_ != NULL);
3389 cricket::AudioOptions audio_options;
3390 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3391 EXPECT_TRUE(
3392 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
3393}
3394
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003395// Tests that we can renegotiate new media content with ICE candidates in the
3396// new remote SDP.
3397TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003398 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003399 InitWithDtls();
3400 SetFactoryDtlsSrtp();
3401
3402 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003403 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003404 SetLocalDescriptionWithoutError(offer);
3405
3406 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3407 SetRemoteDescriptionWithoutError(answer);
3408
3409 cricket::MediaSessionOptions options;
3410 options.has_video = true;
3411 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3412
3413 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003414 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003415 candidate1.set_component(1);
3416 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3417 candidate1);
3418 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3419 SetRemoteDescriptionWithoutError(offer);
3420
3421 answer = CreateAnswer(NULL);
3422 SetLocalDescriptionWithoutError(answer);
3423}
3424
3425// Tests that we can renegotiate new media content with ICE candidates separated
3426// from the remote SDP.
3427TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003428 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003429 InitWithDtls();
3430 SetFactoryDtlsSrtp();
3431
3432 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003433 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003434 SetLocalDescriptionWithoutError(offer);
3435
3436 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3437 SetRemoteDescriptionWithoutError(answer);
3438
3439 cricket::MediaSessionOptions options;
3440 options.has_video = true;
3441 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3442 SetRemoteDescriptionWithoutError(offer);
3443
3444 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003445 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003446 candidate1.set_component(1);
3447 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3448 candidate1);
3449 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3450
3451 answer = CreateAnswer(NULL);
3452 SetLocalDescriptionWithoutError(answer);
3453}
3454
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003455// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
3456// currently fails because upon disconnection and reconnection OnIceComplete is
3457// called more than once without returning to IceGatheringGathering.