blob: 7aa87fbebad2a392672af6a044c7fb91556fa7e2 [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.org52055a22014-09-04 17:12:25 +0000515 // Create an 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);
jiayl@webrtc.org52055a22014-09-04 17:12:25 +00001275 EXPECT_EQ(0u, video_channel_->send_streams().size());
1276 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001277
1278 mediastream_signaling_.SendAudioVideoStream2();
1279 answer = CreateRemoteAnswer(session_->local_description());
1280 SetRemoteDescriptionWithoutError(answer);
1281
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001282 // Make sure the receive streams have not changed.
1283 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1284 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1285 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1286 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1287}
1288
1289// Test receiving offers and creating answers and make sure the
1290// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001291TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001292 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001293 mediastream_signaling_.SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001294 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001295 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001296 SetRemoteDescriptionWithoutError(offer);
1297
1298 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001299 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001300 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001301 SetLocalDescriptionWithoutError(answer);
1302
1303 const std::string session_id_orig = answer->session_id();
1304 const std::string session_version_orig = answer->session_version();
1305
1306 video_channel_ = media_engine_->GetVideoChannel(0);
1307 voice_channel_ = media_engine_->GetVoiceChannel(0);
1308
1309 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1310 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1311
1312 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1313 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1314
1315 ASSERT_EQ(1u, video_channel_->send_streams().size());
1316 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1317 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1318 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1319
1320 mediastream_signaling_.SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001321 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001322 SetRemoteDescriptionWithoutError(offer);
1323
1324 // Answer by turning off all send streams.
1325 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001326 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001327
1328 // Verify the session id is the same and the session version is
1329 // increased.
1330 EXPECT_EQ(session_id_orig, answer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001331 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1332 rtc::FromString<uint64>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001333 SetLocalDescriptionWithoutError(answer);
1334
1335 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1336 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1337 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1338 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1339 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1340 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1341
1342 // Make sure we have no send streams.
1343 EXPECT_EQ(0u, video_channel_->send_streams().size());
1344 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1345}
1346
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001347TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
1348 Init(NULL);
1349 media_engine_->set_fail_create_channel(true);
1350
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001351 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001352 ASSERT_TRUE(offer != NULL);
1353 // SetRemoteDescription and SetLocalDescription will take the ownership of
1354 // the offer.
1355 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001356 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001357 ASSERT_TRUE(offer != NULL);
1358 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1359}
1360
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001361//
1362// Tests for creating/setting SDP under different SDES/DTLS polices:
1363//
1364// --DTLS off and SDES on
1365// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1366// set local/remote offer/answer with crypto --> success
1367// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1368// failure
1369// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1370// failure
1371// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1372// failure
1373//
1374// --DTLS on and SDES off
1375// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1376// set local/remote offer/answer with DTLS fingerprint --> success
1377// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1378// fingerprint --> failure
1379// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1380// --> failure
1381// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1382// --> failure
1383//
1384// --Encryption disabled: DTLS off and SDES off
1385// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1386// answer without SDES or DTLS --> success
1387// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1388// answer without SDES or DTLS --> success
1389//
1390
1391// Test that we return a failure when applying a remote/local offer that doesn't
1392// have cryptos enabled when DTLS is off.
1393TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001394 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001395 cricket::MediaSessionOptions options;
1396 options.has_video = true;
1397 JsepSessionDescription* offer = CreateRemoteOffer(
1398 options, cricket::SEC_DISABLED);
1399 ASSERT_TRUE(offer != NULL);
1400 VerifyNoCryptoParams(offer->description(), false);
1401 // SetRemoteDescription and SetLocalDescription will take the ownership of
1402 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001403 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001404 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1405 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001406 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001407}
1408
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001409// Test that we return a failure when applying a local answer that doesn't have
1410// cryptos enabled when DTLS is off.
1411TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001412 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001413 SessionDescriptionInterface* offer = NULL;
1414 SessionDescriptionInterface* answer = NULL;
1415 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1416 // SetRemoteDescription and SetLocalDescription will take the ownership of
1417 // the offer.
1418 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001419 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001420}
1421
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001422// Test we will return fail when apply an remote answer that doesn't have
1423// crypto enabled when DTLS is off.
1424TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001425 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001426 SessionDescriptionInterface* offer = NULL;
1427 SessionDescriptionInterface* answer = NULL;
1428 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1429 // SetRemoteDescription and SetLocalDescription will take the ownership of
1430 // the offer.
1431 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001432 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001433}
1434
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001435// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1436// and that we return an answer with a DTLS fingerprint.
1437TEST_F(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001438 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001439 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001440 InitWithDtls();
1441 SetFactoryDtlsSrtp();
1442 cricket::MediaSessionOptions options;
1443 options.has_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001444 JsepSessionDescription* offer =
1445 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001446 ASSERT_TRUE(offer != NULL);
1447 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001448 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001449
1450 // SetRemoteDescription will take the ownership of the offer.
1451 SetRemoteDescriptionWithoutError(offer);
1452
1453 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001454 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001455 ASSERT_TRUE(answer != NULL);
1456 VerifyFingerprintStatus(answer->description(), true);
1457 // Check that we don't have an a=crypto line in the answer.
1458 VerifyNoCryptoParams(answer->description(), true);
1459
1460 // Now set the local description, which should work, even without a=crypto.
1461 SetLocalDescriptionWithoutError(answer);
1462}
1463
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001464// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1465// and then we accept a remote answer with a DTLS fingerprint successfully.
1466TEST_F(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001467 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001468 mediastream_signaling_.SendAudioVideoStream1();
1469 InitWithDtls();
1470 SetFactoryDtlsSrtp();
1471
1472 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001473 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001474 ASSERT_TRUE(offer != NULL);
1475 VerifyFingerprintStatus(offer->description(), true);
1476 // Check that we don't have an a=crypto line in the offer.
1477 VerifyNoCryptoParams(offer->description(), true);
1478
1479 // Now set the local description, which should work, even without a=crypto.
1480 SetLocalDescriptionWithoutError(offer);
1481
1482 cricket::MediaSessionOptions options;
1483 options.has_video = true;
1484 JsepSessionDescription* answer =
1485 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1486 ASSERT_TRUE(answer != NULL);
1487 VerifyFingerprintStatus(answer->description(), true);
1488 VerifyNoCryptoParams(answer->description(), true);
1489
1490 // SetRemoteDescription will take the ownership of the answer.
1491 SetRemoteDescriptionWithoutError(answer);
1492}
1493
1494// Test that if we support DTLS and the other side didn't offer a fingerprint,
1495// we will fail to set the remote description.
1496TEST_F(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001497 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001498 InitWithDtls();
1499 cricket::MediaSessionOptions options;
1500 options.has_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001501 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001502 JsepSessionDescription* offer = CreateRemoteOffer(
1503 options, cricket::SEC_REQUIRED);
1504 ASSERT_TRUE(offer != NULL);
1505 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001506 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001507
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001508 // SetRemoteDescription will take the ownership of the offer.
1509 SetRemoteDescriptionOfferExpectError(
1510 kSdpWithoutDtlsFingerprint, offer);
1511
1512 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1513 // SetLocalDescription will take the ownership of the offer.
1514 SetLocalDescriptionOfferExpectError(
1515 kSdpWithoutDtlsFingerprint, offer);
1516}
1517
1518// Test that we return a failure when applying a local answer that doesn't have
1519// a DTLS fingerprint when DTLS is required.
1520TEST_F(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001521 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001522 InitWithDtls();
1523 SessionDescriptionInterface* offer = NULL;
1524 SessionDescriptionInterface* answer = NULL;
1525 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1526
1527 // SetRemoteDescription and SetLocalDescription will take the ownership of
1528 // the offer and answer.
1529 SetRemoteDescriptionWithoutError(offer);
1530 SetLocalDescriptionAnswerExpectError(
1531 kSdpWithoutDtlsFingerprint, answer);
1532}
1533
1534// Test that we return a failure when applying a remote answer that doesn't have
1535// a DTLS fingerprint when DTLS is required.
1536TEST_F(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001537 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001538 InitWithDtls();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001539 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001540 cricket::MediaSessionOptions options;
1541 options.has_video = true;
1542 JsepSessionDescription* answer =
1543 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
1544
1545 // SetRemoteDescription and SetLocalDescription will take the ownership of
1546 // the offer and answer.
1547 SetLocalDescriptionWithoutError(offer);
1548 SetRemoteDescriptionAnswerExpectError(
1549 kSdpWithoutDtlsFingerprint, answer);
1550}
1551
1552// Test that we create a local offer without SDES or DTLS and accept a remote
1553// answer without SDES or DTLS when encryption is disabled.
1554TEST_F(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
1555 mediastream_signaling_.SendAudioVideoStream1();
1556 options_.disable_encryption = true;
1557 InitWithDtls();
1558
1559 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001560 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001561 ASSERT_TRUE(offer != NULL);
1562 VerifyFingerprintStatus(offer->description(), false);
1563 // Check that we don't have an a=crypto line in the offer.
1564 VerifyNoCryptoParams(offer->description(), false);
1565
1566 // Now set the local description, which should work, even without a=crypto.
1567 SetLocalDescriptionWithoutError(offer);
1568
1569 cricket::MediaSessionOptions options;
1570 options.has_video = true;
1571 JsepSessionDescription* answer =
1572 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1573 ASSERT_TRUE(answer != NULL);
1574 VerifyFingerprintStatus(answer->description(), false);
1575 VerifyNoCryptoParams(answer->description(), false);
1576
1577 // SetRemoteDescription will take the ownership of the answer.
1578 SetRemoteDescriptionWithoutError(answer);
1579}
1580
1581// Test that we create a local answer without SDES or DTLS and accept a remote
1582// offer without SDES or DTLS when encryption is disabled.
1583TEST_F(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
1584 options_.disable_encryption = true;
1585 InitWithDtls();
1586
1587 cricket::MediaSessionOptions options;
1588 options.has_video = true;
1589 JsepSessionDescription* offer =
1590 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1591 ASSERT_TRUE(offer != NULL);
1592 VerifyFingerprintStatus(offer->description(), false);
1593 VerifyNoCryptoParams(offer->description(), false);
1594
1595 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001596 SetRemoteDescriptionWithoutError(offer);
1597
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001598 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001599 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001600 ASSERT_TRUE(answer != NULL);
1601 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001602 // Check that we don't have an a=crypto line in the answer.
1603 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001605 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001606 SetLocalDescriptionWithoutError(answer);
1607}
1608
1609TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001610 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001611 mediastream_signaling_.SendNothing();
1612 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001613 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001614 SetLocalDescriptionWithoutError(offer);
1615
1616 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001617 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001618 SetLocalDescriptionWithoutError(offer2);
1619}
1620
1621TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001622 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001623 mediastream_signaling_.SendNothing();
1624 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001625 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626 SetRemoteDescriptionWithoutError(offer);
1627
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001628 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001629 SetRemoteDescriptionWithoutError(offer2);
1630}
1631
1632TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001633 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001634 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001635 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001636 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001637 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001638 SetRemoteDescriptionOfferExpectError(
1639 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001640}
1641
1642TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001643 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001644 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001645 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001646 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001647 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001648 SetLocalDescriptionOfferExpectError(
1649 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001650}
1651
1652TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001653 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654 mediastream_signaling_.SendNothing();
1655 SessionDescriptionInterface* offer = CreateRemoteOffer();
1656 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1657
1658 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001659 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001660 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1661 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1662
1663 mediastream_signaling_.SendAudioVideoStream1();
1664 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001665 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001666 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1667
1668 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1669
1670 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001671 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001672 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1673}
1674
1675TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001676 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001677 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001678 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001679 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1680
1681 JsepSessionDescription* pranswer =
1682 CreateRemoteAnswer(session_->local_description());
1683 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1684
1685 SetRemoteDescriptionExpectState(pranswer,
1686 BaseSession::STATE_RECEIVEDPRACCEPT);
1687
1688 mediastream_signaling_.SendAudioVideoStream1();
1689 JsepSessionDescription* pranswer2 =
1690 CreateRemoteAnswer(session_->local_description());
1691 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1692
1693 SetRemoteDescriptionExpectState(pranswer2,
1694 BaseSession::STATE_RECEIVEDPRACCEPT);
1695
1696 mediastream_signaling_.SendAudioVideoStream2();
1697 SessionDescriptionInterface* answer =
1698 CreateRemoteAnswer(session_->local_description());
1699 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1700}
1701
1702TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001703 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001705 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1706
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001707 SessionDescriptionInterface* answer =
1708 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001709 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1710 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001711}
1712
1713TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001714 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001715 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001716 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1717
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001718 SessionDescriptionInterface* answer =
1719 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001720 SetRemoteDescriptionAnswerExpectError(
1721 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001722}
1723
1724TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001725 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001726 mediastream_signaling_.SendAudioVideoStream1();
1727
1728 cricket::Candidate candidate;
1729 candidate.set_component(1);
1730 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1731
1732 // Fail since we have not set a offer description.
1733 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1734
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001735 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001736 SetLocalDescriptionWithoutError(offer);
1737 // Candidate should be allowed to add before remote description.
1738 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1739 candidate.set_component(2);
1740 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1741 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1742
1743 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1744 session_->local_description());
1745 SetRemoteDescriptionWithoutError(answer);
1746
1747 // Verifying the candidates are copied properly from internal vector.
1748 const SessionDescriptionInterface* remote_desc =
1749 session_->remote_description();
1750 ASSERT_TRUE(remote_desc != NULL);
1751 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1752 const IceCandidateCollection* candidates =
1753 remote_desc->candidates(kMediaContentIndex0);
1754 ASSERT_EQ(2u, candidates->count());
1755 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1756 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1757 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1758 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1759
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001760 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1761 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001762 candidate.set_component(2);
1763 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1764 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001765 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001766
1767 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1768 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1769}
1770
1771// Test that a remote candidate is added to the remote session description and
1772// that it is retained if the remote session description is changed.
1773TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001774 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001775 cricket::Candidate candidate1;
1776 candidate1.set_component(1);
1777 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1778 candidate1);
1779 mediastream_signaling_.SendAudioVideoStream1();
1780 CreateAndSetRemoteOfferAndLocalAnswer();
1781
1782 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1783 const SessionDescriptionInterface* remote_desc =
1784 session_->remote_description();
1785 ASSERT_TRUE(remote_desc != NULL);
1786 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1787 const IceCandidateCollection* candidates =
1788 remote_desc->candidates(kMediaContentIndex0);
1789 ASSERT_EQ(1u, candidates->count());
1790 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1791
1792 // Update the RemoteSessionDescription with a new session description and
1793 // a candidate and check that the new remote session description contains both
1794 // candidates.
1795 SessionDescriptionInterface* offer = CreateRemoteOffer();
1796 cricket::Candidate candidate2;
1797 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1798 candidate2);
1799 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1800 SetRemoteDescriptionWithoutError(offer);
1801
1802 remote_desc = session_->remote_description();
1803 ASSERT_TRUE(remote_desc != NULL);
1804 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1805 candidates = remote_desc->candidates(kMediaContentIndex0);
1806 ASSERT_EQ(2u, candidates->count());
1807 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1808 // Username and password have be updated with the TransportInfo of the
1809 // SessionDescription, won't be equal to the original one.
1810 candidate2.set_username(candidates->at(0)->candidate().username());
1811 candidate2.set_password(candidates->at(0)->candidate().password());
1812 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
1813 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
1814 // No need to verify the username and password.
1815 candidate1.set_username(candidates->at(1)->candidate().username());
1816 candidate1.set_password(candidates->at(1)->candidate().password());
1817 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
1818
1819 // Test that the candidate is ignored if we can add the same candidate again.
1820 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1821}
1822
1823// Test that local candidates are added to the local session description and
1824// that they are retained if the local session description is changed.
1825TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001826 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001827 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001828 mediastream_signaling_.SendAudioVideoStream1();
1829 CreateAndSetRemoteOfferAndLocalAnswer();
1830
1831 const SessionDescriptionInterface* local_desc = session_->local_description();
1832 const IceCandidateCollection* candidates =
1833 local_desc->candidates(kMediaContentIndex0);
1834 ASSERT_TRUE(candidates != NULL);
1835 EXPECT_EQ(0u, candidates->count());
1836
1837 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1838
1839 local_desc = session_->local_description();
1840 candidates = local_desc->candidates(kMediaContentIndex0);
1841 ASSERT_TRUE(candidates != NULL);
1842 EXPECT_LT(0u, candidates->count());
1843 candidates = local_desc->candidates(1);
1844 ASSERT_TRUE(candidates != NULL);
1845 EXPECT_LT(0u, candidates->count());
1846
1847 // Update the session descriptions.
1848 mediastream_signaling_.SendAudioVideoStream1();
1849 CreateAndSetRemoteOfferAndLocalAnswer();
1850
1851 local_desc = session_->local_description();
1852 candidates = local_desc->candidates(kMediaContentIndex0);
1853 ASSERT_TRUE(candidates != NULL);
1854 EXPECT_LT(0u, candidates->count());
1855 candidates = local_desc->candidates(1);
1856 ASSERT_TRUE(candidates != NULL);
1857 EXPECT_LT(0u, candidates->count());
1858}
1859
1860// Test that we can set a remote session description with remote candidates.
1861TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001862 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001863
1864 cricket::Candidate candidate1;
1865 candidate1.set_component(1);
1866 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
1867 candidate1);
1868 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001869 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001870
1871 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
1872 SetRemoteDescriptionWithoutError(offer);
1873
1874 const SessionDescriptionInterface* remote_desc =
1875 session_->remote_description();
1876 ASSERT_TRUE(remote_desc != NULL);
1877 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1878 const IceCandidateCollection* candidates =
1879 remote_desc->candidates(kMediaContentIndex0);
1880 ASSERT_EQ(1u, candidates->count());
1881 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1882
wu@webrtc.org91053e72013-08-10 07:18:04 +00001883 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001884 SetLocalDescriptionWithoutError(answer);
1885}
1886
1887// Test that offers and answers contains ice candidates when Ice candidates have
1888// been gathered.
1889TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001890 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001891 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001892 mediastream_signaling_.SendAudioVideoStream1();
1893 // Ice is started but candidates are not provided until SetLocalDescription
1894 // is called.
1895 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1896 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1897 CreateAndSetRemoteOfferAndLocalAnswer();
1898 // Wait until at least one local candidate has been collected.
1899 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
1900 kIceCandidatesTimeout);
1901 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
1902 kIceCandidatesTimeout);
1903
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001904 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
1905
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001906 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
1907 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
1908 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
1909 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
1910
1911 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
1912 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001913 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001914 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
1915 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
1916 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
1917 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
1918 SetLocalDescriptionWithoutError(answer);
1919}
1920
1921// Verifies TransportProxy and media channels are created with content names
1922// present in the SessionDescription.
1923TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001924 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001925 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001926 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001927
1928 // CreateOffer creates session description with the content names "audio" and
1929 // "video". Goal is to modify these content names and verify transport channel
1930 // proxy in the BaseSession, as proxies are created with the content names
1931 // present in SDP.
1932 std::string sdp;
1933 EXPECT_TRUE(offer->ToString(&sdp));
1934 const std::string kAudioMid = "a=mid:audio";
1935 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
1936 const std::string kVideoMid = "a=mid:video";
1937 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
1938
1939 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001940 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001941 kAudioMidReplaceStr.c_str(),
1942 kAudioMidReplaceStr.length(),
1943 &sdp);
1944 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001945 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001946 kVideoMidReplaceStr.c_str(),
1947 kVideoMidReplaceStr.length(),
1948 &sdp);
1949
1950 SessionDescriptionInterface* modified_offer =
1951 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
1952
1953 SetRemoteDescriptionWithoutError(modified_offer);
1954
1955 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00001956 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001957 SetLocalDescriptionWithoutError(answer);
1958
1959 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
1960 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
1961 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
1962 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
1963}
1964
1965// Test that an offer contains the correct media content descriptions based on
1966// the send streams when no constraints have been set.
1967TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001968 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001969 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1970
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001971 ASSERT_TRUE(offer != NULL);
1972 const cricket::ContentInfo* content =
1973 cricket::GetFirstAudioContent(offer->description());
1974 EXPECT_TRUE(content != NULL);
1975 content = cricket::GetFirstVideoContent(offer->description());
1976 EXPECT_TRUE(content == NULL);
1977}
1978
1979// Test that an offer contains the correct media content descriptions based on
1980// the send streams when no constraints have been set.
1981TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001982 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001983 // Test Audio only offer.
1984 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001985 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1986
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001987 const cricket::ContentInfo* content =
1988 cricket::GetFirstAudioContent(offer->description());
1989 EXPECT_TRUE(content != NULL);
1990 content = cricket::GetFirstVideoContent(offer->description());
1991 EXPECT_TRUE(content == NULL);
1992
1993 // Test Audio / Video offer.
1994 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001995 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996 content = cricket::GetFirstAudioContent(offer->description());
1997 EXPECT_TRUE(content != NULL);
1998 content = cricket::GetFirstVideoContent(offer->description());
1999 EXPECT_TRUE(content != NULL);
2000}
2001
2002// Test that an offer contains no media content descriptions if
2003// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2004TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002005 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002006 PeerConnectionInterface::RTCOfferAnswerOptions options;
2007 options.offer_to_receive_audio = 0;
2008 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002009
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002010 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002011 CreateOffer(options));
2012
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002013 ASSERT_TRUE(offer != NULL);
2014 const cricket::ContentInfo* content =
2015 cricket::GetFirstAudioContent(offer->description());
2016 EXPECT_TRUE(content == NULL);
2017 content = cricket::GetFirstVideoContent(offer->description());
2018 EXPECT_TRUE(content == NULL);
2019}
2020
2021// Test that an offer contains only audio media content descriptions if
2022// kOfferToReceiveAudio constraints are set to true.
2023TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002024 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002025 PeerConnectionInterface::RTCOfferAnswerOptions options;
2026 options.offer_to_receive_audio =
2027 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2028
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002029 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002030 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031
2032 const cricket::ContentInfo* content =
2033 cricket::GetFirstAudioContent(offer->description());
2034 EXPECT_TRUE(content != NULL);
2035 content = cricket::GetFirstVideoContent(offer->description());
2036 EXPECT_TRUE(content == NULL);
2037}
2038
2039// Test that an offer contains audio and video media content descriptions if
2040// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2041TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002042 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002043 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002044 PeerConnectionInterface::RTCOfferAnswerOptions options;
2045 options.offer_to_receive_audio =
2046 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2047 options.offer_to_receive_video =
2048 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2049
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002050 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002051 CreateOffer(options));
2052
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002053 const cricket::ContentInfo* content =
2054 cricket::GetFirstAudioContent(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002055 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org52055a22014-09-04 17:12:25 +00002056
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002057 content = cricket::GetFirstVideoContent(offer->description());
2058 EXPECT_TRUE(content != NULL);
2059
jiayl@webrtc.org52055a22014-09-04 17:12:25 +00002060 // Sets constraints to false and verifies that audio/video contents are
2061 // removed.
2062 options.offer_to_receive_audio = 0;
2063 options.offer_to_receive_video = 0;
2064 offer.reset(CreateOffer(options));
2065
2066 content = cricket::GetFirstAudioContent(offer->description());
2067 EXPECT_TRUE(content == NULL);
2068 content = cricket::GetFirstVideoContent(offer->description());
2069 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002070}
2071
2072// Test that an answer can not be created if the last remote description is not
2073// an offer.
2074TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002075 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002076 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002077 SetLocalDescriptionWithoutError(offer);
2078 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2079 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002080 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002081}
2082
2083// Test that an answer contains the correct media content descriptions when no
2084// constraints have been set.
2085TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002086 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002087 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002088 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002089 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002090 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002091 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002092 const cricket::ContentInfo* content =
2093 cricket::GetFirstAudioContent(answer->description());
2094 ASSERT_TRUE(content != NULL);
2095 EXPECT_FALSE(content->rejected);
2096
2097 content = cricket::GetFirstVideoContent(answer->description());
2098 ASSERT_TRUE(content != NULL);
2099 EXPECT_FALSE(content->rejected);
2100}
2101
2102// Test that an answer contains the correct media content descriptions when no
2103// constraints have been set and the offer only contain audio.
2104TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002105 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002106 // Create a remote offer with audio only.
2107 cricket::MediaSessionOptions options;
jiayl@webrtc.org52055a22014-09-04 17:12:25 +00002108
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002109 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002110 CreateRemoteOffer(options));
2111 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2112 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2113
2114 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002115 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002116 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002117 const cricket::ContentInfo* content =
2118 cricket::GetFirstAudioContent(answer->description());
2119 ASSERT_TRUE(content != NULL);
2120 EXPECT_FALSE(content->rejected);
2121
2122 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2123}
2124
2125// Test that an answer contains the correct media content descriptions when no
2126// constraints have been set.
2127TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002128 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002130 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002131 SetRemoteDescriptionWithoutError(offer.release());
2132 // Test with a stream with tracks.
2133 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002134 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002135 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002136 const cricket::ContentInfo* content =
2137 cricket::GetFirstAudioContent(answer->description());
2138 ASSERT_TRUE(content != NULL);
2139 EXPECT_FALSE(content->rejected);
2140
2141 content = cricket::GetFirstVideoContent(answer->description());
2142 ASSERT_TRUE(content != NULL);
2143 EXPECT_FALSE(content->rejected);
2144}
2145
2146// Test that an answer contains the correct media content descriptions when
2147// constraints have been set but no stream is sent.
2148TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002149 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002150 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002151 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152 SetRemoteDescriptionWithoutError(offer.release());
2153
2154 webrtc::FakeConstraints constraints_no_receive;
2155 constraints_no_receive.SetMandatoryReceiveAudio(false);
2156 constraints_no_receive.SetMandatoryReceiveVideo(false);
2157
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002158 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002159 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002160 const cricket::ContentInfo* content =
2161 cricket::GetFirstAudioContent(answer->description());
2162 ASSERT_TRUE(content != NULL);
2163 EXPECT_TRUE(content->rejected);
2164
2165 content = cricket::GetFirstVideoContent(answer->description());
2166 ASSERT_TRUE(content != NULL);
2167 EXPECT_TRUE(content->rejected);
2168}
2169
2170// Test that an answer contains the correct media content descriptions when
2171// constraints have been set and streams are sent.
2172TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002173 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002174 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002175 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002176 SetRemoteDescriptionWithoutError(offer.release());
2177
2178 webrtc::FakeConstraints constraints_no_receive;
2179 constraints_no_receive.SetMandatoryReceiveAudio(false);
2180 constraints_no_receive.SetMandatoryReceiveVideo(false);
2181
2182 // Test with a stream with tracks.
2183 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002184 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002185 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002186
2187 // TODO(perkj): Should the direction be set to SEND_ONLY?
2188 const cricket::ContentInfo* content =
2189 cricket::GetFirstAudioContent(answer->description());
2190 ASSERT_TRUE(content != NULL);
2191 EXPECT_FALSE(content->rejected);
2192
2193 // TODO(perkj): Should the direction be set to SEND_ONLY?
2194 content = cricket::GetFirstVideoContent(answer->description());
2195 ASSERT_TRUE(content != NULL);
2196 EXPECT_FALSE(content->rejected);
2197}
2198
2199TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2200 AddCNCodecs();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002201 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002202 PeerConnectionInterface::RTCOfferAnswerOptions options;
2203 options.offer_to_receive_audio =
2204 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2205 options.voice_activity_detection = false;
2206
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002207 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002208 CreateOffer(options));
2209
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002210 const cricket::ContentInfo* content =
2211 cricket::GetFirstAudioContent(offer->description());
2212 EXPECT_TRUE(content != NULL);
2213 EXPECT_TRUE(VerifyNoCNCodecs(content));
2214}
2215
2216TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2217 AddCNCodecs();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002218 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002219 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002220 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002221 SetRemoteDescriptionWithoutError(offer.release());
2222
2223 webrtc::FakeConstraints constraints;
2224 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002225 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002226 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002227 const cricket::ContentInfo* content =
2228 cricket::GetFirstAudioContent(answer->description());
2229 ASSERT_TRUE(content != NULL);
2230 EXPECT_TRUE(VerifyNoCNCodecs(content));
2231}
2232
2233// This test verifies the call setup when remote answer with audio only and
2234// later updates with video.
2235TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002236 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002237 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2238 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2239
2240 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002241 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002242
2243 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002244 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2245
2246 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2247 // and answer;
2248 SetLocalDescriptionWithoutError(offer);
2249 SetRemoteDescriptionWithoutError(answer);
2250
2251 video_channel_ = media_engine_->GetVideoChannel(0);
2252 voice_channel_ = media_engine_->GetVoiceChannel(0);
2253
2254 ASSERT_TRUE(video_channel_ == NULL);
2255
2256 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2257 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2258 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2259
2260 // Let the remote end update the session descriptions, with Audio and Video.
2261 mediastream_signaling_.SendAudioVideoStream2();
2262 CreateAndSetRemoteOfferAndLocalAnswer();
2263
2264 video_channel_ = media_engine_->GetVideoChannel(0);
2265 voice_channel_ = media_engine_->GetVoiceChannel(0);
2266
2267 ASSERT_TRUE(video_channel_ != NULL);
2268 ASSERT_TRUE(voice_channel_ != NULL);
2269
2270 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2271 ASSERT_EQ(1u, video_channel_->send_streams().size());
2272 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2273 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2274 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2275 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2276 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2277 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2278
2279 // Change session back to audio only.
2280 mediastream_signaling_.UseOptionsAudioOnly();
2281 CreateAndSetRemoteOfferAndLocalAnswer();
2282
2283 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2284 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2285 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2286 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2287 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2288}
2289
2290// This test verifies the call setup when remote answer with video only and
2291// later updates with audio.
2292TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002293 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002294 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2295 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2296 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002297 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002298
2299 cricket::MediaSessionOptions options;
2300 options.has_audio = false;
2301 options.has_video = true;
2302 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2303 offer, options, cricket::SEC_ENABLED);
2304
2305 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2306 // and answer.
2307 SetLocalDescriptionWithoutError(offer);
2308 SetRemoteDescriptionWithoutError(answer);
2309
2310 video_channel_ = media_engine_->GetVideoChannel(0);
2311 voice_channel_ = media_engine_->GetVoiceChannel(0);
2312
2313 ASSERT_TRUE(voice_channel_ == NULL);
2314 ASSERT_TRUE(video_channel_ != NULL);
2315
2316 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2317 ASSERT_EQ(1u, video_channel_->send_streams().size());
2318 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2319
2320 // Update the session descriptions, with Audio and Video.
2321 mediastream_signaling_.SendAudioVideoStream2();
2322 CreateAndSetRemoteOfferAndLocalAnswer();
2323
2324 voice_channel_ = media_engine_->GetVoiceChannel(0);
2325 ASSERT_TRUE(voice_channel_ != NULL);
2326
2327 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2328 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2329 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2330 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2331
2332 // Change session back to video only.
2333 mediastream_signaling_.UseOptionsVideoOnly();
2334 CreateAndSetRemoteOfferAndLocalAnswer();
2335
2336 video_channel_ = media_engine_->GetVideoChannel(0);
2337 voice_channel_ = media_engine_->GetVoiceChannel(0);
2338
2339 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2340 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2341 ASSERT_EQ(1u, video_channel_->send_streams().size());
2342 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2343}
2344
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002345TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002346 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002347 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002348 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002349 VerifyCryptoParams(offer->description());
2350 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002351 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002352 VerifyCryptoParams(answer->description());
2353}
2354
2355TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002356 options_.disable_encryption = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00002357 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002358 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002359 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002360 VerifyNoCryptoParams(offer->description(), false);
2361}
2362
2363TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002364 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002365 VerifyAnswerFromNonCryptoOffer();
2366}
2367
2368TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002369 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002370 VerifyAnswerFromCryptoOffer();
2371}
2372
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002373// This test verifies that setLocalDescription fails if
2374// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2375TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
2376 Init(NULL);
2377 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002378 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2379
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002380 std::string sdp;
2381 RemoveIceUfragPwdLines(offer.get(), &sdp);
2382 SessionDescriptionInterface* modified_offer =
2383 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002384 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002385}
2386
2387// This test verifies that setRemoteDescription fails if
2388// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2389TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
2390 Init(NULL);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002391 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002392 std::string sdp;
2393 RemoveIceUfragPwdLines(offer.get(), &sdp);
2394 SessionDescriptionInterface* modified_offer =
2395 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002396 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002397}
2398
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002399// This test verifies that setLocalDescription fails if local offer has
2400// too short ice ufrag and pwd strings.
2401TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
2402 Init(NULL);
2403 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
2404 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002405 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2406
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002407 std::string sdp;
2408 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2409 // recommended values of 4 and 22 bytes respectively.
2410 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2411 SessionDescriptionInterface* modified_offer =
2412 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2413 std::string error;
2414 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2415
2416 // Test with string greater than 256.
2417 sdp.clear();
2418 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2419 &sdp);
2420 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2421 NULL);
2422 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2423}
2424
2425// This test verifies that setRemoteDescription fails if remote offer has
2426// too short ice ufrag and pwd strings.
2427TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
2428 Init(NULL);
2429 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002430 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002431 std::string sdp;
2432 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2433 // recommended values of 4 and 22 bytes respectively.
2434 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2435 SessionDescriptionInterface* modified_offer =
2436 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2437 std::string error;
2438 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2439
2440 sdp.clear();
2441 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2442 &sdp);
2443 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2444 NULL);
2445 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2446}
2447
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002448TEST_F(WebRtcSessionTest, VerifyBundleFlagInPA) {
2449 // This test verifies BUNDLE flag in PortAllocator, if BUNDLE information in
2450 // local description is removed by the application, BUNDLE flag should be
2451 // disabled in PortAllocator. By default BUNDLE is enabled in the WebRtc.
wu@webrtc.org91053e72013-08-10 07:18:04 +00002452 Init(NULL);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002453 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2454 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002455 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2456
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002457 cricket::SessionDescription* offer_copy =
2458 offer->description()->Copy();
2459 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2460 JsepSessionDescription* modified_offer =
2461 new JsepSessionDescription(JsepSessionDescription::kOffer);
2462 modified_offer->Initialize(offer_copy, "1", "1");
2463
2464 SetLocalDescriptionWithoutError(modified_offer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002465 EXPECT_FALSE(allocator_->flags() & cricket::PORTALLOCATOR_ENABLE_BUNDLE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002466}
2467
2468TEST_F(WebRtcSessionTest, TestDisabledBundleInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002469 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002470 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002471 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2472 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002473
2474 PeerConnectionInterface::RTCOfferAnswerOptions options;
2475 options.use_rtp_mux = true;
2476
2477 SessionDescriptionInterface* offer = CreateOffer(options);
2478
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002479 SetLocalDescriptionWithoutError(offer);
2480 mediastream_signaling_.SendAudioVideoStream2();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002481 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002482 CreateRemoteAnswer(session_->local_description()));
2483 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2484 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2485 JsepSessionDescription* modified_answer =
2486 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2487 modified_answer->Initialize(answer_copy, "1", "1");
2488 SetRemoteDescriptionWithoutError(modified_answer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002489 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2490 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002491
2492 video_channel_ = media_engine_->GetVideoChannel(0);
2493 voice_channel_ = media_engine_->GetVoiceChannel(0);
2494
2495 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2496 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
2497
2498 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2499 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
2500
2501 ASSERT_EQ(1u, video_channel_->send_streams().size());
2502 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
2503 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2504 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
2505}
2506
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002507// This test verifies that SetLocalDescription and SetRemoteDescription fails
2508// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2509TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002510 WebRtcSessionTest::Init(NULL);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002511 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002512 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2513 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002514
2515 PeerConnectionInterface::RTCOfferAnswerOptions options;
2516 options.use_rtp_mux = true;
2517
2518 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002519 std::string offer_str;
2520 offer->ToString(&offer_str);
2521 // Disable rtcp-mux
2522 const std::string rtcp_mux = "rtcp-mux";
2523 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002524 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002525 xrtcp_mux.c_str(), xrtcp_mux.length(),
2526 &offer_str);
2527 JsepSessionDescription *local_offer =
2528 new JsepSessionDescription(JsepSessionDescription::kOffer);
2529 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002530 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002531 JsepSessionDescription *remote_offer =
2532 new JsepSessionDescription(JsepSessionDescription::kOffer);
2533 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002534 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002535 // Trying unmodified SDP.
2536 SetLocalDescriptionWithoutError(offer);
2537}
2538
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002539TEST_F(WebRtcSessionTest, SetAudioPlayout) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002540 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002541 mediastream_signaling_.SendAudioVideoStream1();
2542 CreateAndSetRemoteOfferAndLocalAnswer();
2543 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2544 ASSERT_TRUE(channel != NULL);
2545 ASSERT_EQ(1u, channel->recv_streams().size());
2546 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2547 double left_vol, right_vol;
2548 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2549 EXPECT_EQ(1, left_vol);
2550 EXPECT_EQ(1, right_vol);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002551 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002552 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002553 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2554 EXPECT_EQ(0, left_vol);
2555 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002556 EXPECT_EQ(0, renderer->channel_id());
2557 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002558 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2559 EXPECT_EQ(1, left_vol);
2560 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002561 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002562}
2563
2564TEST_F(WebRtcSessionTest, SetAudioSend) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002565 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002566 mediastream_signaling_.SendAudioVideoStream1();
2567 CreateAndSetRemoteOfferAndLocalAnswer();
2568 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2569 ASSERT_TRUE(channel != NULL);
2570 ASSERT_EQ(1u, channel->send_streams().size());
2571 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2572 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2573
2574 cricket::AudioOptions options;
2575 options.echo_cancellation.Set(true);
2576
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002577 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002578 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002579 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2580 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002581 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002582 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002583
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002584 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002585 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002586 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2587 bool value;
2588 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
2589 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002590 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002591 EXPECT_TRUE(renderer->sink() == NULL);
2592}
2593
2594TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
2595 Init(NULL);
2596 mediastream_signaling_.SendAudioVideoStream1();
2597 CreateAndSetRemoteOfferAndLocalAnswer();
2598 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2599 ASSERT_TRUE(channel != NULL);
2600 ASSERT_EQ(1u, channel->send_streams().size());
2601 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2602
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002603 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002604 cricket::AudioOptions options;
2605 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
2606 EXPECT_TRUE(renderer->sink() != NULL);
2607
2608 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
2609 // will invalidate the |renderer_| pointer in the sink and prevent getting a
2610 // SetSink(NULL) callback afterwards.
2611 renderer.reset();
2612
2613 // This will trigger SetSink(NULL) if no OnClose() callback.
2614 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002615}
2616
2617TEST_F(WebRtcSessionTest, SetVideoPlayout) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002618 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002619 mediastream_signaling_.SendAudioVideoStream1();
2620 CreateAndSetRemoteOfferAndLocalAnswer();
2621 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2622 ASSERT_TRUE(channel != NULL);
2623 ASSERT_LT(0u, channel->renderers().size());
2624 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2625 ASSERT_EQ(1u, channel->recv_streams().size());
2626 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2627 cricket::FakeVideoRenderer renderer;
2628 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
2629 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
2630 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
2631 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2632}
2633
2634TEST_F(WebRtcSessionTest, SetVideoSend) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002635 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002636 mediastream_signaling_.SendAudioVideoStream1();
2637 CreateAndSetRemoteOfferAndLocalAnswer();
2638 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2639 ASSERT_TRUE(channel != NULL);
2640 ASSERT_EQ(1u, channel->send_streams().size());
2641 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2642 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2643 cricket::VideoOptions* options = NULL;
2644 session_->SetVideoSend(send_ssrc, false, options);
2645 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2646 session_->SetVideoSend(send_ssrc, true, options);
2647 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2648}
2649
2650TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
2651 TestCanInsertDtmf(false);
2652}
2653
2654TEST_F(WebRtcSessionTest, CanInsertDtmf) {
2655 TestCanInsertDtmf(true);
2656}
2657
2658TEST_F(WebRtcSessionTest, InsertDtmf) {
2659 // Setup
wu@webrtc.org91053e72013-08-10 07:18:04 +00002660 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002661 mediastream_signaling_.SendAudioVideoStream1();
2662 CreateAndSetRemoteOfferAndLocalAnswer();
2663 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2664 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
2665
2666 // Insert DTMF
2667 const int expected_flags = DF_SEND;
2668 const int expected_duration = 90;
2669 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
2670 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
2671 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
2672
2673 // Verify
2674 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
2675 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2676 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
2677 expected_duration, expected_flags));
2678 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
2679 expected_duration, expected_flags));
2680 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
2681 expected_duration, expected_flags));
2682}
2683
2684// This test verifies the |initiator| flag when session initiates the call.
2685TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002686 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002687 EXPECT_FALSE(session_->initiator());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002688 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002689 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2690 SetLocalDescriptionWithoutError(offer);
2691 EXPECT_TRUE(session_->initiator());
2692 SetRemoteDescriptionWithoutError(answer);
2693 EXPECT_TRUE(session_->initiator());
2694}
2695
2696// This test verifies the |initiator| flag when session receives the call.
2697TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002698 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002699 EXPECT_FALSE(session_->initiator());
2700 SessionDescriptionInterface* offer = CreateRemoteOffer();
2701 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002702 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002703
2704 EXPECT_FALSE(session_->initiator());
2705 SetLocalDescriptionWithoutError(answer);
2706 EXPECT_FALSE(session_->initiator());
2707}
2708
2709// This test verifies the ice protocol type at initiator of the call
2710// if |a=ice-options:google-ice| is present in answer.
2711TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002712 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002713 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002714 SessionDescriptionInterface* offer = CreateOffer();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002715 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002716 CreateRemoteAnswer(offer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002717 SetLocalDescriptionWithoutError(offer);
2718 std::string sdp;
2719 EXPECT_TRUE(answer->ToString(&sdp));
2720 // Adding ice-options to the session level.
2721 InjectAfter("t=0 0\r\n",
2722 "a=ice-options:google-ice\r\n",
2723 &sdp);
2724 SessionDescriptionInterface* answer_with_gice =
2725 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2726 SetRemoteDescriptionWithoutError(answer_with_gice);
2727 VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE);
2728 VerifyTransportType("video", cricket::ICEPROTO_GOOGLE);
2729}
2730
2731// This test verifies the ice protocol type at initiator of the call
2732// if ICE RFC5245 is supported in answer.
2733TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002734 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002735 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002736 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002737 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2738 SetLocalDescriptionWithoutError(offer);
2739
2740 SetRemoteDescriptionWithoutError(answer);
2741 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2742 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2743}
2744
2745// This test verifies the ice protocol type at receiver side of the call if
2746// receiver decides to use google-ice.
2747TEST_F(WebRtcSessionTest, TestReceiverGIceInOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002748 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002749 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002750 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002751 SetRemoteDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002752 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002753 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002754 std::string sdp;
2755 EXPECT_TRUE(answer->ToString(&sdp));
2756 // Adding ice-options to the session level.
2757 InjectAfter("t=0 0\r\n",
2758 "a=ice-options:google-ice\r\n",
2759 &sdp);
2760 SessionDescriptionInterface* answer_with_gice =
2761 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2762 SetLocalDescriptionWithoutError(answer_with_gice);
2763 VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE);
2764 VerifyTransportType("video", cricket::ICEPROTO_GOOGLE);
2765}
2766
2767// This test verifies the ice protocol type at receiver side of the call if
2768// receiver decides to use ice RFC 5245.
2769TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002770 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002771 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002772 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002773 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002774 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002775 SetLocalDescriptionWithoutError(answer);
2776 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2777 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2778}
2779
2780// This test verifies the session state when ICE RFC5245 in offer and
2781// ICE google-ice in answer.
2782TEST_F(WebRtcSessionTest, TestIceOfferGIceOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002783 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002784 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002785 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2786
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002787 std::string offer_str;
2788 offer->ToString(&offer_str);
2789 // Disable google-ice
2790 const std::string gice_option = "google-ice";
2791 const std::string xgoogle_xice = "xgoogle-xice";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002792 rtc::replace_substrs(gice_option.c_str(), gice_option.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002793 xgoogle_xice.c_str(), xgoogle_xice.length(),
2794 &offer_str);
2795 JsepSessionDescription *ice_only_offer =
2796 new JsepSessionDescription(JsepSessionDescription::kOffer);
2797 EXPECT_TRUE((ice_only_offer)->Initialize(offer_str, NULL));
2798 SetLocalDescriptionWithoutError(ice_only_offer);
2799 std::string original_offer_sdp;
2800 EXPECT_TRUE(offer->ToString(&original_offer_sdp));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002801 SessionDescriptionInterface* pranswer_with_gice =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002802 CreateSessionDescription(JsepSessionDescription::kPrAnswer,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002803 original_offer_sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002804 SetRemoteDescriptionPranswerExpectError(kPushDownTDFailed,
2805 pranswer_with_gice);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002806 SessionDescriptionInterface* answer_with_gice =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002807 CreateSessionDescription(JsepSessionDescription::kAnswer,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002808 original_offer_sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002809 SetRemoteDescriptionAnswerExpectError(kPushDownTDFailed,
2810 answer_with_gice);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002811}
2812
2813// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
2814TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002815 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002816 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002817 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002818 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002819 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002820 CreateRemoteAnswer(session_->local_description()));
2821
2822 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2823 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002824 JsepSessionDescription* modified_answer =
2825 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002826
2827 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2828 answer->session_id(),
2829 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002830 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002831
wu@webrtc.org4e393072014-04-07 17:04:35 +00002832 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002833 std::string sdp;
2834 EXPECT_TRUE(answer->ToString(&sdp));
2835 const std::string kAudioMid = "a=mid:audio";
2836 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002837 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002838 kAudioMidReplaceStr.c_str(),
2839 kAudioMidReplaceStr.length(),
2840 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002841 SessionDescriptionInterface* modified_answer1 =
2842 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002843 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002844
wu@webrtc.org4e393072014-04-07 17:04:35 +00002845 // Different media types.
2846 EXPECT_TRUE(answer->ToString(&sdp));
2847 const std::string kAudioMline = "m=audio";
2848 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002849 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00002850 kAudioMlineReplaceStr.c_str(),
2851 kAudioMlineReplaceStr.length(),
2852 &sdp);
2853 SessionDescriptionInterface* modified_answer2 =
2854 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2855 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
2856
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002857 SetRemoteDescriptionWithoutError(answer.release());
2858}
2859
2860// Verifying remote offer and local answer have matching m-lines as per
2861// RFC 3264.
2862TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002863 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002864 mediastream_signaling_.SendAudioVideoStream1();
2865 SessionDescriptionInterface* offer = CreateRemoteOffer();
2866 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002867 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002868
2869 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2870 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002871 JsepSessionDescription* modified_answer =
2872 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002873
2874 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2875 answer->session_id(),
2876 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002877 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002878 SetLocalDescriptionWithoutError(answer);
2879}
2880
2881// This test verifies that WebRtcSession does not start candidate allocation
2882// before SetLocalDescription is called.
2883TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002884 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002885 mediastream_signaling_.SendAudioVideoStream1();
2886 SessionDescriptionInterface* offer = CreateRemoteOffer();
2887 cricket::Candidate candidate;
2888 candidate.set_component(1);
2889 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2890 candidate);
2891 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2892 cricket::Candidate candidate1;
2893 candidate1.set_component(1);
2894 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2895 candidate1);
2896 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2897 SetRemoteDescriptionWithoutError(offer);
2898 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
2899 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
2900
2901 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002902 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002903 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
2904 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
2905
wu@webrtc.org91053e72013-08-10 07:18:04 +00002906 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002907 SetLocalDescriptionWithoutError(answer);
2908 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
2909 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
2910 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2911}
2912
2913// This test verifies that crypto parameter is updated in local session
2914// description as per security policy set in MediaSessionDescriptionFactory.
2915TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002916 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002917 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002918 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002919
2920 // Making sure SetLocalDescription correctly sets crypto value in
2921 // SessionDescription object after de-serialization of sdp string. The value
2922 // will be set as per MediaSessionDescriptionFactory.
2923 std::string offer_str;
2924 offer->ToString(&offer_str);
2925 SessionDescriptionInterface* jsep_offer_str =
2926 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
2927 SetLocalDescriptionWithoutError(jsep_offer_str);
2928 EXPECT_TRUE(session_->voice_channel()->secure_required());
2929 EXPECT_TRUE(session_->video_channel()->secure_required());
2930}
2931
2932// This test verifies the crypto parameter when security is disabled.
2933TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002934 options_.disable_encryption = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00002935 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002936 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002937 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002938
2939 // Making sure SetLocalDescription correctly sets crypto value in
2940 // SessionDescription object after de-serialization of sdp string. The value
2941 // will be set as per MediaSessionDescriptionFactory.
2942 std::string offer_str;
2943 offer->ToString(&offer_str);
2944 SessionDescriptionInterface *jsep_offer_str =
2945 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
2946 SetLocalDescriptionWithoutError(jsep_offer_str);
2947 EXPECT_FALSE(session_->voice_channel()->secure_required());
2948 EXPECT_FALSE(session_->video_channel()->secure_required());
2949}
2950
2951// This test verifies that an answer contains new ufrag and password if an offer
2952// with new ufrag and password is received.
2953TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002954 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002955 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002956 options.has_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002957 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002958 CreateRemoteOffer(options));
2959 SetRemoteDescriptionWithoutError(offer.release());
2960
2961 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002962 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002963 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002964 SetLocalDescriptionWithoutError(answer.release());
2965
2966 // Receive an offer with new ufrag and password.
2967 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002968 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002969 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002970 SetRemoteDescriptionWithoutError(updated_offer1.release());
2971
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002972 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002973 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002974
2975 CompareIceUfragAndPassword(updated_answer1->description(),
2976 session_->local_description()->description(),
2977 false);
2978
2979 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002980}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002981
wu@webrtc.org91053e72013-08-10 07:18:04 +00002982// This test verifies that an answer contains old ufrag and password if an offer
2983// with old ufrag and password is received.
2984TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
2985 Init(NULL);
2986 cricket::MediaSessionOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00002987 options.has_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002988 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002989 CreateRemoteOffer(options));
2990 SetRemoteDescriptionWithoutError(offer.release());
2991
2992 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002993 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002994 CreateAnswer(NULL));
2995 SetLocalDescriptionWithoutError(answer.release());
2996
2997 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002998 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002999 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003000 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003001 SetRemoteDescriptionWithoutError(updated_offer2.release());
3002
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003003 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003004 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003005
3006 CompareIceUfragAndPassword(updated_answer2->description(),
3007 session_->local_description()->description(),
3008 true);
3009
3010 SetLocalDescriptionWithoutError(updated_answer2.release());
3011}
3012
3013TEST_F(WebRtcSessionTest, TestSessionContentError) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00003014 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003015 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003016 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003017 const std::string session_id_orig = offer->session_id();
3018 const std::string session_version_orig = offer->session_version();
3019 SetLocalDescriptionWithoutError(offer);
3020
3021 video_channel_ = media_engine_->GetVideoChannel(0);
3022 video_channel_->set_fail_set_send_codecs(true);
3023
3024 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003025 SessionDescriptionInterface* answer =
3026 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003027 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003028}
3029
3030// Runs the loopback call test with BUNDLE and STUN disabled.
3031TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3032 // Lets try with only UDP ports.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00003033 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003034 cricket::PORTALLOCATOR_DISABLE_TCP |
3035 cricket::PORTALLOCATOR_DISABLE_STUN |
3036 cricket::PORTALLOCATOR_DISABLE_RELAY);
3037 TestLoopbackCall();
3038}
3039
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003040// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003041TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00003042 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003043 cricket::PORTALLOCATOR_ENABLE_BUNDLE |
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003044 cricket::PORTALLOCATOR_DISABLE_TCP |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003045 cricket::PORTALLOCATOR_DISABLE_RELAY);
3046 TestLoopbackCall();
3047}
3048
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003049TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00003050 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003051 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003052 options.has_video = true;
3053
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003054 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
3055 std::string error_code_str = "ERROR_CONTENT";
3056 std::string error_desc = "Fake session error description.";
3057 session_->SetError(error_code, error_desc);
3058
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003059 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
3060 SessionDescriptionInterface* answer =
3061 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003062
3063 std::string action;
3064 std::ostringstream session_error_msg;
3065 session_error_msg << kSessionError << error_code_str << ". ";
3066 session_error_msg << kSessionErrorDesc << error_desc << ".";
3067 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
3068 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003069}
3070
3071TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3072 constraints_.reset(new FakeConstraints());
3073 constraints_->AddOptional(
3074 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003075 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003076
3077 SetLocalDescriptionWithDataChannel();
3078 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3079}
3080
3081TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003082 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003083
3084 constraints_.reset(new FakeConstraints());
3085 constraints_->AddOptional(
3086 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003087 options_.disable_sctp_data_channels = false;
3088
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003089 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003090
3091 SetLocalDescriptionWithDataChannel();
3092 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3093}
3094
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003095TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003096 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003097
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003098 InitWithDtls();
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003099
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003100 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003101 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003102 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3103}
3104
3105TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003106 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003107 SetFactoryDtlsSrtp();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003108 InitWithDtls();
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003109
3110 // Create remote offer with SCTP.
3111 cricket::MediaSessionOptions options;
3112 options.data_channel_type = cricket::DCT_SCTP;
3113 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003114 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003115 SetRemoteDescriptionWithoutError(offer);
3116
3117 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003118 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003119 EXPECT_TRUE(answer != NULL);
3120 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3121 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003122}
3123
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003124TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
3125 constraints_.reset(new FakeConstraints());
3126 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003127 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003128 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003129
3130 SetLocalDescriptionWithDataChannel();
3131 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3132}
3133
3134TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003135 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003136
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003137 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003138
3139 SetLocalDescriptionWithDataChannel();
3140 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3141}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003142
wu@webrtc.org97077a32013-10-25 21:18:33 +00003143TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003144 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003145 options_.disable_sctp_data_channels = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003146 InitWithDtls();
wu@webrtc.org97077a32013-10-25 21:18:33 +00003147
3148 SetLocalDescriptionWithDataChannel();
3149 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3150}
3151
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003152TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003153 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003154 const int new_send_port = 9998;
3155 const int new_recv_port = 7775;
3156
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003157 InitWithDtls();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003158 SetFactoryDtlsSrtp();
3159
3160 // By default, don't actually add the codecs to desc_factory_; they don't
3161 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3162 // let the session description get parsed. That'll get the proper codecs
3163 // into the stream.
3164 cricket::MediaSessionOptions options;
3165 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3166 "stream1", new_send_port, options);
3167
3168 // SetRemoteDescription will take the ownership of the offer.
3169 SetRemoteDescriptionWithoutError(offer);
3170
3171 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3172 new_recv_port, CreateAnswer(NULL));
3173 ASSERT_TRUE(answer != NULL);
3174
3175 // Now set the local description, which'll take ownership of the answer.
3176 SetLocalDescriptionWithoutError(answer);
3177
3178 // TEST PLAN: Set the port number to something new, set it in the SDP,
3179 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003180 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003181 dci.reliable = true;
3182 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003183 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003184 session_->CreateDataChannel("datachannel", &dci);
3185
3186 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3187 int portnum = -1;
3188 ASSERT_TRUE(ch != NULL);
3189 ASSERT_EQ(1UL, ch->send_codecs().size());
3190 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
3191 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3192 ch->send_codecs()[0].name.c_str()));
3193 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3194 &portnum));
3195 EXPECT_EQ(new_send_port, portnum);
3196
3197 ASSERT_EQ(1UL, ch->recv_codecs().size());
3198 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
3199 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3200 ch->recv_codecs()[0].name.c_str()));
3201 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3202 &portnum));
3203 EXPECT_EQ(new_recv_port, portnum);
3204}
3205
wu@webrtc.org91053e72013-08-10 07:18:04 +00003206// Verifies that CreateOffer succeeds when CreateOffer is called before async
3207// identity generation is finished.
3208TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003209 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003210 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003211
3212 EXPECT_TRUE(session_->waiting_for_identity());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003213 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003214 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3215
wu@webrtc.org91053e72013-08-10 07:18:04 +00003216 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003217 VerifyNoCryptoParams(offer->description(), true);
3218 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003219}
3220
3221// Verifies that CreateAnswer succeeds when CreateOffer is called before async
3222// identity generation is finished.
3223TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003224 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003225 InitWithDtls();
3226 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003227
3228 cricket::MediaSessionOptions options;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003229 options.has_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003230 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003231 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003232 ASSERT_TRUE(offer.get() != NULL);
3233 SetRemoteDescriptionWithoutError(offer.release());
3234
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003235 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003236 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003237 VerifyNoCryptoParams(answer->description(), true);
3238 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003239}
3240
3241// Verifies that CreateOffer succeeds when CreateOffer is called after async
3242// identity generation is finished.
3243TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003244 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003245 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003246
3247 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003248
3249 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003250 EXPECT_TRUE(offer != NULL);
3251}
3252
3253// Verifies that CreateOffer fails when CreateOffer is called after async
3254// identity generation fails.
3255TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003256 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00003257 InitWithDtls(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003258
3259 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003260
3261 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003262 EXPECT_TRUE(offer == NULL);
3263}
3264
3265// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3266// before async identity generation is finished.
3267TEST_F(WebRtcSessionTest,
3268 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003269 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003270 VerifyMultipleAsyncCreateDescription(
3271 true, CreateSessionDescriptionRequest::kOffer);
3272}
3273
3274// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3275// before async identity generation fails.
3276TEST_F(WebRtcSessionTest,
3277 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003278 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003279 VerifyMultipleAsyncCreateDescription(
3280 false, CreateSessionDescriptionRequest::kOffer);
3281}
3282
3283// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3284// before async identity generation is finished.
3285TEST_F(WebRtcSessionTest,
3286 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003287 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003288 VerifyMultipleAsyncCreateDescription(
3289 true, CreateSessionDescriptionRequest::kAnswer);
3290}
3291
3292// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3293// before async identity generation fails.
3294TEST_F(WebRtcSessionTest,
3295 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003296 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003297 VerifyMultipleAsyncCreateDescription(
3298 false, CreateSessionDescriptionRequest::kAnswer);
3299}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003300
3301// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3302// offer has no SDES crypto but only DTLS fingerprint.
3303TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3304 // Init without DTLS.
3305 Init(NULL);
3306 // Create a remote offer with secured transport disabled.
3307 cricket::MediaSessionOptions options;
3308 JsepSessionDescription* offer(CreateRemoteOffer(
3309 options, cricket::SEC_DISABLED));
3310 // Adds a DTLS fingerprint to the remote offer.
3311 cricket::SessionDescription* sdp = offer->description();
3312 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3313 ASSERT_TRUE(audio != NULL);
3314 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3315 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003316 rtc::SSLFingerprint::CreateFromRfc4572(
3317 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003318 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003319 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003320}
3321
wu@webrtc.orgde305012013-10-31 15:40:38 +00003322// This test verifies DSCP is properly applied on the media channels.
3323TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3324 constraints_.reset(new FakeConstraints());
3325 constraints_->AddOptional(
3326 webrtc::MediaConstraintsInterface::kEnableDscp, true);
3327 Init(NULL);
3328 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003329 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003330
3331 SetLocalDescriptionWithoutError(offer);
3332
3333 video_channel_ = media_engine_->GetVideoChannel(0);
3334 voice_channel_ = media_engine_->GetVoiceChannel(0);
3335
3336 ASSERT_TRUE(video_channel_ != NULL);
3337 ASSERT_TRUE(voice_channel_ != NULL);
3338 cricket::AudioOptions audio_options;
3339 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3340 cricket::VideoOptions video_options;
3341 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3342 EXPECT_TRUE(audio_options.dscp.IsSet());
3343 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3344 EXPECT_TRUE(video_options.dscp.IsSet());
3345 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3346}
3347
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003348TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3349 constraints_.reset(new FakeConstraints());
3350 constraints_->AddOptional(
3351 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3352 true);
3353 Init(NULL);
3354 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003355 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003356
3357 SetLocalDescriptionWithoutError(offer);
3358
3359 video_channel_ = media_engine_->GetVideoChannel(0);
3360
3361 ASSERT_TRUE(video_channel_ != NULL);
3362 cricket::VideoOptions video_options;
3363 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3364 EXPECT_TRUE(
3365 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3366}
3367
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00003368TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
3369 // Number of unsignalled receiving streams should be between 0 and
3370 // kMaxUnsignalledRecvStreams.
3371 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
3372 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
3373 kMaxUnsignalledRecvStreams);
3374 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
3375}
3376
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003377TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
3378 constraints_.reset(new FakeConstraints());
3379 constraints_->AddOptional(
3380 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
3381 true);
3382 Init(NULL);
3383 mediastream_signaling_.SendAudioVideoStream1();
3384 SessionDescriptionInterface* offer = CreateOffer();
3385
3386 SetLocalDescriptionWithoutError(offer);
3387
3388 voice_channel_ = media_engine_->GetVoiceChannel(0);
3389
3390 ASSERT_TRUE(voice_channel_ != NULL);
3391 cricket::AudioOptions audio_options;
3392 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3393 EXPECT_TRUE(
3394 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
3395}
3396
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003397// Tests that we can renegotiate new media content with ICE candidates in the
3398// new remote SDP.
3399TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003400 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003401 InitWithDtls();
3402 SetFactoryDtlsSrtp();
3403
3404 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003405 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003406 SetLocalDescriptionWithoutError(offer);
3407
3408 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3409 SetRemoteDescriptionWithoutError(answer);
3410
3411 cricket::MediaSessionOptions options;
3412 options.has_video = true;
3413 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3414
3415 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003416 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003417 candidate1.set_component(1);
3418 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3419 candidate1);
3420 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3421 SetRemoteDescriptionWithoutError(offer);
3422
3423 answer = CreateAnswer(NULL);
3424 SetLocalDescriptionWithoutError(answer);
3425}
3426
3427// Tests that we can renegotiate new media content with ICE candidates separated
3428// from the remote SDP.
3429TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003430 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003431 InitWithDtls();
3432 SetFactoryDtlsSrtp();
3433
3434 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003435 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003436 SetLocalDescriptionWithoutError(offer);
3437
3438 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3439 SetRemoteDescriptionWithoutError(answer);
3440
3441 cricket::MediaSessionOptions options;
3442 options.has_video = true;
3443 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3444 SetRemoteDescriptionWithoutError(offer);
3445
3446 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003447 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003448 candidate1.set_component(1);
3449 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3450 candidate1);
3451 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3452
3453 answer = CreateAnswer(NULL);
3454 SetLocalDescriptionWithoutError(answer);
3455}
3456
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003457// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
3458// currently fails because upon disconnection and reconnection OnIceComplete is
3459// called more than once without returning to IceGatheringGathering.