blob: 51f0c038b5f2a853cad8efb4348de8c409b5435f [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"
33#include "talk/app/webrtc/videotrack.h"
34#include "talk/app/webrtc/test/fakeconstraints.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000035#include "talk/app/webrtc/test/fakedtlsidentityservice.h"
36#include "talk/app/webrtc/test/fakemediastreamsignaling.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.orgd4e598d2014-07-29 17:36:52 +000039#include "webrtc/base/fakenetwork.h"
40#include "webrtc/base/firewallsocketserver.h"
41#include "webrtc/base/gunit.h"
42#include "webrtc/base/logging.h"
43#include "webrtc/base/network.h"
44#include "webrtc/base/physicalsocketserver.h"
45#include "webrtc/base/ssladapter.h"
46#include "webrtc/base/sslstreamadapter.h"
47#include "webrtc/base/stringutils.h"
48#include "webrtc/base/thread.h"
49#include "webrtc/base/virtualsocketserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000050#include "talk/media/base/fakemediaengine.h"
51#include "talk/media/base/fakevideorenderer.h"
52#include "talk/media/base/mediachannel.h"
53#include "talk/media/devices/fakedevicemanager.h"
54#include "talk/p2p/base/stunserver.h"
55#include "talk/p2p/base/teststunserver.h"
buildbot@webrtc.org41451d42014-05-03 05:39:45 +000056#include "talk/p2p/base/testturnserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000057#include "talk/p2p/client/basicportallocator.h"
58#include "talk/session/media/channelmanager.h"
59#include "talk/session/media/mediasession.h"
60
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;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000101
wu@webrtc.org364f2042013-11-20 21:49:41 +0000102static const int kClientAddrPort = 0;
103static const char kClientAddrHost1[] = "11.11.11.11";
104static const char kClientAddrHost2[] = "22.22.22.22";
105static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000106static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
107static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108
109static const char kSessionVersion[] = "1";
110
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000111// Media index of candidates belonging to the first media content.
112static const int kMediaContentIndex0 = 0;
113static const char kMediaContentName0[] = "audio";
114
115// Media index of candidates belonging to the second media content.
116static const int kMediaContentIndex1 = 1;
117static const char kMediaContentName1[] = "video";
118
119static const int kIceCandidatesTimeout = 10000;
120
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000121static const char kFakeDtlsFingerprint[] =
122 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
123 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
124
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000125static const char kTooLongIceUfragPwd[] =
126 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
127 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
128 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
129 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
130
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000131// Add some extra |newlines| to the |message| after |line|.
132static void InjectAfter(const std::string& line,
133 const std::string& newlines,
134 std::string* message) {
135 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000136 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000137 tmp.c_str(), tmp.length(), message);
138}
139
140class MockIceObserver : public webrtc::IceObserver {
141 public:
142 MockIceObserver()
143 : oncandidatesready_(false),
144 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
145 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
146 }
147
148 virtual void OnIceConnectionChange(
149 PeerConnectionInterface::IceConnectionState new_state) {
150 ice_connection_state_ = new_state;
151 }
152 virtual void OnIceGatheringChange(
153 PeerConnectionInterface::IceGatheringState new_state) {
154 // We can never transition back to "new".
155 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
156 ice_gathering_state_ = new_state;
157
158 // oncandidatesready_ really means "ICE gathering is complete".
159 // This if statement ensures that this value remains correct when we
160 // transition from kIceGatheringComplete to kIceGatheringGathering.
161 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
162 oncandidatesready_ = false;
163 }
164 }
165
166 // Found a new candidate.
167 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000168 switch (candidate->sdp_mline_index()) {
169 case kMediaContentIndex0:
170 mline_0_candidates_.push_back(candidate->candidate());
171 break;
172 case kMediaContentIndex1:
173 mline_1_candidates_.push_back(candidate->candidate());
174 break;
175 default:
176 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000177 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000178
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000179 // The ICE gathering state should always be Gathering when a candidate is
180 // received (or possibly Completed in the case of the final candidate).
181 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
182 }
183
184 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
185 virtual void OnIceComplete() {
186 EXPECT_FALSE(oncandidatesready_);
187 oncandidatesready_ = true;
188
189 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
190 // be called approximately simultaneously. For ease of testing, this
191 // check additionally requires that they be called in the above order.
192 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
193 ice_gathering_state_);
194 }
195
196 bool oncandidatesready_;
197 std::vector<cricket::Candidate> mline_0_candidates_;
198 std::vector<cricket::Candidate> mline_1_candidates_;
199 PeerConnectionInterface::IceConnectionState ice_connection_state_;
200 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
201};
202
203class WebRtcSessionForTest : public webrtc::WebRtcSession {
204 public:
205 WebRtcSessionForTest(cricket::ChannelManager* cmgr,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000206 rtc::Thread* signaling_thread,
207 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000208 cricket::PortAllocator* port_allocator,
209 webrtc::IceObserver* ice_observer,
210 webrtc::MediaStreamSignaling* mediastream_signaling)
211 : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator,
212 mediastream_signaling) {
213 RegisterIceObserver(ice_observer);
214 }
215 virtual ~WebRtcSessionForTest() {}
216
217 using cricket::BaseSession::GetTransportProxy;
218 using webrtc::WebRtcSession::SetAudioPlayout;
219 using webrtc::WebRtcSession::SetAudioSend;
220 using webrtc::WebRtcSession::SetCaptureDevice;
221 using webrtc::WebRtcSession::SetVideoPlayout;
222 using webrtc::WebRtcSession::SetVideoSend;
223};
224
wu@webrtc.org91053e72013-08-10 07:18:04 +0000225class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000226 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000227 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000228 enum State {
229 kInit,
230 kFailed,
231 kSucceeded,
232 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000233 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000234
235 // CreateSessionDescriptionObserver implementation.
236 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000237 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000238 state_ = kSucceeded;
239 }
240 virtual void OnFailure(const std::string& error) {
241 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000242 }
243
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000244 SessionDescriptionInterface* description() { return description_.get(); }
245
246 SessionDescriptionInterface* ReleaseDescription() {
247 return description_.release();
248 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000249
wu@webrtc.org91053e72013-08-10 07:18:04 +0000250 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000251
wu@webrtc.org91053e72013-08-10 07:18:04 +0000252 protected:
253 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000254
255 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000256 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000257 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000258};
259
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000260class FakeAudioRenderer : public cricket::AudioRenderer {
261 public:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000262 FakeAudioRenderer() : channel_id_(-1), sink_(NULL) {}
263 virtual ~FakeAudioRenderer() {
264 if (sink_)
265 sink_->OnClose();
266 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000267
268 virtual void AddChannel(int channel_id) OVERRIDE {
269 ASSERT(channel_id_ == -1);
270 channel_id_ = channel_id;
271 }
272 virtual void RemoveChannel(int channel_id) OVERRIDE {
273 ASSERT(channel_id == channel_id_);
274 channel_id_ = -1;
275 }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000276 virtual void SetSink(Sink* sink) OVERRIDE {
277 sink_ = sink;
278 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000279
280 int channel_id() const { return channel_id_; }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000281 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000282 private:
283 int channel_id_;
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000284 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000285};
286
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000287class WebRtcSessionTest : public testing::Test {
288 protected:
289 // TODO Investigate why ChannelManager crashes, if it's created
290 // after stun_server.
291 WebRtcSessionTest()
292 : media_engine_(new cricket::FakeMediaEngine()),
293 data_engine_(new cricket::FakeDataEngine()),
294 device_manager_(new cricket::FakeDeviceManager()),
295 channel_manager_(new cricket::ChannelManager(
296 media_engine_, data_engine_, device_manager_,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000297 new cricket::CaptureManager(), rtc::Thread::Current())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000298 tdesc_factory_(new cricket::TransportDescriptionFactory()),
299 desc_factory_(new cricket::MediaSessionDescriptionFactory(
300 channel_manager_.get(), tdesc_factory_.get())),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000301 pss_(new rtc::PhysicalSocketServer),
302 vss_(new rtc::VirtualSocketServer(pss_.get())),
303 fss_(new rtc::FirewallSocketServer(vss_.get())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000304 ss_scope_(fss_.get()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000305 stun_socket_addr_(rtc::SocketAddress(kStunAddrHost,
wu@webrtc.org364f2042013-11-20 21:49:41 +0000306 cricket::STUN_SERVER_PORT)),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000307 stun_server_(Thread::Current(), stun_socket_addr_),
308 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000309 mediastream_signaling_(channel_manager_.get()),
310 ice_type_(PeerConnectionInterface::kAll) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311 tdesc_factory_->set_protocol(cricket::ICEPROTO_HYBRID);
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000312
313 cricket::ServerAddresses stun_servers;
314 stun_servers.insert(stun_socket_addr_);
315 allocator_.reset(new cricket::BasicPortAllocator(
316 &network_manager_,
317 stun_servers,
318 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000319 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000320 cricket::PORTALLOCATOR_DISABLE_RELAY |
321 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
322 EXPECT_TRUE(channel_manager_->Init());
323 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000324 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000325 }
326
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000327 static void SetUpTestCase() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000328 rtc::InitializeSSL();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000329 }
330
331 static void TearDownTestCase() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000332 rtc::CleanupSSL();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000333 }
334
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000335 void AddInterface(const SocketAddress& addr) {
336 network_manager_.AddInterface(addr);
337 }
338
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000339 void SetIceTransportType(PeerConnectionInterface::IceTransportsType type) {
340 ice_type_ = type;
341 }
342
wu@webrtc.org91053e72013-08-10 07:18:04 +0000343 void Init(DTLSIdentityServiceInterface* identity_service) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000344 ASSERT_TRUE(session_.get() == NULL);
345 session_.reset(new WebRtcSessionForTest(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000346 channel_manager_.get(), rtc::Thread::Current(),
347 rtc::Thread::Current(), allocator_.get(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000348 &observer_,
349 &mediastream_signaling_));
350
351 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
352 observer_.ice_connection_state_);
353 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
354 observer_.ice_gathering_state_);
355
wu@webrtc.org97077a32013-10-25 21:18:33 +0000356 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000357 identity_service, ice_type_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000358 }
359
360 void InitWithDtmfCodec() {
361 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000362 const cricket::AudioCodec kTelephoneEventCodec(
363 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000364 std::vector<cricket::AudioCodec> codecs;
365 codecs.push_back(kTelephoneEventCodec);
366 media_engine_->SetAudioCodecs(codecs);
367 desc_factory_->set_audio_codecs(codecs);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000368 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000369 }
370
henrike@webrtc.org7666db72013-08-22 14:45:42 +0000371 void InitWithDtls(bool identity_request_should_fail = false) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000372 FakeIdentityService* identity_service = new FakeIdentityService();
373 identity_service->set_should_fail(identity_request_should_fail);
374 Init(identity_service);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000375 }
376
377 // Creates a local offer and applies it. Starts ice.
378 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
379 // to decide which streams to create.
380 void InitiateCall() {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000381 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000382 SetLocalDescriptionWithoutError(offer);
383 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
384 observer_.ice_gathering_state_,
385 kIceCandidatesTimeout);
386 }
387
wu@webrtc.org91053e72013-08-10 07:18:04 +0000388 SessionDescriptionInterface* CreateOffer(
389 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000390 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000391 observer = new WebRtcSessionCreateSDPObserverForTest();
392 session_->CreateOffer(observer, constraints);
393 EXPECT_TRUE_WAIT(
394 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000395 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000396 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000397 }
398
399 SessionDescriptionInterface* CreateAnswer(
400 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000401 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000402 = new WebRtcSessionCreateSDPObserverForTest();
403 session_->CreateAnswer(observer, constraints);
404 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
wu@webrtc.org364f2042013-11-20 21:49:41 +0000410 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000411 return (session_->voice_channel() != NULL &&
412 session_->video_channel() != NULL);
413 }
414
wu@webrtc.org364f2042013-11-20 21:49:41 +0000415 void CheckTransportChannels() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000416 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 1) != NULL);
417 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 2) != NULL);
418 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 1) != NULL);
419 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 2) != NULL);
420 }
421
422 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
423 ASSERT_TRUE(session_.get() != NULL);
424 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
425 ASSERT_TRUE(content != NULL);
426 const cricket::AudioContentDescription* audio_content =
427 static_cast<const cricket::AudioContentDescription*>(
428 content->description);
429 ASSERT_TRUE(audio_content != NULL);
430 ASSERT_EQ(1U, audio_content->cryptos().size());
431 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
432 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
433 audio_content->cryptos()[0].cipher_suite);
434 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
435 audio_content->protocol());
436
437 content = cricket::GetFirstVideoContent(sdp);
438 ASSERT_TRUE(content != NULL);
439 const cricket::VideoContentDescription* video_content =
440 static_cast<const cricket::VideoContentDescription*>(
441 content->description);
442 ASSERT_TRUE(video_content != NULL);
443 ASSERT_EQ(1U, video_content->cryptos().size());
444 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
445 video_content->cryptos()[0].cipher_suite);
446 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
447 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
448 video_content->protocol());
449 }
450
451 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
452 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
453 ASSERT_TRUE(content != NULL);
454 const cricket::AudioContentDescription* audio_content =
455 static_cast<const cricket::AudioContentDescription*>(
456 content->description);
457 ASSERT_TRUE(audio_content != NULL);
458 ASSERT_EQ(0U, audio_content->cryptos().size());
459
460 content = cricket::GetFirstVideoContent(sdp);
461 ASSERT_TRUE(content != NULL);
462 const cricket::VideoContentDescription* video_content =
463 static_cast<const cricket::VideoContentDescription*>(
464 content->description);
465 ASSERT_TRUE(video_content != NULL);
466 ASSERT_EQ(0U, video_content->cryptos().size());
467
468 if (dtls) {
469 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
470 audio_content->protocol());
471 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
472 video_content->protocol());
473 } else {
474 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
475 audio_content->protocol());
476 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
477 video_content->protocol());
478 }
479 }
480
481 // Set the internal fake description factories to do DTLS-SRTP.
482 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000483 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000484 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000485 rtc::ToString(rtc::CreateRandomId());
486 identity_.reset(rtc::SSLIdentity::Generate(identity_name));
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000487 tdesc_factory_->set_identity(identity_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000488 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
489 }
490
491 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
492 bool expected) {
493 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
494 ASSERT_TRUE(audio != NULL);
495 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000496 const TransportInfo* video = sdp->GetTransportInfoByName("video");
497 ASSERT_TRUE(video != NULL);
498 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000499 }
500
501 void VerifyAnswerFromNonCryptoOffer() {
502 // Create a SDP without Crypto.
503 cricket::MediaSessionOptions options;
504 options.has_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000505 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000506 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000507 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000508 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000509 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
510 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000511 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000512 // Answer should be NULL as no crypto params in offer.
513 ASSERT_TRUE(answer == NULL);
514 }
515
516 void VerifyAnswerFromCryptoOffer() {
517 cricket::MediaSessionOptions options;
518 options.has_video = true;
519 options.bundle_enabled = true;
520 scoped_ptr<JsepSessionDescription> offer(
521 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
522 ASSERT_TRUE(offer.get() != NULL);
523 VerifyCryptoParams(offer->description());
524 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000525 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000526 ASSERT_TRUE(answer.get() != NULL);
527 VerifyCryptoParams(answer->description());
528 }
529
530 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
531 const cricket::SessionDescription* desc2,
532 bool expect_equal) {
533 if (desc1->contents().size() != desc2->contents().size()) {
534 EXPECT_FALSE(expect_equal);
535 return;
536 }
537
538 const cricket::ContentInfos& contents = desc1->contents();
539 cricket::ContentInfos::const_iterator it = contents.begin();
540
541 for (; it != contents.end(); ++it) {
542 const cricket::TransportDescription* transport_desc1 =
543 desc1->GetTransportDescriptionByName(it->name);
544 const cricket::TransportDescription* transport_desc2 =
545 desc2->GetTransportDescriptionByName(it->name);
546 if (!transport_desc1 || !transport_desc2) {
547 EXPECT_FALSE(expect_equal);
548 return;
549 }
550 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
551 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
552 EXPECT_FALSE(expect_equal);
553 return;
554 }
555 }
556 EXPECT_TRUE(expect_equal);
557 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000558
559 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
560 std::string *sdp) {
561 const cricket::SessionDescription* desc = current_desc->description();
562 EXPECT_TRUE(current_desc->ToString(sdp));
563
564 const cricket::ContentInfos& contents = desc->contents();
565 cricket::ContentInfos::const_iterator it = contents.begin();
566 // Replace ufrag and pwd lines with empty strings.
567 for (; it != contents.end(); ++it) {
568 const cricket::TransportDescription* transport_desc =
569 desc->GetTransportDescriptionByName(it->name);
570 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
571 + "\r\n";
572 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
573 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000574 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000575 "", 0,
576 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000577 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000578 "", 0,
579 sdp);
580 }
581 }
582
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000583 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
584 const std::string& modified_ice_ufrag,
585 const std::string& modified_ice_pwd,
586 std::string* sdp) {
587 const cricket::SessionDescription* desc = current_desc->description();
588 EXPECT_TRUE(current_desc->ToString(sdp));
589
590 const cricket::ContentInfos& contents = desc->contents();
591 cricket::ContentInfos::const_iterator it = contents.begin();
592 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
593 // |modified_ice_pwd| strings.
594 for (; it != contents.end(); ++it) {
595 const cricket::TransportDescription* transport_desc =
596 desc->GetTransportDescriptionByName(it->name);
597 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
598 + "\r\n";
599 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
600 + "\r\n";
601 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
602 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000603 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000604 mod_ufrag.c_str(), mod_ufrag.length(),
605 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000606 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000607 mod_pwd.c_str(), mod_pwd.length(),
608 sdp);
609 }
610 }
611
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000612 // Creates a remote offer and and applies it as a remote description,
613 // creates a local answer and applies is as a local description.
614 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
615 // to decide which local and remote streams to create.
616 void CreateAndSetRemoteOfferAndLocalAnswer() {
617 SessionDescriptionInterface* offer = CreateRemoteOffer();
618 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000619 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000620 SetLocalDescriptionWithoutError(answer);
621 }
622 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
623 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
624 }
625 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
626 BaseSession::State expected_state) {
627 SetLocalDescriptionWithoutError(desc);
628 EXPECT_EQ(expected_state, session_->state());
629 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000630 void SetLocalDescriptionExpectError(const std::string& action,
631 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000632 SessionDescriptionInterface* desc) {
633 std::string error;
634 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000635 std::string sdp_type = "local ";
636 sdp_type.append(action);
637 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000638 EXPECT_NE(std::string::npos, error.find(expected_error));
639 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000640 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
641 SessionDescriptionInterface* desc) {
642 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
643 expected_error, desc);
644 }
645 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
646 SessionDescriptionInterface* desc) {
647 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
648 expected_error, desc);
649 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000650 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
651 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
652 }
653 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
654 BaseSession::State expected_state) {
655 SetRemoteDescriptionWithoutError(desc);
656 EXPECT_EQ(expected_state, session_->state());
657 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000658 void SetRemoteDescriptionExpectError(const std::string& action,
659 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000660 SessionDescriptionInterface* desc) {
661 std::string error;
662 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000663 std::string sdp_type = "remote ";
664 sdp_type.append(action);
665 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000666 EXPECT_NE(std::string::npos, error.find(expected_error));
667 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000668 void SetRemoteDescriptionOfferExpectError(
669 const std::string& expected_error, SessionDescriptionInterface* desc) {
670 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
671 expected_error, desc);
672 }
673 void SetRemoteDescriptionPranswerExpectError(
674 const std::string& expected_error, SessionDescriptionInterface* desc) {
675 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
676 expected_error, desc);
677 }
678 void SetRemoteDescriptionAnswerExpectError(
679 const std::string& expected_error, SessionDescriptionInterface* desc) {
680 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
681 expected_error, desc);
682 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000683
684 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
685 SessionDescriptionInterface** nocrypto_answer) {
686 // Create a SDP without Crypto.
687 cricket::MediaSessionOptions options;
688 options.has_video = true;
689 options.bundle_enabled = true;
690 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
691 ASSERT_TRUE(*offer != NULL);
692 VerifyCryptoParams((*offer)->description());
693
694 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
695 cricket::SEC_DISABLED);
696 EXPECT_TRUE(*nocrypto_answer != NULL);
697 }
698
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000699 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
700 SessionDescriptionInterface** nodtls_answer) {
701 cricket::MediaSessionOptions options;
702 options.has_video = true;
703 options.bundle_enabled = true;
704
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000705 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000706 CreateRemoteOffer(options, cricket::SEC_ENABLED));
707
708 *nodtls_answer =
709 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
710 EXPECT_TRUE(*nodtls_answer != NULL);
711 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
712 VerifyCryptoParams((*nodtls_answer)->description());
713
714 SetFactoryDtlsSrtp();
715 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
716 ASSERT_TRUE(*offer != NULL);
717 VerifyFingerprintStatus((*offer)->description(), true);
718 VerifyCryptoParams((*offer)->description());
719 }
720
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721 JsepSessionDescription* CreateRemoteOfferWithVersion(
722 cricket::MediaSessionOptions options,
723 cricket::SecurePolicy secure_policy,
724 const std::string& session_version,
725 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000726 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000727 const cricket::SessionDescription* cricket_desc = NULL;
728 if (current_desc) {
729 cricket_desc = current_desc->description();
730 session_id = current_desc->session_id();
731 }
732
733 desc_factory_->set_secure(secure_policy);
734 JsepSessionDescription* offer(
735 new JsepSessionDescription(JsepSessionDescription::kOffer));
736 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
737 session_id, session_version)) {
738 delete offer;
739 offer = NULL;
740 }
741 return offer;
742 }
743 JsepSessionDescription* CreateRemoteOffer(
744 cricket::MediaSessionOptions options) {
745 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
746 kSessionVersion, NULL);
747 }
748 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000749 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
750 return CreateRemoteOfferWithVersion(
751 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000752 }
753 JsepSessionDescription* CreateRemoteOffer(
754 cricket::MediaSessionOptions options,
755 const SessionDescriptionInterface* current_desc) {
756 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
757 kSessionVersion, current_desc);
758 }
759
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000760 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
761 const char* sctp_stream_name, int new_port,
762 cricket::MediaSessionOptions options) {
763 options.data_channel_type = cricket::DCT_SCTP;
764 options.AddStream(cricket::MEDIA_TYPE_DATA, "datachannel",
765 sctp_stream_name);
766 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
767 }
768
769 // Takes ownership of offer_basis (and deletes it).
770 JsepSessionDescription* ChangeSDPSctpPort(
771 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
772 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
773 // SessionDescription from the mutated string.
774 const char* default_port_str = "5000";
775 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000776 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000777 std::string offer_str;
778 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000779 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000780 new_port_str, strlen(new_port_str),
781 &offer_str);
782 JsepSessionDescription* offer = new JsepSessionDescription(
783 offer_basis->type());
784 delete offer_basis;
785 offer->Initialize(offer_str, NULL);
786 return offer;
787 }
788
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000789 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
790 // before this function to decide which streams to create.
791 JsepSessionDescription* CreateRemoteOffer() {
792 cricket::MediaSessionOptions options;
793 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
794 return CreateRemoteOffer(options, session_->remote_description());
795 }
796
797 JsepSessionDescription* CreateRemoteAnswer(
798 const SessionDescriptionInterface* offer,
799 cricket::MediaSessionOptions options,
800 cricket::SecurePolicy policy) {
801 desc_factory_->set_secure(policy);
802 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000803 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000804 JsepSessionDescription* answer(
805 new JsepSessionDescription(JsepSessionDescription::kAnswer));
806 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
807 options, NULL),
808 session_id, kSessionVersion)) {
809 delete answer;
810 answer = NULL;
811 }
812 return answer;
813 }
814
815 JsepSessionDescription* CreateRemoteAnswer(
816 const SessionDescriptionInterface* offer,
817 cricket::MediaSessionOptions options) {
818 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
819 }
820
821 // Creates an answer session description with streams based on
822 // |mediastream_signaling_|. Call
823 // mediastream_signaling_.UseOptionsWithStreamX() before this function
824 // to decide which streams to create.
825 JsepSessionDescription* CreateRemoteAnswer(
826 const SessionDescriptionInterface* offer) {
827 cricket::MediaSessionOptions options;
828 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
829 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
830 }
831
832 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000833 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +0000834 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835 mediastream_signaling_.SendAudioVideoStream1();
836 FakeConstraints constraints;
837 constraints.SetMandatoryUseRtpMux(bundle);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000838 SessionDescriptionInterface* offer = CreateOffer(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000839 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
840 // and answer.
841 SetLocalDescriptionWithoutError(offer);
842
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000843 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000844 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000845 std::string sdp;
846 EXPECT_TRUE(answer->ToString(&sdp));
847
848 size_t expected_candidate_num = 2;
849 if (!rtcp_mux) {
850 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
851 // for rtp and rtcp.
852 expected_candidate_num = 4;
853 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 const std::string kRtcpMux = "a=rtcp-mux";
855 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000856 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000857 kXRtcpMux.c_str(), kXRtcpMux.length(),
858 &sdp);
859 }
860
861 SessionDescriptionInterface* new_answer = CreateSessionDescription(
862 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000863
864 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000865 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
867 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
868 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
869 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
870 cricket::Candidate c0 = observer_.mline_0_candidates_[i];
871 cricket::Candidate c1 = observer_.mline_1_candidates_[i];
872 if (bundle) {
873 EXPECT_TRUE(c0.IsEquivalent(c1));
874 } else {
875 EXPECT_FALSE(c0.IsEquivalent(c1));
876 }
877 }
878 }
879 // Tests that we can only send DTMF when the dtmf codec is supported.
880 void TestCanInsertDtmf(bool can) {
881 if (can) {
882 InitWithDtmfCodec();
883 } else {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000884 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000885 }
886 mediastream_signaling_.SendAudioVideoStream1();
887 CreateAndSetRemoteOfferAndLocalAnswer();
888 EXPECT_FALSE(session_->CanInsertDtmf(""));
889 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
890 }
891
892 // The method sets up a call from the session to itself, in a loopback
893 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000894 // disconnection, and then a permanent disconnection.
895 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896 // by multiple tests with different allocators (e.g. with and without BUNDLE).
897 // While running the call, this method also checks if the session goes through
898 // the correct sequence of ICE states when a connection is established,
899 // broken, and re-established.
900 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000901 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
902 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000903 // The Gathering state should go: New -> Gathering -> Completed.
904 void TestLoopbackCall() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000905 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +0000906 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000907 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000908 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000909
910 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
911 observer_.ice_gathering_state_);
912 SetLocalDescriptionWithoutError(offer);
913 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
914 observer_.ice_connection_state_);
915 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
916 observer_.ice_gathering_state_,
917 kIceCandidatesTimeout);
918 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
919 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
920 observer_.ice_gathering_state_,
921 kIceCandidatesTimeout);
922
923 std::string sdp;
924 offer->ToString(&sdp);
925 SessionDescriptionInterface* desc =
926 webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer, sdp);
927 ASSERT_TRUE(desc != NULL);
928 SetRemoteDescriptionWithoutError(desc);
929
930 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
931 observer_.ice_connection_state_,
932 kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +0000933
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000934 // The ice connection state is "Connected" too briefly to catch in a test.
935 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000936 observer_.ice_connection_state_,
937 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000938
939 // Adding firewall rule to block ping requests, which should cause
940 // transport channel failure.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000941 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000942 rtc::FP_ANY,
943 rtc::FD_ANY,
944 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000945 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
946 observer_.ice_connection_state_,
947 kIceCandidatesTimeout);
948
949 // Clearing the rules, session should move back to completed state.
950 fss_->ClearRules();
951 // Session is automatically calling OnSignalingReady after creation of
952 // new portallocator session which will allocate new set of candidates.
953
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000954 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955 observer_.ice_connection_state_,
956 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000957
958 // Now we block ping requests and wait until the ICE connection transitions
959 // to the Failed state. This will take at least 30 seconds because it must
960 // wait for the Port to timeout.
961 int port_timeout = 30000;
962 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000963 rtc::FP_ANY,
964 rtc::FD_ANY,
965 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000966 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionFailed,
967 observer_.ice_connection_state_,
968 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 }
970
971 void VerifyTransportType(const std::string& content_name,
972 cricket::TransportProtocol protocol) {
973 const cricket::Transport* transport = session_->GetTransport(content_name);
974 ASSERT_TRUE(transport != NULL);
975 EXPECT_EQ(protocol, transport->protocol());
976 }
977
978 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
979 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000980 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
981 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
982
983 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000984 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
985 codecs.push_back(kCNCodec1);
986 codecs.push_back(kCNCodec2);
987 media_engine_->SetAudioCodecs(codecs);
988 desc_factory_->set_audio_codecs(codecs);
989 }
990
991 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
992 const cricket::ContentDescription* description = content->description;
993 ASSERT(description != NULL);
994 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000995 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000996 ASSERT(audio_content_desc != NULL);
997 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
998 if (audio_content_desc->codecs()[i].name == "CN")
999 return false;
1000 }
1001 return true;
1002 }
1003
1004 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001005 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001006 dci.reliable = false;
1007 session_->CreateDataChannel("datachannel", &dci);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001008 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001009 SetLocalDescriptionWithoutError(offer);
1010 }
1011
wu@webrtc.org91053e72013-08-10 07:18:04 +00001012 void VerifyMultipleAsyncCreateDescription(
1013 bool success, CreateSessionDescriptionRequest::Type type) {
henrike@webrtc.org7666db72013-08-22 14:45:42 +00001014 InitWithDtls(!success);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001015 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001016 if (type == CreateSessionDescriptionRequest::kAnswer) {
1017 cricket::MediaSessionOptions options;
1018 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001019 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001020 ASSERT_TRUE(offer.get() != NULL);
1021 SetRemoteDescriptionWithoutError(offer.release());
1022 }
1023
1024 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001025 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001026 observers[kNumber];
1027 for (int i = 0; i < kNumber; ++i) {
1028 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1029 if (type == CreateSessionDescriptionRequest::kOffer) {
1030 session_->CreateOffer(observers[i], NULL);
1031 } else {
1032 session_->CreateAnswer(observers[i], NULL);
1033 }
1034 }
1035
1036 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1037 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1038 WebRtcSessionCreateSDPObserverForTest::kFailed;
1039
1040 for (int i = 0; i < kNumber; ++i) {
1041 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1042 if (success) {
1043 EXPECT_TRUE(observers[i]->description() != NULL);
1044 } else {
1045 EXPECT_TRUE(observers[i]->description() == NULL);
1046 }
1047 }
1048 }
1049
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001050 cricket::FakeMediaEngine* media_engine_;
1051 cricket::FakeDataEngine* data_engine_;
1052 cricket::FakeDeviceManager* device_manager_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001053 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
1054 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1055 rtc::scoped_ptr<rtc::SSLIdentity> identity_;
1056 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1057 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1058 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1059 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1060 rtc::SocketServerScope ss_scope_;
1061 rtc::SocketAddress stun_socket_addr_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001062 cricket::TestStunServer stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001063 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001064 rtc::FakeNetworkManager network_manager_;
1065 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001066 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001067 rtc::scoped_ptr<FakeConstraints> constraints_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001068 FakeMediaStreamSignaling mediastream_signaling_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001069 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001070 MockIceObserver observer_;
1071 cricket::FakeVideoMediaChannel* video_channel_;
1072 cricket::FakeVoiceMediaChannel* voice_channel_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001073 PeerConnectionInterface::IceTransportsType ice_type_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001074};
1075
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001076TEST_F(WebRtcSessionTest, TestInitializeWithDtls) {
1077 InitWithDtls();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001078 // SDES is disabled when DTLS is on.
1079 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001080}
1081
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001082TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001083 Init(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001084 // SDES is required if DTLS is off.
1085 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001086}
1087
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001088TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1089 TestSessionCandidatesWithBundleRtcpMux(false, false);
1090}
1091
1092// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1093// with rtcp-mux and/or bundle.
1094TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1095 TestSessionCandidatesWithBundleRtcpMux(false, true);
1096}
1097
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001098TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1099 TestSessionCandidatesWithBundleRtcpMux(true, true);
1100}
1101
1102TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001103 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1104 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001105 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001106 mediastream_signaling_.SendAudioVideoStream1();
1107 InitiateCall();
1108 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1109 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1110 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1111}
1112
1113TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001114 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1115 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001116 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001117 rtc::FP_UDP,
1118 rtc::FD_ANY,
1119 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001120 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001121 mediastream_signaling_.SendAudioVideoStream1();
1122 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001123 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001124 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1125 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1126 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1127}
1128
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001129TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
1130 Init(NULL);
1131 SessionDescriptionInterface* offer = NULL;
1132 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1133 std::string unknown_action;
1134 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1135 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1136}
1137
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001138// Test creating offers and receive answers and make sure the
1139// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001140TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001141 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001142 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001143 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001144 const std::string session_id_orig = offer->session_id();
1145 const std::string session_version_orig = offer->session_version();
1146 SetLocalDescriptionWithoutError(offer);
1147
1148 mediastream_signaling_.SendAudioVideoStream2();
1149 SessionDescriptionInterface* answer =
1150 CreateRemoteAnswer(session_->local_description());
1151 SetRemoteDescriptionWithoutError(answer);
1152
1153 video_channel_ = media_engine_->GetVideoChannel(0);
1154 voice_channel_ = media_engine_->GetVoiceChannel(0);
1155
1156 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1157 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1158
1159 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1160 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1161
1162 ASSERT_EQ(1u, video_channel_->send_streams().size());
1163 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1164 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1165 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1166
1167 // Create new offer without send streams.
1168 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001169 offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001170
1171 // Verify the session id is the same and the session version is
1172 // increased.
1173 EXPECT_EQ(session_id_orig, offer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001174 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1175 rtc::FromString<uint64>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001176
1177 SetLocalDescriptionWithoutError(offer);
1178
1179 mediastream_signaling_.SendAudioVideoStream2();
1180 answer = CreateRemoteAnswer(session_->local_description());
1181 SetRemoteDescriptionWithoutError(answer);
1182
1183 EXPECT_EQ(0u, video_channel_->send_streams().size());
1184 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1185
1186 // Make sure the receive streams have not changed.
1187 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1188 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1189 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1190 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1191}
1192
1193// Test receiving offers and creating answers and make sure the
1194// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001195TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001196 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001197 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001198 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001199 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001200 SetRemoteDescriptionWithoutError(offer);
1201
1202 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001203 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001204 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001205 SetLocalDescriptionWithoutError(answer);
1206
1207 const std::string session_id_orig = answer->session_id();
1208 const std::string session_version_orig = answer->session_version();
1209
1210 video_channel_ = media_engine_->GetVideoChannel(0);
1211 voice_channel_ = media_engine_->GetVoiceChannel(0);
1212
1213 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1214 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1215
1216 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1217 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1218
1219 ASSERT_EQ(1u, video_channel_->send_streams().size());
1220 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1221 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1222 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1223
1224 mediastream_signaling_.SendAudioVideoStream1And2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001225 offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001226 SetRemoteDescriptionWithoutError(offer);
1227
1228 // Answer by turning off all send streams.
1229 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001230 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001231
1232 // Verify the session id is the same and the session version is
1233 // increased.
1234 EXPECT_EQ(session_id_orig, answer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001235 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1236 rtc::FromString<uint64>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001237 SetLocalDescriptionWithoutError(answer);
1238
1239 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1240 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1241 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1242 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1243 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1244 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1245
1246 // Make sure we have no send streams.
1247 EXPECT_EQ(0u, video_channel_->send_streams().size());
1248 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1249}
1250
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001251TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
1252 Init(NULL);
1253 media_engine_->set_fail_create_channel(true);
1254
1255 SessionDescriptionInterface* offer = CreateOffer(NULL);
1256 ASSERT_TRUE(offer != NULL);
1257 // SetRemoteDescription and SetLocalDescription will take the ownership of
1258 // the offer.
1259 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
1260 offer = CreateOffer(NULL);
1261 ASSERT_TRUE(offer != NULL);
1262 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1263}
1264
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001265//
1266// Tests for creating/setting SDP under different SDES/DTLS polices:
1267//
1268// --DTLS off and SDES on
1269// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1270// set local/remote offer/answer with crypto --> success
1271// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1272// failure
1273// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1274// failure
1275// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1276// failure
1277//
1278// --DTLS on and SDES off
1279// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1280// set local/remote offer/answer with DTLS fingerprint --> success
1281// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1282// fingerprint --> failure
1283// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1284// --> failure
1285// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1286// --> failure
1287//
1288// --Encryption disabled: DTLS off and SDES off
1289// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1290// answer without SDES or DTLS --> success
1291// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1292// answer without SDES or DTLS --> success
1293//
1294
1295// Test that we return a failure when applying a remote/local offer that doesn't
1296// have cryptos enabled when DTLS is off.
1297TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001298 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001299 cricket::MediaSessionOptions options;
1300 options.has_video = true;
1301 JsepSessionDescription* offer = CreateRemoteOffer(
1302 options, cricket::SEC_DISABLED);
1303 ASSERT_TRUE(offer != NULL);
1304 VerifyNoCryptoParams(offer->description(), false);
1305 // SetRemoteDescription and SetLocalDescription will take the ownership of
1306 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001307 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001308 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1309 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001310 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001311}
1312
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001313// Test that we return a failure when applying a local answer that doesn't have
1314// cryptos enabled when DTLS is off.
1315TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001316 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001317 SessionDescriptionInterface* offer = NULL;
1318 SessionDescriptionInterface* answer = NULL;
1319 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1320 // SetRemoteDescription and SetLocalDescription will take the ownership of
1321 // the offer.
1322 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001323 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324}
1325
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001326// Test we will return fail when apply an remote answer that doesn't have
1327// crypto enabled when DTLS is off.
1328TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001329 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001330 SessionDescriptionInterface* offer = NULL;
1331 SessionDescriptionInterface* answer = NULL;
1332 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1333 // SetRemoteDescription and SetLocalDescription will take the ownership of
1334 // the offer.
1335 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001336 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001337}
1338
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001339// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1340// and that we return an answer with a DTLS fingerprint.
1341TEST_F(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001342 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001343 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001344 InitWithDtls();
1345 SetFactoryDtlsSrtp();
1346 cricket::MediaSessionOptions options;
1347 options.has_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001348 JsepSessionDescription* offer =
1349 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001350 ASSERT_TRUE(offer != NULL);
1351 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001352 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001353
1354 // SetRemoteDescription will take the ownership of the offer.
1355 SetRemoteDescriptionWithoutError(offer);
1356
1357 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001358 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001359 ASSERT_TRUE(answer != NULL);
1360 VerifyFingerprintStatus(answer->description(), true);
1361 // Check that we don't have an a=crypto line in the answer.
1362 VerifyNoCryptoParams(answer->description(), true);
1363
1364 // Now set the local description, which should work, even without a=crypto.
1365 SetLocalDescriptionWithoutError(answer);
1366}
1367
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001368// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1369// and then we accept a remote answer with a DTLS fingerprint successfully.
1370TEST_F(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001371 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001372 mediastream_signaling_.SendAudioVideoStream1();
1373 InitWithDtls();
1374 SetFactoryDtlsSrtp();
1375
1376 // Verify that we get a crypto fingerprint in the answer.
1377 SessionDescriptionInterface* offer = CreateOffer(NULL);
1378 ASSERT_TRUE(offer != NULL);
1379 VerifyFingerprintStatus(offer->description(), true);
1380 // Check that we don't have an a=crypto line in the offer.
1381 VerifyNoCryptoParams(offer->description(), true);
1382
1383 // Now set the local description, which should work, even without a=crypto.
1384 SetLocalDescriptionWithoutError(offer);
1385
1386 cricket::MediaSessionOptions options;
1387 options.has_video = true;
1388 JsepSessionDescription* answer =
1389 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1390 ASSERT_TRUE(answer != NULL);
1391 VerifyFingerprintStatus(answer->description(), true);
1392 VerifyNoCryptoParams(answer->description(), true);
1393
1394 // SetRemoteDescription will take the ownership of the answer.
1395 SetRemoteDescriptionWithoutError(answer);
1396}
1397
1398// Test that if we support DTLS and the other side didn't offer a fingerprint,
1399// we will fail to set the remote description.
1400TEST_F(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001401 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001402 InitWithDtls();
1403 cricket::MediaSessionOptions options;
1404 options.has_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001405 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001406 JsepSessionDescription* offer = CreateRemoteOffer(
1407 options, cricket::SEC_REQUIRED);
1408 ASSERT_TRUE(offer != NULL);
1409 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001410 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001411
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001412 // SetRemoteDescription will take the ownership of the offer.
1413 SetRemoteDescriptionOfferExpectError(
1414 kSdpWithoutDtlsFingerprint, offer);
1415
1416 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1417 // SetLocalDescription will take the ownership of the offer.
1418 SetLocalDescriptionOfferExpectError(
1419 kSdpWithoutDtlsFingerprint, offer);
1420}
1421
1422// Test that we return a failure when applying a local answer that doesn't have
1423// a DTLS fingerprint when DTLS is required.
1424TEST_F(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001425 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001426 InitWithDtls();
1427 SessionDescriptionInterface* offer = NULL;
1428 SessionDescriptionInterface* answer = NULL;
1429 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1430
1431 // SetRemoteDescription and SetLocalDescription will take the ownership of
1432 // the offer and answer.
1433 SetRemoteDescriptionWithoutError(offer);
1434 SetLocalDescriptionAnswerExpectError(
1435 kSdpWithoutDtlsFingerprint, answer);
1436}
1437
1438// Test that we return a failure when applying a remote answer that doesn't have
1439// a DTLS fingerprint when DTLS is required.
1440TEST_F(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001441 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001442 InitWithDtls();
1443 SessionDescriptionInterface* offer = CreateOffer(NULL);
1444 cricket::MediaSessionOptions options;
1445 options.has_video = true;
1446 JsepSessionDescription* answer =
1447 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
1448
1449 // SetRemoteDescription and SetLocalDescription will take the ownership of
1450 // the offer and answer.
1451 SetLocalDescriptionWithoutError(offer);
1452 SetRemoteDescriptionAnswerExpectError(
1453 kSdpWithoutDtlsFingerprint, answer);
1454}
1455
1456// Test that we create a local offer without SDES or DTLS and accept a remote
1457// answer without SDES or DTLS when encryption is disabled.
1458TEST_F(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
1459 mediastream_signaling_.SendAudioVideoStream1();
1460 options_.disable_encryption = true;
1461 InitWithDtls();
1462
1463 // Verify that we get a crypto fingerprint in the answer.
1464 SessionDescriptionInterface* offer = CreateOffer(NULL);
1465 ASSERT_TRUE(offer != NULL);
1466 VerifyFingerprintStatus(offer->description(), false);
1467 // Check that we don't have an a=crypto line in the offer.
1468 VerifyNoCryptoParams(offer->description(), false);
1469
1470 // Now set the local description, which should work, even without a=crypto.
1471 SetLocalDescriptionWithoutError(offer);
1472
1473 cricket::MediaSessionOptions options;
1474 options.has_video = true;
1475 JsepSessionDescription* answer =
1476 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1477 ASSERT_TRUE(answer != NULL);
1478 VerifyFingerprintStatus(answer->description(), false);
1479 VerifyNoCryptoParams(answer->description(), false);
1480
1481 // SetRemoteDescription will take the ownership of the answer.
1482 SetRemoteDescriptionWithoutError(answer);
1483}
1484
1485// Test that we create a local answer without SDES or DTLS and accept a remote
1486// offer without SDES or DTLS when encryption is disabled.
1487TEST_F(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
1488 options_.disable_encryption = true;
1489 InitWithDtls();
1490
1491 cricket::MediaSessionOptions options;
1492 options.has_video = true;
1493 JsepSessionDescription* offer =
1494 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1495 ASSERT_TRUE(offer != NULL);
1496 VerifyFingerprintStatus(offer->description(), false);
1497 VerifyNoCryptoParams(offer->description(), false);
1498
1499 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001500 SetRemoteDescriptionWithoutError(offer);
1501
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001502 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001503 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001504 ASSERT_TRUE(answer != NULL);
1505 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001506 // Check that we don't have an a=crypto line in the answer.
1507 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001508
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001509 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001510 SetLocalDescriptionWithoutError(answer);
1511}
1512
1513TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001514 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001515 mediastream_signaling_.SendNothing();
1516 // SetLocalDescription take ownership of offer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001517 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001518 SetLocalDescriptionWithoutError(offer);
1519
1520 // SetLocalDescription take ownership of offer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001521 SessionDescriptionInterface* offer2 = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001522 SetLocalDescriptionWithoutError(offer2);
1523}
1524
1525TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001526 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001527 mediastream_signaling_.SendNothing();
1528 // SetLocalDescription take ownership of offer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001529 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001530 SetRemoteDescriptionWithoutError(offer);
1531
wu@webrtc.org91053e72013-08-10 07:18:04 +00001532 SessionDescriptionInterface* offer2 = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001533 SetRemoteDescriptionWithoutError(offer2);
1534}
1535
1536TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001537 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001538 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001539 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001540 SetLocalDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001541 offer = CreateOffer(NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001542 SetRemoteDescriptionOfferExpectError(
1543 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001544}
1545
1546TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001547 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001548 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001549 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001550 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001551 offer = CreateOffer(NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001552 SetLocalDescriptionOfferExpectError(
1553 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001554}
1555
1556TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001557 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001558 mediastream_signaling_.SendNothing();
1559 SessionDescriptionInterface* offer = CreateRemoteOffer();
1560 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1561
1562 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001563 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001564 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1565 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1566
1567 mediastream_signaling_.SendAudioVideoStream1();
1568 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001569 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001570 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1571
1572 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1573
1574 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001575 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001576 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1577}
1578
1579TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001580 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001581 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001582 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001583 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1584
1585 JsepSessionDescription* pranswer =
1586 CreateRemoteAnswer(session_->local_description());
1587 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1588
1589 SetRemoteDescriptionExpectState(pranswer,
1590 BaseSession::STATE_RECEIVEDPRACCEPT);
1591
1592 mediastream_signaling_.SendAudioVideoStream1();
1593 JsepSessionDescription* pranswer2 =
1594 CreateRemoteAnswer(session_->local_description());
1595 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1596
1597 SetRemoteDescriptionExpectState(pranswer2,
1598 BaseSession::STATE_RECEIVEDPRACCEPT);
1599
1600 mediastream_signaling_.SendAudioVideoStream2();
1601 SessionDescriptionInterface* answer =
1602 CreateRemoteAnswer(session_->local_description());
1603 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1604}
1605
1606TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001607 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001608 mediastream_signaling_.SendNothing();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001609 rtc::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001610 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001611 SessionDescriptionInterface* answer =
1612 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001613 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1614 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001615}
1616
1617TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001618 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619 mediastream_signaling_.SendNothing();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001620 rtc::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001621 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001622 SessionDescriptionInterface* answer =
1623 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001624 SetRemoteDescriptionAnswerExpectError(
1625 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001626}
1627
1628TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001629 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001630 mediastream_signaling_.SendAudioVideoStream1();
1631
1632 cricket::Candidate candidate;
1633 candidate.set_component(1);
1634 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1635
1636 // Fail since we have not set a offer description.
1637 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1638
wu@webrtc.org91053e72013-08-10 07:18:04 +00001639 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001640 SetLocalDescriptionWithoutError(offer);
1641 // Candidate should be allowed to add before remote description.
1642 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1643 candidate.set_component(2);
1644 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1645 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1646
1647 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1648 session_->local_description());
1649 SetRemoteDescriptionWithoutError(answer);
1650
1651 // Verifying the candidates are copied properly from internal vector.
1652 const SessionDescriptionInterface* remote_desc =
1653 session_->remote_description();
1654 ASSERT_TRUE(remote_desc != NULL);
1655 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1656 const IceCandidateCollection* candidates =
1657 remote_desc->candidates(kMediaContentIndex0);
1658 ASSERT_EQ(2u, candidates->count());
1659 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1660 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1661 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1662 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1663
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001664 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1665 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001666 candidate.set_component(2);
1667 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1668 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001669 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001670
1671 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1672 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1673}
1674
1675// Test that a remote candidate is added to the remote session description and
1676// that it is retained if the remote session description is changed.
1677TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001678 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001679 cricket::Candidate candidate1;
1680 candidate1.set_component(1);
1681 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1682 candidate1);
1683 mediastream_signaling_.SendAudioVideoStream1();
1684 CreateAndSetRemoteOfferAndLocalAnswer();
1685
1686 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
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(1u, candidates->count());
1694 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1695
1696 // Update the RemoteSessionDescription with a new session description and
1697 // a candidate and check that the new remote session description contains both
1698 // candidates.
1699 SessionDescriptionInterface* offer = CreateRemoteOffer();
1700 cricket::Candidate candidate2;
1701 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1702 candidate2);
1703 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1704 SetRemoteDescriptionWithoutError(offer);
1705
1706 remote_desc = session_->remote_description();
1707 ASSERT_TRUE(remote_desc != NULL);
1708 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1709 candidates = remote_desc->candidates(kMediaContentIndex0);
1710 ASSERT_EQ(2u, candidates->count());
1711 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1712 // Username and password have be updated with the TransportInfo of the
1713 // SessionDescription, won't be equal to the original one.
1714 candidate2.set_username(candidates->at(0)->candidate().username());
1715 candidate2.set_password(candidates->at(0)->candidate().password());
1716 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
1717 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
1718 // No need to verify the username and password.
1719 candidate1.set_username(candidates->at(1)->candidate().username());
1720 candidate1.set_password(candidates->at(1)->candidate().password());
1721 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
1722
1723 // Test that the candidate is ignored if we can add the same candidate again.
1724 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1725}
1726
1727// Test that local candidates are added to the local session description and
1728// that they are retained if the local session description is changed.
1729TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001730 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001731 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001732 mediastream_signaling_.SendAudioVideoStream1();
1733 CreateAndSetRemoteOfferAndLocalAnswer();
1734
1735 const SessionDescriptionInterface* local_desc = session_->local_description();
1736 const IceCandidateCollection* candidates =
1737 local_desc->candidates(kMediaContentIndex0);
1738 ASSERT_TRUE(candidates != NULL);
1739 EXPECT_EQ(0u, candidates->count());
1740
1741 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1742
1743 local_desc = session_->local_description();
1744 candidates = local_desc->candidates(kMediaContentIndex0);
1745 ASSERT_TRUE(candidates != NULL);
1746 EXPECT_LT(0u, candidates->count());
1747 candidates = local_desc->candidates(1);
1748 ASSERT_TRUE(candidates != NULL);
1749 EXPECT_LT(0u, candidates->count());
1750
1751 // Update the session descriptions.
1752 mediastream_signaling_.SendAudioVideoStream1();
1753 CreateAndSetRemoteOfferAndLocalAnswer();
1754
1755 local_desc = session_->local_description();
1756 candidates = local_desc->candidates(kMediaContentIndex0);
1757 ASSERT_TRUE(candidates != NULL);
1758 EXPECT_LT(0u, candidates->count());
1759 candidates = local_desc->candidates(1);
1760 ASSERT_TRUE(candidates != NULL);
1761 EXPECT_LT(0u, candidates->count());
1762}
1763
1764// Test that we can set a remote session description with remote candidates.
1765TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001766 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001767
1768 cricket::Candidate candidate1;
1769 candidate1.set_component(1);
1770 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
1771 candidate1);
1772 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001773 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001774
1775 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
1776 SetRemoteDescriptionWithoutError(offer);
1777
1778 const SessionDescriptionInterface* remote_desc =
1779 session_->remote_description();
1780 ASSERT_TRUE(remote_desc != NULL);
1781 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1782 const IceCandidateCollection* candidates =
1783 remote_desc->candidates(kMediaContentIndex0);
1784 ASSERT_EQ(1u, candidates->count());
1785 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1786
wu@webrtc.org91053e72013-08-10 07:18:04 +00001787 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788 SetLocalDescriptionWithoutError(answer);
1789}
1790
1791// Test that offers and answers contains ice candidates when Ice candidates have
1792// been gathered.
1793TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001794 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001795 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001796 mediastream_signaling_.SendAudioVideoStream1();
1797 // Ice is started but candidates are not provided until SetLocalDescription
1798 // is called.
1799 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1800 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1801 CreateAndSetRemoteOfferAndLocalAnswer();
1802 // Wait until at least one local candidate has been collected.
1803 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
1804 kIceCandidatesTimeout);
1805 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
1806 kIceCandidatesTimeout);
1807
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001808 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001809 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
1811 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
1812 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
1813 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
1814
1815 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
1816 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001817 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001818 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
1819 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
1820 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
1821 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
1822 SetLocalDescriptionWithoutError(answer);
1823}
1824
1825// Verifies TransportProxy and media channels are created with content names
1826// present in the SessionDescription.
1827TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001828 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001829 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001830 rtc::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001831 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001832
1833 // CreateOffer creates session description with the content names "audio" and
1834 // "video". Goal is to modify these content names and verify transport channel
1835 // proxy in the BaseSession, as proxies are created with the content names
1836 // present in SDP.
1837 std::string sdp;
1838 EXPECT_TRUE(offer->ToString(&sdp));
1839 const std::string kAudioMid = "a=mid:audio";
1840 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
1841 const std::string kVideoMid = "a=mid:video";
1842 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
1843
1844 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001845 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001846 kAudioMidReplaceStr.c_str(),
1847 kAudioMidReplaceStr.length(),
1848 &sdp);
1849 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001850 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001851 kVideoMidReplaceStr.c_str(),
1852 kVideoMidReplaceStr.length(),
1853 &sdp);
1854
1855 SessionDescriptionInterface* modified_offer =
1856 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
1857
1858 SetRemoteDescriptionWithoutError(modified_offer);
1859
1860 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00001861 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001862 SetLocalDescriptionWithoutError(answer);
1863
1864 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
1865 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
1866 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
1867 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
1868}
1869
1870// Test that an offer contains the correct media content descriptions based on
1871// the send streams when no constraints have been set.
1872TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001873 Init(NULL);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001874 rtc::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001875 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001876 ASSERT_TRUE(offer != NULL);
1877 const cricket::ContentInfo* content =
1878 cricket::GetFirstAudioContent(offer->description());
1879 EXPECT_TRUE(content != NULL);
1880 content = cricket::GetFirstVideoContent(offer->description());
1881 EXPECT_TRUE(content == NULL);
1882}
1883
1884// Test that an offer contains the correct media content descriptions based on
1885// the send streams when no constraints have been set.
1886TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001887 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001888 // Test Audio only offer.
1889 mediastream_signaling_.UseOptionsAudioOnly();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001890 rtc::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001891 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001892 const cricket::ContentInfo* content =
1893 cricket::GetFirstAudioContent(offer->description());
1894 EXPECT_TRUE(content != NULL);
1895 content = cricket::GetFirstVideoContent(offer->description());
1896 EXPECT_TRUE(content == NULL);
1897
1898 // Test Audio / Video offer.
1899 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001900 offer.reset(CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001901 content = cricket::GetFirstAudioContent(offer->description());
1902 EXPECT_TRUE(content != NULL);
1903 content = cricket::GetFirstVideoContent(offer->description());
1904 EXPECT_TRUE(content != NULL);
1905}
1906
1907// Test that an offer contains no media content descriptions if
1908// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
1909TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001910 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001911 webrtc::FakeConstraints constraints_no_receive;
1912 constraints_no_receive.SetMandatoryReceiveAudio(false);
1913 constraints_no_receive.SetMandatoryReceiveVideo(false);
1914
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001915 rtc::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001916 CreateOffer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001917 ASSERT_TRUE(offer != NULL);
1918 const cricket::ContentInfo* content =
1919 cricket::GetFirstAudioContent(offer->description());
1920 EXPECT_TRUE(content == NULL);
1921 content = cricket::GetFirstVideoContent(offer->description());
1922 EXPECT_TRUE(content == NULL);
1923}
1924
1925// Test that an offer contains only audio media content descriptions if
1926// kOfferToReceiveAudio constraints are set to true.
1927TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001928 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001929 webrtc::FakeConstraints constraints_audio_only;
1930 constraints_audio_only.SetMandatoryReceiveAudio(true);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001931 rtc::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001932 CreateOffer(&constraints_audio_only));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001933
1934 const cricket::ContentInfo* content =
1935 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 audio and video media content descriptions if
1942// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
1943TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001944 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001945 // Test Audio / Video offer.
1946 webrtc::FakeConstraints constraints_audio_video;
1947 constraints_audio_video.SetMandatoryReceiveAudio(true);
1948 constraints_audio_video.SetMandatoryReceiveVideo(true);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001949 rtc::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001950 CreateOffer(&constraints_audio_video));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001951 const cricket::ContentInfo* content =
1952 cricket::GetFirstAudioContent(offer->description());
1953
1954 EXPECT_TRUE(content != NULL);
1955 content = cricket::GetFirstVideoContent(offer->description());
1956 EXPECT_TRUE(content != NULL);
1957
1958 // TODO(perkj): Should the direction be set to SEND_ONLY if
1959 // The constraints is set to not receive audio or video but a track is added?
1960}
1961
1962// Test that an answer can not be created if the last remote description is not
1963// an offer.
1964TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001965 Init(NULL);
1966 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001967 SetLocalDescriptionWithoutError(offer);
1968 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
1969 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001970 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001971}
1972
1973// Test that an answer contains the correct media content descriptions when no
1974// constraints have been set.
1975TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001976 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001977 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001978 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001979 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001980 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001981 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001982 const cricket::ContentInfo* content =
1983 cricket::GetFirstAudioContent(answer->description());
1984 ASSERT_TRUE(content != NULL);
1985 EXPECT_FALSE(content->rejected);
1986
1987 content = cricket::GetFirstVideoContent(answer->description());
1988 ASSERT_TRUE(content != NULL);
1989 EXPECT_FALSE(content->rejected);
1990}
1991
1992// Test that an answer contains the correct media content descriptions when no
1993// constraints have been set and the offer only contain audio.
1994TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001995 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996 // Create a remote offer with audio only.
1997 cricket::MediaSessionOptions options;
1998 options.has_audio = true;
1999 options.has_video = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002000 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001 CreateRemoteOffer(options));
2002 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2003 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2004
2005 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002006 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002007 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002008 const cricket::ContentInfo* content =
2009 cricket::GetFirstAudioContent(answer->description());
2010 ASSERT_TRUE(content != NULL);
2011 EXPECT_FALSE(content->rejected);
2012
2013 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2014}
2015
2016// Test that an answer contains the correct media content descriptions when no
2017// constraints have been set.
2018TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002019 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002021 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002022 SetRemoteDescriptionWithoutError(offer.release());
2023 // Test with a stream with tracks.
2024 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002025 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002026 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002027 const cricket::ContentInfo* content =
2028 cricket::GetFirstAudioContent(answer->description());
2029 ASSERT_TRUE(content != NULL);
2030 EXPECT_FALSE(content->rejected);
2031
2032 content = cricket::GetFirstVideoContent(answer->description());
2033 ASSERT_TRUE(content != NULL);
2034 EXPECT_FALSE(content->rejected);
2035}
2036
2037// Test that an answer contains the correct media content descriptions when
2038// constraints have been set but no stream is sent.
2039TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002040 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002042 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002043 SetRemoteDescriptionWithoutError(offer.release());
2044
2045 webrtc::FakeConstraints constraints_no_receive;
2046 constraints_no_receive.SetMandatoryReceiveAudio(false);
2047 constraints_no_receive.SetMandatoryReceiveVideo(false);
2048
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002049 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002050 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002051 const cricket::ContentInfo* content =
2052 cricket::GetFirstAudioContent(answer->description());
2053 ASSERT_TRUE(content != NULL);
2054 EXPECT_TRUE(content->rejected);
2055
2056 content = cricket::GetFirstVideoContent(answer->description());
2057 ASSERT_TRUE(content != NULL);
2058 EXPECT_TRUE(content->rejected);
2059}
2060
2061// Test that an answer contains the correct media content descriptions when
2062// constraints have been set and streams are sent.
2063TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002064 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002065 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002066 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002067 SetRemoteDescriptionWithoutError(offer.release());
2068
2069 webrtc::FakeConstraints constraints_no_receive;
2070 constraints_no_receive.SetMandatoryReceiveAudio(false);
2071 constraints_no_receive.SetMandatoryReceiveVideo(false);
2072
2073 // Test with a stream with tracks.
2074 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002075 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002076 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002077
2078 // TODO(perkj): Should the direction be set to SEND_ONLY?
2079 const cricket::ContentInfo* content =
2080 cricket::GetFirstAudioContent(answer->description());
2081 ASSERT_TRUE(content != NULL);
2082 EXPECT_FALSE(content->rejected);
2083
2084 // TODO(perkj): Should the direction be set to SEND_ONLY?
2085 content = cricket::GetFirstVideoContent(answer->description());
2086 ASSERT_TRUE(content != NULL);
2087 EXPECT_FALSE(content->rejected);
2088}
2089
2090TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2091 AddCNCodecs();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002092 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093 webrtc::FakeConstraints constraints;
2094 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002095 rtc::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002096 CreateOffer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002097 const cricket::ContentInfo* content =
2098 cricket::GetFirstAudioContent(offer->description());
2099 EXPECT_TRUE(content != NULL);
2100 EXPECT_TRUE(VerifyNoCNCodecs(content));
2101}
2102
2103TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2104 AddCNCodecs();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002105 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002106 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002107 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002108 SetRemoteDescriptionWithoutError(offer.release());
2109
2110 webrtc::FakeConstraints constraints;
2111 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002112 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002113 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002114 const cricket::ContentInfo* content =
2115 cricket::GetFirstAudioContent(answer->description());
2116 ASSERT_TRUE(content != NULL);
2117 EXPECT_TRUE(VerifyNoCNCodecs(content));
2118}
2119
2120// This test verifies the call setup when remote answer with audio only and
2121// later updates with video.
2122TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002123 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002124 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2125 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2126
2127 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002128 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129
2130 cricket::MediaSessionOptions options;
2131 options.has_video = false;
2132 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2133
2134 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2135 // and answer;
2136 SetLocalDescriptionWithoutError(offer);
2137 SetRemoteDescriptionWithoutError(answer);
2138
2139 video_channel_ = media_engine_->GetVideoChannel(0);
2140 voice_channel_ = media_engine_->GetVoiceChannel(0);
2141
2142 ASSERT_TRUE(video_channel_ == NULL);
2143
2144 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2145 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2146 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2147
2148 // Let the remote end update the session descriptions, with Audio and Video.
2149 mediastream_signaling_.SendAudioVideoStream2();
2150 CreateAndSetRemoteOfferAndLocalAnswer();
2151
2152 video_channel_ = media_engine_->GetVideoChannel(0);
2153 voice_channel_ = media_engine_->GetVoiceChannel(0);
2154
2155 ASSERT_TRUE(video_channel_ != NULL);
2156 ASSERT_TRUE(voice_channel_ != NULL);
2157
2158 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2159 ASSERT_EQ(1u, video_channel_->send_streams().size());
2160 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2161 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2162 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2163 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2164 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2165 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2166
2167 // Change session back to audio only.
2168 mediastream_signaling_.UseOptionsAudioOnly();
2169 CreateAndSetRemoteOfferAndLocalAnswer();
2170
2171 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2172 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2173 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2174 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2175 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2176}
2177
2178// This test verifies the call setup when remote answer with video only and
2179// later updates with audio.
2180TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002181 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002182 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2183 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2184 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002185 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002186
2187 cricket::MediaSessionOptions options;
2188 options.has_audio = false;
2189 options.has_video = true;
2190 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2191 offer, options, cricket::SEC_ENABLED);
2192
2193 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2194 // and answer.
2195 SetLocalDescriptionWithoutError(offer);
2196 SetRemoteDescriptionWithoutError(answer);
2197
2198 video_channel_ = media_engine_->GetVideoChannel(0);
2199 voice_channel_ = media_engine_->GetVoiceChannel(0);
2200
2201 ASSERT_TRUE(voice_channel_ == NULL);
2202 ASSERT_TRUE(video_channel_ != NULL);
2203
2204 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2205 ASSERT_EQ(1u, video_channel_->send_streams().size());
2206 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2207
2208 // Update the session descriptions, with Audio and Video.
2209 mediastream_signaling_.SendAudioVideoStream2();
2210 CreateAndSetRemoteOfferAndLocalAnswer();
2211
2212 voice_channel_ = media_engine_->GetVoiceChannel(0);
2213 ASSERT_TRUE(voice_channel_ != NULL);
2214
2215 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2216 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2217 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2218 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2219
2220 // Change session back to video only.
2221 mediastream_signaling_.UseOptionsVideoOnly();
2222 CreateAndSetRemoteOfferAndLocalAnswer();
2223
2224 video_channel_ = media_engine_->GetVideoChannel(0);
2225 voice_channel_ = media_engine_->GetVoiceChannel(0);
2226
2227 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2228 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2229 ASSERT_EQ(1u, video_channel_->send_streams().size());
2230 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2231}
2232
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002233TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002234 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002235 mediastream_signaling_.SendAudioVideoStream1();
2236 scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002237 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002238 VerifyCryptoParams(offer->description());
2239 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002240 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002241 VerifyCryptoParams(answer->description());
2242}
2243
2244TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002245 options_.disable_encryption = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00002246 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002247 mediastream_signaling_.SendAudioVideoStream1();
2248 scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002249 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002250 VerifyNoCryptoParams(offer->description(), false);
2251}
2252
2253TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002254 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002255 VerifyAnswerFromNonCryptoOffer();
2256}
2257
2258TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002259 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002260 VerifyAnswerFromCryptoOffer();
2261}
2262
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002263// This test verifies that setLocalDescription fails if
2264// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2265TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
2266 Init(NULL);
2267 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002268 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL));
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002269 std::string sdp;
2270 RemoveIceUfragPwdLines(offer.get(), &sdp);
2271 SessionDescriptionInterface* modified_offer =
2272 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002273 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002274}
2275
2276// This test verifies that setRemoteDescription fails if
2277// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2278TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
2279 Init(NULL);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002280 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002281 std::string sdp;
2282 RemoveIceUfragPwdLines(offer.get(), &sdp);
2283 SessionDescriptionInterface* modified_offer =
2284 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002285 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002286}
2287
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002288// This test verifies that setLocalDescription fails if local offer has
2289// too short ice ufrag and pwd strings.
2290TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
2291 Init(NULL);
2292 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
2293 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002294 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL));
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002295 std::string sdp;
2296 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2297 // recommended values of 4 and 22 bytes respectively.
2298 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2299 SessionDescriptionInterface* modified_offer =
2300 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2301 std::string error;
2302 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2303
2304 // Test with string greater than 256.
2305 sdp.clear();
2306 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2307 &sdp);
2308 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2309 NULL);
2310 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2311}
2312
2313// This test verifies that setRemoteDescription fails if remote offer has
2314// too short ice ufrag and pwd strings.
2315TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
2316 Init(NULL);
2317 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002318 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002319 std::string sdp;
2320 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2321 // recommended values of 4 and 22 bytes respectively.
2322 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2323 SessionDescriptionInterface* modified_offer =
2324 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2325 std::string error;
2326 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2327
2328 sdp.clear();
2329 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2330 &sdp);
2331 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2332 NULL);
2333 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2334}
2335
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002336TEST_F(WebRtcSessionTest, VerifyBundleFlagInPA) {
2337 // This test verifies BUNDLE flag in PortAllocator, if BUNDLE information in
2338 // local description is removed by the application, BUNDLE flag should be
2339 // disabled in PortAllocator. By default BUNDLE is enabled in the WebRtc.
wu@webrtc.org91053e72013-08-10 07:18:04 +00002340 Init(NULL);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002341 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2342 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002343 rtc::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002344 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002345 cricket::SessionDescription* offer_copy =
2346 offer->description()->Copy();
2347 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2348 JsepSessionDescription* modified_offer =
2349 new JsepSessionDescription(JsepSessionDescription::kOffer);
2350 modified_offer->Initialize(offer_copy, "1", "1");
2351
2352 SetLocalDescriptionWithoutError(modified_offer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002353 EXPECT_FALSE(allocator_->flags() & cricket::PORTALLOCATOR_ENABLE_BUNDLE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002354}
2355
2356TEST_F(WebRtcSessionTest, TestDisabledBundleInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002357 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002358 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002359 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2360 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002361 FakeConstraints constraints;
2362 constraints.SetMandatoryUseRtpMux(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002363 SessionDescriptionInterface* offer = CreateOffer(&constraints);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002364 SetLocalDescriptionWithoutError(offer);
2365 mediastream_signaling_.SendAudioVideoStream2();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002366 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002367 CreateRemoteAnswer(session_->local_description()));
2368 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2369 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2370 JsepSessionDescription* modified_answer =
2371 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2372 modified_answer->Initialize(answer_copy, "1", "1");
2373 SetRemoteDescriptionWithoutError(modified_answer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002374 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2375 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002376
2377 video_channel_ = media_engine_->GetVideoChannel(0);
2378 voice_channel_ = media_engine_->GetVoiceChannel(0);
2379
2380 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2381 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
2382
2383 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2384 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
2385
2386 ASSERT_EQ(1u, video_channel_->send_streams().size());
2387 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
2388 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2389 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
2390}
2391
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002392// This test verifies that SetLocalDescription and SetRemoteDescription fails
2393// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2394TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002395 WebRtcSessionTest::Init(NULL);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002396 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002397 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2398 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002399 FakeConstraints constraints;
2400 constraints.SetMandatoryUseRtpMux(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002401 SessionDescriptionInterface* offer = CreateOffer(&constraints);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002402 std::string offer_str;
2403 offer->ToString(&offer_str);
2404 // Disable rtcp-mux
2405 const std::string rtcp_mux = "rtcp-mux";
2406 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002407 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002408 xrtcp_mux.c_str(), xrtcp_mux.length(),
2409 &offer_str);
2410 JsepSessionDescription *local_offer =
2411 new JsepSessionDescription(JsepSessionDescription::kOffer);
2412 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002413 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002414 JsepSessionDescription *remote_offer =
2415 new JsepSessionDescription(JsepSessionDescription::kOffer);
2416 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002417 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002418 // Trying unmodified SDP.
2419 SetLocalDescriptionWithoutError(offer);
2420}
2421
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002422TEST_F(WebRtcSessionTest, SetAudioPlayout) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002423 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002424 mediastream_signaling_.SendAudioVideoStream1();
2425 CreateAndSetRemoteOfferAndLocalAnswer();
2426 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2427 ASSERT_TRUE(channel != NULL);
2428 ASSERT_EQ(1u, channel->recv_streams().size());
2429 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2430 double left_vol, right_vol;
2431 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2432 EXPECT_EQ(1, left_vol);
2433 EXPECT_EQ(1, right_vol);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002434 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002435 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002436 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2437 EXPECT_EQ(0, left_vol);
2438 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002439 EXPECT_EQ(0, renderer->channel_id());
2440 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002441 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2442 EXPECT_EQ(1, left_vol);
2443 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002444 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002445}
2446
2447TEST_F(WebRtcSessionTest, SetAudioSend) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002448 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002449 mediastream_signaling_.SendAudioVideoStream1();
2450 CreateAndSetRemoteOfferAndLocalAnswer();
2451 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2452 ASSERT_TRUE(channel != NULL);
2453 ASSERT_EQ(1u, channel->send_streams().size());
2454 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2455 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2456
2457 cricket::AudioOptions options;
2458 options.echo_cancellation.Set(true);
2459
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002460 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002461 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002462 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2463 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002464 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002465 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002466
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002467 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002468 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002469 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2470 bool value;
2471 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
2472 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002473 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002474 EXPECT_TRUE(renderer->sink() == NULL);
2475}
2476
2477TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
2478 Init(NULL);
2479 mediastream_signaling_.SendAudioVideoStream1();
2480 CreateAndSetRemoteOfferAndLocalAnswer();
2481 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2482 ASSERT_TRUE(channel != NULL);
2483 ASSERT_EQ(1u, channel->send_streams().size());
2484 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2485
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002486 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002487 cricket::AudioOptions options;
2488 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
2489 EXPECT_TRUE(renderer->sink() != NULL);
2490
2491 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
2492 // will invalidate the |renderer_| pointer in the sink and prevent getting a
2493 // SetSink(NULL) callback afterwards.
2494 renderer.reset();
2495
2496 // This will trigger SetSink(NULL) if no OnClose() callback.
2497 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002498}
2499
2500TEST_F(WebRtcSessionTest, SetVideoPlayout) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002501 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002502 mediastream_signaling_.SendAudioVideoStream1();
2503 CreateAndSetRemoteOfferAndLocalAnswer();
2504 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2505 ASSERT_TRUE(channel != NULL);
2506 ASSERT_LT(0u, channel->renderers().size());
2507 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2508 ASSERT_EQ(1u, channel->recv_streams().size());
2509 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2510 cricket::FakeVideoRenderer renderer;
2511 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
2512 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
2513 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
2514 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2515}
2516
2517TEST_F(WebRtcSessionTest, SetVideoSend) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002518 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002519 mediastream_signaling_.SendAudioVideoStream1();
2520 CreateAndSetRemoteOfferAndLocalAnswer();
2521 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2522 ASSERT_TRUE(channel != NULL);
2523 ASSERT_EQ(1u, channel->send_streams().size());
2524 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2525 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2526 cricket::VideoOptions* options = NULL;
2527 session_->SetVideoSend(send_ssrc, false, options);
2528 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2529 session_->SetVideoSend(send_ssrc, true, options);
2530 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2531}
2532
2533TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
2534 TestCanInsertDtmf(false);
2535}
2536
2537TEST_F(WebRtcSessionTest, CanInsertDtmf) {
2538 TestCanInsertDtmf(true);
2539}
2540
2541TEST_F(WebRtcSessionTest, InsertDtmf) {
2542 // Setup
wu@webrtc.org91053e72013-08-10 07:18:04 +00002543 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002544 mediastream_signaling_.SendAudioVideoStream1();
2545 CreateAndSetRemoteOfferAndLocalAnswer();
2546 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2547 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
2548
2549 // Insert DTMF
2550 const int expected_flags = DF_SEND;
2551 const int expected_duration = 90;
2552 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
2553 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
2554 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
2555
2556 // Verify
2557 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
2558 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2559 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
2560 expected_duration, expected_flags));
2561 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
2562 expected_duration, expected_flags));
2563 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
2564 expected_duration, expected_flags));
2565}
2566
2567// This test verifies the |initiator| flag when session initiates the call.
2568TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002569 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002570 EXPECT_FALSE(session_->initiator());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002571 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002572 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2573 SetLocalDescriptionWithoutError(offer);
2574 EXPECT_TRUE(session_->initiator());
2575 SetRemoteDescriptionWithoutError(answer);
2576 EXPECT_TRUE(session_->initiator());
2577}
2578
2579// This test verifies the |initiator| flag when session receives the call.
2580TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002581 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002582 EXPECT_FALSE(session_->initiator());
2583 SessionDescriptionInterface* offer = CreateRemoteOffer();
2584 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002585 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002586
2587 EXPECT_FALSE(session_->initiator());
2588 SetLocalDescriptionWithoutError(answer);
2589 EXPECT_FALSE(session_->initiator());
2590}
2591
2592// This test verifies the ice protocol type at initiator of the call
2593// if |a=ice-options:google-ice| is present in answer.
2594TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002595 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002596 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002597 SessionDescriptionInterface* offer = CreateOffer(NULL);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002598 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002599 CreateRemoteAnswer(offer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002600 SetLocalDescriptionWithoutError(offer);
2601 std::string sdp;
2602 EXPECT_TRUE(answer->ToString(&sdp));
2603 // Adding ice-options to the session level.
2604 InjectAfter("t=0 0\r\n",
2605 "a=ice-options:google-ice\r\n",
2606 &sdp);
2607 SessionDescriptionInterface* answer_with_gice =
2608 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2609 SetRemoteDescriptionWithoutError(answer_with_gice);
2610 VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE);
2611 VerifyTransportType("video", cricket::ICEPROTO_GOOGLE);
2612}
2613
2614// This test verifies the ice protocol type at initiator of the call
2615// if ICE RFC5245 is supported in answer.
2616TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002617 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002618 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002619 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002620 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2621 SetLocalDescriptionWithoutError(offer);
2622
2623 SetRemoteDescriptionWithoutError(answer);
2624 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2625 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2626}
2627
2628// This test verifies the ice protocol type at receiver side of the call if
2629// receiver decides to use google-ice.
2630TEST_F(WebRtcSessionTest, TestReceiverGIceInOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002631 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002632 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002633 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002634 SetRemoteDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002635 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002636 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002637 std::string sdp;
2638 EXPECT_TRUE(answer->ToString(&sdp));
2639 // Adding ice-options to the session level.
2640 InjectAfter("t=0 0\r\n",
2641 "a=ice-options:google-ice\r\n",
2642 &sdp);
2643 SessionDescriptionInterface* answer_with_gice =
2644 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2645 SetLocalDescriptionWithoutError(answer_with_gice);
2646 VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE);
2647 VerifyTransportType("video", cricket::ICEPROTO_GOOGLE);
2648}
2649
2650// This test verifies the ice protocol type at receiver side of the call if
2651// receiver decides to use ice RFC 5245.
2652TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002653 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002654 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002655 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002656 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002657 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002658 SetLocalDescriptionWithoutError(answer);
2659 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2660 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2661}
2662
2663// This test verifies the session state when ICE RFC5245 in offer and
2664// ICE google-ice in answer.
2665TEST_F(WebRtcSessionTest, TestIceOfferGIceOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002666 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002667 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002668 rtc::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002669 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002670 std::string offer_str;
2671 offer->ToString(&offer_str);
2672 // Disable google-ice
2673 const std::string gice_option = "google-ice";
2674 const std::string xgoogle_xice = "xgoogle-xice";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002675 rtc::replace_substrs(gice_option.c_str(), gice_option.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002676 xgoogle_xice.c_str(), xgoogle_xice.length(),
2677 &offer_str);
2678 JsepSessionDescription *ice_only_offer =
2679 new JsepSessionDescription(JsepSessionDescription::kOffer);
2680 EXPECT_TRUE((ice_only_offer)->Initialize(offer_str, NULL));
2681 SetLocalDescriptionWithoutError(ice_only_offer);
2682 std::string original_offer_sdp;
2683 EXPECT_TRUE(offer->ToString(&original_offer_sdp));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002684 SessionDescriptionInterface* pranswer_with_gice =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002685 CreateSessionDescription(JsepSessionDescription::kPrAnswer,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002686 original_offer_sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002687 SetRemoteDescriptionPranswerExpectError(kPushDownTDFailed,
2688 pranswer_with_gice);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002689 SessionDescriptionInterface* answer_with_gice =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002690 CreateSessionDescription(JsepSessionDescription::kAnswer,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002691 original_offer_sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002692 SetRemoteDescriptionAnswerExpectError(kPushDownTDFailed,
2693 answer_with_gice);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002694}
2695
2696// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
2697TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002698 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002699 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002700 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002701 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002702 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002703 CreateRemoteAnswer(session_->local_description()));
2704
2705 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2706 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002707 JsepSessionDescription* modified_answer =
2708 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002709
2710 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2711 answer->session_id(),
2712 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002713 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002714
wu@webrtc.org4e393072014-04-07 17:04:35 +00002715 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002716 std::string sdp;
2717 EXPECT_TRUE(answer->ToString(&sdp));
2718 const std::string kAudioMid = "a=mid:audio";
2719 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002720 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002721 kAudioMidReplaceStr.c_str(),
2722 kAudioMidReplaceStr.length(),
2723 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002724 SessionDescriptionInterface* modified_answer1 =
2725 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002726 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002727
wu@webrtc.org4e393072014-04-07 17:04:35 +00002728 // Different media types.
2729 EXPECT_TRUE(answer->ToString(&sdp));
2730 const std::string kAudioMline = "m=audio";
2731 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002732 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00002733 kAudioMlineReplaceStr.c_str(),
2734 kAudioMlineReplaceStr.length(),
2735 &sdp);
2736 SessionDescriptionInterface* modified_answer2 =
2737 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2738 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
2739
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002740 SetRemoteDescriptionWithoutError(answer.release());
2741}
2742
2743// Verifying remote offer and local answer have matching m-lines as per
2744// RFC 3264.
2745TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002746 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002747 mediastream_signaling_.SendAudioVideoStream1();
2748 SessionDescriptionInterface* offer = CreateRemoteOffer();
2749 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002750 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002751
2752 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2753 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002754 JsepSessionDescription* modified_answer =
2755 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002756
2757 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2758 answer->session_id(),
2759 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002760 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002761 SetLocalDescriptionWithoutError(answer);
2762}
2763
2764// This test verifies that WebRtcSession does not start candidate allocation
2765// before SetLocalDescription is called.
2766TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002767 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002768 mediastream_signaling_.SendAudioVideoStream1();
2769 SessionDescriptionInterface* offer = CreateRemoteOffer();
2770 cricket::Candidate candidate;
2771 candidate.set_component(1);
2772 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2773 candidate);
2774 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2775 cricket::Candidate candidate1;
2776 candidate1.set_component(1);
2777 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2778 candidate1);
2779 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2780 SetRemoteDescriptionWithoutError(offer);
2781 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
2782 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
2783
2784 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002785 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002786 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
2787 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
2788
wu@webrtc.org91053e72013-08-10 07:18:04 +00002789 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002790 SetLocalDescriptionWithoutError(answer);
2791 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
2792 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
2793 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2794}
2795
2796// This test verifies that crypto parameter is updated in local session
2797// description as per security policy set in MediaSessionDescriptionFactory.
2798TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002799 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002800 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002801 rtc::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002802 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002803
2804 // Making sure SetLocalDescription correctly sets crypto value in
2805 // SessionDescription object after de-serialization of sdp string. The value
2806 // will be set as per MediaSessionDescriptionFactory.
2807 std::string offer_str;
2808 offer->ToString(&offer_str);
2809 SessionDescriptionInterface* jsep_offer_str =
2810 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
2811 SetLocalDescriptionWithoutError(jsep_offer_str);
2812 EXPECT_TRUE(session_->voice_channel()->secure_required());
2813 EXPECT_TRUE(session_->video_channel()->secure_required());
2814}
2815
2816// This test verifies the crypto parameter when security is disabled.
2817TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002818 options_.disable_encryption = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00002819 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002820 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002821 rtc::scoped_ptr<SessionDescriptionInterface> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002822 CreateOffer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002823
2824 // Making sure SetLocalDescription correctly sets crypto value in
2825 // SessionDescription object after de-serialization of sdp string. The value
2826 // will be set as per MediaSessionDescriptionFactory.
2827 std::string offer_str;
2828 offer->ToString(&offer_str);
2829 SessionDescriptionInterface *jsep_offer_str =
2830 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
2831 SetLocalDescriptionWithoutError(jsep_offer_str);
2832 EXPECT_FALSE(session_->voice_channel()->secure_required());
2833 EXPECT_FALSE(session_->video_channel()->secure_required());
2834}
2835
2836// This test verifies that an answer contains new ufrag and password if an offer
2837// with new ufrag and password is received.
2838TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002839 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002840 cricket::MediaSessionOptions options;
2841 options.has_audio = true;
2842 options.has_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002843 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002844 CreateRemoteOffer(options));
2845 SetRemoteDescriptionWithoutError(offer.release());
2846
2847 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002848 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002849 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002850 SetLocalDescriptionWithoutError(answer.release());
2851
2852 // Receive an offer with new ufrag and password.
2853 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002854 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002855 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002856 SetRemoteDescriptionWithoutError(updated_offer1.release());
2857
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002858 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002859 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002860
2861 CompareIceUfragAndPassword(updated_answer1->description(),
2862 session_->local_description()->description(),
2863 false);
2864
2865 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002866}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002867
wu@webrtc.org91053e72013-08-10 07:18:04 +00002868// This test verifies that an answer contains old ufrag and password if an offer
2869// with old ufrag and password is received.
2870TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
2871 Init(NULL);
2872 cricket::MediaSessionOptions options;
2873 options.has_audio = true;
2874 options.has_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002875 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002876 CreateRemoteOffer(options));
2877 SetRemoteDescriptionWithoutError(offer.release());
2878
2879 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002880 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002881 CreateAnswer(NULL));
2882 SetLocalDescriptionWithoutError(answer.release());
2883
2884 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002885 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002886 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002887 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002888 SetRemoteDescriptionWithoutError(updated_offer2.release());
2889
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002890 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002891 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002892
2893 CompareIceUfragAndPassword(updated_answer2->description(),
2894 session_->local_description()->description(),
2895 true);
2896
2897 SetLocalDescriptionWithoutError(updated_answer2.release());
2898}
2899
2900TEST_F(WebRtcSessionTest, TestSessionContentError) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002901 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002902 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002903 SessionDescriptionInterface* offer = CreateOffer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002904 const std::string session_id_orig = offer->session_id();
2905 const std::string session_version_orig = offer->session_version();
2906 SetLocalDescriptionWithoutError(offer);
2907
2908 video_channel_ = media_engine_->GetVideoChannel(0);
2909 video_channel_->set_fail_set_send_codecs(true);
2910
2911 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002912 SessionDescriptionInterface* answer =
2913 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002914 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002915}
2916
2917// Runs the loopback call test with BUNDLE and STUN disabled.
2918TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
2919 // Lets try with only UDP ports.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002920 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002921 cricket::PORTALLOCATOR_DISABLE_TCP |
2922 cricket::PORTALLOCATOR_DISABLE_STUN |
2923 cricket::PORTALLOCATOR_DISABLE_RELAY);
2924 TestLoopbackCall();
2925}
2926
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00002927// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00002928TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002929 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00002930 cricket::PORTALLOCATOR_ENABLE_BUNDLE |
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00002931 cricket::PORTALLOCATOR_DISABLE_TCP |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00002932 cricket::PORTALLOCATOR_DISABLE_RELAY);
2933 TestLoopbackCall();
2934}
2935
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002936TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002937 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002938 cricket::MediaSessionOptions options;
2939 options.has_audio = true;
2940 options.has_video = true;
2941
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002942 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
2943 std::string error_code_str = "ERROR_CONTENT";
2944 std::string error_desc = "Fake session error description.";
2945 session_->SetError(error_code, error_desc);
2946
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002947 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
2948 SessionDescriptionInterface* answer =
2949 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002950
2951 std::string action;
2952 std::ostringstream session_error_msg;
2953 session_error_msg << kSessionError << error_code_str << ". ";
2954 session_error_msg << kSessionErrorDesc << error_desc << ".";
2955 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
2956 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002957}
2958
2959TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
2960 constraints_.reset(new FakeConstraints());
2961 constraints_->AddOptional(
2962 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002963 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002964
2965 SetLocalDescriptionWithDataChannel();
2966 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
2967}
2968
2969TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002970 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002971
2972 constraints_.reset(new FakeConstraints());
2973 constraints_->AddOptional(
2974 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00002975 options_.disable_sctp_data_channels = false;
2976
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002977 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002978
2979 SetLocalDescriptionWithDataChannel();
2980 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
2981}
2982
wu@webrtc.org967bfff2013-09-19 05:49:50 +00002983TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002984 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00002985
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002986 InitWithDtls();
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002987
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002988 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL));
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002989 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00002990 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
2991}
2992
2993TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002994 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00002995 SetFactoryDtlsSrtp();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002996 InitWithDtls();
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00002997
2998 // Create remote offer with SCTP.
2999 cricket::MediaSessionOptions options;
3000 options.data_channel_type = cricket::DCT_SCTP;
3001 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003002 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003003 SetRemoteDescriptionWithoutError(offer);
3004
3005 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003006 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003007 EXPECT_TRUE(answer != NULL);
3008 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3009 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003010}
3011
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003012TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
3013 constraints_.reset(new FakeConstraints());
3014 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003015 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003016 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003017
3018 SetLocalDescriptionWithDataChannel();
3019 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3020}
3021
3022TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003023 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003024
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003025 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003026
3027 SetLocalDescriptionWithDataChannel();
3028 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3029}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003030
wu@webrtc.org97077a32013-10-25 21:18:33 +00003031TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003032 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003033 options_.disable_sctp_data_channels = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003034 InitWithDtls();
wu@webrtc.org97077a32013-10-25 21:18:33 +00003035
3036 SetLocalDescriptionWithDataChannel();
3037 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3038}
3039
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003040TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003041 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003042 const int new_send_port = 9998;
3043 const int new_recv_port = 7775;
3044
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003045 InitWithDtls();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003046 SetFactoryDtlsSrtp();
3047
3048 // By default, don't actually add the codecs to desc_factory_; they don't
3049 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3050 // let the session description get parsed. That'll get the proper codecs
3051 // into the stream.
3052 cricket::MediaSessionOptions options;
3053 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3054 "stream1", new_send_port, options);
3055
3056 // SetRemoteDescription will take the ownership of the offer.
3057 SetRemoteDescriptionWithoutError(offer);
3058
3059 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3060 new_recv_port, CreateAnswer(NULL));
3061 ASSERT_TRUE(answer != NULL);
3062
3063 // Now set the local description, which'll take ownership of the answer.
3064 SetLocalDescriptionWithoutError(answer);
3065
3066 // TEST PLAN: Set the port number to something new, set it in the SDP,
3067 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003068 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003069 dci.reliable = true;
3070 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003071 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003072 session_->CreateDataChannel("datachannel", &dci);
3073
3074 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3075 int portnum = -1;
3076 ASSERT_TRUE(ch != NULL);
3077 ASSERT_EQ(1UL, ch->send_codecs().size());
3078 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
3079 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3080 ch->send_codecs()[0].name.c_str()));
3081 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3082 &portnum));
3083 EXPECT_EQ(new_send_port, portnum);
3084
3085 ASSERT_EQ(1UL, ch->recv_codecs().size());
3086 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
3087 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3088 ch->recv_codecs()[0].name.c_str()));
3089 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3090 &portnum));
3091 EXPECT_EQ(new_recv_port, portnum);
3092}
3093
wu@webrtc.org91053e72013-08-10 07:18:04 +00003094// Verifies that CreateOffer succeeds when CreateOffer is called before async
3095// identity generation is finished.
3096TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003097 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003098 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003099
3100 EXPECT_TRUE(session_->waiting_for_identity());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003101 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003102 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003103 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003104 VerifyNoCryptoParams(offer->description(), true);
3105 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003106}
3107
3108// Verifies that CreateAnswer succeeds when CreateOffer is called before async
3109// identity generation is finished.
3110TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003111 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003112 InitWithDtls();
3113 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003114
3115 cricket::MediaSessionOptions options;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003116 options.has_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003117 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003118 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003119 ASSERT_TRUE(offer.get() != NULL);
3120 SetRemoteDescriptionWithoutError(offer.release());
3121
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003122 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003123 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003124 VerifyNoCryptoParams(answer->description(), true);
3125 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003126}
3127
3128// Verifies that CreateOffer succeeds when CreateOffer is called after async
3129// identity generation is finished.
3130TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003131 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003132 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003133
3134 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003135 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003136 EXPECT_TRUE(offer != NULL);
3137}
3138
3139// Verifies that CreateOffer fails when CreateOffer is called after async
3140// identity generation fails.
3141TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003142 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00003143 InitWithDtls(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003144
3145 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003146 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003147 EXPECT_TRUE(offer == NULL);
3148}
3149
3150// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3151// before async identity generation is finished.
3152TEST_F(WebRtcSessionTest,
3153 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003154 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003155 VerifyMultipleAsyncCreateDescription(
3156 true, CreateSessionDescriptionRequest::kOffer);
3157}
3158
3159// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3160// before async identity generation fails.
3161TEST_F(WebRtcSessionTest,
3162 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003163 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003164 VerifyMultipleAsyncCreateDescription(
3165 false, CreateSessionDescriptionRequest::kOffer);
3166}
3167
3168// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3169// before async identity generation is finished.
3170TEST_F(WebRtcSessionTest,
3171 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003172 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003173 VerifyMultipleAsyncCreateDescription(
3174 true, CreateSessionDescriptionRequest::kAnswer);
3175}
3176
3177// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3178// before async identity generation fails.
3179TEST_F(WebRtcSessionTest,
3180 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003181 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003182 VerifyMultipleAsyncCreateDescription(
3183 false, CreateSessionDescriptionRequest::kAnswer);
3184}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003185
3186// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3187// offer has no SDES crypto but only DTLS fingerprint.
3188TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3189 // Init without DTLS.
3190 Init(NULL);
3191 // Create a remote offer with secured transport disabled.
3192 cricket::MediaSessionOptions options;
3193 JsepSessionDescription* offer(CreateRemoteOffer(
3194 options, cricket::SEC_DISABLED));
3195 // Adds a DTLS fingerprint to the remote offer.
3196 cricket::SessionDescription* sdp = offer->description();
3197 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3198 ASSERT_TRUE(audio != NULL);
3199 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3200 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003201 rtc::SSLFingerprint::CreateFromRfc4572(
3202 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003203 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003204 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003205}
3206
wu@webrtc.orgde305012013-10-31 15:40:38 +00003207// This test verifies DSCP is properly applied on the media channels.
3208TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3209 constraints_.reset(new FakeConstraints());
3210 constraints_->AddOptional(
3211 webrtc::MediaConstraintsInterface::kEnableDscp, true);
3212 Init(NULL);
3213 mediastream_signaling_.SendAudioVideoStream1();
3214 SessionDescriptionInterface* offer = CreateOffer(NULL);
3215
3216 SetLocalDescriptionWithoutError(offer);
3217
3218 video_channel_ = media_engine_->GetVideoChannel(0);
3219 voice_channel_ = media_engine_->GetVoiceChannel(0);
3220
3221 ASSERT_TRUE(video_channel_ != NULL);
3222 ASSERT_TRUE(voice_channel_ != NULL);
3223 cricket::AudioOptions audio_options;
3224 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3225 cricket::VideoOptions video_options;
3226 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3227 EXPECT_TRUE(audio_options.dscp.IsSet());
3228 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3229 EXPECT_TRUE(video_options.dscp.IsSet());
3230 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3231}
3232
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003233TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3234 constraints_.reset(new FakeConstraints());
3235 constraints_->AddOptional(
3236 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3237 true);
3238 Init(NULL);
3239 mediastream_signaling_.SendAudioVideoStream1();
3240 SessionDescriptionInterface* offer = CreateOffer(NULL);
3241
3242 SetLocalDescriptionWithoutError(offer);
3243
3244 video_channel_ = media_engine_->GetVideoChannel(0);
3245
3246 ASSERT_TRUE(video_channel_ != NULL);
3247 cricket::VideoOptions video_options;
3248 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3249 EXPECT_TRUE(
3250 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3251}
3252
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003253// Tests that we can renegotiate new media content with ICE candidates in the
3254// new remote SDP.
3255TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003256 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003257 InitWithDtls();
3258 SetFactoryDtlsSrtp();
3259
3260 mediastream_signaling_.UseOptionsAudioOnly();
3261 SessionDescriptionInterface* offer = CreateOffer(NULL);
3262 SetLocalDescriptionWithoutError(offer);
3263
3264 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3265 SetRemoteDescriptionWithoutError(answer);
3266
3267 cricket::MediaSessionOptions options;
3268 options.has_video = true;
3269 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3270
3271 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003272 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003273 candidate1.set_component(1);
3274 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3275 candidate1);
3276 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3277 SetRemoteDescriptionWithoutError(offer);
3278
3279 answer = CreateAnswer(NULL);
3280 SetLocalDescriptionWithoutError(answer);
3281}
3282
3283// Tests that we can renegotiate new media content with ICE candidates separated
3284// from the remote SDP.
3285TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003286 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003287 InitWithDtls();
3288 SetFactoryDtlsSrtp();
3289
3290 mediastream_signaling_.UseOptionsAudioOnly();
3291 SessionDescriptionInterface* offer = CreateOffer(NULL);
3292 SetLocalDescriptionWithoutError(offer);
3293
3294 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3295 SetRemoteDescriptionWithoutError(answer);
3296
3297 cricket::MediaSessionOptions options;
3298 options.has_video = true;
3299 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3300 SetRemoteDescriptionWithoutError(offer);
3301
3302 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003303 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003304 candidate1.set_component(1);
3305 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3306 candidate1);
3307 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3308
3309 answer = CreateAnswer(NULL);
3310 SetLocalDescriptionWithoutError(answer);
3311}
3312
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003313// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
3314// currently fails because upon disconnection and reconnection OnIceComplete is
3315// called more than once without returning to IceGatheringGathering.