blob: 001156d338660c1f5a5447114d018df44d19682d [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
3 * Copyright 2012, Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include "talk/app/webrtc/audiotrack.h"
29#include "talk/app/webrtc/jsepicecandidate.h"
30#include "talk/app/webrtc/jsepsessiondescription.h"
31#include "talk/app/webrtc/mediastreamsignaling.h"
32#include "talk/app/webrtc/streamcollection.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000033#include "talk/app/webrtc/test/fakeconstraints.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000034#include "talk/app/webrtc/test/fakedtlsidentityservice.h"
35#include "talk/app/webrtc/test/fakemediastreamsignaling.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000036#include "talk/app/webrtc/videotrack.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000037#include "talk/app/webrtc/webrtcsession.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000038#include "talk/app/webrtc/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000039#include "talk/media/base/fakemediaengine.h"
40#include "talk/media/base/fakevideorenderer.h"
41#include "talk/media/base/mediachannel.h"
42#include "talk/media/devices/fakedevicemanager.h"
43#include "talk/p2p/base/stunserver.h"
44#include "talk/p2p/base/teststunserver.h"
45#include "talk/p2p/base/testturnserver.h"
46#include "talk/p2p/client/basicportallocator.h"
47#include "talk/session/media/channelmanager.h"
48#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000049#include "webrtc/base/fakenetwork.h"
50#include "webrtc/base/firewallsocketserver.h"
51#include "webrtc/base/gunit.h"
52#include "webrtc/base/logging.h"
53#include "webrtc/base/network.h"
54#include "webrtc/base/physicalsocketserver.h"
55#include "webrtc/base/ssladapter.h"
56#include "webrtc/base/sslstreamadapter.h"
57#include "webrtc/base/stringutils.h"
58#include "webrtc/base/thread.h"
59#include "webrtc/base/virtualsocketserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000060
61#define MAYBE_SKIP_TEST(feature) \
62 if (!(feature())) { \
63 LOG(LS_INFO) << "Feature disabled... skipping"; \
64 return; \
65 }
66
67using cricket::BaseSession;
68using cricket::DF_PLAY;
69using cricket::DF_SEND;
70using cricket::FakeVoiceMediaChannel;
71using cricket::NS_GINGLE_P2P;
72using cricket::NS_JINGLE_ICE_UDP;
73using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000074using rtc::SocketAddress;
75using rtc::scoped_ptr;
76using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000077using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000078using webrtc::CreateSessionDescriptionObserver;
79using webrtc::CreateSessionDescriptionRequest;
80using webrtc::DTLSIdentityRequestObserver;
81using webrtc::DTLSIdentityServiceInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082using webrtc::FakeConstraints;
83using webrtc::IceCandidateCollection;
84using webrtc::JsepIceCandidate;
85using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000086using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087using webrtc::PeerConnectionInterface;
88using webrtc::SessionDescriptionInterface;
89using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000090using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000091using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000092using webrtc::kCreateChannelFailed;
93using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000095using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000096using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000097using webrtc::kSdpWithoutDtlsFingerprint;
98using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000100using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000101using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000102
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000103typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
104
wu@webrtc.org364f2042013-11-20 21:49:41 +0000105static const int kClientAddrPort = 0;
106static const char kClientAddrHost1[] = "11.11.11.11";
107static const char kClientAddrHost2[] = "22.22.22.22";
108static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000109static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
110static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000111
112static const char kSessionVersion[] = "1";
113
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000114// Media index of candidates belonging to the first media content.
115static const int kMediaContentIndex0 = 0;
116static const char kMediaContentName0[] = "audio";
117
118// Media index of candidates belonging to the second media content.
119static const int kMediaContentIndex1 = 1;
120static const char kMediaContentName1[] = "video";
121
122static const int kIceCandidatesTimeout = 10000;
123
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000124static const char kFakeDtlsFingerprint[] =
125 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
126 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
127
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000128static const char kTooLongIceUfragPwd[] =
129 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
130 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
131 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
132 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
133
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000134// Add some extra |newlines| to the |message| after |line|.
135static void InjectAfter(const std::string& line,
136 const std::string& newlines,
137 std::string* message) {
138 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000139 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000140 tmp.c_str(), tmp.length(), message);
141}
142
143class MockIceObserver : public webrtc::IceObserver {
144 public:
145 MockIceObserver()
146 : oncandidatesready_(false),
147 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
148 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
149 }
150
151 virtual void OnIceConnectionChange(
152 PeerConnectionInterface::IceConnectionState new_state) {
153 ice_connection_state_ = new_state;
154 }
155 virtual void OnIceGatheringChange(
156 PeerConnectionInterface::IceGatheringState new_state) {
157 // We can never transition back to "new".
158 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
159 ice_gathering_state_ = new_state;
160
161 // oncandidatesready_ really means "ICE gathering is complete".
162 // This if statement ensures that this value remains correct when we
163 // transition from kIceGatheringComplete to kIceGatheringGathering.
164 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
165 oncandidatesready_ = false;
166 }
167 }
168
169 // Found a new candidate.
170 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000171 switch (candidate->sdp_mline_index()) {
172 case kMediaContentIndex0:
173 mline_0_candidates_.push_back(candidate->candidate());
174 break;
175 case kMediaContentIndex1:
176 mline_1_candidates_.push_back(candidate->candidate());
177 break;
178 default:
179 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000180 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000181
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000182 // The ICE gathering state should always be Gathering when a candidate is
183 // received (or possibly Completed in the case of the final candidate).
184 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
185 }
186
187 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
188 virtual void OnIceComplete() {
189 EXPECT_FALSE(oncandidatesready_);
190 oncandidatesready_ = true;
191
192 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
193 // be called approximately simultaneously. For ease of testing, this
194 // check additionally requires that they be called in the above order.
195 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
196 ice_gathering_state_);
197 }
198
199 bool oncandidatesready_;
200 std::vector<cricket::Candidate> mline_0_candidates_;
201 std::vector<cricket::Candidate> mline_1_candidates_;
202 PeerConnectionInterface::IceConnectionState ice_connection_state_;
203 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
204};
205
206class WebRtcSessionForTest : public webrtc::WebRtcSession {
207 public:
208 WebRtcSessionForTest(cricket::ChannelManager* cmgr,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000209 rtc::Thread* signaling_thread,
210 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000211 cricket::PortAllocator* port_allocator,
212 webrtc::IceObserver* ice_observer,
213 webrtc::MediaStreamSignaling* mediastream_signaling)
214 : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator,
215 mediastream_signaling) {
216 RegisterIceObserver(ice_observer);
217 }
218 virtual ~WebRtcSessionForTest() {}
219
220 using cricket::BaseSession::GetTransportProxy;
221 using webrtc::WebRtcSession::SetAudioPlayout;
222 using webrtc::WebRtcSession::SetAudioSend;
223 using webrtc::WebRtcSession::SetCaptureDevice;
224 using webrtc::WebRtcSession::SetVideoPlayout;
225 using webrtc::WebRtcSession::SetVideoSend;
226};
227
wu@webrtc.org91053e72013-08-10 07:18:04 +0000228class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000229 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000230 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000231 enum State {
232 kInit,
233 kFailed,
234 kSucceeded,
235 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000236 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000237
238 // CreateSessionDescriptionObserver implementation.
239 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000240 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000241 state_ = kSucceeded;
242 }
243 virtual void OnFailure(const std::string& error) {
244 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000245 }
246
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000247 SessionDescriptionInterface* description() { return description_.get(); }
248
249 SessionDescriptionInterface* ReleaseDescription() {
250 return description_.release();
251 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000252
wu@webrtc.org91053e72013-08-10 07:18:04 +0000253 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000254
wu@webrtc.org91053e72013-08-10 07:18:04 +0000255 protected:
256 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257
258 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000259 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000260 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000261};
262
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000263class FakeAudioRenderer : public cricket::AudioRenderer {
264 public:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000265 FakeAudioRenderer() : channel_id_(-1), sink_(NULL) {}
266 virtual ~FakeAudioRenderer() {
267 if (sink_)
268 sink_->OnClose();
269 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000270
271 virtual void AddChannel(int channel_id) OVERRIDE {
272 ASSERT(channel_id_ == -1);
273 channel_id_ = channel_id;
274 }
275 virtual void RemoveChannel(int channel_id) OVERRIDE {
276 ASSERT(channel_id == channel_id_);
277 channel_id_ = -1;
278 }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000279 virtual void SetSink(Sink* sink) OVERRIDE {
280 sink_ = sink;
281 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000282
283 int channel_id() const { return channel_id_; }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000284 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000285 private:
286 int channel_id_;
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000287 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000288};
289
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000290class WebRtcSessionTest : public testing::Test {
291 protected:
292 // TODO Investigate why ChannelManager crashes, if it's created
293 // after stun_server.
294 WebRtcSessionTest()
295 : media_engine_(new cricket::FakeMediaEngine()),
296 data_engine_(new cricket::FakeDataEngine()),
297 device_manager_(new cricket::FakeDeviceManager()),
298 channel_manager_(new cricket::ChannelManager(
299 media_engine_, data_engine_, device_manager_,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000300 new cricket::CaptureManager(), rtc::Thread::Current())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000301 tdesc_factory_(new cricket::TransportDescriptionFactory()),
302 desc_factory_(new cricket::MediaSessionDescriptionFactory(
303 channel_manager_.get(), tdesc_factory_.get())),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000304 pss_(new rtc::PhysicalSocketServer),
305 vss_(new rtc::VirtualSocketServer(pss_.get())),
306 fss_(new rtc::FirewallSocketServer(vss_.get())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000307 ss_scope_(fss_.get()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000308 stun_socket_addr_(rtc::SocketAddress(kStunAddrHost,
wu@webrtc.org364f2042013-11-20 21:49:41 +0000309 cricket::STUN_SERVER_PORT)),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000310 stun_server_(Thread::Current(), stun_socket_addr_),
311 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000312 mediastream_signaling_(channel_manager_.get()),
313 ice_type_(PeerConnectionInterface::kAll) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000314 tdesc_factory_->set_protocol(cricket::ICEPROTO_HYBRID);
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000315
316 cricket::ServerAddresses stun_servers;
317 stun_servers.insert(stun_socket_addr_);
318 allocator_.reset(new cricket::BasicPortAllocator(
319 &network_manager_,
320 stun_servers,
321 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000322 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323 cricket::PORTALLOCATOR_DISABLE_RELAY |
324 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
325 EXPECT_TRUE(channel_manager_->Init());
326 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000327 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000328 }
329
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000330 static void SetUpTestCase() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000331 rtc::InitializeSSL();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000332 }
333
334 static void TearDownTestCase() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000335 rtc::CleanupSSL();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000336 }
337
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000338 void AddInterface(const SocketAddress& addr) {
339 network_manager_.AddInterface(addr);
340 }
341
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000342 void SetIceTransportType(PeerConnectionInterface::IceTransportsType type) {
343 ice_type_ = type;
344 }
345
wu@webrtc.org91053e72013-08-10 07:18:04 +0000346 void Init(DTLSIdentityServiceInterface* identity_service) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000347 ASSERT_TRUE(session_.get() == NULL);
348 session_.reset(new WebRtcSessionForTest(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000349 channel_manager_.get(), rtc::Thread::Current(),
350 rtc::Thread::Current(), allocator_.get(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000351 &observer_,
352 &mediastream_signaling_));
353
354 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
355 observer_.ice_connection_state_);
356 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
357 observer_.ice_gathering_state_);
358
wu@webrtc.org97077a32013-10-25 21:18:33 +0000359 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000360 identity_service, ice_type_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000361 }
362
363 void InitWithDtmfCodec() {
364 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000365 const cricket::AudioCodec kTelephoneEventCodec(
366 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000367 std::vector<cricket::AudioCodec> codecs;
368 codecs.push_back(kTelephoneEventCodec);
369 media_engine_->SetAudioCodecs(codecs);
370 desc_factory_->set_audio_codecs(codecs);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000371 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000372 }
373
henrike@webrtc.org7666db72013-08-22 14:45:42 +0000374 void InitWithDtls(bool identity_request_should_fail = false) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000375 FakeIdentityService* identity_service = new FakeIdentityService();
376 identity_service->set_should_fail(identity_request_should_fail);
377 Init(identity_service);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000378 }
379
380 // Creates a local offer and applies it. Starts ice.
381 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
382 // to decide which streams to create.
383 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000384 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000385 SetLocalDescriptionWithoutError(offer);
386 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
387 observer_.ice_gathering_state_,
388 kIceCandidatesTimeout);
389 }
390
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000391 SessionDescriptionInterface* CreateOffer() {
392 PeerConnectionInterface::RTCOfferAnswerOptions options;
393 options.offer_to_receive_audio =
394 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
395
396 return CreateOffer(options);
397 }
398
wu@webrtc.org91053e72013-08-10 07:18:04 +0000399 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000400 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000401 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000402 observer = new WebRtcSessionCreateSDPObserverForTest();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000403 session_->CreateOffer(observer, options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000404 EXPECT_TRUE_WAIT(
405 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000406 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000407 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000408 }
409
410 SessionDescriptionInterface* CreateAnswer(
411 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000412 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000413 = new WebRtcSessionCreateSDPObserverForTest();
414 session_->CreateAnswer(observer, constraints);
415 EXPECT_TRUE_WAIT(
416 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000417 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000418 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000419 }
420
wu@webrtc.org364f2042013-11-20 21:49:41 +0000421 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000422 return (session_->voice_channel() != NULL &&
423 session_->video_channel() != NULL);
424 }
425
wu@webrtc.org364f2042013-11-20 21:49:41 +0000426 void CheckTransportChannels() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000427 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 1) != NULL);
428 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 2) != NULL);
429 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 1) != NULL);
430 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 2) != NULL);
431 }
432
433 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
434 ASSERT_TRUE(session_.get() != NULL);
435 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
436 ASSERT_TRUE(content != NULL);
437 const cricket::AudioContentDescription* audio_content =
438 static_cast<const cricket::AudioContentDescription*>(
439 content->description);
440 ASSERT_TRUE(audio_content != NULL);
441 ASSERT_EQ(1U, audio_content->cryptos().size());
442 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
443 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
444 audio_content->cryptos()[0].cipher_suite);
445 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
446 audio_content->protocol());
447
448 content = cricket::GetFirstVideoContent(sdp);
449 ASSERT_TRUE(content != NULL);
450 const cricket::VideoContentDescription* video_content =
451 static_cast<const cricket::VideoContentDescription*>(
452 content->description);
453 ASSERT_TRUE(video_content != NULL);
454 ASSERT_EQ(1U, video_content->cryptos().size());
455 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
456 video_content->cryptos()[0].cipher_suite);
457 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
458 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
459 video_content->protocol());
460 }
461
462 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
463 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
464 ASSERT_TRUE(content != NULL);
465 const cricket::AudioContentDescription* audio_content =
466 static_cast<const cricket::AudioContentDescription*>(
467 content->description);
468 ASSERT_TRUE(audio_content != NULL);
469 ASSERT_EQ(0U, audio_content->cryptos().size());
470
471 content = cricket::GetFirstVideoContent(sdp);
472 ASSERT_TRUE(content != NULL);
473 const cricket::VideoContentDescription* video_content =
474 static_cast<const cricket::VideoContentDescription*>(
475 content->description);
476 ASSERT_TRUE(video_content != NULL);
477 ASSERT_EQ(0U, video_content->cryptos().size());
478
479 if (dtls) {
480 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
481 audio_content->protocol());
482 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
483 video_content->protocol());
484 } else {
485 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
486 audio_content->protocol());
487 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
488 video_content->protocol());
489 }
490 }
491
492 // Set the internal fake description factories to do DTLS-SRTP.
493 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000494 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000495 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000496 rtc::ToString(rtc::CreateRandomId());
497 identity_.reset(rtc::SSLIdentity::Generate(identity_name));
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000498 tdesc_factory_->set_identity(identity_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000499 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
500 }
501
502 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
503 bool expected) {
504 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
505 ASSERT_TRUE(audio != NULL);
506 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000507 const TransportInfo* video = sdp->GetTransportInfoByName("video");
508 ASSERT_TRUE(video != NULL);
509 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000510 }
511
512 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org52055a22014-09-04 17:12:25 +0000513 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000514 cricket::MediaSessionOptions options;
515 options.has_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000516 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000517 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000518 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000519 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000520 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
521 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000522 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000523 // Answer should be NULL as no crypto params in offer.
524 ASSERT_TRUE(answer == NULL);
525 }
526
527 void VerifyAnswerFromCryptoOffer() {
528 cricket::MediaSessionOptions options;
529 options.has_video = true;
530 options.bundle_enabled = true;
531 scoped_ptr<JsepSessionDescription> offer(
532 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
533 ASSERT_TRUE(offer.get() != NULL);
534 VerifyCryptoParams(offer->description());
535 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000536 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000537 ASSERT_TRUE(answer.get() != NULL);
538 VerifyCryptoParams(answer->description());
539 }
540
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000541 void SetAndVerifyNumUnsignalledRecvStreams(
542 int value_set, int value_expected) {
543 constraints_.reset(new FakeConstraints());
544 constraints_->AddOptional(
545 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
546 value_set);
547 session_.reset();
548 Init(NULL);
549 mediastream_signaling_.SendAudioVideoStream1();
550 SessionDescriptionInterface* offer = CreateOffer();
551
552 SetLocalDescriptionWithoutError(offer);
553
554 video_channel_ = media_engine_->GetVideoChannel(0);
555
556 ASSERT_TRUE(video_channel_ != NULL);
557 cricket::VideoOptions video_options;
558 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
559 EXPECT_EQ(value_expected,
560 video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1));
561 }
562
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000563 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
564 const cricket::SessionDescription* desc2,
565 bool expect_equal) {
566 if (desc1->contents().size() != desc2->contents().size()) {
567 EXPECT_FALSE(expect_equal);
568 return;
569 }
570
571 const cricket::ContentInfos& contents = desc1->contents();
572 cricket::ContentInfos::const_iterator it = contents.begin();
573
574 for (; it != contents.end(); ++it) {
575 const cricket::TransportDescription* transport_desc1 =
576 desc1->GetTransportDescriptionByName(it->name);
577 const cricket::TransportDescription* transport_desc2 =
578 desc2->GetTransportDescriptionByName(it->name);
579 if (!transport_desc1 || !transport_desc2) {
580 EXPECT_FALSE(expect_equal);
581 return;
582 }
583 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
584 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
585 EXPECT_FALSE(expect_equal);
586 return;
587 }
588 }
589 EXPECT_TRUE(expect_equal);
590 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000591
592 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
593 std::string *sdp) {
594 const cricket::SessionDescription* desc = current_desc->description();
595 EXPECT_TRUE(current_desc->ToString(sdp));
596
597 const cricket::ContentInfos& contents = desc->contents();
598 cricket::ContentInfos::const_iterator it = contents.begin();
599 // Replace ufrag and pwd lines with empty strings.
600 for (; it != contents.end(); ++it) {
601 const cricket::TransportDescription* transport_desc =
602 desc->GetTransportDescriptionByName(it->name);
603 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
604 + "\r\n";
605 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
606 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000607 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000608 "", 0,
609 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000610 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000611 "", 0,
612 sdp);
613 }
614 }
615
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000616 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
617 const std::string& modified_ice_ufrag,
618 const std::string& modified_ice_pwd,
619 std::string* sdp) {
620 const cricket::SessionDescription* desc = current_desc->description();
621 EXPECT_TRUE(current_desc->ToString(sdp));
622
623 const cricket::ContentInfos& contents = desc->contents();
624 cricket::ContentInfos::const_iterator it = contents.begin();
625 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
626 // |modified_ice_pwd| strings.
627 for (; it != contents.end(); ++it) {
628 const cricket::TransportDescription* transport_desc =
629 desc->GetTransportDescriptionByName(it->name);
630 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
631 + "\r\n";
632 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
633 + "\r\n";
634 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
635 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000636 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000637 mod_ufrag.c_str(), mod_ufrag.length(),
638 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000639 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000640 mod_pwd.c_str(), mod_pwd.length(),
641 sdp);
642 }
643 }
644
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000645 // Creates a remote offer and and applies it as a remote description,
646 // creates a local answer and applies is as a local description.
647 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
648 // to decide which local and remote streams to create.
649 void CreateAndSetRemoteOfferAndLocalAnswer() {
650 SessionDescriptionInterface* offer = CreateRemoteOffer();
651 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000652 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000653 SetLocalDescriptionWithoutError(answer);
654 }
655 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
656 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
657 }
658 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
659 BaseSession::State expected_state) {
660 SetLocalDescriptionWithoutError(desc);
661 EXPECT_EQ(expected_state, session_->state());
662 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000663 void SetLocalDescriptionExpectError(const std::string& action,
664 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000665 SessionDescriptionInterface* desc) {
666 std::string error;
667 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000668 std::string sdp_type = "local ";
669 sdp_type.append(action);
670 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000671 EXPECT_NE(std::string::npos, error.find(expected_error));
672 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000673 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
674 SessionDescriptionInterface* desc) {
675 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
676 expected_error, desc);
677 }
678 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
679 SessionDescriptionInterface* desc) {
680 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
681 expected_error, desc);
682 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000683 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
684 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
685 }
686 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
687 BaseSession::State expected_state) {
688 SetRemoteDescriptionWithoutError(desc);
689 EXPECT_EQ(expected_state, session_->state());
690 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000691 void SetRemoteDescriptionExpectError(const std::string& action,
692 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693 SessionDescriptionInterface* desc) {
694 std::string error;
695 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000696 std::string sdp_type = "remote ";
697 sdp_type.append(action);
698 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000699 EXPECT_NE(std::string::npos, error.find(expected_error));
700 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000701 void SetRemoteDescriptionOfferExpectError(
702 const std::string& expected_error, SessionDescriptionInterface* desc) {
703 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
704 expected_error, desc);
705 }
706 void SetRemoteDescriptionPranswerExpectError(
707 const std::string& expected_error, SessionDescriptionInterface* desc) {
708 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
709 expected_error, desc);
710 }
711 void SetRemoteDescriptionAnswerExpectError(
712 const std::string& expected_error, SessionDescriptionInterface* desc) {
713 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
714 expected_error, desc);
715 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000716
717 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
718 SessionDescriptionInterface** nocrypto_answer) {
719 // Create a SDP without Crypto.
720 cricket::MediaSessionOptions options;
721 options.has_video = true;
722 options.bundle_enabled = true;
723 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
724 ASSERT_TRUE(*offer != NULL);
725 VerifyCryptoParams((*offer)->description());
726
727 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
728 cricket::SEC_DISABLED);
729 EXPECT_TRUE(*nocrypto_answer != NULL);
730 }
731
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000732 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
733 SessionDescriptionInterface** nodtls_answer) {
734 cricket::MediaSessionOptions options;
735 options.has_video = true;
736 options.bundle_enabled = true;
737
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000738 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000739 CreateRemoteOffer(options, cricket::SEC_ENABLED));
740
741 *nodtls_answer =
742 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
743 EXPECT_TRUE(*nodtls_answer != NULL);
744 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
745 VerifyCryptoParams((*nodtls_answer)->description());
746
747 SetFactoryDtlsSrtp();
748 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
749 ASSERT_TRUE(*offer != NULL);
750 VerifyFingerprintStatus((*offer)->description(), true);
751 VerifyCryptoParams((*offer)->description());
752 }
753
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754 JsepSessionDescription* CreateRemoteOfferWithVersion(
755 cricket::MediaSessionOptions options,
756 cricket::SecurePolicy secure_policy,
757 const std::string& session_version,
758 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000759 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000760 const cricket::SessionDescription* cricket_desc = NULL;
761 if (current_desc) {
762 cricket_desc = current_desc->description();
763 session_id = current_desc->session_id();
764 }
765
766 desc_factory_->set_secure(secure_policy);
767 JsepSessionDescription* offer(
768 new JsepSessionDescription(JsepSessionDescription::kOffer));
769 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
770 session_id, session_version)) {
771 delete offer;
772 offer = NULL;
773 }
774 return offer;
775 }
776 JsepSessionDescription* CreateRemoteOffer(
777 cricket::MediaSessionOptions options) {
778 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
779 kSessionVersion, NULL);
780 }
781 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000782 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
783 return CreateRemoteOfferWithVersion(
784 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785 }
786 JsepSessionDescription* CreateRemoteOffer(
787 cricket::MediaSessionOptions options,
788 const SessionDescriptionInterface* current_desc) {
789 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
790 kSessionVersion, current_desc);
791 }
792
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000793 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
794 const char* sctp_stream_name, int new_port,
795 cricket::MediaSessionOptions options) {
796 options.data_channel_type = cricket::DCT_SCTP;
797 options.AddStream(cricket::MEDIA_TYPE_DATA, "datachannel",
798 sctp_stream_name);
799 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
800 }
801
802 // Takes ownership of offer_basis (and deletes it).
803 JsepSessionDescription* ChangeSDPSctpPort(
804 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
805 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
806 // SessionDescription from the mutated string.
807 const char* default_port_str = "5000";
808 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000809 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000810 std::string offer_str;
811 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000812 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000813 new_port_str, strlen(new_port_str),
814 &offer_str);
815 JsepSessionDescription* offer = new JsepSessionDescription(
816 offer_basis->type());
817 delete offer_basis;
818 offer->Initialize(offer_str, NULL);
819 return offer;
820 }
821
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
823 // before this function to decide which streams to create.
824 JsepSessionDescription* CreateRemoteOffer() {
825 cricket::MediaSessionOptions options;
826 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
827 return CreateRemoteOffer(options, session_->remote_description());
828 }
829
830 JsepSessionDescription* CreateRemoteAnswer(
831 const SessionDescriptionInterface* offer,
832 cricket::MediaSessionOptions options,
833 cricket::SecurePolicy policy) {
834 desc_factory_->set_secure(policy);
835 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000836 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000837 JsepSessionDescription* answer(
838 new JsepSessionDescription(JsepSessionDescription::kAnswer));
839 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
840 options, NULL),
841 session_id, kSessionVersion)) {
842 delete answer;
843 answer = NULL;
844 }
845 return answer;
846 }
847
848 JsepSessionDescription* CreateRemoteAnswer(
849 const SessionDescriptionInterface* offer,
850 cricket::MediaSessionOptions options) {
851 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
852 }
853
854 // Creates an answer session description with streams based on
855 // |mediastream_signaling_|. Call
856 // mediastream_signaling_.UseOptionsWithStreamX() before this function
857 // to decide which streams to create.
858 JsepSessionDescription* CreateRemoteAnswer(
859 const SessionDescriptionInterface* offer) {
860 cricket::MediaSessionOptions options;
861 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
862 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
863 }
864
865 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000866 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +0000867 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000868 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000869
870 PeerConnectionInterface::RTCOfferAnswerOptions options;
871 options.use_rtp_mux = bundle;
872
873 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000874 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
875 // and answer.
876 SetLocalDescriptionWithoutError(offer);
877
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000878 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000879 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000880 std::string sdp;
881 EXPECT_TRUE(answer->ToString(&sdp));
882
883 size_t expected_candidate_num = 2;
884 if (!rtcp_mux) {
885 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
886 // for rtp and rtcp.
887 expected_candidate_num = 4;
888 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000889 const std::string kRtcpMux = "a=rtcp-mux";
890 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000891 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000892 kXRtcpMux.c_str(), kXRtcpMux.length(),
893 &sdp);
894 }
895
896 SessionDescriptionInterface* new_answer = CreateSessionDescription(
897 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000898
899 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000900 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000901 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
902 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
903 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
904 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
905 cricket::Candidate c0 = observer_.mline_0_candidates_[i];
906 cricket::Candidate c1 = observer_.mline_1_candidates_[i];
907 if (bundle) {
908 EXPECT_TRUE(c0.IsEquivalent(c1));
909 } else {
910 EXPECT_FALSE(c0.IsEquivalent(c1));
911 }
912 }
913 }
914 // Tests that we can only send DTMF when the dtmf codec is supported.
915 void TestCanInsertDtmf(bool can) {
916 if (can) {
917 InitWithDtmfCodec();
918 } else {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000919 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000920 }
921 mediastream_signaling_.SendAudioVideoStream1();
922 CreateAndSetRemoteOfferAndLocalAnswer();
923 EXPECT_FALSE(session_->CanInsertDtmf(""));
924 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
925 }
926
927 // The method sets up a call from the session to itself, in a loopback
928 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000929 // disconnection, and then a permanent disconnection.
930 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000931 // by multiple tests with different allocators (e.g. with and without BUNDLE).
932 // While running the call, this method also checks if the session goes through
933 // the correct sequence of ICE states when a connection is established,
934 // broken, and re-established.
935 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000936 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
937 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000938 // The Gathering state should go: New -> Gathering -> Completed.
939 void TestLoopbackCall() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000940 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +0000941 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000942 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000943 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000944
945 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
946 observer_.ice_gathering_state_);
947 SetLocalDescriptionWithoutError(offer);
948 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
949 observer_.ice_connection_state_);
950 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
951 observer_.ice_gathering_state_,
952 kIceCandidatesTimeout);
953 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
954 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
955 observer_.ice_gathering_state_,
956 kIceCandidatesTimeout);
957
958 std::string sdp;
959 offer->ToString(&sdp);
960 SessionDescriptionInterface* desc =
961 webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer, sdp);
962 ASSERT_TRUE(desc != NULL);
963 SetRemoteDescriptionWithoutError(desc);
964
965 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
966 observer_.ice_connection_state_,
967 kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +0000968
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000969 // The ice connection state is "Connected" too briefly to catch in a test.
970 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000971 observer_.ice_connection_state_,
972 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000973
974 // Adding firewall rule to block ping requests, which should cause
975 // transport channel failure.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000976 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000977 rtc::FP_ANY,
978 rtc::FD_ANY,
979 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000980 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
981 observer_.ice_connection_state_,
982 kIceCandidatesTimeout);
983
984 // Clearing the rules, session should move back to completed state.
985 fss_->ClearRules();
986 // Session is automatically calling OnSignalingReady after creation of
987 // new portallocator session which will allocate new set of candidates.
988
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000989 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000990 observer_.ice_connection_state_,
991 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000992
993 // Now we block ping requests and wait until the ICE connection transitions
994 // to the Failed state. This will take at least 30 seconds because it must
995 // wait for the Port to timeout.
996 int port_timeout = 30000;
997 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000998 rtc::FP_ANY,
999 rtc::FD_ANY,
1000 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001001 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionFailed,
1002 observer_.ice_connection_state_,
1003 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001004 }
1005
1006 void VerifyTransportType(const std::string& content_name,
1007 cricket::TransportProtocol protocol) {
1008 const cricket::Transport* transport = session_->GetTransport(content_name);
1009 ASSERT_TRUE(transport != NULL);
1010 EXPECT_EQ(protocol, transport->protocol());
1011 }
1012
1013 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1014 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001015 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1016 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1017
1018 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001019 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1020 codecs.push_back(kCNCodec1);
1021 codecs.push_back(kCNCodec2);
1022 media_engine_->SetAudioCodecs(codecs);
1023 desc_factory_->set_audio_codecs(codecs);
1024 }
1025
1026 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1027 const cricket::ContentDescription* description = content->description;
1028 ASSERT(description != NULL);
1029 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001030 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001031 ASSERT(audio_content_desc != NULL);
1032 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1033 if (audio_content_desc->codecs()[i].name == "CN")
1034 return false;
1035 }
1036 return true;
1037 }
1038
1039 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001040 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001041 dci.reliable = false;
1042 session_->CreateDataChannel("datachannel", &dci);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001043 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001044 SetLocalDescriptionWithoutError(offer);
1045 }
1046
wu@webrtc.org91053e72013-08-10 07:18:04 +00001047 void VerifyMultipleAsyncCreateDescription(
1048 bool success, CreateSessionDescriptionRequest::Type type) {
henrike@webrtc.org7666db72013-08-22 14:45:42 +00001049 InitWithDtls(!success);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001050 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001051 if (type == CreateSessionDescriptionRequest::kAnswer) {
1052 cricket::MediaSessionOptions options;
1053 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001054 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001055 ASSERT_TRUE(offer.get() != NULL);
1056 SetRemoteDescriptionWithoutError(offer.release());
1057 }
1058
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001059 PeerConnectionInterface::RTCOfferAnswerOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001060 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001061 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001062 observers[kNumber];
1063 for (int i = 0; i < kNumber; ++i) {
1064 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1065 if (type == CreateSessionDescriptionRequest::kOffer) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001066 session_->CreateOffer(observers[i], options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001067 } else {
1068 session_->CreateAnswer(observers[i], NULL);
1069 }
1070 }
1071
1072 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1073 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1074 WebRtcSessionCreateSDPObserverForTest::kFailed;
1075
1076 for (int i = 0; i < kNumber; ++i) {
1077 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1078 if (success) {
1079 EXPECT_TRUE(observers[i]->description() != NULL);
1080 } else {
1081 EXPECT_TRUE(observers[i]->description() == NULL);
1082 }
1083 }
1084 }
1085
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001086 cricket::FakeMediaEngine* media_engine_;
1087 cricket::FakeDataEngine* data_engine_;
1088 cricket::FakeDeviceManager* device_manager_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001089 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
1090 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1091 rtc::scoped_ptr<rtc::SSLIdentity> identity_;
1092 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1093 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1094 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1095 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1096 rtc::SocketServerScope ss_scope_;
1097 rtc::SocketAddress stun_socket_addr_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001098 cricket::TestStunServer stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001099 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001100 rtc::FakeNetworkManager network_manager_;
1101 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001102 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001103 rtc::scoped_ptr<FakeConstraints> constraints_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001104 FakeMediaStreamSignaling mediastream_signaling_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001105 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001106 MockIceObserver observer_;
1107 cricket::FakeVideoMediaChannel* video_channel_;
1108 cricket::FakeVoiceMediaChannel* voice_channel_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001109 PeerConnectionInterface::IceTransportsType ice_type_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001110};
1111
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001112TEST_F(WebRtcSessionTest, TestInitializeWithDtls) {
1113 InitWithDtls();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001114 // SDES is disabled when DTLS is on.
1115 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001116}
1117
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001118TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001119 Init(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001120 // SDES is required if DTLS is off.
1121 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001122}
1123
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001124TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1125 TestSessionCandidatesWithBundleRtcpMux(false, false);
1126}
1127
1128// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1129// with rtcp-mux and/or bundle.
1130TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1131 TestSessionCandidatesWithBundleRtcpMux(false, true);
1132}
1133
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001134TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1135 TestSessionCandidatesWithBundleRtcpMux(true, true);
1136}
1137
1138TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001139 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1140 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001141 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001142 mediastream_signaling_.SendAudioVideoStream1();
1143 InitiateCall();
1144 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1145 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1146 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1147}
1148
1149TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001150 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1151 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001152 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001153 rtc::FP_UDP,
1154 rtc::FD_ANY,
1155 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001156 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001157 mediastream_signaling_.SendAudioVideoStream1();
1158 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001159 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001160 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1161 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1162 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1163}
1164
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001165TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
1166 Init(NULL);
1167 SessionDescriptionInterface* offer = NULL;
1168 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1169 std::string unknown_action;
1170 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1171 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1172}
1173
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001174// Test creating offers and receive answers and make sure the
1175// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001176TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001177 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001178 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001179 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001180 const std::string session_id_orig = offer->session_id();
1181 const std::string session_version_orig = offer->session_version();
1182 SetLocalDescriptionWithoutError(offer);
1183
1184 mediastream_signaling_.SendAudioVideoStream2();
1185 SessionDescriptionInterface* answer =
1186 CreateRemoteAnswer(session_->local_description());
1187 SetRemoteDescriptionWithoutError(answer);
1188
1189 video_channel_ = media_engine_->GetVideoChannel(0);
1190 voice_channel_ = media_engine_->GetVoiceChannel(0);
1191
1192 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1193 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1194
1195 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1196 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1197
1198 ASSERT_EQ(1u, video_channel_->send_streams().size());
1199 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1200 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1201 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1202
1203 // Create new offer without send streams.
1204 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001205 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001206
1207 // Verify the session id is the same and the session version is
1208 // increased.
1209 EXPECT_EQ(session_id_orig, offer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001210 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1211 rtc::FromString<uint64>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001212
1213 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org52055a22014-09-04 17:12:25 +00001214 EXPECT_EQ(0u, video_channel_->send_streams().size());
1215 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001216
1217 mediastream_signaling_.SendAudioVideoStream2();
1218 answer = CreateRemoteAnswer(session_->local_description());
1219 SetRemoteDescriptionWithoutError(answer);
1220
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001221 // Make sure the receive streams have not changed.
1222 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1223 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1224 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1225 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1226}
1227
1228// Test receiving offers and creating 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, TestReceiveSdesOfferCreateSdesAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001231 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001232 mediastream_signaling_.SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001233 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001234 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001235 SetRemoteDescriptionWithoutError(offer);
1236
1237 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001238 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001239 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001240 SetLocalDescriptionWithoutError(answer);
1241
1242 const std::string session_id_orig = answer->session_id();
1243 const std::string session_version_orig = answer->session_version();
1244
1245 video_channel_ = media_engine_->GetVideoChannel(0);
1246 voice_channel_ = media_engine_->GetVoiceChannel(0);
1247
1248 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1249 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1250
1251 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1252 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1253
1254 ASSERT_EQ(1u, video_channel_->send_streams().size());
1255 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1256 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1257 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1258
1259 mediastream_signaling_.SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001260 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001261 SetRemoteDescriptionWithoutError(offer);
1262
1263 // Answer by turning off all send streams.
1264 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001265 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001266
1267 // Verify the session id is the same and the session version is
1268 // increased.
1269 EXPECT_EQ(session_id_orig, answer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001270 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1271 rtc::FromString<uint64>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001272 SetLocalDescriptionWithoutError(answer);
1273
1274 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1275 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1276 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1277 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1278 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1279 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1280
1281 // Make sure we have no send streams.
1282 EXPECT_EQ(0u, video_channel_->send_streams().size());
1283 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1284}
1285
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001286TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
1287 Init(NULL);
1288 media_engine_->set_fail_create_channel(true);
1289
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001290 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001291 ASSERT_TRUE(offer != NULL);
1292 // SetRemoteDescription and SetLocalDescription will take the ownership of
1293 // the offer.
1294 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001295 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001296 ASSERT_TRUE(offer != NULL);
1297 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1298}
1299
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001300//
1301// Tests for creating/setting SDP under different SDES/DTLS polices:
1302//
1303// --DTLS off and SDES on
1304// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1305// set local/remote offer/answer with crypto --> success
1306// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1307// failure
1308// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1309// failure
1310// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1311// failure
1312//
1313// --DTLS on and SDES off
1314// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1315// set local/remote offer/answer with DTLS fingerprint --> success
1316// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1317// fingerprint --> failure
1318// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1319// --> failure
1320// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1321// --> failure
1322//
1323// --Encryption disabled: DTLS off and SDES off
1324// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1325// answer without SDES or DTLS --> success
1326// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1327// answer without SDES or DTLS --> success
1328//
1329
1330// Test that we return a failure when applying a remote/local offer that doesn't
1331// have cryptos enabled when DTLS is off.
1332TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001333 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001334 cricket::MediaSessionOptions options;
1335 options.has_video = true;
1336 JsepSessionDescription* offer = CreateRemoteOffer(
1337 options, cricket::SEC_DISABLED);
1338 ASSERT_TRUE(offer != NULL);
1339 VerifyNoCryptoParams(offer->description(), false);
1340 // SetRemoteDescription and SetLocalDescription will take the ownership of
1341 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001342 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001343 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1344 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001345 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001346}
1347
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001348// Test that we return a failure when applying a local answer that doesn't have
1349// cryptos enabled when DTLS is off.
1350TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001351 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001352 SessionDescriptionInterface* offer = NULL;
1353 SessionDescriptionInterface* answer = NULL;
1354 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1355 // SetRemoteDescription and SetLocalDescription will take the ownership of
1356 // the offer.
1357 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001358 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001359}
1360
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001361// Test we will return fail when apply an remote answer that doesn't have
1362// crypto enabled when DTLS is off.
1363TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001364 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001365 SessionDescriptionInterface* offer = NULL;
1366 SessionDescriptionInterface* answer = NULL;
1367 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1368 // SetRemoteDescription and SetLocalDescription will take the ownership of
1369 // the offer.
1370 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001371 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001372}
1373
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001374// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1375// and that we return an answer with a DTLS fingerprint.
1376TEST_F(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001377 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001378 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001379 InitWithDtls();
1380 SetFactoryDtlsSrtp();
1381 cricket::MediaSessionOptions options;
1382 options.has_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001383 JsepSessionDescription* offer =
1384 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001385 ASSERT_TRUE(offer != NULL);
1386 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001387 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001388
1389 // SetRemoteDescription will take the ownership of the offer.
1390 SetRemoteDescriptionWithoutError(offer);
1391
1392 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001393 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001394 ASSERT_TRUE(answer != NULL);
1395 VerifyFingerprintStatus(answer->description(), true);
1396 // Check that we don't have an a=crypto line in the answer.
1397 VerifyNoCryptoParams(answer->description(), true);
1398
1399 // Now set the local description, which should work, even without a=crypto.
1400 SetLocalDescriptionWithoutError(answer);
1401}
1402
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001403// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1404// and then we accept a remote answer with a DTLS fingerprint successfully.
1405TEST_F(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001406 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001407 mediastream_signaling_.SendAudioVideoStream1();
1408 InitWithDtls();
1409 SetFactoryDtlsSrtp();
1410
1411 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001412 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001413 ASSERT_TRUE(offer != NULL);
1414 VerifyFingerprintStatus(offer->description(), true);
1415 // Check that we don't have an a=crypto line in the offer.
1416 VerifyNoCryptoParams(offer->description(), true);
1417
1418 // Now set the local description, which should work, even without a=crypto.
1419 SetLocalDescriptionWithoutError(offer);
1420
1421 cricket::MediaSessionOptions options;
1422 options.has_video = true;
1423 JsepSessionDescription* answer =
1424 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1425 ASSERT_TRUE(answer != NULL);
1426 VerifyFingerprintStatus(answer->description(), true);
1427 VerifyNoCryptoParams(answer->description(), true);
1428
1429 // SetRemoteDescription will take the ownership of the answer.
1430 SetRemoteDescriptionWithoutError(answer);
1431}
1432
1433// Test that if we support DTLS and the other side didn't offer a fingerprint,
1434// we will fail to set the remote description.
1435TEST_F(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001436 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001437 InitWithDtls();
1438 cricket::MediaSessionOptions options;
1439 options.has_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001440 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001441 JsepSessionDescription* offer = CreateRemoteOffer(
1442 options, cricket::SEC_REQUIRED);
1443 ASSERT_TRUE(offer != NULL);
1444 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001445 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001446
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001447 // SetRemoteDescription will take the ownership of the offer.
1448 SetRemoteDescriptionOfferExpectError(
1449 kSdpWithoutDtlsFingerprint, offer);
1450
1451 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1452 // SetLocalDescription will take the ownership of the offer.
1453 SetLocalDescriptionOfferExpectError(
1454 kSdpWithoutDtlsFingerprint, offer);
1455}
1456
1457// Test that we return a failure when applying a local answer that doesn't have
1458// a DTLS fingerprint when DTLS is required.
1459TEST_F(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001460 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001461 InitWithDtls();
1462 SessionDescriptionInterface* offer = NULL;
1463 SessionDescriptionInterface* answer = NULL;
1464 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1465
1466 // SetRemoteDescription and SetLocalDescription will take the ownership of
1467 // the offer and answer.
1468 SetRemoteDescriptionWithoutError(offer);
1469 SetLocalDescriptionAnswerExpectError(
1470 kSdpWithoutDtlsFingerprint, answer);
1471}
1472
1473// Test that we return a failure when applying a remote answer that doesn't have
1474// a DTLS fingerprint when DTLS is required.
1475TEST_F(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001476 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001477 InitWithDtls();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001478 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001479 cricket::MediaSessionOptions options;
1480 options.has_video = true;
1481 JsepSessionDescription* answer =
1482 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
1483
1484 // SetRemoteDescription and SetLocalDescription will take the ownership of
1485 // the offer and answer.
1486 SetLocalDescriptionWithoutError(offer);
1487 SetRemoteDescriptionAnswerExpectError(
1488 kSdpWithoutDtlsFingerprint, answer);
1489}
1490
1491// Test that we create a local offer without SDES or DTLS and accept a remote
1492// answer without SDES or DTLS when encryption is disabled.
1493TEST_F(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
1494 mediastream_signaling_.SendAudioVideoStream1();
1495 options_.disable_encryption = true;
1496 InitWithDtls();
1497
1498 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001499 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001500 ASSERT_TRUE(offer != NULL);
1501 VerifyFingerprintStatus(offer->description(), false);
1502 // Check that we don't have an a=crypto line in the offer.
1503 VerifyNoCryptoParams(offer->description(), false);
1504
1505 // Now set the local description, which should work, even without a=crypto.
1506 SetLocalDescriptionWithoutError(offer);
1507
1508 cricket::MediaSessionOptions options;
1509 options.has_video = true;
1510 JsepSessionDescription* answer =
1511 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1512 ASSERT_TRUE(answer != NULL);
1513 VerifyFingerprintStatus(answer->description(), false);
1514 VerifyNoCryptoParams(answer->description(), false);
1515
1516 // SetRemoteDescription will take the ownership of the answer.
1517 SetRemoteDescriptionWithoutError(answer);
1518}
1519
1520// Test that we create a local answer without SDES or DTLS and accept a remote
1521// offer without SDES or DTLS when encryption is disabled.
1522TEST_F(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
1523 options_.disable_encryption = true;
1524 InitWithDtls();
1525
1526 cricket::MediaSessionOptions options;
1527 options.has_video = true;
1528 JsepSessionDescription* offer =
1529 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1530 ASSERT_TRUE(offer != NULL);
1531 VerifyFingerprintStatus(offer->description(), false);
1532 VerifyNoCryptoParams(offer->description(), false);
1533
1534 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001535 SetRemoteDescriptionWithoutError(offer);
1536
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001537 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001538 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001539 ASSERT_TRUE(answer != NULL);
1540 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001541 // Check that we don't have an a=crypto line in the answer.
1542 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001543
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001544 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001545 SetLocalDescriptionWithoutError(answer);
1546}
1547
1548TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001549 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001550 mediastream_signaling_.SendNothing();
1551 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001552 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001553 SetLocalDescriptionWithoutError(offer);
1554
1555 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001556 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001557 SetLocalDescriptionWithoutError(offer2);
1558}
1559
1560TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001561 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001562 mediastream_signaling_.SendNothing();
1563 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001564 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001565 SetRemoteDescriptionWithoutError(offer);
1566
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001567 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001568 SetRemoteDescriptionWithoutError(offer2);
1569}
1570
1571TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001572 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001573 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001574 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001575 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001576 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001577 SetRemoteDescriptionOfferExpectError(
1578 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001579}
1580
1581TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001582 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001583 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001584 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001585 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001586 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001587 SetLocalDescriptionOfferExpectError(
1588 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001589}
1590
1591TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001592 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001593 mediastream_signaling_.SendNothing();
1594 SessionDescriptionInterface* offer = CreateRemoteOffer();
1595 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1596
1597 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001598 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001599 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1600 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1601
1602 mediastream_signaling_.SendAudioVideoStream1();
1603 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001604 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001605 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1606
1607 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1608
1609 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001610 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001611 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1612}
1613
1614TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001615 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001616 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001617 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001618 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1619
1620 JsepSessionDescription* pranswer =
1621 CreateRemoteAnswer(session_->local_description());
1622 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1623
1624 SetRemoteDescriptionExpectState(pranswer,
1625 BaseSession::STATE_RECEIVEDPRACCEPT);
1626
1627 mediastream_signaling_.SendAudioVideoStream1();
1628 JsepSessionDescription* pranswer2 =
1629 CreateRemoteAnswer(session_->local_description());
1630 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1631
1632 SetRemoteDescriptionExpectState(pranswer2,
1633 BaseSession::STATE_RECEIVEDPRACCEPT);
1634
1635 mediastream_signaling_.SendAudioVideoStream2();
1636 SessionDescriptionInterface* answer =
1637 CreateRemoteAnswer(session_->local_description());
1638 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1639}
1640
1641TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001642 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001643 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001644 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1645
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001646 SessionDescriptionInterface* answer =
1647 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001648 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1649 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001650}
1651
1652TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001653 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001655 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1656
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001657 SessionDescriptionInterface* answer =
1658 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001659 SetRemoteDescriptionAnswerExpectError(
1660 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001661}
1662
1663TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001664 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001665 mediastream_signaling_.SendAudioVideoStream1();
1666
1667 cricket::Candidate candidate;
1668 candidate.set_component(1);
1669 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1670
1671 // Fail since we have not set a offer description.
1672 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1673
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001674 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001675 SetLocalDescriptionWithoutError(offer);
1676 // Candidate should be allowed to add before remote description.
1677 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1678 candidate.set_component(2);
1679 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1680 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1681
1682 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1683 session_->local_description());
1684 SetRemoteDescriptionWithoutError(answer);
1685
1686 // Verifying the candidates are copied properly from internal vector.
1687 const SessionDescriptionInterface* remote_desc =
1688 session_->remote_description();
1689 ASSERT_TRUE(remote_desc != NULL);
1690 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1691 const IceCandidateCollection* candidates =
1692 remote_desc->candidates(kMediaContentIndex0);
1693 ASSERT_EQ(2u, candidates->count());
1694 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1695 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1696 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1697 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1698
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001699 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1700 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001701 candidate.set_component(2);
1702 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1703 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001704 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001705
1706 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1707 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1708}
1709
1710// Test that a remote candidate is added to the remote session description and
1711// that it is retained if the remote session description is changed.
1712TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001713 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001714 cricket::Candidate candidate1;
1715 candidate1.set_component(1);
1716 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1717 candidate1);
1718 mediastream_signaling_.SendAudioVideoStream1();
1719 CreateAndSetRemoteOfferAndLocalAnswer();
1720
1721 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1722 const SessionDescriptionInterface* remote_desc =
1723 session_->remote_description();
1724 ASSERT_TRUE(remote_desc != NULL);
1725 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1726 const IceCandidateCollection* candidates =
1727 remote_desc->candidates(kMediaContentIndex0);
1728 ASSERT_EQ(1u, candidates->count());
1729 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1730
1731 // Update the RemoteSessionDescription with a new session description and
1732 // a candidate and check that the new remote session description contains both
1733 // candidates.
1734 SessionDescriptionInterface* offer = CreateRemoteOffer();
1735 cricket::Candidate candidate2;
1736 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1737 candidate2);
1738 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1739 SetRemoteDescriptionWithoutError(offer);
1740
1741 remote_desc = session_->remote_description();
1742 ASSERT_TRUE(remote_desc != NULL);
1743 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1744 candidates = remote_desc->candidates(kMediaContentIndex0);
1745 ASSERT_EQ(2u, candidates->count());
1746 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1747 // Username and password have be updated with the TransportInfo of the
1748 // SessionDescription, won't be equal to the original one.
1749 candidate2.set_username(candidates->at(0)->candidate().username());
1750 candidate2.set_password(candidates->at(0)->candidate().password());
1751 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
1752 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
1753 // No need to verify the username and password.
1754 candidate1.set_username(candidates->at(1)->candidate().username());
1755 candidate1.set_password(candidates->at(1)->candidate().password());
1756 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
1757
1758 // Test that the candidate is ignored if we can add the same candidate again.
1759 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1760}
1761
1762// Test that local candidates are added to the local session description and
1763// that they are retained if the local session description is changed.
1764TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001765 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001766 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001767 mediastream_signaling_.SendAudioVideoStream1();
1768 CreateAndSetRemoteOfferAndLocalAnswer();
1769
1770 const SessionDescriptionInterface* local_desc = session_->local_description();
1771 const IceCandidateCollection* candidates =
1772 local_desc->candidates(kMediaContentIndex0);
1773 ASSERT_TRUE(candidates != NULL);
1774 EXPECT_EQ(0u, candidates->count());
1775
1776 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1777
1778 local_desc = session_->local_description();
1779 candidates = local_desc->candidates(kMediaContentIndex0);
1780 ASSERT_TRUE(candidates != NULL);
1781 EXPECT_LT(0u, candidates->count());
1782 candidates = local_desc->candidates(1);
1783 ASSERT_TRUE(candidates != NULL);
1784 EXPECT_LT(0u, candidates->count());
1785
1786 // Update the session descriptions.
1787 mediastream_signaling_.SendAudioVideoStream1();
1788 CreateAndSetRemoteOfferAndLocalAnswer();
1789
1790 local_desc = session_->local_description();
1791 candidates = local_desc->candidates(kMediaContentIndex0);
1792 ASSERT_TRUE(candidates != NULL);
1793 EXPECT_LT(0u, candidates->count());
1794 candidates = local_desc->candidates(1);
1795 ASSERT_TRUE(candidates != NULL);
1796 EXPECT_LT(0u, candidates->count());
1797}
1798
1799// Test that we can set a remote session description with remote candidates.
1800TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001801 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001802
1803 cricket::Candidate candidate1;
1804 candidate1.set_component(1);
1805 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
1806 candidate1);
1807 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001808 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001809
1810 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
1811 SetRemoteDescriptionWithoutError(offer);
1812
1813 const SessionDescriptionInterface* remote_desc =
1814 session_->remote_description();
1815 ASSERT_TRUE(remote_desc != NULL);
1816 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1817 const IceCandidateCollection* candidates =
1818 remote_desc->candidates(kMediaContentIndex0);
1819 ASSERT_EQ(1u, candidates->count());
1820 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1821
wu@webrtc.org91053e72013-08-10 07:18:04 +00001822 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001823 SetLocalDescriptionWithoutError(answer);
1824}
1825
1826// Test that offers and answers contains ice candidates when Ice candidates have
1827// been gathered.
1828TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001829 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001830 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001831 mediastream_signaling_.SendAudioVideoStream1();
1832 // Ice is started but candidates are not provided until SetLocalDescription
1833 // is called.
1834 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1835 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1836 CreateAndSetRemoteOfferAndLocalAnswer();
1837 // Wait until at least one local candidate has been collected.
1838 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
1839 kIceCandidatesTimeout);
1840 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
1841 kIceCandidatesTimeout);
1842
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001843 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
1844
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001845 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
1846 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
1847 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
1848 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
1849
1850 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
1851 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001852 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001853 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
1854 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
1855 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
1856 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
1857 SetLocalDescriptionWithoutError(answer);
1858}
1859
1860// Verifies TransportProxy and media channels are created with content names
1861// present in the SessionDescription.
1862TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001863 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001864 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001865 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001866
1867 // CreateOffer creates session description with the content names "audio" and
1868 // "video". Goal is to modify these content names and verify transport channel
1869 // proxy in the BaseSession, as proxies are created with the content names
1870 // present in SDP.
1871 std::string sdp;
1872 EXPECT_TRUE(offer->ToString(&sdp));
1873 const std::string kAudioMid = "a=mid:audio";
1874 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
1875 const std::string kVideoMid = "a=mid:video";
1876 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
1877
1878 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001879 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001880 kAudioMidReplaceStr.c_str(),
1881 kAudioMidReplaceStr.length(),
1882 &sdp);
1883 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001884 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001885 kVideoMidReplaceStr.c_str(),
1886 kVideoMidReplaceStr.length(),
1887 &sdp);
1888
1889 SessionDescriptionInterface* modified_offer =
1890 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
1891
1892 SetRemoteDescriptionWithoutError(modified_offer);
1893
1894 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00001895 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001896 SetLocalDescriptionWithoutError(answer);
1897
1898 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
1899 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
1900 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
1901 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
1902}
1903
1904// Test that an offer contains the correct media content descriptions based on
1905// the send streams when no constraints have been set.
1906TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001907 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001908 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1909
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001910 ASSERT_TRUE(offer != NULL);
1911 const cricket::ContentInfo* content =
1912 cricket::GetFirstAudioContent(offer->description());
1913 EXPECT_TRUE(content != NULL);
1914 content = cricket::GetFirstVideoContent(offer->description());
1915 EXPECT_TRUE(content == NULL);
1916}
1917
1918// Test that an offer contains the correct media content descriptions based on
1919// the send streams when no constraints have been set.
1920TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001921 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001922 // Test Audio only offer.
1923 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001924 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1925
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001926 const cricket::ContentInfo* content =
1927 cricket::GetFirstAudioContent(offer->description());
1928 EXPECT_TRUE(content != NULL);
1929 content = cricket::GetFirstVideoContent(offer->description());
1930 EXPECT_TRUE(content == NULL);
1931
1932 // Test Audio / Video offer.
1933 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001934 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001935 content = cricket::GetFirstAudioContent(offer->description());
1936 EXPECT_TRUE(content != NULL);
1937 content = cricket::GetFirstVideoContent(offer->description());
1938 EXPECT_TRUE(content != NULL);
1939}
1940
1941// Test that an offer contains no media content descriptions if
1942// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
1943TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001944 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001945 PeerConnectionInterface::RTCOfferAnswerOptions options;
1946 options.offer_to_receive_audio = 0;
1947 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001948
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001949 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001950 CreateOffer(options));
1951
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001952 ASSERT_TRUE(offer != NULL);
1953 const cricket::ContentInfo* content =
1954 cricket::GetFirstAudioContent(offer->description());
1955 EXPECT_TRUE(content == NULL);
1956 content = cricket::GetFirstVideoContent(offer->description());
1957 EXPECT_TRUE(content == NULL);
1958}
1959
1960// Test that an offer contains only audio media content descriptions if
1961// kOfferToReceiveAudio constraints are set to true.
1962TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001963 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001964 PeerConnectionInterface::RTCOfferAnswerOptions options;
1965 options.offer_to_receive_audio =
1966 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
1967
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001968 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001969 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001970
1971 const cricket::ContentInfo* content =
1972 cricket::GetFirstAudioContent(offer->description());
1973 EXPECT_TRUE(content != NULL);
1974 content = cricket::GetFirstVideoContent(offer->description());
1975 EXPECT_TRUE(content == NULL);
1976}
1977
1978// Test that an offer contains audio and video media content descriptions if
1979// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
1980TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001981 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001982 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001983 PeerConnectionInterface::RTCOfferAnswerOptions options;
1984 options.offer_to_receive_audio =
1985 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
1986 options.offer_to_receive_video =
1987 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
1988
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001989 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001990 CreateOffer(options));
1991
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001992 const cricket::ContentInfo* content =
1993 cricket::GetFirstAudioContent(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001994 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org52055a22014-09-04 17:12:25 +00001995
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996 content = cricket::GetFirstVideoContent(offer->description());
1997 EXPECT_TRUE(content != NULL);
1998
jiayl@webrtc.org52055a22014-09-04 17:12:25 +00001999 // Sets constraints to false and verifies that audio/video contents are
2000 // removed.
2001 options.offer_to_receive_audio = 0;
2002 options.offer_to_receive_video = 0;
2003 offer.reset(CreateOffer(options));
2004
2005 content = cricket::GetFirstAudioContent(offer->description());
2006 EXPECT_TRUE(content == NULL);
2007 content = cricket::GetFirstVideoContent(offer->description());
2008 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002009}
2010
2011// Test that an answer can not be created if the last remote description is not
2012// an offer.
2013TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002014 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002015 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002016 SetLocalDescriptionWithoutError(offer);
2017 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2018 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002019 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020}
2021
2022// Test that an answer contains the correct media content descriptions when no
2023// constraints have been set.
2024TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002025 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002026 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002027 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002028 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002029 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002030 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002031 const cricket::ContentInfo* content =
2032 cricket::GetFirstAudioContent(answer->description());
2033 ASSERT_TRUE(content != NULL);
2034 EXPECT_FALSE(content->rejected);
2035
2036 content = cricket::GetFirstVideoContent(answer->description());
2037 ASSERT_TRUE(content != NULL);
2038 EXPECT_FALSE(content->rejected);
2039}
2040
2041// Test that an answer contains the correct media content descriptions when no
2042// constraints have been set and the offer only contain audio.
2043TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002044 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002045 // Create a remote offer with audio only.
2046 cricket::MediaSessionOptions options;
jiayl@webrtc.org52055a22014-09-04 17:12:25 +00002047
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002048 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049 CreateRemoteOffer(options));
2050 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2051 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2052
2053 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002054 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002055 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002056 const cricket::ContentInfo* content =
2057 cricket::GetFirstAudioContent(answer->description());
2058 ASSERT_TRUE(content != NULL);
2059 EXPECT_FALSE(content->rejected);
2060
2061 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2062}
2063
2064// Test that an answer contains the correct media content descriptions when no
2065// constraints have been set.
2066TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002067 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002068 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002069 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002070 SetRemoteDescriptionWithoutError(offer.release());
2071 // Test with a stream with tracks.
2072 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002073 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002074 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002075 const cricket::ContentInfo* content =
2076 cricket::GetFirstAudioContent(answer->description());
2077 ASSERT_TRUE(content != NULL);
2078 EXPECT_FALSE(content->rejected);
2079
2080 content = cricket::GetFirstVideoContent(answer->description());
2081 ASSERT_TRUE(content != NULL);
2082 EXPECT_FALSE(content->rejected);
2083}
2084
2085// Test that an answer contains the correct media content descriptions when
2086// constraints have been set but no stream is sent.
2087TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002088 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002089 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002090 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002091 SetRemoteDescriptionWithoutError(offer.release());
2092
2093 webrtc::FakeConstraints constraints_no_receive;
2094 constraints_no_receive.SetMandatoryReceiveAudio(false);
2095 constraints_no_receive.SetMandatoryReceiveVideo(false);
2096
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002097 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002098 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002099 const cricket::ContentInfo* content =
2100 cricket::GetFirstAudioContent(answer->description());
2101 ASSERT_TRUE(content != NULL);
2102 EXPECT_TRUE(content->rejected);
2103
2104 content = cricket::GetFirstVideoContent(answer->description());
2105 ASSERT_TRUE(content != NULL);
2106 EXPECT_TRUE(content->rejected);
2107}
2108
2109// Test that an answer contains the correct media content descriptions when
2110// constraints have been set and streams are sent.
2111TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002112 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002113 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002114 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002115 SetRemoteDescriptionWithoutError(offer.release());
2116
2117 webrtc::FakeConstraints constraints_no_receive;
2118 constraints_no_receive.SetMandatoryReceiveAudio(false);
2119 constraints_no_receive.SetMandatoryReceiveVideo(false);
2120
2121 // Test with a stream with tracks.
2122 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002123 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002124 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002125
2126 // TODO(perkj): Should the direction be set to SEND_ONLY?
2127 const cricket::ContentInfo* content =
2128 cricket::GetFirstAudioContent(answer->description());
2129 ASSERT_TRUE(content != NULL);
2130 EXPECT_FALSE(content->rejected);
2131
2132 // TODO(perkj): Should the direction be set to SEND_ONLY?
2133 content = cricket::GetFirstVideoContent(answer->description());
2134 ASSERT_TRUE(content != NULL);
2135 EXPECT_FALSE(content->rejected);
2136}
2137
2138TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2139 AddCNCodecs();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002140 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002141 PeerConnectionInterface::RTCOfferAnswerOptions options;
2142 options.offer_to_receive_audio =
2143 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2144 options.voice_activity_detection = false;
2145
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002146 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002147 CreateOffer(options));
2148
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002149 const cricket::ContentInfo* content =
2150 cricket::GetFirstAudioContent(offer->description());
2151 EXPECT_TRUE(content != NULL);
2152 EXPECT_TRUE(VerifyNoCNCodecs(content));
2153}
2154
2155TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2156 AddCNCodecs();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002157 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002158 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002159 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002160 SetRemoteDescriptionWithoutError(offer.release());
2161
2162 webrtc::FakeConstraints constraints;
2163 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002164 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002165 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002166 const cricket::ContentInfo* content =
2167 cricket::GetFirstAudioContent(answer->description());
2168 ASSERT_TRUE(content != NULL);
2169 EXPECT_TRUE(VerifyNoCNCodecs(content));
2170}
2171
2172// This test verifies the call setup when remote answer with audio only and
2173// later updates with video.
2174TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002175 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002176 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2177 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2178
2179 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002180 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002181
2182 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002183 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2184
2185 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2186 // and answer;
2187 SetLocalDescriptionWithoutError(offer);
2188 SetRemoteDescriptionWithoutError(answer);
2189
2190 video_channel_ = media_engine_->GetVideoChannel(0);
2191 voice_channel_ = media_engine_->GetVoiceChannel(0);
2192
2193 ASSERT_TRUE(video_channel_ == NULL);
2194
2195 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2196 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2197 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2198
2199 // Let the remote end update the session descriptions, with Audio and Video.
2200 mediastream_signaling_.SendAudioVideoStream2();
2201 CreateAndSetRemoteOfferAndLocalAnswer();
2202
2203 video_channel_ = media_engine_->GetVideoChannel(0);
2204 voice_channel_ = media_engine_->GetVoiceChannel(0);
2205
2206 ASSERT_TRUE(video_channel_ != NULL);
2207 ASSERT_TRUE(voice_channel_ != NULL);
2208
2209 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2210 ASSERT_EQ(1u, video_channel_->send_streams().size());
2211 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2212 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2213 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2214 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2215 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2216 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2217
2218 // Change session back to audio only.
2219 mediastream_signaling_.UseOptionsAudioOnly();
2220 CreateAndSetRemoteOfferAndLocalAnswer();
2221
2222 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2223 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2224 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2225 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2226 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2227}
2228
2229// This test verifies the call setup when remote answer with video only and
2230// later updates with audio.
2231TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002232 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002233 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2234 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2235 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002236 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002237
2238 cricket::MediaSessionOptions options;
2239 options.has_audio = false;
2240 options.has_video = true;
2241 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2242 offer, options, cricket::SEC_ENABLED);
2243
2244 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2245 // and answer.
2246 SetLocalDescriptionWithoutError(offer);
2247 SetRemoteDescriptionWithoutError(answer);
2248
2249 video_channel_ = media_engine_->GetVideoChannel(0);
2250 voice_channel_ = media_engine_->GetVoiceChannel(0);
2251
2252 ASSERT_TRUE(voice_channel_ == NULL);
2253 ASSERT_TRUE(video_channel_ != NULL);
2254
2255 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2256 ASSERT_EQ(1u, video_channel_->send_streams().size());
2257 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2258
2259 // Update the session descriptions, with Audio and Video.
2260 mediastream_signaling_.SendAudioVideoStream2();
2261 CreateAndSetRemoteOfferAndLocalAnswer();
2262
2263 voice_channel_ = media_engine_->GetVoiceChannel(0);
2264 ASSERT_TRUE(voice_channel_ != NULL);
2265
2266 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2267 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2268 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2269 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2270
2271 // Change session back to video only.
2272 mediastream_signaling_.UseOptionsVideoOnly();
2273 CreateAndSetRemoteOfferAndLocalAnswer();
2274
2275 video_channel_ = media_engine_->GetVideoChannel(0);
2276 voice_channel_ = media_engine_->GetVoiceChannel(0);
2277
2278 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2279 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2280 ASSERT_EQ(1u, video_channel_->send_streams().size());
2281 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2282}
2283
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002284TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002285 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002286 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002287 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002288 VerifyCryptoParams(offer->description());
2289 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002290 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002291 VerifyCryptoParams(answer->description());
2292}
2293
2294TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002295 options_.disable_encryption = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00002296 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002297 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002298 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002299 VerifyNoCryptoParams(offer->description(), false);
2300}
2301
2302TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002303 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002304 VerifyAnswerFromNonCryptoOffer();
2305}
2306
2307TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002308 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002309 VerifyAnswerFromCryptoOffer();
2310}
2311
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002312// This test verifies that setLocalDescription fails if
2313// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2314TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
2315 Init(NULL);
2316 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002317 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2318
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002319 std::string sdp;
2320 RemoveIceUfragPwdLines(offer.get(), &sdp);
2321 SessionDescriptionInterface* modified_offer =
2322 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002323 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002324}
2325
2326// This test verifies that setRemoteDescription fails if
2327// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2328TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
2329 Init(NULL);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002330 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002331 std::string sdp;
2332 RemoveIceUfragPwdLines(offer.get(), &sdp);
2333 SessionDescriptionInterface* modified_offer =
2334 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002335 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002336}
2337
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002338// This test verifies that setLocalDescription fails if local offer has
2339// too short ice ufrag and pwd strings.
2340TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
2341 Init(NULL);
2342 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
2343 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002344 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2345
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002346 std::string sdp;
2347 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2348 // recommended values of 4 and 22 bytes respectively.
2349 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2350 SessionDescriptionInterface* modified_offer =
2351 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2352 std::string error;
2353 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2354
2355 // Test with string greater than 256.
2356 sdp.clear();
2357 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2358 &sdp);
2359 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2360 NULL);
2361 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2362}
2363
2364// This test verifies that setRemoteDescription fails if remote offer has
2365// too short ice ufrag and pwd strings.
2366TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
2367 Init(NULL);
2368 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002369 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002370 std::string sdp;
2371 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2372 // recommended values of 4 and 22 bytes respectively.
2373 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2374 SessionDescriptionInterface* modified_offer =
2375 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2376 std::string error;
2377 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2378
2379 sdp.clear();
2380 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2381 &sdp);
2382 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2383 NULL);
2384 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2385}
2386
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002387TEST_F(WebRtcSessionTest, VerifyBundleFlagInPA) {
2388 // This test verifies BUNDLE flag in PortAllocator, if BUNDLE information in
2389 // local description is removed by the application, BUNDLE flag should be
2390 // disabled in PortAllocator. By default BUNDLE is enabled in the WebRtc.
wu@webrtc.org91053e72013-08-10 07:18:04 +00002391 Init(NULL);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002392 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2393 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002394 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2395
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002396 cricket::SessionDescription* offer_copy =
2397 offer->description()->Copy();
2398 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2399 JsepSessionDescription* modified_offer =
2400 new JsepSessionDescription(JsepSessionDescription::kOffer);
2401 modified_offer->Initialize(offer_copy, "1", "1");
2402
2403 SetLocalDescriptionWithoutError(modified_offer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002404 EXPECT_FALSE(allocator_->flags() & cricket::PORTALLOCATOR_ENABLE_BUNDLE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002405}
2406
2407TEST_F(WebRtcSessionTest, TestDisabledBundleInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002408 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002410 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2411 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002412
2413 PeerConnectionInterface::RTCOfferAnswerOptions options;
2414 options.use_rtp_mux = true;
2415
2416 SessionDescriptionInterface* offer = CreateOffer(options);
2417
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002418 SetLocalDescriptionWithoutError(offer);
2419 mediastream_signaling_.SendAudioVideoStream2();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002420 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002421 CreateRemoteAnswer(session_->local_description()));
2422 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2423 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2424 JsepSessionDescription* modified_answer =
2425 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2426 modified_answer->Initialize(answer_copy, "1", "1");
2427 SetRemoteDescriptionWithoutError(modified_answer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002428 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2429 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002430
2431 video_channel_ = media_engine_->GetVideoChannel(0);
2432 voice_channel_ = media_engine_->GetVoiceChannel(0);
2433
2434 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2435 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
2436
2437 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2438 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
2439
2440 ASSERT_EQ(1u, video_channel_->send_streams().size());
2441 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
2442 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2443 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
2444}
2445
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002446// This test verifies that SetLocalDescription and SetRemoteDescription fails
2447// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2448TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002449 WebRtcSessionTest::Init(NULL);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002450 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002451 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2452 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002453
2454 PeerConnectionInterface::RTCOfferAnswerOptions options;
2455 options.use_rtp_mux = true;
2456
2457 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002458 std::string offer_str;
2459 offer->ToString(&offer_str);
2460 // Disable rtcp-mux
2461 const std::string rtcp_mux = "rtcp-mux";
2462 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002463 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002464 xrtcp_mux.c_str(), xrtcp_mux.length(),
2465 &offer_str);
2466 JsepSessionDescription *local_offer =
2467 new JsepSessionDescription(JsepSessionDescription::kOffer);
2468 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002469 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002470 JsepSessionDescription *remote_offer =
2471 new JsepSessionDescription(JsepSessionDescription::kOffer);
2472 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002473 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002474 // Trying unmodified SDP.
2475 SetLocalDescriptionWithoutError(offer);
2476}
2477
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002478TEST_F(WebRtcSessionTest, SetAudioPlayout) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002479 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002480 mediastream_signaling_.SendAudioVideoStream1();
2481 CreateAndSetRemoteOfferAndLocalAnswer();
2482 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2483 ASSERT_TRUE(channel != NULL);
2484 ASSERT_EQ(1u, channel->recv_streams().size());
2485 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2486 double left_vol, right_vol;
2487 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2488 EXPECT_EQ(1, left_vol);
2489 EXPECT_EQ(1, right_vol);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002490 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002491 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002492 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2493 EXPECT_EQ(0, left_vol);
2494 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002495 EXPECT_EQ(0, renderer->channel_id());
2496 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002497 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2498 EXPECT_EQ(1, left_vol);
2499 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002500 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002501}
2502
2503TEST_F(WebRtcSessionTest, SetAudioSend) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002504 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002505 mediastream_signaling_.SendAudioVideoStream1();
2506 CreateAndSetRemoteOfferAndLocalAnswer();
2507 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2508 ASSERT_TRUE(channel != NULL);
2509 ASSERT_EQ(1u, channel->send_streams().size());
2510 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2511 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2512
2513 cricket::AudioOptions options;
2514 options.echo_cancellation.Set(true);
2515
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002516 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002517 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002518 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2519 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002520 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002521 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002522
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002523 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002524 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002525 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2526 bool value;
2527 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
2528 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002529 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002530 EXPECT_TRUE(renderer->sink() == NULL);
2531}
2532
2533TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
2534 Init(NULL);
2535 mediastream_signaling_.SendAudioVideoStream1();
2536 CreateAndSetRemoteOfferAndLocalAnswer();
2537 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2538 ASSERT_TRUE(channel != NULL);
2539 ASSERT_EQ(1u, channel->send_streams().size());
2540 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2541
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002542 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002543 cricket::AudioOptions options;
2544 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
2545 EXPECT_TRUE(renderer->sink() != NULL);
2546
2547 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
2548 // will invalidate the |renderer_| pointer in the sink and prevent getting a
2549 // SetSink(NULL) callback afterwards.
2550 renderer.reset();
2551
2552 // This will trigger SetSink(NULL) if no OnClose() callback.
2553 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002554}
2555
2556TEST_F(WebRtcSessionTest, SetVideoPlayout) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002557 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002558 mediastream_signaling_.SendAudioVideoStream1();
2559 CreateAndSetRemoteOfferAndLocalAnswer();
2560 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2561 ASSERT_TRUE(channel != NULL);
2562 ASSERT_LT(0u, channel->renderers().size());
2563 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2564 ASSERT_EQ(1u, channel->recv_streams().size());
2565 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2566 cricket::FakeVideoRenderer renderer;
2567 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
2568 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
2569 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
2570 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2571}
2572
2573TEST_F(WebRtcSessionTest, SetVideoSend) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002574 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002575 mediastream_signaling_.SendAudioVideoStream1();
2576 CreateAndSetRemoteOfferAndLocalAnswer();
2577 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2578 ASSERT_TRUE(channel != NULL);
2579 ASSERT_EQ(1u, channel->send_streams().size());
2580 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2581 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2582 cricket::VideoOptions* options = NULL;
2583 session_->SetVideoSend(send_ssrc, false, options);
2584 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2585 session_->SetVideoSend(send_ssrc, true, options);
2586 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2587}
2588
2589TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
2590 TestCanInsertDtmf(false);
2591}
2592
2593TEST_F(WebRtcSessionTest, CanInsertDtmf) {
2594 TestCanInsertDtmf(true);
2595}
2596
2597TEST_F(WebRtcSessionTest, InsertDtmf) {
2598 // Setup
wu@webrtc.org91053e72013-08-10 07:18:04 +00002599 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002600 mediastream_signaling_.SendAudioVideoStream1();
2601 CreateAndSetRemoteOfferAndLocalAnswer();
2602 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2603 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
2604
2605 // Insert DTMF
2606 const int expected_flags = DF_SEND;
2607 const int expected_duration = 90;
2608 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
2609 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
2610 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
2611
2612 // Verify
2613 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
2614 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2615 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
2616 expected_duration, expected_flags));
2617 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
2618 expected_duration, expected_flags));
2619 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
2620 expected_duration, expected_flags));
2621}
2622
2623// This test verifies the |initiator| flag when session initiates the call.
2624TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002625 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002626 EXPECT_FALSE(session_->initiator());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002627 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002628 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2629 SetLocalDescriptionWithoutError(offer);
2630 EXPECT_TRUE(session_->initiator());
2631 SetRemoteDescriptionWithoutError(answer);
2632 EXPECT_TRUE(session_->initiator());
2633}
2634
2635// This test verifies the |initiator| flag when session receives the call.
2636TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002637 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002638 EXPECT_FALSE(session_->initiator());
2639 SessionDescriptionInterface* offer = CreateRemoteOffer();
2640 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002641 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002642
2643 EXPECT_FALSE(session_->initiator());
2644 SetLocalDescriptionWithoutError(answer);
2645 EXPECT_FALSE(session_->initiator());
2646}
2647
2648// This test verifies the ice protocol type at initiator of the call
2649// if |a=ice-options:google-ice| is present in answer.
2650TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002651 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002652 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002653 SessionDescriptionInterface* offer = CreateOffer();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002654 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002655 CreateRemoteAnswer(offer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002656 SetLocalDescriptionWithoutError(offer);
2657 std::string sdp;
2658 EXPECT_TRUE(answer->ToString(&sdp));
2659 // Adding ice-options to the session level.
2660 InjectAfter("t=0 0\r\n",
2661 "a=ice-options:google-ice\r\n",
2662 &sdp);
2663 SessionDescriptionInterface* answer_with_gice =
2664 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2665 SetRemoteDescriptionWithoutError(answer_with_gice);
2666 VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE);
2667 VerifyTransportType("video", cricket::ICEPROTO_GOOGLE);
2668}
2669
2670// This test verifies the ice protocol type at initiator of the call
2671// if ICE RFC5245 is supported in answer.
2672TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002673 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002674 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002675 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002676 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2677 SetLocalDescriptionWithoutError(offer);
2678
2679 SetRemoteDescriptionWithoutError(answer);
2680 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2681 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2682}
2683
2684// This test verifies the ice protocol type at receiver side of the call if
2685// receiver decides to use google-ice.
2686TEST_F(WebRtcSessionTest, TestReceiverGIceInOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002687 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002688 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002689 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002690 SetRemoteDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002691 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002692 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002693 std::string sdp;
2694 EXPECT_TRUE(answer->ToString(&sdp));
2695 // Adding ice-options to the session level.
2696 InjectAfter("t=0 0\r\n",
2697 "a=ice-options:google-ice\r\n",
2698 &sdp);
2699 SessionDescriptionInterface* answer_with_gice =
2700 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2701 SetLocalDescriptionWithoutError(answer_with_gice);
2702 VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE);
2703 VerifyTransportType("video", cricket::ICEPROTO_GOOGLE);
2704}
2705
2706// This test verifies the ice protocol type at receiver side of the call if
2707// receiver decides to use ice RFC 5245.
2708TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002709 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002710 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002711 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002712 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002713 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002714 SetLocalDescriptionWithoutError(answer);
2715 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2716 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2717}
2718
2719// This test verifies the session state when ICE RFC5245 in offer and
2720// ICE google-ice in answer.
2721TEST_F(WebRtcSessionTest, TestIceOfferGIceOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002722 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002723 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002724 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2725
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002726 std::string offer_str;
2727 offer->ToString(&offer_str);
2728 // Disable google-ice
2729 const std::string gice_option = "google-ice";
2730 const std::string xgoogle_xice = "xgoogle-xice";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002731 rtc::replace_substrs(gice_option.c_str(), gice_option.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002732 xgoogle_xice.c_str(), xgoogle_xice.length(),
2733 &offer_str);
2734 JsepSessionDescription *ice_only_offer =
2735 new JsepSessionDescription(JsepSessionDescription::kOffer);
2736 EXPECT_TRUE((ice_only_offer)->Initialize(offer_str, NULL));
2737 SetLocalDescriptionWithoutError(ice_only_offer);
2738 std::string original_offer_sdp;
2739 EXPECT_TRUE(offer->ToString(&original_offer_sdp));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002740 SessionDescriptionInterface* pranswer_with_gice =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002741 CreateSessionDescription(JsepSessionDescription::kPrAnswer,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002742 original_offer_sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002743 SetRemoteDescriptionPranswerExpectError(kPushDownTDFailed,
2744 pranswer_with_gice);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002745 SessionDescriptionInterface* answer_with_gice =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002746 CreateSessionDescription(JsepSessionDescription::kAnswer,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002747 original_offer_sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002748 SetRemoteDescriptionAnswerExpectError(kPushDownTDFailed,
2749 answer_with_gice);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002750}
2751
2752// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
2753TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002754 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002755 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002756 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002757 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002758 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002759 CreateRemoteAnswer(session_->local_description()));
2760
2761 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2762 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002763 JsepSessionDescription* modified_answer =
2764 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002765
2766 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2767 answer->session_id(),
2768 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002769 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002770
wu@webrtc.org4e393072014-04-07 17:04:35 +00002771 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002772 std::string sdp;
2773 EXPECT_TRUE(answer->ToString(&sdp));
2774 const std::string kAudioMid = "a=mid:audio";
2775 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002776 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002777 kAudioMidReplaceStr.c_str(),
2778 kAudioMidReplaceStr.length(),
2779 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002780 SessionDescriptionInterface* modified_answer1 =
2781 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002782 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002783
wu@webrtc.org4e393072014-04-07 17:04:35 +00002784 // Different media types.
2785 EXPECT_TRUE(answer->ToString(&sdp));
2786 const std::string kAudioMline = "m=audio";
2787 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002788 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00002789 kAudioMlineReplaceStr.c_str(),
2790 kAudioMlineReplaceStr.length(),
2791 &sdp);
2792 SessionDescriptionInterface* modified_answer2 =
2793 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2794 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
2795
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002796 SetRemoteDescriptionWithoutError(answer.release());
2797}
2798
2799// Verifying remote offer and local answer have matching m-lines as per
2800// RFC 3264.
2801TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002802 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002803 mediastream_signaling_.SendAudioVideoStream1();
2804 SessionDescriptionInterface* offer = CreateRemoteOffer();
2805 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002806 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002807
2808 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2809 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002810 JsepSessionDescription* modified_answer =
2811 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002812
2813 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2814 answer->session_id(),
2815 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002816 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002817 SetLocalDescriptionWithoutError(answer);
2818}
2819
2820// This test verifies that WebRtcSession does not start candidate allocation
2821// before SetLocalDescription is called.
2822TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002823 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002824 mediastream_signaling_.SendAudioVideoStream1();
2825 SessionDescriptionInterface* offer = CreateRemoteOffer();
2826 cricket::Candidate candidate;
2827 candidate.set_component(1);
2828 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2829 candidate);
2830 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2831 cricket::Candidate candidate1;
2832 candidate1.set_component(1);
2833 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2834 candidate1);
2835 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2836 SetRemoteDescriptionWithoutError(offer);
2837 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
2838 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
2839
2840 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002841 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002842 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
2843 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
2844
wu@webrtc.org91053e72013-08-10 07:18:04 +00002845 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002846 SetLocalDescriptionWithoutError(answer);
2847 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
2848 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
2849 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2850}
2851
2852// This test verifies that crypto parameter is updated in local session
2853// description as per security policy set in MediaSessionDescriptionFactory.
2854TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002855 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002856 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002857 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002858
2859 // Making sure SetLocalDescription correctly sets crypto value in
2860 // SessionDescription object after de-serialization of sdp string. The value
2861 // will be set as per MediaSessionDescriptionFactory.
2862 std::string offer_str;
2863 offer->ToString(&offer_str);
2864 SessionDescriptionInterface* jsep_offer_str =
2865 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
2866 SetLocalDescriptionWithoutError(jsep_offer_str);
2867 EXPECT_TRUE(session_->voice_channel()->secure_required());
2868 EXPECT_TRUE(session_->video_channel()->secure_required());
2869}
2870
2871// This test verifies the crypto parameter when security is disabled.
2872TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002873 options_.disable_encryption = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00002874 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002875 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002876 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002877
2878 // Making sure SetLocalDescription correctly sets crypto value in
2879 // SessionDescription object after de-serialization of sdp string. The value
2880 // will be set as per MediaSessionDescriptionFactory.
2881 std::string offer_str;
2882 offer->ToString(&offer_str);
2883 SessionDescriptionInterface *jsep_offer_str =
2884 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
2885 SetLocalDescriptionWithoutError(jsep_offer_str);
2886 EXPECT_FALSE(session_->voice_channel()->secure_required());
2887 EXPECT_FALSE(session_->video_channel()->secure_required());
2888}
2889
2890// This test verifies that an answer contains new ufrag and password if an offer
2891// with new ufrag and password is received.
2892TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002893 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002894 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002895 options.has_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002896 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002897 CreateRemoteOffer(options));
2898 SetRemoteDescriptionWithoutError(offer.release());
2899
2900 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002901 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002902 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002903 SetLocalDescriptionWithoutError(answer.release());
2904
2905 // Receive an offer with new ufrag and password.
2906 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002907 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002908 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002909 SetRemoteDescriptionWithoutError(updated_offer1.release());
2910
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002911 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002912 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002913
2914 CompareIceUfragAndPassword(updated_answer1->description(),
2915 session_->local_description()->description(),
2916 false);
2917
2918 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002919}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002920
wu@webrtc.org91053e72013-08-10 07:18:04 +00002921// This test verifies that an answer contains old ufrag and password if an offer
2922// with old ufrag and password is received.
2923TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
2924 Init(NULL);
2925 cricket::MediaSessionOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00002926 options.has_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002927 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002928 CreateRemoteOffer(options));
2929 SetRemoteDescriptionWithoutError(offer.release());
2930
2931 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002932 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002933 CreateAnswer(NULL));
2934 SetLocalDescriptionWithoutError(answer.release());
2935
2936 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002937 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002938 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002939 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002940 SetRemoteDescriptionWithoutError(updated_offer2.release());
2941
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002942 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002943 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002944
2945 CompareIceUfragAndPassword(updated_answer2->description(),
2946 session_->local_description()->description(),
2947 true);
2948
2949 SetLocalDescriptionWithoutError(updated_answer2.release());
2950}
2951
2952TEST_F(WebRtcSessionTest, TestSessionContentError) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002953 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002954 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002955 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002956 const std::string session_id_orig = offer->session_id();
2957 const std::string session_version_orig = offer->session_version();
2958 SetLocalDescriptionWithoutError(offer);
2959
2960 video_channel_ = media_engine_->GetVideoChannel(0);
2961 video_channel_->set_fail_set_send_codecs(true);
2962
2963 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002964 SessionDescriptionInterface* answer =
2965 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002966 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002967}
2968
2969// Runs the loopback call test with BUNDLE and STUN disabled.
2970TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
2971 // Lets try with only UDP ports.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002972 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002973 cricket::PORTALLOCATOR_DISABLE_TCP |
2974 cricket::PORTALLOCATOR_DISABLE_STUN |
2975 cricket::PORTALLOCATOR_DISABLE_RELAY);
2976 TestLoopbackCall();
2977}
2978
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00002979// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00002980TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002981 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00002982 cricket::PORTALLOCATOR_ENABLE_BUNDLE |
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00002983 cricket::PORTALLOCATOR_DISABLE_TCP |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00002984 cricket::PORTALLOCATOR_DISABLE_RELAY);
2985 TestLoopbackCall();
2986}
2987
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002988TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002989 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002990 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002991 options.has_video = true;
2992
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002993 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
2994 std::string error_code_str = "ERROR_CONTENT";
2995 std::string error_desc = "Fake session error description.";
2996 session_->SetError(error_code, error_desc);
2997
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002998 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
2999 SessionDescriptionInterface* answer =
3000 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003001
3002 std::string action;
3003 std::ostringstream session_error_msg;
3004 session_error_msg << kSessionError << error_code_str << ". ";
3005 session_error_msg << kSessionErrorDesc << error_desc << ".";
3006 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
3007 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003008}
3009
3010TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3011 constraints_.reset(new FakeConstraints());
3012 constraints_->AddOptional(
3013 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003014 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003015
3016 SetLocalDescriptionWithDataChannel();
3017 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3018}
3019
3020TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003021 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003022
3023 constraints_.reset(new FakeConstraints());
3024 constraints_->AddOptional(
3025 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003026 options_.disable_sctp_data_channels = false;
3027
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003028 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003029
3030 SetLocalDescriptionWithDataChannel();
3031 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3032}
3033
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003034TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003035 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003036
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003037 InitWithDtls();
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003038
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003039 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003040 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003041 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3042}
3043
3044TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003045 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003046 SetFactoryDtlsSrtp();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003047 InitWithDtls();
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003048
3049 // Create remote offer with SCTP.
3050 cricket::MediaSessionOptions options;
3051 options.data_channel_type = cricket::DCT_SCTP;
3052 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003053 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003054 SetRemoteDescriptionWithoutError(offer);
3055
3056 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003057 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003058 EXPECT_TRUE(answer != NULL);
3059 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3060 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003061}
3062
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003063TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
3064 constraints_.reset(new FakeConstraints());
3065 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003066 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003067 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003068
3069 SetLocalDescriptionWithDataChannel();
3070 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3071}
3072
3073TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003074 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003075
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003076 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003077
3078 SetLocalDescriptionWithDataChannel();
3079 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3080}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003081
wu@webrtc.org97077a32013-10-25 21:18:33 +00003082TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003083 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003084 options_.disable_sctp_data_channels = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003085 InitWithDtls();
wu@webrtc.org97077a32013-10-25 21:18:33 +00003086
3087 SetLocalDescriptionWithDataChannel();
3088 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3089}
3090
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003091TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003092 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003093 const int new_send_port = 9998;
3094 const int new_recv_port = 7775;
3095
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003096 InitWithDtls();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003097 SetFactoryDtlsSrtp();
3098
3099 // By default, don't actually add the codecs to desc_factory_; they don't
3100 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3101 // let the session description get parsed. That'll get the proper codecs
3102 // into the stream.
3103 cricket::MediaSessionOptions options;
3104 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3105 "stream1", new_send_port, options);
3106
3107 // SetRemoteDescription will take the ownership of the offer.
3108 SetRemoteDescriptionWithoutError(offer);
3109
3110 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3111 new_recv_port, CreateAnswer(NULL));
3112 ASSERT_TRUE(answer != NULL);
3113
3114 // Now set the local description, which'll take ownership of the answer.
3115 SetLocalDescriptionWithoutError(answer);
3116
3117 // TEST PLAN: Set the port number to something new, set it in the SDP,
3118 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003119 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003120 dci.reliable = true;
3121 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003122 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003123 session_->CreateDataChannel("datachannel", &dci);
3124
3125 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3126 int portnum = -1;
3127 ASSERT_TRUE(ch != NULL);
3128 ASSERT_EQ(1UL, ch->send_codecs().size());
3129 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
3130 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3131 ch->send_codecs()[0].name.c_str()));
3132 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3133 &portnum));
3134 EXPECT_EQ(new_send_port, portnum);
3135
3136 ASSERT_EQ(1UL, ch->recv_codecs().size());
3137 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
3138 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3139 ch->recv_codecs()[0].name.c_str()));
3140 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3141 &portnum));
3142 EXPECT_EQ(new_recv_port, portnum);
3143}
3144
wu@webrtc.org91053e72013-08-10 07:18:04 +00003145// Verifies that CreateOffer succeeds when CreateOffer is called before async
3146// identity generation is finished.
3147TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003148 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003149 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003150
3151 EXPECT_TRUE(session_->waiting_for_identity());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003152 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003153 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3154
wu@webrtc.org91053e72013-08-10 07:18:04 +00003155 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003156 VerifyNoCryptoParams(offer->description(), true);
3157 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003158}
3159
3160// Verifies that CreateAnswer succeeds when CreateOffer is called before async
3161// identity generation is finished.
3162TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003163 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003164 InitWithDtls();
3165 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003166
3167 cricket::MediaSessionOptions options;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003168 options.has_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003169 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003170 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003171 ASSERT_TRUE(offer.get() != NULL);
3172 SetRemoteDescriptionWithoutError(offer.release());
3173
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003174 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003175 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003176 VerifyNoCryptoParams(answer->description(), true);
3177 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003178}
3179
3180// Verifies that CreateOffer succeeds when CreateOffer is called after async
3181// identity generation is finished.
3182TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003183 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003184 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003185
3186 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003187
3188 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003189 EXPECT_TRUE(offer != NULL);
3190}
3191
3192// Verifies that CreateOffer fails when CreateOffer is called after async
3193// identity generation fails.
3194TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003195 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00003196 InitWithDtls(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003197
3198 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003199
3200 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003201 EXPECT_TRUE(offer == NULL);
3202}
3203
3204// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3205// before async identity generation is finished.
3206TEST_F(WebRtcSessionTest,
3207 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003208 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003209 VerifyMultipleAsyncCreateDescription(
3210 true, CreateSessionDescriptionRequest::kOffer);
3211}
3212
3213// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3214// before async identity generation fails.
3215TEST_F(WebRtcSessionTest,
3216 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003217 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003218 VerifyMultipleAsyncCreateDescription(
3219 false, CreateSessionDescriptionRequest::kOffer);
3220}
3221
3222// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3223// before async identity generation is finished.
3224TEST_F(WebRtcSessionTest,
3225 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003226 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003227 VerifyMultipleAsyncCreateDescription(
3228 true, CreateSessionDescriptionRequest::kAnswer);
3229}
3230
3231// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3232// before async identity generation fails.
3233TEST_F(WebRtcSessionTest,
3234 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003235 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003236 VerifyMultipleAsyncCreateDescription(
3237 false, CreateSessionDescriptionRequest::kAnswer);
3238}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003239
3240// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3241// offer has no SDES crypto but only DTLS fingerprint.
3242TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3243 // Init without DTLS.
3244 Init(NULL);
3245 // Create a remote offer with secured transport disabled.
3246 cricket::MediaSessionOptions options;
3247 JsepSessionDescription* offer(CreateRemoteOffer(
3248 options, cricket::SEC_DISABLED));
3249 // Adds a DTLS fingerprint to the remote offer.
3250 cricket::SessionDescription* sdp = offer->description();
3251 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3252 ASSERT_TRUE(audio != NULL);
3253 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3254 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003255 rtc::SSLFingerprint::CreateFromRfc4572(
3256 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003257 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003258 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003259}
3260
wu@webrtc.orgde305012013-10-31 15:40:38 +00003261// This test verifies DSCP is properly applied on the media channels.
3262TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3263 constraints_.reset(new FakeConstraints());
3264 constraints_->AddOptional(
3265 webrtc::MediaConstraintsInterface::kEnableDscp, true);
3266 Init(NULL);
3267 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003268 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003269
3270 SetLocalDescriptionWithoutError(offer);
3271
3272 video_channel_ = media_engine_->GetVideoChannel(0);
3273 voice_channel_ = media_engine_->GetVoiceChannel(0);
3274
3275 ASSERT_TRUE(video_channel_ != NULL);
3276 ASSERT_TRUE(voice_channel_ != NULL);
3277 cricket::AudioOptions audio_options;
3278 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3279 cricket::VideoOptions video_options;
3280 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3281 EXPECT_TRUE(audio_options.dscp.IsSet());
3282 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3283 EXPECT_TRUE(video_options.dscp.IsSet());
3284 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3285}
3286
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003287TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3288 constraints_.reset(new FakeConstraints());
3289 constraints_->AddOptional(
3290 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3291 true);
3292 Init(NULL);
3293 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003294 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003295
3296 SetLocalDescriptionWithoutError(offer);
3297
3298 video_channel_ = media_engine_->GetVideoChannel(0);
3299
3300 ASSERT_TRUE(video_channel_ != NULL);
3301 cricket::VideoOptions video_options;
3302 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3303 EXPECT_TRUE(
3304 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3305}
3306
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00003307TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
3308 // Number of unsignalled receiving streams should be between 0 and
3309 // kMaxUnsignalledRecvStreams.
3310 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
3311 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
3312 kMaxUnsignalledRecvStreams);
3313 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
3314}
3315
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003316TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
3317 constraints_.reset(new FakeConstraints());
3318 constraints_->AddOptional(
3319 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
3320 true);
3321 Init(NULL);
3322 mediastream_signaling_.SendAudioVideoStream1();
3323 SessionDescriptionInterface* offer = CreateOffer();
3324
3325 SetLocalDescriptionWithoutError(offer);
3326
3327 voice_channel_ = media_engine_->GetVoiceChannel(0);
3328
3329 ASSERT_TRUE(voice_channel_ != NULL);
3330 cricket::AudioOptions audio_options;
3331 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3332 EXPECT_TRUE(
3333 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
3334}
3335
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003336// Tests that we can renegotiate new media content with ICE candidates in the
3337// new remote SDP.
3338TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003339 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003340 InitWithDtls();
3341 SetFactoryDtlsSrtp();
3342
3343 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003344 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003345 SetLocalDescriptionWithoutError(offer);
3346
3347 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3348 SetRemoteDescriptionWithoutError(answer);
3349
3350 cricket::MediaSessionOptions options;
3351 options.has_video = true;
3352 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3353
3354 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003355 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003356 candidate1.set_component(1);
3357 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3358 candidate1);
3359 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3360 SetRemoteDescriptionWithoutError(offer);
3361
3362 answer = CreateAnswer(NULL);
3363 SetLocalDescriptionWithoutError(answer);
3364}
3365
3366// Tests that we can renegotiate new media content with ICE candidates separated
3367// from the remote SDP.
3368TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003369 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003370 InitWithDtls();
3371 SetFactoryDtlsSrtp();
3372
3373 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003374 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003375 SetLocalDescriptionWithoutError(offer);
3376
3377 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3378 SetRemoteDescriptionWithoutError(answer);
3379
3380 cricket::MediaSessionOptions options;
3381 options.has_video = true;
3382 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3383 SetRemoteDescriptionWithoutError(offer);
3384
3385 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003386 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003387 candidate1.set_component(1);
3388 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3389 candidate1);
3390 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3391
3392 answer = CreateAnswer(NULL);
3393 SetLocalDescriptionWithoutError(answer);
3394}
3395
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003396// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
3397// currently fails because upon disconnection and reconnection OnIceComplete is
3398// called more than once without returning to IceGatheringGathering.