blob: d3480a09bb840343b7c0721fe6dd0f5a9d068797 [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"
henrike@webrtc.org28100cb2014-10-17 22:03:39 +000043#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"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000047#include "talk/session/media/channelmanager.h"
48#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000049#include "webrtc/base/fakenetwork.h"
50#include "webrtc/base/firewallsocketserver.h"
51#include "webrtc/base/gunit.h"
52#include "webrtc/base/logging.h"
53#include "webrtc/base/network.h"
54#include "webrtc/base/physicalsocketserver.h"
55#include "webrtc/base/ssladapter.h"
56#include "webrtc/base/sslstreamadapter.h"
57#include "webrtc/base/stringutils.h"
58#include "webrtc/base/thread.h"
59#include "webrtc/base/virtualsocketserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060
61#define MAYBE_SKIP_TEST(feature) \
62 if (!(feature())) { \
63 LOG(LS_INFO) << "Feature disabled... skipping"; \
64 return; \
65 }
66
67using cricket::BaseSession;
68using cricket::DF_PLAY;
69using cricket::DF_SEND;
70using cricket::FakeVoiceMediaChannel;
71using cricket::NS_GINGLE_P2P;
72using cricket::NS_JINGLE_ICE_UDP;
73using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000074using rtc::SocketAddress;
75using rtc::scoped_ptr;
76using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000078using webrtc::CreateSessionDescriptionObserver;
79using webrtc::CreateSessionDescriptionRequest;
80using webrtc::DTLSIdentityRequestObserver;
81using webrtc::DTLSIdentityServiceInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082using webrtc::FakeConstraints;
83using webrtc::IceCandidateCollection;
84using webrtc::JsepIceCandidate;
85using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000086using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087using webrtc::PeerConnectionInterface;
88using webrtc::SessionDescriptionInterface;
89using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000090using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000091using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000092using webrtc::kCreateChannelFailed;
93using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000095using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000096using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000097using webrtc::kSdpWithoutDtlsFingerprint;
98using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000100using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000101using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000103typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
104
wu@webrtc.org364f2042013-11-20 21:49:41 +0000105static const int kClientAddrPort = 0;
106static const char kClientAddrHost1[] = "11.11.11.11";
107static const char kClientAddrHost2[] = "22.22.22.22";
108static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000109static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
110static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000111static const char kTurnUsername[] = "test";
112static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000113
114static const char kSessionVersion[] = "1";
115
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116// Media index of candidates belonging to the first media content.
117static const int kMediaContentIndex0 = 0;
118static const char kMediaContentName0[] = "audio";
119
120// Media index of candidates belonging to the second media content.
121static const int kMediaContentIndex1 = 1;
122static const char kMediaContentName1[] = "video";
123
124static const int kIceCandidatesTimeout = 10000;
125
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000126static const char kFakeDtlsFingerprint[] =
127 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
128 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
129
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000130static const char kTooLongIceUfragPwd[] =
131 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
132 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
133 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
134 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
135
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000136// Add some extra |newlines| to the |message| after |line|.
137static void InjectAfter(const std::string& line,
138 const std::string& newlines,
139 std::string* message) {
140 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000141 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000142 tmp.c_str(), tmp.length(), message);
143}
144
145class MockIceObserver : public webrtc::IceObserver {
146 public:
147 MockIceObserver()
148 : oncandidatesready_(false),
149 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
150 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
151 }
152
153 virtual void OnIceConnectionChange(
154 PeerConnectionInterface::IceConnectionState new_state) {
155 ice_connection_state_ = new_state;
156 }
157 virtual void OnIceGatheringChange(
158 PeerConnectionInterface::IceGatheringState new_state) {
159 // We can never transition back to "new".
160 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
161 ice_gathering_state_ = new_state;
162
163 // oncandidatesready_ really means "ICE gathering is complete".
164 // This if statement ensures that this value remains correct when we
165 // transition from kIceGatheringComplete to kIceGatheringGathering.
166 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
167 oncandidatesready_ = false;
168 }
169 }
170
171 // Found a new candidate.
172 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000173 switch (candidate->sdp_mline_index()) {
174 case kMediaContentIndex0:
175 mline_0_candidates_.push_back(candidate->candidate());
176 break;
177 case kMediaContentIndex1:
178 mline_1_candidates_.push_back(candidate->candidate());
179 break;
180 default:
181 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000182 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000183
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000184 // The ICE gathering state should always be Gathering when a candidate is
185 // received (or possibly Completed in the case of the final candidate).
186 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
187 }
188
189 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
190 virtual void OnIceComplete() {
191 EXPECT_FALSE(oncandidatesready_);
192 oncandidatesready_ = true;
193
194 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
195 // be called approximately simultaneously. For ease of testing, this
196 // check additionally requires that they be called in the above order.
197 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
198 ice_gathering_state_);
199 }
200
201 bool oncandidatesready_;
202 std::vector<cricket::Candidate> mline_0_candidates_;
203 std::vector<cricket::Candidate> mline_1_candidates_;
204 PeerConnectionInterface::IceConnectionState ice_connection_state_;
205 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
206};
207
208class WebRtcSessionForTest : public webrtc::WebRtcSession {
209 public:
210 WebRtcSessionForTest(cricket::ChannelManager* cmgr,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000211 rtc::Thread* signaling_thread,
212 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000213 cricket::PortAllocator* port_allocator,
214 webrtc::IceObserver* ice_observer,
215 webrtc::MediaStreamSignaling* mediastream_signaling)
216 : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator,
217 mediastream_signaling) {
218 RegisterIceObserver(ice_observer);
219 }
220 virtual ~WebRtcSessionForTest() {}
221
222 using cricket::BaseSession::GetTransportProxy;
223 using webrtc::WebRtcSession::SetAudioPlayout;
224 using webrtc::WebRtcSession::SetAudioSend;
225 using webrtc::WebRtcSession::SetCaptureDevice;
226 using webrtc::WebRtcSession::SetVideoPlayout;
227 using webrtc::WebRtcSession::SetVideoSend;
228};
229
wu@webrtc.org91053e72013-08-10 07:18:04 +0000230class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000231 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000232 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000233 enum State {
234 kInit,
235 kFailed,
236 kSucceeded,
237 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000238 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000239
240 // CreateSessionDescriptionObserver implementation.
241 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000242 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000243 state_ = kSucceeded;
244 }
245 virtual void OnFailure(const std::string& error) {
246 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000247 }
248
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000249 SessionDescriptionInterface* description() { return description_.get(); }
250
251 SessionDescriptionInterface* ReleaseDescription() {
252 return description_.release();
253 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000254
wu@webrtc.org91053e72013-08-10 07:18:04 +0000255 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256
wu@webrtc.org91053e72013-08-10 07:18:04 +0000257 protected:
258 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000259
260 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000261 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000262 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000263};
264
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000265class FakeAudioRenderer : public cricket::AudioRenderer {
266 public:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000267 FakeAudioRenderer() : channel_id_(-1), sink_(NULL) {}
268 virtual ~FakeAudioRenderer() {
269 if (sink_)
270 sink_->OnClose();
271 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000272
273 virtual void AddChannel(int channel_id) OVERRIDE {
274 ASSERT(channel_id_ == -1);
275 channel_id_ = channel_id;
276 }
277 virtual void RemoveChannel(int channel_id) OVERRIDE {
278 ASSERT(channel_id == channel_id_);
279 channel_id_ = -1;
280 }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000281 virtual void SetSink(Sink* sink) OVERRIDE {
282 sink_ = sink;
283 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000284
285 int channel_id() const { return channel_id_; }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000286 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000287 private:
288 int channel_id_;
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000289 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000290};
291
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000292class WebRtcSessionTest : public testing::Test {
293 protected:
294 // TODO Investigate why ChannelManager crashes, if it's created
295 // after stun_server.
296 WebRtcSessionTest()
297 : media_engine_(new cricket::FakeMediaEngine()),
298 data_engine_(new cricket::FakeDataEngine()),
299 device_manager_(new cricket::FakeDeviceManager()),
300 channel_manager_(new cricket::ChannelManager(
301 media_engine_, data_engine_, device_manager_,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000302 new cricket::CaptureManager(), rtc::Thread::Current())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000303 tdesc_factory_(new cricket::TransportDescriptionFactory()),
304 desc_factory_(new cricket::MediaSessionDescriptionFactory(
305 channel_manager_.get(), tdesc_factory_.get())),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000306 pss_(new rtc::PhysicalSocketServer),
307 vss_(new rtc::VirtualSocketServer(pss_.get())),
308 fss_(new rtc::FirewallSocketServer(vss_.get())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000309 ss_scope_(fss_.get()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000310 stun_socket_addr_(rtc::SocketAddress(kStunAddrHost,
wu@webrtc.org364f2042013-11-20 21:49:41 +0000311 cricket::STUN_SERVER_PORT)),
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +0000312 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
313 stun_socket_addr_)),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000314 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000315 mediastream_signaling_(channel_manager_.get()),
316 ice_type_(PeerConnectionInterface::kAll) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000317 tdesc_factory_->set_protocol(cricket::ICEPROTO_HYBRID);
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000318
319 cricket::ServerAddresses stun_servers;
320 stun_servers.insert(stun_socket_addr_);
321 allocator_.reset(new cricket::BasicPortAllocator(
322 &network_manager_,
323 stun_servers,
324 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000325 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326 cricket::PORTALLOCATOR_DISABLE_RELAY |
327 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
328 EXPECT_TRUE(channel_manager_->Init());
329 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000330 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000331 }
332
333 void AddInterface(const SocketAddress& addr) {
334 network_manager_.AddInterface(addr);
335 }
336
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000337 void SetIceTransportType(PeerConnectionInterface::IceTransportsType type) {
338 ice_type_ = type;
339 }
340
wu@webrtc.org91053e72013-08-10 07:18:04 +0000341 void Init(DTLSIdentityServiceInterface* identity_service) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000342 ASSERT_TRUE(session_.get() == NULL);
343 session_.reset(new WebRtcSessionForTest(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000344 channel_manager_.get(), rtc::Thread::Current(),
345 rtc::Thread::Current(), allocator_.get(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000346 &observer_,
347 &mediastream_signaling_));
348
349 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
350 observer_.ice_connection_state_);
351 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
352 observer_.ice_gathering_state_);
353
wu@webrtc.org97077a32013-10-25 21:18:33 +0000354 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000355 identity_service, ice_type_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000356 }
357
358 void InitWithDtmfCodec() {
359 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000360 const cricket::AudioCodec kTelephoneEventCodec(
361 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000362 std::vector<cricket::AudioCodec> codecs;
363 codecs.push_back(kTelephoneEventCodec);
364 media_engine_->SetAudioCodecs(codecs);
365 desc_factory_->set_audio_codecs(codecs);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000366 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000367 }
368
henrike@webrtc.org7666db72013-08-22 14:45:42 +0000369 void InitWithDtls(bool identity_request_should_fail = false) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000370 FakeIdentityService* identity_service = new FakeIdentityService();
371 identity_service->set_should_fail(identity_request_should_fail);
372 Init(identity_service);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000373 }
374
375 // Creates a local offer and applies it. Starts ice.
376 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
377 // to decide which streams to create.
378 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000379 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000380 SetLocalDescriptionWithoutError(offer);
381 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
382 observer_.ice_gathering_state_,
383 kIceCandidatesTimeout);
384 }
385
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000386 SessionDescriptionInterface* CreateOffer() {
387 PeerConnectionInterface::RTCOfferAnswerOptions options;
388 options.offer_to_receive_audio =
389 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
390
391 return CreateOffer(options);
392 }
393
wu@webrtc.org91053e72013-08-10 07:18:04 +0000394 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000395 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000396 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000397 observer = new WebRtcSessionCreateSDPObserverForTest();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000398 session_->CreateOffer(observer, options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000399 EXPECT_TRUE_WAIT(
400 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000401 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000402 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000403 }
404
405 SessionDescriptionInterface* CreateAnswer(
406 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000407 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000408 = new WebRtcSessionCreateSDPObserverForTest();
409 session_->CreateAnswer(observer, constraints);
410 EXPECT_TRUE_WAIT(
411 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000412 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000413 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000414 }
415
wu@webrtc.org364f2042013-11-20 21:49:41 +0000416 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000417 return (session_->voice_channel() != NULL &&
418 session_->video_channel() != NULL);
419 }
420
wu@webrtc.org364f2042013-11-20 21:49:41 +0000421 void CheckTransportChannels() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000422 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 1) != NULL);
423 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 2) != NULL);
424 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 1) != NULL);
425 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 2) != NULL);
426 }
427
428 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
429 ASSERT_TRUE(session_.get() != NULL);
430 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
431 ASSERT_TRUE(content != NULL);
432 const cricket::AudioContentDescription* audio_content =
433 static_cast<const cricket::AudioContentDescription*>(
434 content->description);
435 ASSERT_TRUE(audio_content != NULL);
436 ASSERT_EQ(1U, audio_content->cryptos().size());
437 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
438 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
439 audio_content->cryptos()[0].cipher_suite);
440 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
441 audio_content->protocol());
442
443 content = cricket::GetFirstVideoContent(sdp);
444 ASSERT_TRUE(content != NULL);
445 const cricket::VideoContentDescription* video_content =
446 static_cast<const cricket::VideoContentDescription*>(
447 content->description);
448 ASSERT_TRUE(video_content != NULL);
449 ASSERT_EQ(1U, video_content->cryptos().size());
450 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
451 video_content->cryptos()[0].cipher_suite);
452 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
453 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
454 video_content->protocol());
455 }
456
457 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
458 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
459 ASSERT_TRUE(content != NULL);
460 const cricket::AudioContentDescription* audio_content =
461 static_cast<const cricket::AudioContentDescription*>(
462 content->description);
463 ASSERT_TRUE(audio_content != NULL);
464 ASSERT_EQ(0U, audio_content->cryptos().size());
465
466 content = cricket::GetFirstVideoContent(sdp);
467 ASSERT_TRUE(content != NULL);
468 const cricket::VideoContentDescription* video_content =
469 static_cast<const cricket::VideoContentDescription*>(
470 content->description);
471 ASSERT_TRUE(video_content != NULL);
472 ASSERT_EQ(0U, video_content->cryptos().size());
473
474 if (dtls) {
475 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
476 audio_content->protocol());
477 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
478 video_content->protocol());
479 } else {
480 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
481 audio_content->protocol());
482 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
483 video_content->protocol());
484 }
485 }
486
487 // Set the internal fake description factories to do DTLS-SRTP.
488 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000489 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000490 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000491 rtc::ToString(rtc::CreateRandomId());
492 identity_.reset(rtc::SSLIdentity::Generate(identity_name));
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000493 tdesc_factory_->set_identity(identity_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000494 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
495 }
496
497 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
498 bool expected) {
499 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
500 ASSERT_TRUE(audio != NULL);
501 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000502 const TransportInfo* video = sdp->GetTransportInfoByName("video");
503 ASSERT_TRUE(video != NULL);
504 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000505 }
506
507 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000508 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000509 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000510 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000511 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000512 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000513 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000514 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000515 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
516 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000517 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000518 // Answer should be NULL as no crypto params in offer.
519 ASSERT_TRUE(answer == NULL);
520 }
521
522 void VerifyAnswerFromCryptoOffer() {
523 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000524 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000525 options.bundle_enabled = true;
526 scoped_ptr<JsepSessionDescription> offer(
527 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
528 ASSERT_TRUE(offer.get() != NULL);
529 VerifyCryptoParams(offer->description());
530 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000531 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000532 ASSERT_TRUE(answer.get() != NULL);
533 VerifyCryptoParams(answer->description());
534 }
535
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000536 void SetAndVerifyNumUnsignalledRecvStreams(
537 int value_set, int value_expected) {
538 constraints_.reset(new FakeConstraints());
539 constraints_->AddOptional(
540 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
541 value_set);
542 session_.reset();
543 Init(NULL);
544 mediastream_signaling_.SendAudioVideoStream1();
545 SessionDescriptionInterface* offer = CreateOffer();
546
547 SetLocalDescriptionWithoutError(offer);
548
549 video_channel_ = media_engine_->GetVideoChannel(0);
550
551 ASSERT_TRUE(video_channel_ != NULL);
552 cricket::VideoOptions video_options;
553 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
554 EXPECT_EQ(value_expected,
555 video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1));
556 }
557
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000558 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
559 const cricket::SessionDescription* desc2,
560 bool expect_equal) {
561 if (desc1->contents().size() != desc2->contents().size()) {
562 EXPECT_FALSE(expect_equal);
563 return;
564 }
565
566 const cricket::ContentInfos& contents = desc1->contents();
567 cricket::ContentInfos::const_iterator it = contents.begin();
568
569 for (; it != contents.end(); ++it) {
570 const cricket::TransportDescription* transport_desc1 =
571 desc1->GetTransportDescriptionByName(it->name);
572 const cricket::TransportDescription* transport_desc2 =
573 desc2->GetTransportDescriptionByName(it->name);
574 if (!transport_desc1 || !transport_desc2) {
575 EXPECT_FALSE(expect_equal);
576 return;
577 }
578 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
579 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
580 EXPECT_FALSE(expect_equal);
581 return;
582 }
583 }
584 EXPECT_TRUE(expect_equal);
585 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000586
587 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
588 std::string *sdp) {
589 const cricket::SessionDescription* desc = current_desc->description();
590 EXPECT_TRUE(current_desc->ToString(sdp));
591
592 const cricket::ContentInfos& contents = desc->contents();
593 cricket::ContentInfos::const_iterator it = contents.begin();
594 // Replace ufrag and pwd lines with empty strings.
595 for (; it != contents.end(); ++it) {
596 const cricket::TransportDescription* transport_desc =
597 desc->GetTransportDescriptionByName(it->name);
598 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
599 + "\r\n";
600 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
601 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000602 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000603 "", 0,
604 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000605 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000606 "", 0,
607 sdp);
608 }
609 }
610
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000611 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
612 const std::string& modified_ice_ufrag,
613 const std::string& modified_ice_pwd,
614 std::string* sdp) {
615 const cricket::SessionDescription* desc = current_desc->description();
616 EXPECT_TRUE(current_desc->ToString(sdp));
617
618 const cricket::ContentInfos& contents = desc->contents();
619 cricket::ContentInfos::const_iterator it = contents.begin();
620 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
621 // |modified_ice_pwd| strings.
622 for (; it != contents.end(); ++it) {
623 const cricket::TransportDescription* transport_desc =
624 desc->GetTransportDescriptionByName(it->name);
625 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
626 + "\r\n";
627 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
628 + "\r\n";
629 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
630 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000631 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000632 mod_ufrag.c_str(), mod_ufrag.length(),
633 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000634 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000635 mod_pwd.c_str(), mod_pwd.length(),
636 sdp);
637 }
638 }
639
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000640 // Creates a remote offer and and applies it as a remote description,
641 // creates a local answer and applies is as a local description.
642 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
643 // to decide which local and remote streams to create.
644 void CreateAndSetRemoteOfferAndLocalAnswer() {
645 SessionDescriptionInterface* offer = CreateRemoteOffer();
646 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000647 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000648 SetLocalDescriptionWithoutError(answer);
649 }
650 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
651 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
652 }
653 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
654 BaseSession::State expected_state) {
655 SetLocalDescriptionWithoutError(desc);
656 EXPECT_EQ(expected_state, session_->state());
657 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000658 void SetLocalDescriptionExpectError(const std::string& action,
659 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000660 SessionDescriptionInterface* desc) {
661 std::string error;
662 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000663 std::string sdp_type = "local ";
664 sdp_type.append(action);
665 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000666 EXPECT_NE(std::string::npos, error.find(expected_error));
667 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000668 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
669 SessionDescriptionInterface* desc) {
670 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
671 expected_error, desc);
672 }
673 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
674 SessionDescriptionInterface* desc) {
675 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
676 expected_error, desc);
677 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000678 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
679 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
680 }
681 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
682 BaseSession::State expected_state) {
683 SetRemoteDescriptionWithoutError(desc);
684 EXPECT_EQ(expected_state, session_->state());
685 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000686 void SetRemoteDescriptionExpectError(const std::string& action,
687 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000688 SessionDescriptionInterface* desc) {
689 std::string error;
690 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000691 std::string sdp_type = "remote ";
692 sdp_type.append(action);
693 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000694 EXPECT_NE(std::string::npos, error.find(expected_error));
695 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000696 void SetRemoteDescriptionOfferExpectError(
697 const std::string& expected_error, SessionDescriptionInterface* desc) {
698 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
699 expected_error, desc);
700 }
701 void SetRemoteDescriptionPranswerExpectError(
702 const std::string& expected_error, SessionDescriptionInterface* desc) {
703 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
704 expected_error, desc);
705 }
706 void SetRemoteDescriptionAnswerExpectError(
707 const std::string& expected_error, SessionDescriptionInterface* desc) {
708 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
709 expected_error, desc);
710 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000711
712 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
713 SessionDescriptionInterface** nocrypto_answer) {
714 // Create a SDP without Crypto.
715 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000716 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000717 options.bundle_enabled = true;
718 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
719 ASSERT_TRUE(*offer != NULL);
720 VerifyCryptoParams((*offer)->description());
721
722 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
723 cricket::SEC_DISABLED);
724 EXPECT_TRUE(*nocrypto_answer != NULL);
725 }
726
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000727 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
728 SessionDescriptionInterface** nodtls_answer) {
729 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000730 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000731 options.bundle_enabled = true;
732
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000733 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000734 CreateRemoteOffer(options, cricket::SEC_ENABLED));
735
736 *nodtls_answer =
737 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
738 EXPECT_TRUE(*nodtls_answer != NULL);
739 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
740 VerifyCryptoParams((*nodtls_answer)->description());
741
742 SetFactoryDtlsSrtp();
743 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
744 ASSERT_TRUE(*offer != NULL);
745 VerifyFingerprintStatus((*offer)->description(), true);
746 VerifyCryptoParams((*offer)->description());
747 }
748
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000749 JsepSessionDescription* CreateRemoteOfferWithVersion(
750 cricket::MediaSessionOptions options,
751 cricket::SecurePolicy secure_policy,
752 const std::string& session_version,
753 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000754 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000755 const cricket::SessionDescription* cricket_desc = NULL;
756 if (current_desc) {
757 cricket_desc = current_desc->description();
758 session_id = current_desc->session_id();
759 }
760
761 desc_factory_->set_secure(secure_policy);
762 JsepSessionDescription* offer(
763 new JsepSessionDescription(JsepSessionDescription::kOffer));
764 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
765 session_id, session_version)) {
766 delete offer;
767 offer = NULL;
768 }
769 return offer;
770 }
771 JsepSessionDescription* CreateRemoteOffer(
772 cricket::MediaSessionOptions options) {
773 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
774 kSessionVersion, NULL);
775 }
776 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000777 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
778 return CreateRemoteOfferWithVersion(
779 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000780 }
781 JsepSessionDescription* CreateRemoteOffer(
782 cricket::MediaSessionOptions options,
783 const SessionDescriptionInterface* current_desc) {
784 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
785 kSessionVersion, current_desc);
786 }
787
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000788 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
789 const char* sctp_stream_name, int new_port,
790 cricket::MediaSessionOptions options) {
791 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000792 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
793 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000794 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
795 }
796
797 // Takes ownership of offer_basis (and deletes it).
798 JsepSessionDescription* ChangeSDPSctpPort(
799 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
800 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
801 // SessionDescription from the mutated string.
802 const char* default_port_str = "5000";
803 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000804 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000805 std::string offer_str;
806 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000807 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000808 new_port_str, strlen(new_port_str),
809 &offer_str);
810 JsepSessionDescription* offer = new JsepSessionDescription(
811 offer_basis->type());
812 delete offer_basis;
813 offer->Initialize(offer_str, NULL);
814 return offer;
815 }
816
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000817 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
818 // before this function to decide which streams to create.
819 JsepSessionDescription* CreateRemoteOffer() {
820 cricket::MediaSessionOptions options;
821 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
822 return CreateRemoteOffer(options, session_->remote_description());
823 }
824
825 JsepSessionDescription* CreateRemoteAnswer(
826 const SessionDescriptionInterface* offer,
827 cricket::MediaSessionOptions options,
828 cricket::SecurePolicy policy) {
829 desc_factory_->set_secure(policy);
830 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000831 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000832 JsepSessionDescription* answer(
833 new JsepSessionDescription(JsepSessionDescription::kAnswer));
834 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
835 options, NULL),
836 session_id, kSessionVersion)) {
837 delete answer;
838 answer = NULL;
839 }
840 return answer;
841 }
842
843 JsepSessionDescription* CreateRemoteAnswer(
844 const SessionDescriptionInterface* offer,
845 cricket::MediaSessionOptions options) {
846 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
847 }
848
849 // Creates an answer session description with streams based on
850 // |mediastream_signaling_|. Call
851 // mediastream_signaling_.UseOptionsWithStreamX() before this function
852 // to decide which streams to create.
853 JsepSessionDescription* CreateRemoteAnswer(
854 const SessionDescriptionInterface* offer) {
855 cricket::MediaSessionOptions options;
856 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
857 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
858 }
859
860 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000861 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +0000862 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000863 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000864
865 PeerConnectionInterface::RTCOfferAnswerOptions options;
866 options.use_rtp_mux = bundle;
867
868 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
870 // and answer.
871 SetLocalDescriptionWithoutError(offer);
872
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000873 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000874 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000875 std::string sdp;
876 EXPECT_TRUE(answer->ToString(&sdp));
877
878 size_t expected_candidate_num = 2;
879 if (!rtcp_mux) {
880 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
881 // for rtp and rtcp.
882 expected_candidate_num = 4;
883 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000884 const std::string kRtcpMux = "a=rtcp-mux";
885 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000886 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000887 kXRtcpMux.c_str(), kXRtcpMux.length(),
888 &sdp);
889 }
890
891 SessionDescriptionInterface* new_answer = CreateSessionDescription(
892 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000893
894 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000895 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
897 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
898 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
899 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
900 cricket::Candidate c0 = observer_.mline_0_candidates_[i];
901 cricket::Candidate c1 = observer_.mline_1_candidates_[i];
902 if (bundle) {
903 EXPECT_TRUE(c0.IsEquivalent(c1));
904 } else {
905 EXPECT_FALSE(c0.IsEquivalent(c1));
906 }
907 }
908 }
909 // Tests that we can only send DTMF when the dtmf codec is supported.
910 void TestCanInsertDtmf(bool can) {
911 if (can) {
912 InitWithDtmfCodec();
913 } else {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000914 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 }
916 mediastream_signaling_.SendAudioVideoStream1();
917 CreateAndSetRemoteOfferAndLocalAnswer();
918 EXPECT_FALSE(session_->CanInsertDtmf(""));
919 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
920 }
921
922 // The method sets up a call from the session to itself, in a loopback
923 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000924 // disconnection, and then a permanent disconnection.
925 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000926 // by multiple tests with different allocators (e.g. with and without BUNDLE).
927 // While running the call, this method also checks if the session goes through
928 // the correct sequence of ICE states when a connection is established,
929 // broken, and re-established.
930 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000931 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
932 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000933 // The Gathering state should go: New -> Gathering -> Completed.
934 void TestLoopbackCall() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000935 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +0000936 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000937 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000938 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000939
940 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
941 observer_.ice_gathering_state_);
942 SetLocalDescriptionWithoutError(offer);
943 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
944 observer_.ice_connection_state_);
945 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
946 observer_.ice_gathering_state_,
947 kIceCandidatesTimeout);
948 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
949 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
950 observer_.ice_gathering_state_,
951 kIceCandidatesTimeout);
952
953 std::string sdp;
954 offer->ToString(&sdp);
955 SessionDescriptionInterface* desc =
956 webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer, sdp);
957 ASSERT_TRUE(desc != NULL);
958 SetRemoteDescriptionWithoutError(desc);
959
960 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
961 observer_.ice_connection_state_,
962 kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +0000963
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000964 // The ice connection state is "Connected" too briefly to catch in a test.
965 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000966 observer_.ice_connection_state_,
967 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000968
969 // Adding firewall rule to block ping requests, which should cause
970 // transport channel failure.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000971 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000972 rtc::FP_ANY,
973 rtc::FD_ANY,
974 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000975 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
976 observer_.ice_connection_state_,
977 kIceCandidatesTimeout);
978
979 // Clearing the rules, session should move back to completed state.
980 fss_->ClearRules();
981 // Session is automatically calling OnSignalingReady after creation of
982 // new portallocator session which will allocate new set of candidates.
983
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000984 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000985 observer_.ice_connection_state_,
986 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000987
988 // Now we block ping requests and wait until the ICE connection transitions
989 // to the Failed state. This will take at least 30 seconds because it must
990 // wait for the Port to timeout.
991 int port_timeout = 30000;
992 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000993 rtc::FP_ANY,
994 rtc::FD_ANY,
995 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000996 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionFailed,
997 observer_.ice_connection_state_,
998 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000999 }
1000
1001 void VerifyTransportType(const std::string& content_name,
1002 cricket::TransportProtocol protocol) {
1003 const cricket::Transport* transport = session_->GetTransport(content_name);
1004 ASSERT_TRUE(transport != NULL);
1005 EXPECT_EQ(protocol, transport->protocol());
1006 }
1007
1008 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1009 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001010 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1011 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1012
1013 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001014 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1015 codecs.push_back(kCNCodec1);
1016 codecs.push_back(kCNCodec2);
1017 media_engine_->SetAudioCodecs(codecs);
1018 desc_factory_->set_audio_codecs(codecs);
1019 }
1020
1021 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1022 const cricket::ContentDescription* description = content->description;
1023 ASSERT(description != NULL);
1024 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001025 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001026 ASSERT(audio_content_desc != NULL);
1027 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1028 if (audio_content_desc->codecs()[i].name == "CN")
1029 return false;
1030 }
1031 return true;
1032 }
1033
1034 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001035 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001036 dci.reliable = false;
1037 session_->CreateDataChannel("datachannel", &dci);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001038 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001039 SetLocalDescriptionWithoutError(offer);
1040 }
1041
wu@webrtc.org91053e72013-08-10 07:18:04 +00001042 void VerifyMultipleAsyncCreateDescription(
1043 bool success, CreateSessionDescriptionRequest::Type type) {
henrike@webrtc.org7666db72013-08-22 14:45:42 +00001044 InitWithDtls(!success);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001045 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001046 if (type == CreateSessionDescriptionRequest::kAnswer) {
1047 cricket::MediaSessionOptions options;
1048 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001049 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001050 ASSERT_TRUE(offer.get() != NULL);
1051 SetRemoteDescriptionWithoutError(offer.release());
1052 }
1053
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001054 PeerConnectionInterface::RTCOfferAnswerOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001055 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001056 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001057 observers[kNumber];
1058 for (int i = 0; i < kNumber; ++i) {
1059 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1060 if (type == CreateSessionDescriptionRequest::kOffer) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001061 session_->CreateOffer(observers[i], options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001062 } else {
1063 session_->CreateAnswer(observers[i], NULL);
1064 }
1065 }
1066
1067 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1068 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1069 WebRtcSessionCreateSDPObserverForTest::kFailed;
1070
1071 for (int i = 0; i < kNumber; ++i) {
1072 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1073 if (success) {
1074 EXPECT_TRUE(observers[i]->description() != NULL);
1075 } else {
1076 EXPECT_TRUE(observers[i]->description() == NULL);
1077 }
1078 }
1079 }
1080
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001081 void ConfigureAllocatorWithTurn() {
1082 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1083 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
1084 relay_server.credentials = credentials;
1085 relay_server.ports.push_back(cricket::ProtocolAddress(
1086 kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1087 allocator_->AddRelay(relay_server);
1088 allocator_->set_step_delay(cricket::kMinimumStepDelay);
1089 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
1090 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
1091 }
1092
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001093 cricket::FakeMediaEngine* media_engine_;
1094 cricket::FakeDataEngine* data_engine_;
1095 cricket::FakeDeviceManager* device_manager_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001096 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
1097 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1098 rtc::scoped_ptr<rtc::SSLIdentity> identity_;
1099 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1100 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1101 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1102 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1103 rtc::SocketServerScope ss_scope_;
1104 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001105 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001106 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001107 rtc::FakeNetworkManager network_manager_;
1108 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001109 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001110 rtc::scoped_ptr<FakeConstraints> constraints_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001111 FakeMediaStreamSignaling mediastream_signaling_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001112 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001113 MockIceObserver observer_;
1114 cricket::FakeVideoMediaChannel* video_channel_;
1115 cricket::FakeVoiceMediaChannel* voice_channel_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001116 PeerConnectionInterface::IceTransportsType ice_type_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001117};
1118
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001119TEST_F(WebRtcSessionTest, TestInitializeWithDtls) {
1120 InitWithDtls();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001121 // SDES is disabled when DTLS is on.
1122 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001123}
1124
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001125TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001126 Init(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001127 // SDES is required if DTLS is off.
1128 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001129}
1130
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001131TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1132 TestSessionCandidatesWithBundleRtcpMux(false, false);
1133}
1134
1135// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1136// with rtcp-mux and/or bundle.
1137TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1138 TestSessionCandidatesWithBundleRtcpMux(false, true);
1139}
1140
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001141TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1142 TestSessionCandidatesWithBundleRtcpMux(true, true);
1143}
1144
1145TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001146 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1147 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001148 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001149 mediastream_signaling_.SendAudioVideoStream1();
1150 InitiateCall();
1151 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1152 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1153 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1154}
1155
1156TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001157 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1158 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001159 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001160 rtc::FP_UDP,
1161 rtc::FD_ANY,
1162 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001163 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001164 mediastream_signaling_.SendAudioVideoStream1();
1165 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001166 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001167 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1168 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1169 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1170}
1171
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001172// Test session delivers no candidates gathered when constraint set to "none".
1173TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1174 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1175 SetIceTransportType(PeerConnectionInterface::kNone);
1176 Init(NULL);
1177 mediastream_signaling_.SendAudioVideoStream1();
1178 InitiateCall();
1179 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1180 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1181 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1182}
1183
1184// Test session delivers only relay candidates gathered when constaint set to
1185// "relay".
1186TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1187 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1188 ConfigureAllocatorWithTurn();
1189 SetIceTransportType(PeerConnectionInterface::kRelay);
1190 Init(NULL);
1191 mediastream_signaling_.SendAudioVideoStream1();
1192 InitiateCall();
1193 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1194 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1195 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1196 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1197 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1198 observer_.mline_0_candidates_[i].type());
1199 }
1200 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1201 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1202 observer_.mline_1_candidates_[i].type());
1203 }
1204}
1205
1206// Test session delivers all candidates gathered when constaint set to "all".
1207TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1208 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1209 SetIceTransportType(PeerConnectionInterface::kAll);
1210 Init(NULL);
1211 mediastream_signaling_.SendAudioVideoStream1();
1212 InitiateCall();
1213 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1214 // Host + STUN. By default allocator is disabled to gather relay candidates.
1215 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1216 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1217}
1218
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001219TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
1220 Init(NULL);
1221 SessionDescriptionInterface* offer = NULL;
1222 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1223 std::string unknown_action;
1224 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1225 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1226}
1227
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001228// Test creating offers and receive answers and make sure the
1229// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001230TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001231 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001232 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001233 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001234 const std::string session_id_orig = offer->session_id();
1235 const std::string session_version_orig = offer->session_version();
1236 SetLocalDescriptionWithoutError(offer);
1237
1238 mediastream_signaling_.SendAudioVideoStream2();
1239 SessionDescriptionInterface* answer =
1240 CreateRemoteAnswer(session_->local_description());
1241 SetRemoteDescriptionWithoutError(answer);
1242
1243 video_channel_ = media_engine_->GetVideoChannel(0);
1244 voice_channel_ = media_engine_->GetVoiceChannel(0);
1245
1246 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1247 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1248
1249 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1250 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1251
1252 ASSERT_EQ(1u, video_channel_->send_streams().size());
1253 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1254 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1255 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1256
1257 // Create new offer without send streams.
1258 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001259 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001260
1261 // Verify the session id is the same and the session version is
1262 // increased.
1263 EXPECT_EQ(session_id_orig, offer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001264 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1265 rtc::FromString<uint64>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001266
1267 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001268 EXPECT_EQ(0u, video_channel_->send_streams().size());
1269 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001270
1271 mediastream_signaling_.SendAudioVideoStream2();
1272 answer = CreateRemoteAnswer(session_->local_description());
1273 SetRemoteDescriptionWithoutError(answer);
1274
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001275 // Make sure the receive streams have not changed.
1276 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1277 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1278 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1279 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1280}
1281
1282// Test receiving offers and creating answers and make sure the
1283// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001284TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001285 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001286 mediastream_signaling_.SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001287 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001288 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001289 SetRemoteDescriptionWithoutError(offer);
1290
1291 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001292 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001293 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001294 SetLocalDescriptionWithoutError(answer);
1295
1296 const std::string session_id_orig = answer->session_id();
1297 const std::string session_version_orig = answer->session_version();
1298
1299 video_channel_ = media_engine_->GetVideoChannel(0);
1300 voice_channel_ = media_engine_->GetVoiceChannel(0);
1301
1302 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1303 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1304
1305 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1306 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1307
1308 ASSERT_EQ(1u, video_channel_->send_streams().size());
1309 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1310 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1311 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1312
1313 mediastream_signaling_.SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001314 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001315 SetRemoteDescriptionWithoutError(offer);
1316
1317 // Answer by turning off all send streams.
1318 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001319 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320
1321 // Verify the session id is the same and the session version is
1322 // increased.
1323 EXPECT_EQ(session_id_orig, answer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001324 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1325 rtc::FromString<uint64>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001326 SetLocalDescriptionWithoutError(answer);
1327
1328 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1329 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1330 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1331 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1332 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1333 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1334
1335 // Make sure we have no send streams.
1336 EXPECT_EQ(0u, video_channel_->send_streams().size());
1337 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1338}
1339
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001340TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
1341 Init(NULL);
1342 media_engine_->set_fail_create_channel(true);
1343
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001344 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001345 ASSERT_TRUE(offer != NULL);
1346 // SetRemoteDescription and SetLocalDescription will take the ownership of
1347 // the offer.
1348 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001349 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001350 ASSERT_TRUE(offer != NULL);
1351 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1352}
1353
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001354//
1355// Tests for creating/setting SDP under different SDES/DTLS polices:
1356//
1357// --DTLS off and SDES on
1358// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1359// set local/remote offer/answer with crypto --> success
1360// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1361// failure
1362// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1363// failure
1364// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1365// failure
1366//
1367// --DTLS on and SDES off
1368// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1369// set local/remote offer/answer with DTLS fingerprint --> success
1370// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1371// fingerprint --> failure
1372// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1373// --> failure
1374// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1375// --> failure
1376//
1377// --Encryption disabled: DTLS off and SDES off
1378// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1379// answer without SDES or DTLS --> success
1380// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1381// answer without SDES or DTLS --> success
1382//
1383
1384// Test that we return a failure when applying a remote/local offer that doesn't
1385// have cryptos enabled when DTLS is off.
1386TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001387 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001388 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001389 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001390 JsepSessionDescription* offer = CreateRemoteOffer(
1391 options, cricket::SEC_DISABLED);
1392 ASSERT_TRUE(offer != NULL);
1393 VerifyNoCryptoParams(offer->description(), false);
1394 // SetRemoteDescription and SetLocalDescription will take the ownership of
1395 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001396 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001397 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1398 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001399 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001400}
1401
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001402// Test that we return a failure when applying a local answer that doesn't have
1403// cryptos enabled when DTLS is off.
1404TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001405 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001406 SessionDescriptionInterface* offer = NULL;
1407 SessionDescriptionInterface* answer = NULL;
1408 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1409 // SetRemoteDescription and SetLocalDescription will take the ownership of
1410 // the offer.
1411 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001412 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001413}
1414
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001415// Test we will return fail when apply an remote answer that doesn't have
1416// crypto enabled when DTLS is off.
1417TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001418 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001419 SessionDescriptionInterface* offer = NULL;
1420 SessionDescriptionInterface* answer = NULL;
1421 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1422 // SetRemoteDescription and SetLocalDescription will take the ownership of
1423 // the offer.
1424 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001425 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001426}
1427
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001428// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1429// and that we return an answer with a DTLS fingerprint.
1430TEST_F(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001431 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001432 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001433 InitWithDtls();
1434 SetFactoryDtlsSrtp();
1435 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001436 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001437 JsepSessionDescription* offer =
1438 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001439 ASSERT_TRUE(offer != NULL);
1440 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001441 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001442
1443 // SetRemoteDescription will take the ownership of the offer.
1444 SetRemoteDescriptionWithoutError(offer);
1445
1446 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001447 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001448 ASSERT_TRUE(answer != NULL);
1449 VerifyFingerprintStatus(answer->description(), true);
1450 // Check that we don't have an a=crypto line in the answer.
1451 VerifyNoCryptoParams(answer->description(), true);
1452
1453 // Now set the local description, which should work, even without a=crypto.
1454 SetLocalDescriptionWithoutError(answer);
1455}
1456
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001457// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1458// and then we accept a remote answer with a DTLS fingerprint successfully.
1459TEST_F(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001460 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001461 mediastream_signaling_.SendAudioVideoStream1();
1462 InitWithDtls();
1463 SetFactoryDtlsSrtp();
1464
1465 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001466 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001467 ASSERT_TRUE(offer != NULL);
1468 VerifyFingerprintStatus(offer->description(), true);
1469 // Check that we don't have an a=crypto line in the offer.
1470 VerifyNoCryptoParams(offer->description(), true);
1471
1472 // Now set the local description, which should work, even without a=crypto.
1473 SetLocalDescriptionWithoutError(offer);
1474
1475 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001476 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001477 JsepSessionDescription* answer =
1478 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1479 ASSERT_TRUE(answer != NULL);
1480 VerifyFingerprintStatus(answer->description(), true);
1481 VerifyNoCryptoParams(answer->description(), true);
1482
1483 // SetRemoteDescription will take the ownership of the answer.
1484 SetRemoteDescriptionWithoutError(answer);
1485}
1486
1487// Test that if we support DTLS and the other side didn't offer a fingerprint,
1488// we will fail to set the remote description.
1489TEST_F(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001490 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001491 InitWithDtls();
1492 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001493 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001494 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001495 JsepSessionDescription* offer = CreateRemoteOffer(
1496 options, cricket::SEC_REQUIRED);
1497 ASSERT_TRUE(offer != NULL);
1498 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001499 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001500
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001501 // SetRemoteDescription will take the ownership of the offer.
1502 SetRemoteDescriptionOfferExpectError(
1503 kSdpWithoutDtlsFingerprint, offer);
1504
1505 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1506 // SetLocalDescription will take the ownership of the offer.
1507 SetLocalDescriptionOfferExpectError(
1508 kSdpWithoutDtlsFingerprint, offer);
1509}
1510
1511// Test that we return a failure when applying a local answer that doesn't have
1512// a DTLS fingerprint when DTLS is required.
1513TEST_F(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001514 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001515 InitWithDtls();
1516 SessionDescriptionInterface* offer = NULL;
1517 SessionDescriptionInterface* answer = NULL;
1518 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1519
1520 // SetRemoteDescription and SetLocalDescription will take the ownership of
1521 // the offer and answer.
1522 SetRemoteDescriptionWithoutError(offer);
1523 SetLocalDescriptionAnswerExpectError(
1524 kSdpWithoutDtlsFingerprint, answer);
1525}
1526
1527// Test that we return a failure when applying a remote answer that doesn't have
1528// a DTLS fingerprint when DTLS is required.
1529TEST_F(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001530 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001531 InitWithDtls();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001532 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001533 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001534 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001535 JsepSessionDescription* answer =
1536 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
1537
1538 // SetRemoteDescription and SetLocalDescription will take the ownership of
1539 // the offer and answer.
1540 SetLocalDescriptionWithoutError(offer);
1541 SetRemoteDescriptionAnswerExpectError(
1542 kSdpWithoutDtlsFingerprint, answer);
1543}
1544
1545// Test that we create a local offer without SDES or DTLS and accept a remote
1546// answer without SDES or DTLS when encryption is disabled.
1547TEST_F(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
1548 mediastream_signaling_.SendAudioVideoStream1();
1549 options_.disable_encryption = true;
1550 InitWithDtls();
1551
1552 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001553 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001554 ASSERT_TRUE(offer != NULL);
1555 VerifyFingerprintStatus(offer->description(), false);
1556 // Check that we don't have an a=crypto line in the offer.
1557 VerifyNoCryptoParams(offer->description(), false);
1558
1559 // Now set the local description, which should work, even without a=crypto.
1560 SetLocalDescriptionWithoutError(offer);
1561
1562 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001563 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001564 JsepSessionDescription* answer =
1565 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1566 ASSERT_TRUE(answer != NULL);
1567 VerifyFingerprintStatus(answer->description(), false);
1568 VerifyNoCryptoParams(answer->description(), false);
1569
1570 // SetRemoteDescription will take the ownership of the answer.
1571 SetRemoteDescriptionWithoutError(answer);
1572}
1573
1574// Test that we create a local answer without SDES or DTLS and accept a remote
1575// offer without SDES or DTLS when encryption is disabled.
1576TEST_F(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
1577 options_.disable_encryption = true;
1578 InitWithDtls();
1579
1580 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001581 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001582 JsepSessionDescription* offer =
1583 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1584 ASSERT_TRUE(offer != NULL);
1585 VerifyFingerprintStatus(offer->description(), false);
1586 VerifyNoCryptoParams(offer->description(), false);
1587
1588 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001589 SetRemoteDescriptionWithoutError(offer);
1590
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001591 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001592 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001593 ASSERT_TRUE(answer != NULL);
1594 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001595 // Check that we don't have an a=crypto line in the answer.
1596 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001597
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001598 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001599 SetLocalDescriptionWithoutError(answer);
1600}
1601
1602TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001603 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604 mediastream_signaling_.SendNothing();
1605 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001606 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001607 SetLocalDescriptionWithoutError(offer);
1608
1609 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001610 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001611 SetLocalDescriptionWithoutError(offer2);
1612}
1613
1614TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001615 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001616 mediastream_signaling_.SendNothing();
1617 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001618 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619 SetRemoteDescriptionWithoutError(offer);
1620
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001621 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001622 SetRemoteDescriptionWithoutError(offer2);
1623}
1624
1625TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001626 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001627 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001628 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001629 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001630 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001631 SetRemoteDescriptionOfferExpectError(
1632 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001633}
1634
1635TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001636 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001637 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001638 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001639 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001640 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001641 SetLocalDescriptionOfferExpectError(
1642 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001643}
1644
1645TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001646 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001647 mediastream_signaling_.SendNothing();
1648 SessionDescriptionInterface* offer = CreateRemoteOffer();
1649 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1650
1651 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001652 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001653 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1654 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1655
1656 mediastream_signaling_.SendAudioVideoStream1();
1657 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001658 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001659 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1660
1661 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1662
1663 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001664 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001665 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1666}
1667
1668TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001669 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001670 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001671 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001672 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1673
1674 JsepSessionDescription* pranswer =
1675 CreateRemoteAnswer(session_->local_description());
1676 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1677
1678 SetRemoteDescriptionExpectState(pranswer,
1679 BaseSession::STATE_RECEIVEDPRACCEPT);
1680
1681 mediastream_signaling_.SendAudioVideoStream1();
1682 JsepSessionDescription* pranswer2 =
1683 CreateRemoteAnswer(session_->local_description());
1684 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1685
1686 SetRemoteDescriptionExpectState(pranswer2,
1687 BaseSession::STATE_RECEIVEDPRACCEPT);
1688
1689 mediastream_signaling_.SendAudioVideoStream2();
1690 SessionDescriptionInterface* answer =
1691 CreateRemoteAnswer(session_->local_description());
1692 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1693}
1694
1695TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001696 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001697 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001698 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1699
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001700 SessionDescriptionInterface* answer =
1701 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001702 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1703 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001704}
1705
1706TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001707 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001708 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001709 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1710
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001711 SessionDescriptionInterface* answer =
1712 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001713 SetRemoteDescriptionAnswerExpectError(
1714 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001715}
1716
1717TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001718 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001719 mediastream_signaling_.SendAudioVideoStream1();
1720
1721 cricket::Candidate candidate;
1722 candidate.set_component(1);
1723 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1724
1725 // Fail since we have not set a offer description.
1726 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1727
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001728 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001729 SetLocalDescriptionWithoutError(offer);
1730 // Candidate should be allowed to add before remote description.
1731 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1732 candidate.set_component(2);
1733 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1734 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1735
1736 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1737 session_->local_description());
1738 SetRemoteDescriptionWithoutError(answer);
1739
1740 // Verifying the candidates are copied properly from internal vector.
1741 const SessionDescriptionInterface* remote_desc =
1742 session_->remote_description();
1743 ASSERT_TRUE(remote_desc != NULL);
1744 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1745 const IceCandidateCollection* candidates =
1746 remote_desc->candidates(kMediaContentIndex0);
1747 ASSERT_EQ(2u, candidates->count());
1748 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1749 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1750 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1751 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1752
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001753 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1754 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755 candidate.set_component(2);
1756 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1757 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001758 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001759
1760 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1761 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1762}
1763
1764// Test that a remote candidate is added to the remote session description and
1765// that it is retained if the remote session description is changed.
1766TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001767 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768 cricket::Candidate candidate1;
1769 candidate1.set_component(1);
1770 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1771 candidate1);
1772 mediastream_signaling_.SendAudioVideoStream1();
1773 CreateAndSetRemoteOfferAndLocalAnswer();
1774
1775 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1776 const SessionDescriptionInterface* remote_desc =
1777 session_->remote_description();
1778 ASSERT_TRUE(remote_desc != NULL);
1779 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1780 const IceCandidateCollection* candidates =
1781 remote_desc->candidates(kMediaContentIndex0);
1782 ASSERT_EQ(1u, candidates->count());
1783 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1784
1785 // Update the RemoteSessionDescription with a new session description and
1786 // a candidate and check that the new remote session description contains both
1787 // candidates.
1788 SessionDescriptionInterface* offer = CreateRemoteOffer();
1789 cricket::Candidate candidate2;
1790 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1791 candidate2);
1792 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1793 SetRemoteDescriptionWithoutError(offer);
1794
1795 remote_desc = session_->remote_description();
1796 ASSERT_TRUE(remote_desc != NULL);
1797 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1798 candidates = remote_desc->candidates(kMediaContentIndex0);
1799 ASSERT_EQ(2u, candidates->count());
1800 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1801 // Username and password have be updated with the TransportInfo of the
1802 // SessionDescription, won't be equal to the original one.
1803 candidate2.set_username(candidates->at(0)->candidate().username());
1804 candidate2.set_password(candidates->at(0)->candidate().password());
1805 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
1806 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
1807 // No need to verify the username and password.
1808 candidate1.set_username(candidates->at(1)->candidate().username());
1809 candidate1.set_password(candidates->at(1)->candidate().password());
1810 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
1811
1812 // Test that the candidate is ignored if we can add the same candidate again.
1813 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1814}
1815
1816// Test that local candidates are added to the local session description and
1817// that they are retained if the local session description is changed.
1818TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001819 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001820 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001821 mediastream_signaling_.SendAudioVideoStream1();
1822 CreateAndSetRemoteOfferAndLocalAnswer();
1823
1824 const SessionDescriptionInterface* local_desc = session_->local_description();
1825 const IceCandidateCollection* candidates =
1826 local_desc->candidates(kMediaContentIndex0);
1827 ASSERT_TRUE(candidates != NULL);
1828 EXPECT_EQ(0u, candidates->count());
1829
1830 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1831
1832 local_desc = session_->local_description();
1833 candidates = local_desc->candidates(kMediaContentIndex0);
1834 ASSERT_TRUE(candidates != NULL);
1835 EXPECT_LT(0u, candidates->count());
1836 candidates = local_desc->candidates(1);
1837 ASSERT_TRUE(candidates != NULL);
1838 EXPECT_LT(0u, candidates->count());
1839
1840 // Update the session descriptions.
1841 mediastream_signaling_.SendAudioVideoStream1();
1842 CreateAndSetRemoteOfferAndLocalAnswer();
1843
1844 local_desc = session_->local_description();
1845 candidates = local_desc->candidates(kMediaContentIndex0);
1846 ASSERT_TRUE(candidates != NULL);
1847 EXPECT_LT(0u, candidates->count());
1848 candidates = local_desc->candidates(1);
1849 ASSERT_TRUE(candidates != NULL);
1850 EXPECT_LT(0u, candidates->count());
1851}
1852
1853// Test that we can set a remote session description with remote candidates.
1854TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001855 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001856
1857 cricket::Candidate candidate1;
1858 candidate1.set_component(1);
1859 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
1860 candidate1);
1861 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001862 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001863
1864 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
1865 SetRemoteDescriptionWithoutError(offer);
1866
1867 const SessionDescriptionInterface* remote_desc =
1868 session_->remote_description();
1869 ASSERT_TRUE(remote_desc != NULL);
1870 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1871 const IceCandidateCollection* candidates =
1872 remote_desc->candidates(kMediaContentIndex0);
1873 ASSERT_EQ(1u, candidates->count());
1874 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1875
wu@webrtc.org91053e72013-08-10 07:18:04 +00001876 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001877 SetLocalDescriptionWithoutError(answer);
1878}
1879
1880// Test that offers and answers contains ice candidates when Ice candidates have
1881// been gathered.
1882TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001883 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001884 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001885 mediastream_signaling_.SendAudioVideoStream1();
1886 // Ice is started but candidates are not provided until SetLocalDescription
1887 // is called.
1888 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1889 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1890 CreateAndSetRemoteOfferAndLocalAnswer();
1891 // Wait until at least one local candidate has been collected.
1892 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
1893 kIceCandidatesTimeout);
1894 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
1895 kIceCandidatesTimeout);
1896
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001897 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
1898
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001899 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
1900 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
1901 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
1902 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
1903
1904 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
1905 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001906 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001907 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
1908 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
1909 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
1910 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
1911 SetLocalDescriptionWithoutError(answer);
1912}
1913
1914// Verifies TransportProxy and media channels are created with content names
1915// present in the SessionDescription.
1916TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001917 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001918 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001919 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001920
1921 // CreateOffer creates session description with the content names "audio" and
1922 // "video". Goal is to modify these content names and verify transport channel
1923 // proxy in the BaseSession, as proxies are created with the content names
1924 // present in SDP.
1925 std::string sdp;
1926 EXPECT_TRUE(offer->ToString(&sdp));
1927 const std::string kAudioMid = "a=mid:audio";
1928 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
1929 const std::string kVideoMid = "a=mid:video";
1930 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
1931
1932 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001933 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001934 kAudioMidReplaceStr.c_str(),
1935 kAudioMidReplaceStr.length(),
1936 &sdp);
1937 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001938 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001939 kVideoMidReplaceStr.c_str(),
1940 kVideoMidReplaceStr.length(),
1941 &sdp);
1942
1943 SessionDescriptionInterface* modified_offer =
1944 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
1945
1946 SetRemoteDescriptionWithoutError(modified_offer);
1947
1948 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00001949 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001950 SetLocalDescriptionWithoutError(answer);
1951
1952 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
1953 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
1954 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
1955 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
1956}
1957
1958// Test that an offer contains the correct media content descriptions based on
1959// the send streams when no constraints have been set.
1960TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001961 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001962 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1963
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001964 ASSERT_TRUE(offer != NULL);
1965 const cricket::ContentInfo* content =
1966 cricket::GetFirstAudioContent(offer->description());
1967 EXPECT_TRUE(content != NULL);
1968 content = cricket::GetFirstVideoContent(offer->description());
1969 EXPECT_TRUE(content == NULL);
1970}
1971
1972// Test that an offer contains the correct media content descriptions based on
1973// the send streams when no constraints have been set.
1974TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001975 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001976 // Test Audio only offer.
1977 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001978 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1979
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001980 const cricket::ContentInfo* content =
1981 cricket::GetFirstAudioContent(offer->description());
1982 EXPECT_TRUE(content != NULL);
1983 content = cricket::GetFirstVideoContent(offer->description());
1984 EXPECT_TRUE(content == NULL);
1985
1986 // Test Audio / Video offer.
1987 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001988 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001989 content = cricket::GetFirstAudioContent(offer->description());
1990 EXPECT_TRUE(content != NULL);
1991 content = cricket::GetFirstVideoContent(offer->description());
1992 EXPECT_TRUE(content != NULL);
1993}
1994
1995// Test that an offer contains no media content descriptions if
1996// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
1997TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001998 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001999 PeerConnectionInterface::RTCOfferAnswerOptions options;
2000 options.offer_to_receive_audio = 0;
2001 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002002
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002003 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002004 CreateOffer(options));
2005
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002006 ASSERT_TRUE(offer != NULL);
2007 const cricket::ContentInfo* content =
2008 cricket::GetFirstAudioContent(offer->description());
2009 EXPECT_TRUE(content == NULL);
2010 content = cricket::GetFirstVideoContent(offer->description());
2011 EXPECT_TRUE(content == NULL);
2012}
2013
2014// Test that an offer contains only audio media content descriptions if
2015// kOfferToReceiveAudio constraints are set to true.
2016TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002017 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002018 PeerConnectionInterface::RTCOfferAnswerOptions options;
2019 options.offer_to_receive_audio =
2020 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2021
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002022 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002023 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002024
2025 const cricket::ContentInfo* content =
2026 cricket::GetFirstAudioContent(offer->description());
2027 EXPECT_TRUE(content != NULL);
2028 content = cricket::GetFirstVideoContent(offer->description());
2029 EXPECT_TRUE(content == NULL);
2030}
2031
2032// Test that an offer contains audio and video media content descriptions if
2033// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2034TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002035 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002036 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002037 PeerConnectionInterface::RTCOfferAnswerOptions options;
2038 options.offer_to_receive_audio =
2039 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2040 options.offer_to_receive_video =
2041 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2042
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002043 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002044 CreateOffer(options));
2045
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002046 const cricket::ContentInfo* content =
2047 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002048 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002049
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002050 content = cricket::GetFirstVideoContent(offer->description());
2051 EXPECT_TRUE(content != NULL);
2052
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002053 // Sets constraints to false and verifies that audio/video contents are
2054 // removed.
2055 options.offer_to_receive_audio = 0;
2056 options.offer_to_receive_video = 0;
2057 offer.reset(CreateOffer(options));
2058
2059 content = cricket::GetFirstAudioContent(offer->description());
2060 EXPECT_TRUE(content == NULL);
2061 content = cricket::GetFirstVideoContent(offer->description());
2062 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002063}
2064
2065// Test that an answer can not be created if the last remote description is not
2066// an offer.
2067TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002068 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002069 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002070 SetLocalDescriptionWithoutError(offer);
2071 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2072 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002073 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002074}
2075
2076// Test that an answer contains the correct media content descriptions when no
2077// constraints have been set.
2078TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002079 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002080 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002081 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002082 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002083 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002084 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002085 const cricket::ContentInfo* content =
2086 cricket::GetFirstAudioContent(answer->description());
2087 ASSERT_TRUE(content != NULL);
2088 EXPECT_FALSE(content->rejected);
2089
2090 content = cricket::GetFirstVideoContent(answer->description());
2091 ASSERT_TRUE(content != NULL);
2092 EXPECT_FALSE(content->rejected);
2093}
2094
2095// Test that an answer contains the correct media content descriptions when no
2096// constraints have been set and the offer only contain audio.
2097TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002098 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002099 // Create a remote offer with audio only.
2100 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002101
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002102 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103 CreateRemoteOffer(options));
2104 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2105 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2106
2107 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002108 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002109 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002110 const cricket::ContentInfo* content =
2111 cricket::GetFirstAudioContent(answer->description());
2112 ASSERT_TRUE(content != NULL);
2113 EXPECT_FALSE(content->rejected);
2114
2115 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2116}
2117
2118// Test that an answer contains the correct media content descriptions when no
2119// constraints have been set.
2120TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002121 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002122 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002123 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124 SetRemoteDescriptionWithoutError(offer.release());
2125 // Test with a stream with tracks.
2126 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002127 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002128 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129 const cricket::ContentInfo* content =
2130 cricket::GetFirstAudioContent(answer->description());
2131 ASSERT_TRUE(content != NULL);
2132 EXPECT_FALSE(content->rejected);
2133
2134 content = cricket::GetFirstVideoContent(answer->description());
2135 ASSERT_TRUE(content != NULL);
2136 EXPECT_FALSE(content->rejected);
2137}
2138
2139// Test that an answer contains the correct media content descriptions when
2140// constraints have been set but no stream is sent.
2141TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002142 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002143 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002144 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002145 SetRemoteDescriptionWithoutError(offer.release());
2146
2147 webrtc::FakeConstraints constraints_no_receive;
2148 constraints_no_receive.SetMandatoryReceiveAudio(false);
2149 constraints_no_receive.SetMandatoryReceiveVideo(false);
2150
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002151 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002152 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002153 const cricket::ContentInfo* content =
2154 cricket::GetFirstAudioContent(answer->description());
2155 ASSERT_TRUE(content != NULL);
2156 EXPECT_TRUE(content->rejected);
2157
2158 content = cricket::GetFirstVideoContent(answer->description());
2159 ASSERT_TRUE(content != NULL);
2160 EXPECT_TRUE(content->rejected);
2161}
2162
2163// Test that an answer contains the correct media content descriptions when
2164// constraints have been set and streams are sent.
2165TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002166 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002167 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002168 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002169 SetRemoteDescriptionWithoutError(offer.release());
2170
2171 webrtc::FakeConstraints constraints_no_receive;
2172 constraints_no_receive.SetMandatoryReceiveAudio(false);
2173 constraints_no_receive.SetMandatoryReceiveVideo(false);
2174
2175 // Test with a stream with tracks.
2176 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002177 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002178 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002179
2180 // TODO(perkj): Should the direction be set to SEND_ONLY?
2181 const cricket::ContentInfo* content =
2182 cricket::GetFirstAudioContent(answer->description());
2183 ASSERT_TRUE(content != NULL);
2184 EXPECT_FALSE(content->rejected);
2185
2186 // TODO(perkj): Should the direction be set to SEND_ONLY?
2187 content = cricket::GetFirstVideoContent(answer->description());
2188 ASSERT_TRUE(content != NULL);
2189 EXPECT_FALSE(content->rejected);
2190}
2191
2192TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2193 AddCNCodecs();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002194 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002195 PeerConnectionInterface::RTCOfferAnswerOptions options;
2196 options.offer_to_receive_audio =
2197 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2198 options.voice_activity_detection = false;
2199
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002200 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002201 CreateOffer(options));
2202
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002203 const cricket::ContentInfo* content =
2204 cricket::GetFirstAudioContent(offer->description());
2205 EXPECT_TRUE(content != NULL);
2206 EXPECT_TRUE(VerifyNoCNCodecs(content));
2207}
2208
2209TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2210 AddCNCodecs();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002211 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002212 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002213 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002214 SetRemoteDescriptionWithoutError(offer.release());
2215
2216 webrtc::FakeConstraints constraints;
2217 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002218 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002219 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002220 const cricket::ContentInfo* content =
2221 cricket::GetFirstAudioContent(answer->description());
2222 ASSERT_TRUE(content != NULL);
2223 EXPECT_TRUE(VerifyNoCNCodecs(content));
2224}
2225
2226// This test verifies the call setup when remote answer with audio only and
2227// later updates with video.
2228TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002229 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002230 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2231 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2232
2233 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002234 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002235
2236 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002237 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2238
2239 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2240 // and answer;
2241 SetLocalDescriptionWithoutError(offer);
2242 SetRemoteDescriptionWithoutError(answer);
2243
2244 video_channel_ = media_engine_->GetVideoChannel(0);
2245 voice_channel_ = media_engine_->GetVoiceChannel(0);
2246
2247 ASSERT_TRUE(video_channel_ == NULL);
2248
2249 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2250 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2251 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2252
2253 // Let the remote end update the session descriptions, with Audio and Video.
2254 mediastream_signaling_.SendAudioVideoStream2();
2255 CreateAndSetRemoteOfferAndLocalAnswer();
2256
2257 video_channel_ = media_engine_->GetVideoChannel(0);
2258 voice_channel_ = media_engine_->GetVoiceChannel(0);
2259
2260 ASSERT_TRUE(video_channel_ != NULL);
2261 ASSERT_TRUE(voice_channel_ != NULL);
2262
2263 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2264 ASSERT_EQ(1u, video_channel_->send_streams().size());
2265 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2266 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2267 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2268 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2269 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2270 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2271
2272 // Change session back to audio only.
2273 mediastream_signaling_.UseOptionsAudioOnly();
2274 CreateAndSetRemoteOfferAndLocalAnswer();
2275
2276 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2277 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2278 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2279 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2280 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2281}
2282
2283// This test verifies the call setup when remote answer with video only and
2284// later updates with audio.
2285TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002286 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002287 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2288 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2289 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002290 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002291
2292 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002293 options.recv_audio = false;
2294 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002295 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2296 offer, options, cricket::SEC_ENABLED);
2297
2298 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2299 // and answer.
2300 SetLocalDescriptionWithoutError(offer);
2301 SetRemoteDescriptionWithoutError(answer);
2302
2303 video_channel_ = media_engine_->GetVideoChannel(0);
2304 voice_channel_ = media_engine_->GetVoiceChannel(0);
2305
2306 ASSERT_TRUE(voice_channel_ == NULL);
2307 ASSERT_TRUE(video_channel_ != NULL);
2308
2309 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2310 ASSERT_EQ(1u, video_channel_->send_streams().size());
2311 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2312
2313 // Update the session descriptions, with Audio and Video.
2314 mediastream_signaling_.SendAudioVideoStream2();
2315 CreateAndSetRemoteOfferAndLocalAnswer();
2316
2317 voice_channel_ = media_engine_->GetVoiceChannel(0);
2318 ASSERT_TRUE(voice_channel_ != NULL);
2319
2320 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2321 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2322 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2323 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2324
2325 // Change session back to video only.
2326 mediastream_signaling_.UseOptionsVideoOnly();
2327 CreateAndSetRemoteOfferAndLocalAnswer();
2328
2329 video_channel_ = media_engine_->GetVideoChannel(0);
2330 voice_channel_ = media_engine_->GetVoiceChannel(0);
2331
2332 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2333 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2334 ASSERT_EQ(1u, video_channel_->send_streams().size());
2335 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2336}
2337
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002338TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002339 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002340 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002341 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002342 VerifyCryptoParams(offer->description());
2343 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002344 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002345 VerifyCryptoParams(answer->description());
2346}
2347
2348TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002349 options_.disable_encryption = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00002350 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002351 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002352 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002353 VerifyNoCryptoParams(offer->description(), false);
2354}
2355
2356TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002357 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002358 VerifyAnswerFromNonCryptoOffer();
2359}
2360
2361TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002362 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002363 VerifyAnswerFromCryptoOffer();
2364}
2365
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002366// This test verifies that setLocalDescription fails if
2367// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2368TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
2369 Init(NULL);
2370 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002371 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2372
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002373 std::string sdp;
2374 RemoveIceUfragPwdLines(offer.get(), &sdp);
2375 SessionDescriptionInterface* modified_offer =
2376 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002377 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002378}
2379
2380// This test verifies that setRemoteDescription fails if
2381// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2382TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
2383 Init(NULL);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002384 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002385 std::string sdp;
2386 RemoveIceUfragPwdLines(offer.get(), &sdp);
2387 SessionDescriptionInterface* modified_offer =
2388 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002389 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002390}
2391
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002392// This test verifies that setLocalDescription fails if local offer has
2393// too short ice ufrag and pwd strings.
2394TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
2395 Init(NULL);
2396 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
2397 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002398 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2399
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002400 std::string sdp;
2401 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2402 // recommended values of 4 and 22 bytes respectively.
2403 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2404 SessionDescriptionInterface* modified_offer =
2405 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2406 std::string error;
2407 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2408
2409 // Test with string greater than 256.
2410 sdp.clear();
2411 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2412 &sdp);
2413 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2414 NULL);
2415 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2416}
2417
2418// This test verifies that setRemoteDescription fails if remote offer has
2419// too short ice ufrag and pwd strings.
2420TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
2421 Init(NULL);
2422 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002423 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002424 std::string sdp;
2425 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2426 // recommended values of 4 and 22 bytes respectively.
2427 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2428 SessionDescriptionInterface* modified_offer =
2429 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2430 std::string error;
2431 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2432
2433 sdp.clear();
2434 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2435 &sdp);
2436 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2437 NULL);
2438 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2439}
2440
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002441TEST_F(WebRtcSessionTest, VerifyBundleFlagInPA) {
2442 // This test verifies BUNDLE flag in PortAllocator, if BUNDLE information in
2443 // local description is removed by the application, BUNDLE flag should be
2444 // disabled in PortAllocator. By default BUNDLE is enabled in the WebRtc.
wu@webrtc.org91053e72013-08-10 07:18:04 +00002445 Init(NULL);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002446 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2447 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002448 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2449
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002450 cricket::SessionDescription* offer_copy =
2451 offer->description()->Copy();
2452 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2453 JsepSessionDescription* modified_offer =
2454 new JsepSessionDescription(JsepSessionDescription::kOffer);
2455 modified_offer->Initialize(offer_copy, "1", "1");
2456
2457 SetLocalDescriptionWithoutError(modified_offer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002458 EXPECT_FALSE(allocator_->flags() & cricket::PORTALLOCATOR_ENABLE_BUNDLE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002459}
2460
2461TEST_F(WebRtcSessionTest, TestDisabledBundleInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002462 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002463 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002464 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2465 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002466
2467 PeerConnectionInterface::RTCOfferAnswerOptions options;
2468 options.use_rtp_mux = true;
2469
2470 SessionDescriptionInterface* offer = CreateOffer(options);
2471
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002472 SetLocalDescriptionWithoutError(offer);
2473 mediastream_signaling_.SendAudioVideoStream2();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002474 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002475 CreateRemoteAnswer(session_->local_description()));
2476 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2477 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2478 JsepSessionDescription* modified_answer =
2479 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2480 modified_answer->Initialize(answer_copy, "1", "1");
2481 SetRemoteDescriptionWithoutError(modified_answer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002482 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2483 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002484
2485 video_channel_ = media_engine_->GetVideoChannel(0);
2486 voice_channel_ = media_engine_->GetVoiceChannel(0);
2487
2488 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2489 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
2490
2491 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2492 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
2493
2494 ASSERT_EQ(1u, video_channel_->send_streams().size());
2495 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
2496 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2497 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
2498}
2499
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002500// This test verifies that SetLocalDescription and SetRemoteDescription fails
2501// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2502TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002503 WebRtcSessionTest::Init(NULL);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002504 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002505 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2506 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002507
2508 PeerConnectionInterface::RTCOfferAnswerOptions options;
2509 options.use_rtp_mux = true;
2510
2511 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002512 std::string offer_str;
2513 offer->ToString(&offer_str);
2514 // Disable rtcp-mux
2515 const std::string rtcp_mux = "rtcp-mux";
2516 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002517 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002518 xrtcp_mux.c_str(), xrtcp_mux.length(),
2519 &offer_str);
2520 JsepSessionDescription *local_offer =
2521 new JsepSessionDescription(JsepSessionDescription::kOffer);
2522 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002523 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002524 JsepSessionDescription *remote_offer =
2525 new JsepSessionDescription(JsepSessionDescription::kOffer);
2526 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002527 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002528 // Trying unmodified SDP.
2529 SetLocalDescriptionWithoutError(offer);
2530}
2531
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002532TEST_F(WebRtcSessionTest, SetAudioPlayout) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002533 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002534 mediastream_signaling_.SendAudioVideoStream1();
2535 CreateAndSetRemoteOfferAndLocalAnswer();
2536 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2537 ASSERT_TRUE(channel != NULL);
2538 ASSERT_EQ(1u, channel->recv_streams().size());
2539 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2540 double left_vol, right_vol;
2541 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2542 EXPECT_EQ(1, left_vol);
2543 EXPECT_EQ(1, right_vol);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002544 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002545 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002546 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2547 EXPECT_EQ(0, left_vol);
2548 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002549 EXPECT_EQ(0, renderer->channel_id());
2550 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002551 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2552 EXPECT_EQ(1, left_vol);
2553 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002554 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002555}
2556
2557TEST_F(WebRtcSessionTest, SetAudioSend) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002558 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002559 mediastream_signaling_.SendAudioVideoStream1();
2560 CreateAndSetRemoteOfferAndLocalAnswer();
2561 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2562 ASSERT_TRUE(channel != NULL);
2563 ASSERT_EQ(1u, channel->send_streams().size());
2564 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2565 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2566
2567 cricket::AudioOptions options;
2568 options.echo_cancellation.Set(true);
2569
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002570 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002571 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002572 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2573 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002574 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002575 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002576
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002577 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002578 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002579 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2580 bool value;
2581 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
2582 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002583 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002584 EXPECT_TRUE(renderer->sink() == NULL);
2585}
2586
2587TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
2588 Init(NULL);
2589 mediastream_signaling_.SendAudioVideoStream1();
2590 CreateAndSetRemoteOfferAndLocalAnswer();
2591 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2592 ASSERT_TRUE(channel != NULL);
2593 ASSERT_EQ(1u, channel->send_streams().size());
2594 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2595
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002596 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002597 cricket::AudioOptions options;
2598 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
2599 EXPECT_TRUE(renderer->sink() != NULL);
2600
2601 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
2602 // will invalidate the |renderer_| pointer in the sink and prevent getting a
2603 // SetSink(NULL) callback afterwards.
2604 renderer.reset();
2605
2606 // This will trigger SetSink(NULL) if no OnClose() callback.
2607 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002608}
2609
2610TEST_F(WebRtcSessionTest, SetVideoPlayout) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002611 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002612 mediastream_signaling_.SendAudioVideoStream1();
2613 CreateAndSetRemoteOfferAndLocalAnswer();
2614 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2615 ASSERT_TRUE(channel != NULL);
2616 ASSERT_LT(0u, channel->renderers().size());
2617 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2618 ASSERT_EQ(1u, channel->recv_streams().size());
2619 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2620 cricket::FakeVideoRenderer renderer;
2621 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
2622 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
2623 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
2624 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2625}
2626
2627TEST_F(WebRtcSessionTest, SetVideoSend) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002628 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002629 mediastream_signaling_.SendAudioVideoStream1();
2630 CreateAndSetRemoteOfferAndLocalAnswer();
2631 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2632 ASSERT_TRUE(channel != NULL);
2633 ASSERT_EQ(1u, channel->send_streams().size());
2634 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2635 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2636 cricket::VideoOptions* options = NULL;
2637 session_->SetVideoSend(send_ssrc, false, options);
2638 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2639 session_->SetVideoSend(send_ssrc, true, options);
2640 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2641}
2642
2643TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
2644 TestCanInsertDtmf(false);
2645}
2646
2647TEST_F(WebRtcSessionTest, CanInsertDtmf) {
2648 TestCanInsertDtmf(true);
2649}
2650
2651TEST_F(WebRtcSessionTest, InsertDtmf) {
2652 // Setup
wu@webrtc.org91053e72013-08-10 07:18:04 +00002653 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002654 mediastream_signaling_.SendAudioVideoStream1();
2655 CreateAndSetRemoteOfferAndLocalAnswer();
2656 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2657 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
2658
2659 // Insert DTMF
2660 const int expected_flags = DF_SEND;
2661 const int expected_duration = 90;
2662 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
2663 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
2664 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
2665
2666 // Verify
2667 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
2668 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2669 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
2670 expected_duration, expected_flags));
2671 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
2672 expected_duration, expected_flags));
2673 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
2674 expected_duration, expected_flags));
2675}
2676
2677// This test verifies the |initiator| flag when session initiates the call.
2678TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002679 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002680 EXPECT_FALSE(session_->initiator());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002681 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002682 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2683 SetLocalDescriptionWithoutError(offer);
2684 EXPECT_TRUE(session_->initiator());
2685 SetRemoteDescriptionWithoutError(answer);
2686 EXPECT_TRUE(session_->initiator());
2687}
2688
2689// This test verifies the |initiator| flag when session receives the call.
2690TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002691 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002692 EXPECT_FALSE(session_->initiator());
2693 SessionDescriptionInterface* offer = CreateRemoteOffer();
2694 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002695 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002696
2697 EXPECT_FALSE(session_->initiator());
2698 SetLocalDescriptionWithoutError(answer);
2699 EXPECT_FALSE(session_->initiator());
2700}
2701
2702// This test verifies the ice protocol type at initiator of the call
2703// if |a=ice-options:google-ice| is present in answer.
2704TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002705 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002706 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002707 SessionDescriptionInterface* offer = CreateOffer();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002708 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002709 CreateRemoteAnswer(offer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002710 SetLocalDescriptionWithoutError(offer);
2711 std::string sdp;
2712 EXPECT_TRUE(answer->ToString(&sdp));
2713 // Adding ice-options to the session level.
2714 InjectAfter("t=0 0\r\n",
2715 "a=ice-options:google-ice\r\n",
2716 &sdp);
2717 SessionDescriptionInterface* answer_with_gice =
2718 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2719 SetRemoteDescriptionWithoutError(answer_with_gice);
2720 VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE);
2721 VerifyTransportType("video", cricket::ICEPROTO_GOOGLE);
2722}
2723
2724// This test verifies the ice protocol type at initiator of the call
2725// if ICE RFC5245 is supported in answer.
2726TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002727 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002728 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002729 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002730 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2731 SetLocalDescriptionWithoutError(offer);
2732
2733 SetRemoteDescriptionWithoutError(answer);
2734 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2735 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2736}
2737
2738// This test verifies the ice protocol type at receiver side of the call if
2739// receiver decides to use google-ice.
2740TEST_F(WebRtcSessionTest, TestReceiverGIceInOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002741 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002742 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002743 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002744 SetRemoteDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002745 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002746 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002747 std::string sdp;
2748 EXPECT_TRUE(answer->ToString(&sdp));
2749 // Adding ice-options to the session level.
2750 InjectAfter("t=0 0\r\n",
2751 "a=ice-options:google-ice\r\n",
2752 &sdp);
2753 SessionDescriptionInterface* answer_with_gice =
2754 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2755 SetLocalDescriptionWithoutError(answer_with_gice);
2756 VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE);
2757 VerifyTransportType("video", cricket::ICEPROTO_GOOGLE);
2758}
2759
2760// This test verifies the ice protocol type at receiver side of the call if
2761// receiver decides to use ice RFC 5245.
2762TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002763 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002764 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002765 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002766 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002767 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002768 SetLocalDescriptionWithoutError(answer);
2769 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2770 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2771}
2772
2773// This test verifies the session state when ICE RFC5245 in offer and
2774// ICE google-ice in answer.
2775TEST_F(WebRtcSessionTest, TestIceOfferGIceOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002776 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002777 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002778 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2779
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002780 std::string offer_str;
2781 offer->ToString(&offer_str);
2782 // Disable google-ice
2783 const std::string gice_option = "google-ice";
2784 const std::string xgoogle_xice = "xgoogle-xice";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002785 rtc::replace_substrs(gice_option.c_str(), gice_option.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002786 xgoogle_xice.c_str(), xgoogle_xice.length(),
2787 &offer_str);
2788 JsepSessionDescription *ice_only_offer =
2789 new JsepSessionDescription(JsepSessionDescription::kOffer);
2790 EXPECT_TRUE((ice_only_offer)->Initialize(offer_str, NULL));
2791 SetLocalDescriptionWithoutError(ice_only_offer);
2792 std::string original_offer_sdp;
2793 EXPECT_TRUE(offer->ToString(&original_offer_sdp));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002794 SessionDescriptionInterface* pranswer_with_gice =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002795 CreateSessionDescription(JsepSessionDescription::kPrAnswer,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002796 original_offer_sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002797 SetRemoteDescriptionPranswerExpectError(kPushDownTDFailed,
2798 pranswer_with_gice);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002799 SessionDescriptionInterface* answer_with_gice =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002800 CreateSessionDescription(JsepSessionDescription::kAnswer,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002801 original_offer_sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002802 SetRemoteDescriptionAnswerExpectError(kPushDownTDFailed,
2803 answer_with_gice);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002804}
2805
2806// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
2807TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002808 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002809 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002810 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002811 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002812 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002813 CreateRemoteAnswer(session_->local_description()));
2814
2815 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2816 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002817 JsepSessionDescription* modified_answer =
2818 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002819
2820 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2821 answer->session_id(),
2822 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002823 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002824
wu@webrtc.org4e393072014-04-07 17:04:35 +00002825 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002826 std::string sdp;
2827 EXPECT_TRUE(answer->ToString(&sdp));
2828 const std::string kAudioMid = "a=mid:audio";
2829 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002830 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002831 kAudioMidReplaceStr.c_str(),
2832 kAudioMidReplaceStr.length(),
2833 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002834 SessionDescriptionInterface* modified_answer1 =
2835 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002836 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002837
wu@webrtc.org4e393072014-04-07 17:04:35 +00002838 // Different media types.
2839 EXPECT_TRUE(answer->ToString(&sdp));
2840 const std::string kAudioMline = "m=audio";
2841 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002842 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00002843 kAudioMlineReplaceStr.c_str(),
2844 kAudioMlineReplaceStr.length(),
2845 &sdp);
2846 SessionDescriptionInterface* modified_answer2 =
2847 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2848 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
2849
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002850 SetRemoteDescriptionWithoutError(answer.release());
2851}
2852
2853// Verifying remote offer and local answer have matching m-lines as per
2854// RFC 3264.
2855TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002856 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002857 mediastream_signaling_.SendAudioVideoStream1();
2858 SessionDescriptionInterface* offer = CreateRemoteOffer();
2859 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002860 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002861
2862 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2863 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002864 JsepSessionDescription* modified_answer =
2865 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002866
2867 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2868 answer->session_id(),
2869 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002870 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002871 SetLocalDescriptionWithoutError(answer);
2872}
2873
2874// This test verifies that WebRtcSession does not start candidate allocation
2875// before SetLocalDescription is called.
2876TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002877 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002878 mediastream_signaling_.SendAudioVideoStream1();
2879 SessionDescriptionInterface* offer = CreateRemoteOffer();
2880 cricket::Candidate candidate;
2881 candidate.set_component(1);
2882 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2883 candidate);
2884 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2885 cricket::Candidate candidate1;
2886 candidate1.set_component(1);
2887 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2888 candidate1);
2889 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2890 SetRemoteDescriptionWithoutError(offer);
2891 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
2892 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
2893
2894 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002895 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002896 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
2897 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
2898
wu@webrtc.org91053e72013-08-10 07:18:04 +00002899 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002900 SetLocalDescriptionWithoutError(answer);
2901 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
2902 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
2903 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2904}
2905
2906// This test verifies that crypto parameter is updated in local session
2907// description as per security policy set in MediaSessionDescriptionFactory.
2908TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002909 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002910 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002911 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002912
2913 // Making sure SetLocalDescription correctly sets crypto value in
2914 // SessionDescription object after de-serialization of sdp string. The value
2915 // will be set as per MediaSessionDescriptionFactory.
2916 std::string offer_str;
2917 offer->ToString(&offer_str);
2918 SessionDescriptionInterface* jsep_offer_str =
2919 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
2920 SetLocalDescriptionWithoutError(jsep_offer_str);
2921 EXPECT_TRUE(session_->voice_channel()->secure_required());
2922 EXPECT_TRUE(session_->video_channel()->secure_required());
2923}
2924
2925// This test verifies the crypto parameter when security is disabled.
2926TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002927 options_.disable_encryption = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00002928 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002929 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002930 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002931
2932 // Making sure SetLocalDescription correctly sets crypto value in
2933 // SessionDescription object after de-serialization of sdp string. The value
2934 // will be set as per MediaSessionDescriptionFactory.
2935 std::string offer_str;
2936 offer->ToString(&offer_str);
2937 SessionDescriptionInterface *jsep_offer_str =
2938 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
2939 SetLocalDescriptionWithoutError(jsep_offer_str);
2940 EXPECT_FALSE(session_->voice_channel()->secure_required());
2941 EXPECT_FALSE(session_->video_channel()->secure_required());
2942}
2943
2944// This test verifies that an answer contains new ufrag and password if an offer
2945// with new ufrag and password is received.
2946TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002947 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002948 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002949 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002950 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002951 CreateRemoteOffer(options));
2952 SetRemoteDescriptionWithoutError(offer.release());
2953
2954 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002955 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002956 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002957 SetLocalDescriptionWithoutError(answer.release());
2958
2959 // Receive an offer with new ufrag and password.
2960 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002961 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002962 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002963 SetRemoteDescriptionWithoutError(updated_offer1.release());
2964
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002965 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002966 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002967
2968 CompareIceUfragAndPassword(updated_answer1->description(),
2969 session_->local_description()->description(),
2970 false);
2971
2972 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002973}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002974
wu@webrtc.org91053e72013-08-10 07:18:04 +00002975// This test verifies that an answer contains old ufrag and password if an offer
2976// with old ufrag and password is received.
2977TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
2978 Init(NULL);
2979 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002980 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002981 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002982 CreateRemoteOffer(options));
2983 SetRemoteDescriptionWithoutError(offer.release());
2984
2985 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002986 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002987 CreateAnswer(NULL));
2988 SetLocalDescriptionWithoutError(answer.release());
2989
2990 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002991 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002992 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002993 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002994 SetRemoteDescriptionWithoutError(updated_offer2.release());
2995
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002996 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002997 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002998
2999 CompareIceUfragAndPassword(updated_answer2->description(),
3000 session_->local_description()->description(),
3001 true);
3002
3003 SetLocalDescriptionWithoutError(updated_answer2.release());
3004}
3005
3006TEST_F(WebRtcSessionTest, TestSessionContentError) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00003007 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003008 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003009 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003010 const std::string session_id_orig = offer->session_id();
3011 const std::string session_version_orig = offer->session_version();
3012 SetLocalDescriptionWithoutError(offer);
3013
3014 video_channel_ = media_engine_->GetVideoChannel(0);
3015 video_channel_->set_fail_set_send_codecs(true);
3016
3017 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003018 SessionDescriptionInterface* answer =
3019 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003020 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003021}
3022
3023// Runs the loopback call test with BUNDLE and STUN disabled.
3024TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3025 // Lets try with only UDP ports.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00003026 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003027 cricket::PORTALLOCATOR_DISABLE_TCP |
3028 cricket::PORTALLOCATOR_DISABLE_STUN |
3029 cricket::PORTALLOCATOR_DISABLE_RELAY);
3030 TestLoopbackCall();
3031}
3032
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003033// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003034TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00003035 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003036 cricket::PORTALLOCATOR_ENABLE_BUNDLE |
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003037 cricket::PORTALLOCATOR_DISABLE_TCP |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003038 cricket::PORTALLOCATOR_DISABLE_RELAY);
3039 TestLoopbackCall();
3040}
3041
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003042TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00003043 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003044 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003045 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003046
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003047 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
3048 std::string error_code_str = "ERROR_CONTENT";
3049 std::string error_desc = "Fake session error description.";
3050 session_->SetError(error_code, error_desc);
3051
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003052 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
3053 SessionDescriptionInterface* answer =
3054 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003055
3056 std::string action;
3057 std::ostringstream session_error_msg;
3058 session_error_msg << kSessionError << error_code_str << ". ";
3059 session_error_msg << kSessionErrorDesc << error_desc << ".";
3060 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
3061 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003062}
3063
3064TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3065 constraints_.reset(new FakeConstraints());
3066 constraints_->AddOptional(
3067 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003068 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003069
3070 SetLocalDescriptionWithDataChannel();
3071 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3072}
3073
3074TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003075 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003076
3077 constraints_.reset(new FakeConstraints());
3078 constraints_->AddOptional(
3079 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003080 options_.disable_sctp_data_channels = false;
3081
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003082 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003083
3084 SetLocalDescriptionWithDataChannel();
3085 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3086}
3087
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003088TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003089 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003090
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003091 InitWithDtls();
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003092
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003093 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003094 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003095 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3096}
3097
3098TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003099 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003100 SetFactoryDtlsSrtp();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003101 InitWithDtls();
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003102
3103 // Create remote offer with SCTP.
3104 cricket::MediaSessionOptions options;
3105 options.data_channel_type = cricket::DCT_SCTP;
3106 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003107 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003108 SetRemoteDescriptionWithoutError(offer);
3109
3110 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003111 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003112 EXPECT_TRUE(answer != NULL);
3113 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3114 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003115}
3116
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003117TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
3118 constraints_.reset(new FakeConstraints());
3119 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003120 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003121 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003122
3123 SetLocalDescriptionWithDataChannel();
3124 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3125}
3126
3127TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003128 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003129
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003130 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003131
3132 SetLocalDescriptionWithDataChannel();
3133 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3134}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003135
wu@webrtc.org97077a32013-10-25 21:18:33 +00003136TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003137 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003138 options_.disable_sctp_data_channels = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003139 InitWithDtls();
wu@webrtc.org97077a32013-10-25 21:18:33 +00003140
3141 SetLocalDescriptionWithDataChannel();
3142 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3143}
3144
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003145TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003146 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003147 const int new_send_port = 9998;
3148 const int new_recv_port = 7775;
3149
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003150 InitWithDtls();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003151 SetFactoryDtlsSrtp();
3152
3153 // By default, don't actually add the codecs to desc_factory_; they don't
3154 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3155 // let the session description get parsed. That'll get the proper codecs
3156 // into the stream.
3157 cricket::MediaSessionOptions options;
3158 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3159 "stream1", new_send_port, options);
3160
3161 // SetRemoteDescription will take the ownership of the offer.
3162 SetRemoteDescriptionWithoutError(offer);
3163
3164 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3165 new_recv_port, CreateAnswer(NULL));
3166 ASSERT_TRUE(answer != NULL);
3167
3168 // Now set the local description, which'll take ownership of the answer.
3169 SetLocalDescriptionWithoutError(answer);
3170
3171 // TEST PLAN: Set the port number to something new, set it in the SDP,
3172 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003173 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003174 dci.reliable = true;
3175 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003176 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003177 session_->CreateDataChannel("datachannel", &dci);
3178
3179 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3180 int portnum = -1;
3181 ASSERT_TRUE(ch != NULL);
3182 ASSERT_EQ(1UL, ch->send_codecs().size());
3183 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
3184 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3185 ch->send_codecs()[0].name.c_str()));
3186 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3187 &portnum));
3188 EXPECT_EQ(new_send_port, portnum);
3189
3190 ASSERT_EQ(1UL, ch->recv_codecs().size());
3191 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
3192 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3193 ch->recv_codecs()[0].name.c_str()));
3194 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3195 &portnum));
3196 EXPECT_EQ(new_recv_port, portnum);
3197}
3198
wu@webrtc.org91053e72013-08-10 07:18:04 +00003199// Verifies that CreateOffer succeeds when CreateOffer is called before async
3200// identity generation is finished.
3201TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003202 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003203 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003204
3205 EXPECT_TRUE(session_->waiting_for_identity());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003206 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003207 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3208
wu@webrtc.org91053e72013-08-10 07:18:04 +00003209 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003210 VerifyNoCryptoParams(offer->description(), true);
3211 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003212}
3213
3214// Verifies that CreateAnswer succeeds when CreateOffer is called before async
3215// identity generation is finished.
3216TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003217 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003218 InitWithDtls();
3219 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003220
3221 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003222 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003223 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003224 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003225 ASSERT_TRUE(offer.get() != NULL);
3226 SetRemoteDescriptionWithoutError(offer.release());
3227
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003228 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003229 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003230 VerifyNoCryptoParams(answer->description(), true);
3231 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003232}
3233
3234// Verifies that CreateOffer succeeds when CreateOffer is called after async
3235// identity generation is finished.
3236TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003237 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003238 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003239
3240 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003241
3242 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003243 EXPECT_TRUE(offer != NULL);
3244}
3245
3246// Verifies that CreateOffer fails when CreateOffer is called after async
3247// identity generation fails.
3248TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003249 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00003250 InitWithDtls(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003251
3252 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003253
3254 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003255 EXPECT_TRUE(offer == NULL);
3256}
3257
3258// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3259// before async identity generation is finished.
3260TEST_F(WebRtcSessionTest,
3261 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003262 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003263 VerifyMultipleAsyncCreateDescription(
3264 true, CreateSessionDescriptionRequest::kOffer);
3265}
3266
3267// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3268// before async identity generation fails.
3269TEST_F(WebRtcSessionTest,
3270 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003271 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003272 VerifyMultipleAsyncCreateDescription(
3273 false, CreateSessionDescriptionRequest::kOffer);
3274}
3275
3276// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3277// before async identity generation is finished.
3278TEST_F(WebRtcSessionTest,
3279 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003280 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003281 VerifyMultipleAsyncCreateDescription(
3282 true, CreateSessionDescriptionRequest::kAnswer);
3283}
3284
3285// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3286// before async identity generation fails.
3287TEST_F(WebRtcSessionTest,
3288 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003289 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003290 VerifyMultipleAsyncCreateDescription(
3291 false, CreateSessionDescriptionRequest::kAnswer);
3292}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003293
3294// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3295// offer has no SDES crypto but only DTLS fingerprint.
3296TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3297 // Init without DTLS.
3298 Init(NULL);
3299 // Create a remote offer with secured transport disabled.
3300 cricket::MediaSessionOptions options;
3301 JsepSessionDescription* offer(CreateRemoteOffer(
3302 options, cricket::SEC_DISABLED));
3303 // Adds a DTLS fingerprint to the remote offer.
3304 cricket::SessionDescription* sdp = offer->description();
3305 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3306 ASSERT_TRUE(audio != NULL);
3307 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3308 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003309 rtc::SSLFingerprint::CreateFromRfc4572(
3310 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003311 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003312 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003313}
3314
wu@webrtc.orgde305012013-10-31 15:40:38 +00003315// This test verifies DSCP is properly applied on the media channels.
3316TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3317 constraints_.reset(new FakeConstraints());
3318 constraints_->AddOptional(
3319 webrtc::MediaConstraintsInterface::kEnableDscp, true);
3320 Init(NULL);
3321 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003322 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003323
3324 SetLocalDescriptionWithoutError(offer);
3325
3326 video_channel_ = media_engine_->GetVideoChannel(0);
3327 voice_channel_ = media_engine_->GetVoiceChannel(0);
3328
3329 ASSERT_TRUE(video_channel_ != NULL);
3330 ASSERT_TRUE(voice_channel_ != NULL);
3331 cricket::AudioOptions audio_options;
3332 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3333 cricket::VideoOptions video_options;
3334 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3335 EXPECT_TRUE(audio_options.dscp.IsSet());
3336 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3337 EXPECT_TRUE(video_options.dscp.IsSet());
3338 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3339}
3340
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003341TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3342 constraints_.reset(new FakeConstraints());
3343 constraints_->AddOptional(
3344 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3345 true);
3346 Init(NULL);
3347 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003348 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003349
3350 SetLocalDescriptionWithoutError(offer);
3351
3352 video_channel_ = media_engine_->GetVideoChannel(0);
3353
3354 ASSERT_TRUE(video_channel_ != NULL);
3355 cricket::VideoOptions video_options;
3356 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3357 EXPECT_TRUE(
3358 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3359}
3360
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00003361TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
3362 // Number of unsignalled receiving streams should be between 0 and
3363 // kMaxUnsignalledRecvStreams.
3364 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
3365 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
3366 kMaxUnsignalledRecvStreams);
3367 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
3368}
3369
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003370TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
3371 constraints_.reset(new FakeConstraints());
3372 constraints_->AddOptional(
3373 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
3374 true);
3375 Init(NULL);
3376 mediastream_signaling_.SendAudioVideoStream1();
3377 SessionDescriptionInterface* offer = CreateOffer();
3378
3379 SetLocalDescriptionWithoutError(offer);
3380
3381 voice_channel_ = media_engine_->GetVoiceChannel(0);
3382
3383 ASSERT_TRUE(voice_channel_ != NULL);
3384 cricket::AudioOptions audio_options;
3385 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3386 EXPECT_TRUE(
3387 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
3388}
3389
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003390// Tests that we can renegotiate new media content with ICE candidates in the
3391// new remote SDP.
3392TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003393 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003394 InitWithDtls();
3395 SetFactoryDtlsSrtp();
3396
3397 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003398 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003399 SetLocalDescriptionWithoutError(offer);
3400
3401 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3402 SetRemoteDescriptionWithoutError(answer);
3403
3404 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003405 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003406 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3407
3408 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003409 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003410 candidate1.set_component(1);
3411 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3412 candidate1);
3413 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3414 SetRemoteDescriptionWithoutError(offer);
3415
3416 answer = CreateAnswer(NULL);
3417 SetLocalDescriptionWithoutError(answer);
3418}
3419
3420// Tests that we can renegotiate new media content with ICE candidates separated
3421// from the remote SDP.
3422TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003423 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003424 InitWithDtls();
3425 SetFactoryDtlsSrtp();
3426
3427 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003428 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003429 SetLocalDescriptionWithoutError(offer);
3430
3431 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3432 SetRemoteDescriptionWithoutError(answer);
3433
3434 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003435 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003436 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3437 SetRemoteDescriptionWithoutError(offer);
3438
3439 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003440 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003441 candidate1.set_component(1);
3442 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3443 candidate1);
3444 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3445
3446 answer = CreateAnswer(NULL);
3447 SetLocalDescriptionWithoutError(answer);
3448}
3449
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003450// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
3451// currently fails because upon disconnection and reconnection OnIceComplete is
3452// called more than once without returning to IceGatheringGathering.