blob: b5e1ddad01433b54749faed062bf1ab7dbbfa3ff [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
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000102typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
103
wu@webrtc.org364f2042013-11-20 21:49:41 +0000104static const int kClientAddrPort = 0;
105static const char kClientAddrHost1[] = "11.11.11.11";
106static const char kClientAddrHost2[] = "22.22.22.22";
107static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000108static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
109static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000110
111static const char kSessionVersion[] = "1";
112
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000113// Media index of candidates belonging to the first media content.
114static const int kMediaContentIndex0 = 0;
115static const char kMediaContentName0[] = "audio";
116
117// Media index of candidates belonging to the second media content.
118static const int kMediaContentIndex1 = 1;
119static const char kMediaContentName1[] = "video";
120
121static const int kIceCandidatesTimeout = 10000;
122
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000123static const char kFakeDtlsFingerprint[] =
124 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
125 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
126
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000127static const char kTooLongIceUfragPwd[] =
128 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
129 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
130 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
131 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
132
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000133// Add some extra |newlines| to the |message| after |line|.
134static void InjectAfter(const std::string& line,
135 const std::string& newlines,
136 std::string* message) {
137 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000138 rtc::replace_substrs(line.c_str(), line.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000139 tmp.c_str(), tmp.length(), message);
140}
141
142class MockIceObserver : public webrtc::IceObserver {
143 public:
144 MockIceObserver()
145 : oncandidatesready_(false),
146 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
147 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
148 }
149
150 virtual void OnIceConnectionChange(
151 PeerConnectionInterface::IceConnectionState new_state) {
152 ice_connection_state_ = new_state;
153 }
154 virtual void OnIceGatheringChange(
155 PeerConnectionInterface::IceGatheringState new_state) {
156 // We can never transition back to "new".
157 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
158 ice_gathering_state_ = new_state;
159
160 // oncandidatesready_ really means "ICE gathering is complete".
161 // This if statement ensures that this value remains correct when we
162 // transition from kIceGatheringComplete to kIceGatheringGathering.
163 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
164 oncandidatesready_ = false;
165 }
166 }
167
168 // Found a new candidate.
169 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000170 switch (candidate->sdp_mline_index()) {
171 case kMediaContentIndex0:
172 mline_0_candidates_.push_back(candidate->candidate());
173 break;
174 case kMediaContentIndex1:
175 mline_1_candidates_.push_back(candidate->candidate());
176 break;
177 default:
178 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000179 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000180
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181 // The ICE gathering state should always be Gathering when a candidate is
182 // received (or possibly Completed in the case of the final candidate).
183 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
184 }
185
186 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
187 virtual void OnIceComplete() {
188 EXPECT_FALSE(oncandidatesready_);
189 oncandidatesready_ = true;
190
191 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
192 // be called approximately simultaneously. For ease of testing, this
193 // check additionally requires that they be called in the above order.
194 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
195 ice_gathering_state_);
196 }
197
198 bool oncandidatesready_;
199 std::vector<cricket::Candidate> mline_0_candidates_;
200 std::vector<cricket::Candidate> mline_1_candidates_;
201 PeerConnectionInterface::IceConnectionState ice_connection_state_;
202 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
203};
204
205class WebRtcSessionForTest : public webrtc::WebRtcSession {
206 public:
207 WebRtcSessionForTest(cricket::ChannelManager* cmgr,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000208 rtc::Thread* signaling_thread,
209 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000210 cricket::PortAllocator* port_allocator,
211 webrtc::IceObserver* ice_observer,
212 webrtc::MediaStreamSignaling* mediastream_signaling)
213 : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator,
214 mediastream_signaling) {
215 RegisterIceObserver(ice_observer);
216 }
217 virtual ~WebRtcSessionForTest() {}
218
219 using cricket::BaseSession::GetTransportProxy;
220 using webrtc::WebRtcSession::SetAudioPlayout;
221 using webrtc::WebRtcSession::SetAudioSend;
222 using webrtc::WebRtcSession::SetCaptureDevice;
223 using webrtc::WebRtcSession::SetVideoPlayout;
224 using webrtc::WebRtcSession::SetVideoSend;
225};
226
wu@webrtc.org91053e72013-08-10 07:18:04 +0000227class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000228 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000229 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000230 enum State {
231 kInit,
232 kFailed,
233 kSucceeded,
234 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000235 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000236
237 // CreateSessionDescriptionObserver implementation.
238 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000239 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000240 state_ = kSucceeded;
241 }
242 virtual void OnFailure(const std::string& error) {
243 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000244 }
245
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000246 SessionDescriptionInterface* description() { return description_.get(); }
247
248 SessionDescriptionInterface* ReleaseDescription() {
249 return description_.release();
250 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000251
wu@webrtc.org91053e72013-08-10 07:18:04 +0000252 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000253
wu@webrtc.org91053e72013-08-10 07:18:04 +0000254 protected:
255 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000256
257 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000258 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000259 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000260};
261
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000262class FakeAudioRenderer : public cricket::AudioRenderer {
263 public:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000264 FakeAudioRenderer() : channel_id_(-1), sink_(NULL) {}
265 virtual ~FakeAudioRenderer() {
266 if (sink_)
267 sink_->OnClose();
268 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000269
270 virtual void AddChannel(int channel_id) OVERRIDE {
271 ASSERT(channel_id_ == -1);
272 channel_id_ = channel_id;
273 }
274 virtual void RemoveChannel(int channel_id) OVERRIDE {
275 ASSERT(channel_id == channel_id_);
276 channel_id_ = -1;
277 }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000278 virtual void SetSink(Sink* sink) OVERRIDE {
279 sink_ = sink;
280 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000281
282 int channel_id() const { return channel_id_; }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000283 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000284 private:
285 int channel_id_;
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000286 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000287};
288
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000289class WebRtcSessionTest : public testing::Test {
290 protected:
291 // TODO Investigate why ChannelManager crashes, if it's created
292 // after stun_server.
293 WebRtcSessionTest()
294 : media_engine_(new cricket::FakeMediaEngine()),
295 data_engine_(new cricket::FakeDataEngine()),
296 device_manager_(new cricket::FakeDeviceManager()),
297 channel_manager_(new cricket::ChannelManager(
298 media_engine_, data_engine_, device_manager_,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000299 new cricket::CaptureManager(), rtc::Thread::Current())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000300 tdesc_factory_(new cricket::TransportDescriptionFactory()),
301 desc_factory_(new cricket::MediaSessionDescriptionFactory(
302 channel_manager_.get(), tdesc_factory_.get())),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000303 pss_(new rtc::PhysicalSocketServer),
304 vss_(new rtc::VirtualSocketServer(pss_.get())),
305 fss_(new rtc::FirewallSocketServer(vss_.get())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000306 ss_scope_(fss_.get()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000307 stun_socket_addr_(rtc::SocketAddress(kStunAddrHost,
wu@webrtc.org364f2042013-11-20 21:49:41 +0000308 cricket::STUN_SERVER_PORT)),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000309 stun_server_(Thread::Current(), stun_socket_addr_),
310 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000311 mediastream_signaling_(channel_manager_.get()),
312 ice_type_(PeerConnectionInterface::kAll) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000313 tdesc_factory_->set_protocol(cricket::ICEPROTO_HYBRID);
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000314
315 cricket::ServerAddresses stun_servers;
316 stun_servers.insert(stun_socket_addr_);
317 allocator_.reset(new cricket::BasicPortAllocator(
318 &network_manager_,
319 stun_servers,
320 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000321 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000322 cricket::PORTALLOCATOR_DISABLE_RELAY |
323 cricket::PORTALLOCATOR_ENABLE_BUNDLE);
324 EXPECT_TRUE(channel_manager_->Init());
325 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000326 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327 }
328
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000329 static void SetUpTestCase() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000330 rtc::InitializeSSL();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000331 }
332
333 static void TearDownTestCase() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000334 rtc::CleanupSSL();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000335 }
336
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000337 void AddInterface(const SocketAddress& addr) {
338 network_manager_.AddInterface(addr);
339 }
340
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000341 void SetIceTransportType(PeerConnectionInterface::IceTransportsType type) {
342 ice_type_ = type;
343 }
344
wu@webrtc.org91053e72013-08-10 07:18:04 +0000345 void Init(DTLSIdentityServiceInterface* identity_service) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000346 ASSERT_TRUE(session_.get() == NULL);
347 session_.reset(new WebRtcSessionForTest(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000348 channel_manager_.get(), rtc::Thread::Current(),
349 rtc::Thread::Current(), allocator_.get(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000350 &observer_,
351 &mediastream_signaling_));
352
353 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
354 observer_.ice_connection_state_);
355 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
356 observer_.ice_gathering_state_);
357
wu@webrtc.org97077a32013-10-25 21:18:33 +0000358 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000359 identity_service, ice_type_));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000360 }
361
362 void InitWithDtmfCodec() {
363 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000364 const cricket::AudioCodec kTelephoneEventCodec(
365 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366 std::vector<cricket::AudioCodec> codecs;
367 codecs.push_back(kTelephoneEventCodec);
368 media_engine_->SetAudioCodecs(codecs);
369 desc_factory_->set_audio_codecs(codecs);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000370 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000371 }
372
henrike@webrtc.org7666db72013-08-22 14:45:42 +0000373 void InitWithDtls(bool identity_request_should_fail = false) {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000374 FakeIdentityService* identity_service = new FakeIdentityService();
375 identity_service->set_should_fail(identity_request_should_fail);
376 Init(identity_service);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000377 }
378
379 // Creates a local offer and applies it. Starts ice.
380 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
381 // to decide which streams to create.
382 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000383 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000384 SetLocalDescriptionWithoutError(offer);
385 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
386 observer_.ice_gathering_state_,
387 kIceCandidatesTimeout);
388 }
389
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000390 SessionDescriptionInterface* CreateOffer() {
391 PeerConnectionInterface::RTCOfferAnswerOptions options;
392 options.offer_to_receive_audio =
393 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
394
395 return CreateOffer(options);
396 }
397
wu@webrtc.org91053e72013-08-10 07:18:04 +0000398 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000399 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000400 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000401 observer = new WebRtcSessionCreateSDPObserverForTest();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000402 session_->CreateOffer(observer, options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000403 EXPECT_TRUE_WAIT(
404 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000405 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000406 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000407 }
408
409 SessionDescriptionInterface* CreateAnswer(
410 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000411 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000412 = new WebRtcSessionCreateSDPObserverForTest();
413 session_->CreateAnswer(observer, constraints);
414 EXPECT_TRUE_WAIT(
415 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000416 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000417 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000418 }
419
wu@webrtc.org364f2042013-11-20 21:49:41 +0000420 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000421 return (session_->voice_channel() != NULL &&
422 session_->video_channel() != NULL);
423 }
424
wu@webrtc.org364f2042013-11-20 21:49:41 +0000425 void CheckTransportChannels() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000426 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 1) != NULL);
427 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 2) != NULL);
428 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 1) != NULL);
429 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 2) != NULL);
430 }
431
432 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
433 ASSERT_TRUE(session_.get() != NULL);
434 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
435 ASSERT_TRUE(content != NULL);
436 const cricket::AudioContentDescription* audio_content =
437 static_cast<const cricket::AudioContentDescription*>(
438 content->description);
439 ASSERT_TRUE(audio_content != NULL);
440 ASSERT_EQ(1U, audio_content->cryptos().size());
441 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
442 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
443 audio_content->cryptos()[0].cipher_suite);
444 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
445 audio_content->protocol());
446
447 content = cricket::GetFirstVideoContent(sdp);
448 ASSERT_TRUE(content != NULL);
449 const cricket::VideoContentDescription* video_content =
450 static_cast<const cricket::VideoContentDescription*>(
451 content->description);
452 ASSERT_TRUE(video_content != NULL);
453 ASSERT_EQ(1U, video_content->cryptos().size());
454 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
455 video_content->cryptos()[0].cipher_suite);
456 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
457 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
458 video_content->protocol());
459 }
460
461 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
462 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
463 ASSERT_TRUE(content != NULL);
464 const cricket::AudioContentDescription* audio_content =
465 static_cast<const cricket::AudioContentDescription*>(
466 content->description);
467 ASSERT_TRUE(audio_content != NULL);
468 ASSERT_EQ(0U, audio_content->cryptos().size());
469
470 content = cricket::GetFirstVideoContent(sdp);
471 ASSERT_TRUE(content != NULL);
472 const cricket::VideoContentDescription* video_content =
473 static_cast<const cricket::VideoContentDescription*>(
474 content->description);
475 ASSERT_TRUE(video_content != NULL);
476 ASSERT_EQ(0U, video_content->cryptos().size());
477
478 if (dtls) {
479 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
480 audio_content->protocol());
481 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
482 video_content->protocol());
483 } else {
484 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
485 audio_content->protocol());
486 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
487 video_content->protocol());
488 }
489 }
490
491 // Set the internal fake description factories to do DTLS-SRTP.
492 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000493 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000494 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000495 rtc::ToString(rtc::CreateRandomId());
496 identity_.reset(rtc::SSLIdentity::Generate(identity_name));
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000497 tdesc_factory_->set_identity(identity_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000498 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
499 }
500
501 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
502 bool expected) {
503 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
504 ASSERT_TRUE(audio != NULL);
505 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000506 const TransportInfo* video = sdp->GetTransportInfoByName("video");
507 ASSERT_TRUE(video != NULL);
508 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000509 }
510
511 void VerifyAnswerFromNonCryptoOffer() {
512 // Create a SDP without Crypto.
513 cricket::MediaSessionOptions options;
514 options.has_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000515 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000516 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000517 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000518 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000519 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
520 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000521 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000522 // Answer should be NULL as no crypto params in offer.
523 ASSERT_TRUE(answer == NULL);
524 }
525
526 void VerifyAnswerFromCryptoOffer() {
527 cricket::MediaSessionOptions options;
528 options.has_video = true;
529 options.bundle_enabled = true;
530 scoped_ptr<JsepSessionDescription> offer(
531 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
532 ASSERT_TRUE(offer.get() != NULL);
533 VerifyCryptoParams(offer->description());
534 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000535 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000536 ASSERT_TRUE(answer.get() != NULL);
537 VerifyCryptoParams(answer->description());
538 }
539
540 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
541 const cricket::SessionDescription* desc2,
542 bool expect_equal) {
543 if (desc1->contents().size() != desc2->contents().size()) {
544 EXPECT_FALSE(expect_equal);
545 return;
546 }
547
548 const cricket::ContentInfos& contents = desc1->contents();
549 cricket::ContentInfos::const_iterator it = contents.begin();
550
551 for (; it != contents.end(); ++it) {
552 const cricket::TransportDescription* transport_desc1 =
553 desc1->GetTransportDescriptionByName(it->name);
554 const cricket::TransportDescription* transport_desc2 =
555 desc2->GetTransportDescriptionByName(it->name);
556 if (!transport_desc1 || !transport_desc2) {
557 EXPECT_FALSE(expect_equal);
558 return;
559 }
560 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
561 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
562 EXPECT_FALSE(expect_equal);
563 return;
564 }
565 }
566 EXPECT_TRUE(expect_equal);
567 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000568
569 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
570 std::string *sdp) {
571 const cricket::SessionDescription* desc = current_desc->description();
572 EXPECT_TRUE(current_desc->ToString(sdp));
573
574 const cricket::ContentInfos& contents = desc->contents();
575 cricket::ContentInfos::const_iterator it = contents.begin();
576 // Replace ufrag and pwd lines with empty strings.
577 for (; it != contents.end(); ++it) {
578 const cricket::TransportDescription* transport_desc =
579 desc->GetTransportDescriptionByName(it->name);
580 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
581 + "\r\n";
582 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
583 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000584 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000585 "", 0,
586 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000587 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000588 "", 0,
589 sdp);
590 }
591 }
592
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000593 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
594 const std::string& modified_ice_ufrag,
595 const std::string& modified_ice_pwd,
596 std::string* sdp) {
597 const cricket::SessionDescription* desc = current_desc->description();
598 EXPECT_TRUE(current_desc->ToString(sdp));
599
600 const cricket::ContentInfos& contents = desc->contents();
601 cricket::ContentInfos::const_iterator it = contents.begin();
602 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
603 // |modified_ice_pwd| strings.
604 for (; it != contents.end(); ++it) {
605 const cricket::TransportDescription* transport_desc =
606 desc->GetTransportDescriptionByName(it->name);
607 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
608 + "\r\n";
609 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
610 + "\r\n";
611 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
612 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000613 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000614 mod_ufrag.c_str(), mod_ufrag.length(),
615 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000616 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000617 mod_pwd.c_str(), mod_pwd.length(),
618 sdp);
619 }
620 }
621
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000622 // Creates a remote offer and and applies it as a remote description,
623 // creates a local answer and applies is as a local description.
624 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
625 // to decide which local and remote streams to create.
626 void CreateAndSetRemoteOfferAndLocalAnswer() {
627 SessionDescriptionInterface* offer = CreateRemoteOffer();
628 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000629 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000630 SetLocalDescriptionWithoutError(answer);
631 }
632 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
633 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
634 }
635 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
636 BaseSession::State expected_state) {
637 SetLocalDescriptionWithoutError(desc);
638 EXPECT_EQ(expected_state, session_->state());
639 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000640 void SetLocalDescriptionExpectError(const std::string& action,
641 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000642 SessionDescriptionInterface* desc) {
643 std::string error;
644 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000645 std::string sdp_type = "local ";
646 sdp_type.append(action);
647 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000648 EXPECT_NE(std::string::npos, error.find(expected_error));
649 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000650 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
651 SessionDescriptionInterface* desc) {
652 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
653 expected_error, desc);
654 }
655 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
656 SessionDescriptionInterface* desc) {
657 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
658 expected_error, desc);
659 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000660 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
661 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
662 }
663 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
664 BaseSession::State expected_state) {
665 SetRemoteDescriptionWithoutError(desc);
666 EXPECT_EQ(expected_state, session_->state());
667 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000668 void SetRemoteDescriptionExpectError(const std::string& action,
669 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000670 SessionDescriptionInterface* desc) {
671 std::string error;
672 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000673 std::string sdp_type = "remote ";
674 sdp_type.append(action);
675 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000676 EXPECT_NE(std::string::npos, error.find(expected_error));
677 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000678 void SetRemoteDescriptionOfferExpectError(
679 const std::string& expected_error, SessionDescriptionInterface* desc) {
680 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
681 expected_error, desc);
682 }
683 void SetRemoteDescriptionPranswerExpectError(
684 const std::string& expected_error, SessionDescriptionInterface* desc) {
685 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
686 expected_error, desc);
687 }
688 void SetRemoteDescriptionAnswerExpectError(
689 const std::string& expected_error, SessionDescriptionInterface* desc) {
690 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
691 expected_error, desc);
692 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000693
694 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
695 SessionDescriptionInterface** nocrypto_answer) {
696 // Create a SDP without Crypto.
697 cricket::MediaSessionOptions options;
698 options.has_video = true;
699 options.bundle_enabled = true;
700 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
701 ASSERT_TRUE(*offer != NULL);
702 VerifyCryptoParams((*offer)->description());
703
704 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
705 cricket::SEC_DISABLED);
706 EXPECT_TRUE(*nocrypto_answer != NULL);
707 }
708
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000709 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
710 SessionDescriptionInterface** nodtls_answer) {
711 cricket::MediaSessionOptions options;
712 options.has_video = true;
713 options.bundle_enabled = true;
714
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000715 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000716 CreateRemoteOffer(options, cricket::SEC_ENABLED));
717
718 *nodtls_answer =
719 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
720 EXPECT_TRUE(*nodtls_answer != NULL);
721 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
722 VerifyCryptoParams((*nodtls_answer)->description());
723
724 SetFactoryDtlsSrtp();
725 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
726 ASSERT_TRUE(*offer != NULL);
727 VerifyFingerprintStatus((*offer)->description(), true);
728 VerifyCryptoParams((*offer)->description());
729 }
730
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000731 JsepSessionDescription* CreateRemoteOfferWithVersion(
732 cricket::MediaSessionOptions options,
733 cricket::SecurePolicy secure_policy,
734 const std::string& session_version,
735 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000736 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000737 const cricket::SessionDescription* cricket_desc = NULL;
738 if (current_desc) {
739 cricket_desc = current_desc->description();
740 session_id = current_desc->session_id();
741 }
742
743 desc_factory_->set_secure(secure_policy);
744 JsepSessionDescription* offer(
745 new JsepSessionDescription(JsepSessionDescription::kOffer));
746 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
747 session_id, session_version)) {
748 delete offer;
749 offer = NULL;
750 }
751 return offer;
752 }
753 JsepSessionDescription* CreateRemoteOffer(
754 cricket::MediaSessionOptions options) {
755 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
756 kSessionVersion, NULL);
757 }
758 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000759 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
760 return CreateRemoteOfferWithVersion(
761 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762 }
763 JsepSessionDescription* CreateRemoteOffer(
764 cricket::MediaSessionOptions options,
765 const SessionDescriptionInterface* current_desc) {
766 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
767 kSessionVersion, current_desc);
768 }
769
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000770 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
771 const char* sctp_stream_name, int new_port,
772 cricket::MediaSessionOptions options) {
773 options.data_channel_type = cricket::DCT_SCTP;
774 options.AddStream(cricket::MEDIA_TYPE_DATA, "datachannel",
775 sctp_stream_name);
776 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
777 }
778
779 // Takes ownership of offer_basis (and deletes it).
780 JsepSessionDescription* ChangeSDPSctpPort(
781 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
782 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
783 // SessionDescription from the mutated string.
784 const char* default_port_str = "5000";
785 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000786 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000787 std::string offer_str;
788 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000789 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000790 new_port_str, strlen(new_port_str),
791 &offer_str);
792 JsepSessionDescription* offer = new JsepSessionDescription(
793 offer_basis->type());
794 delete offer_basis;
795 offer->Initialize(offer_str, NULL);
796 return offer;
797 }
798
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000799 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
800 // before this function to decide which streams to create.
801 JsepSessionDescription* CreateRemoteOffer() {
802 cricket::MediaSessionOptions options;
803 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
804 return CreateRemoteOffer(options, session_->remote_description());
805 }
806
807 JsepSessionDescription* CreateRemoteAnswer(
808 const SessionDescriptionInterface* offer,
809 cricket::MediaSessionOptions options,
810 cricket::SecurePolicy policy) {
811 desc_factory_->set_secure(policy);
812 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000813 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000814 JsepSessionDescription* answer(
815 new JsepSessionDescription(JsepSessionDescription::kAnswer));
816 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
817 options, NULL),
818 session_id, kSessionVersion)) {
819 delete answer;
820 answer = NULL;
821 }
822 return answer;
823 }
824
825 JsepSessionDescription* CreateRemoteAnswer(
826 const SessionDescriptionInterface* offer,
827 cricket::MediaSessionOptions options) {
828 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
829 }
830
831 // Creates an answer session description with streams based on
832 // |mediastream_signaling_|. Call
833 // mediastream_signaling_.UseOptionsWithStreamX() before this function
834 // to decide which streams to create.
835 JsepSessionDescription* CreateRemoteAnswer(
836 const SessionDescriptionInterface* offer) {
837 cricket::MediaSessionOptions options;
838 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
839 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
840 }
841
842 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000843 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +0000844 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000845 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000846
847 PeerConnectionInterface::RTCOfferAnswerOptions options;
848 options.use_rtp_mux = bundle;
849
850 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000851 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
852 // and answer.
853 SetLocalDescriptionWithoutError(offer);
854
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000855 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000856 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000857 std::string sdp;
858 EXPECT_TRUE(answer->ToString(&sdp));
859
860 size_t expected_candidate_num = 2;
861 if (!rtcp_mux) {
862 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
863 // for rtp and rtcp.
864 expected_candidate_num = 4;
865 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000866 const std::string kRtcpMux = "a=rtcp-mux";
867 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000868 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 kXRtcpMux.c_str(), kXRtcpMux.length(),
870 &sdp);
871 }
872
873 SessionDescriptionInterface* new_answer = CreateSessionDescription(
874 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000875
876 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000877 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
879 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
880 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
881 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
882 cricket::Candidate c0 = observer_.mline_0_candidates_[i];
883 cricket::Candidate c1 = observer_.mline_1_candidates_[i];
884 if (bundle) {
885 EXPECT_TRUE(c0.IsEquivalent(c1));
886 } else {
887 EXPECT_FALSE(c0.IsEquivalent(c1));
888 }
889 }
890 }
891 // Tests that we can only send DTMF when the dtmf codec is supported.
892 void TestCanInsertDtmf(bool can) {
893 if (can) {
894 InitWithDtmfCodec();
895 } else {
wu@webrtc.org91053e72013-08-10 07:18:04 +0000896 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000897 }
898 mediastream_signaling_.SendAudioVideoStream1();
899 CreateAndSetRemoteOfferAndLocalAnswer();
900 EXPECT_FALSE(session_->CanInsertDtmf(""));
901 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
902 }
903
904 // The method sets up a call from the session to itself, in a loopback
905 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000906 // disconnection, and then a permanent disconnection.
907 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000908 // by multiple tests with different allocators (e.g. with and without BUNDLE).
909 // While running the call, this method also checks if the session goes through
910 // the correct sequence of ICE states when a connection is established,
911 // broken, and re-established.
912 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000913 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
914 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000915 // The Gathering state should go: New -> Gathering -> Completed.
916 void TestLoopbackCall() {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000917 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +0000918 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000920 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000921
922 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
923 observer_.ice_gathering_state_);
924 SetLocalDescriptionWithoutError(offer);
925 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
926 observer_.ice_connection_state_);
927 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
928 observer_.ice_gathering_state_,
929 kIceCandidatesTimeout);
930 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
931 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
932 observer_.ice_gathering_state_,
933 kIceCandidatesTimeout);
934
935 std::string sdp;
936 offer->ToString(&sdp);
937 SessionDescriptionInterface* desc =
938 webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer, sdp);
939 ASSERT_TRUE(desc != NULL);
940 SetRemoteDescriptionWithoutError(desc);
941
942 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
943 observer_.ice_connection_state_,
944 kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +0000945
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000946 // The ice connection state is "Connected" too briefly to catch in a test.
947 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 observer_.ice_connection_state_,
949 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000950
951 // Adding firewall rule to block ping requests, which should cause
952 // transport channel failure.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000953 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000954 rtc::FP_ANY,
955 rtc::FD_ANY,
956 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000957 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
958 observer_.ice_connection_state_,
959 kIceCandidatesTimeout);
960
961 // Clearing the rules, session should move back to completed state.
962 fss_->ClearRules();
963 // Session is automatically calling OnSignalingReady after creation of
964 // new portallocator session which will allocate new set of candidates.
965
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000966 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000967 observer_.ice_connection_state_,
968 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000969
970 // Now we block ping requests and wait until the ICE connection transitions
971 // to the Failed state. This will take at least 30 seconds because it must
972 // wait for the Port to timeout.
973 int port_timeout = 30000;
974 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000975 rtc::FP_ANY,
976 rtc::FD_ANY,
977 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
mallinath@webrtc.org385857d2014-02-14 00:56:12 +0000978 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionFailed,
979 observer_.ice_connection_state_,
980 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000981 }
982
983 void VerifyTransportType(const std::string& content_name,
984 cricket::TransportProtocol protocol) {
985 const cricket::Transport* transport = session_->GetTransport(content_name);
986 ASSERT_TRUE(transport != NULL);
987 EXPECT_EQ(protocol, transport->protocol());
988 }
989
990 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
991 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000992 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
993 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
994
995 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000996 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
997 codecs.push_back(kCNCodec1);
998 codecs.push_back(kCNCodec2);
999 media_engine_->SetAudioCodecs(codecs);
1000 desc_factory_->set_audio_codecs(codecs);
1001 }
1002
1003 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1004 const cricket::ContentDescription* description = content->description;
1005 ASSERT(description != NULL);
1006 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001007 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001008 ASSERT(audio_content_desc != NULL);
1009 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1010 if (audio_content_desc->codecs()[i].name == "CN")
1011 return false;
1012 }
1013 return true;
1014 }
1015
1016 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001017 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001018 dci.reliable = false;
1019 session_->CreateDataChannel("datachannel", &dci);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001020 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001021 SetLocalDescriptionWithoutError(offer);
1022 }
1023
wu@webrtc.org91053e72013-08-10 07:18:04 +00001024 void VerifyMultipleAsyncCreateDescription(
1025 bool success, CreateSessionDescriptionRequest::Type type) {
henrike@webrtc.org7666db72013-08-22 14:45:42 +00001026 InitWithDtls(!success);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001027 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001028 if (type == CreateSessionDescriptionRequest::kAnswer) {
1029 cricket::MediaSessionOptions options;
1030 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001031 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001032 ASSERT_TRUE(offer.get() != NULL);
1033 SetRemoteDescriptionWithoutError(offer.release());
1034 }
1035
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001036 PeerConnectionInterface::RTCOfferAnswerOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001037 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001038 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001039 observers[kNumber];
1040 for (int i = 0; i < kNumber; ++i) {
1041 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1042 if (type == CreateSessionDescriptionRequest::kOffer) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001043 session_->CreateOffer(observers[i], options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001044 } else {
1045 session_->CreateAnswer(observers[i], NULL);
1046 }
1047 }
1048
1049 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1050 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1051 WebRtcSessionCreateSDPObserverForTest::kFailed;
1052
1053 for (int i = 0; i < kNumber; ++i) {
1054 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1055 if (success) {
1056 EXPECT_TRUE(observers[i]->description() != NULL);
1057 } else {
1058 EXPECT_TRUE(observers[i]->description() == NULL);
1059 }
1060 }
1061 }
1062
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001063 cricket::FakeMediaEngine* media_engine_;
1064 cricket::FakeDataEngine* data_engine_;
1065 cricket::FakeDeviceManager* device_manager_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001066 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
1067 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1068 rtc::scoped_ptr<rtc::SSLIdentity> identity_;
1069 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1070 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1071 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1072 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1073 rtc::SocketServerScope ss_scope_;
1074 rtc::SocketAddress stun_socket_addr_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001075 cricket::TestStunServer stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001076 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001077 rtc::FakeNetworkManager network_manager_;
1078 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001079 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001080 rtc::scoped_ptr<FakeConstraints> constraints_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001081 FakeMediaStreamSignaling mediastream_signaling_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001082 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001083 MockIceObserver observer_;
1084 cricket::FakeVideoMediaChannel* video_channel_;
1085 cricket::FakeVoiceMediaChannel* voice_channel_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001086 PeerConnectionInterface::IceTransportsType ice_type_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001087};
1088
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001089TEST_F(WebRtcSessionTest, TestInitializeWithDtls) {
1090 InitWithDtls();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001091 // SDES is disabled when DTLS is on.
1092 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001093}
1094
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001095TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001096 Init(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001097 // SDES is required if DTLS is off.
1098 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001099}
1100
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001101TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1102 TestSessionCandidatesWithBundleRtcpMux(false, false);
1103}
1104
1105// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1106// with rtcp-mux and/or bundle.
1107TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1108 TestSessionCandidatesWithBundleRtcpMux(false, true);
1109}
1110
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001111TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1112 TestSessionCandidatesWithBundleRtcpMux(true, true);
1113}
1114
1115TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001116 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1117 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001118 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001119 mediastream_signaling_.SendAudioVideoStream1();
1120 InitiateCall();
1121 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1122 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1123 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1124}
1125
1126TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001127 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1128 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001129 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001130 rtc::FP_UDP,
1131 rtc::FD_ANY,
1132 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001133 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001134 mediastream_signaling_.SendAudioVideoStream1();
1135 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001136 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001137 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1138 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1139 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1140}
1141
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001142TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
1143 Init(NULL);
1144 SessionDescriptionInterface* offer = NULL;
1145 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1146 std::string unknown_action;
1147 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1148 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1149}
1150
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001151// Test creating offers and receive answers and make sure the
1152// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001153TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001154 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001155 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001156 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001157 const std::string session_id_orig = offer->session_id();
1158 const std::string session_version_orig = offer->session_version();
1159 SetLocalDescriptionWithoutError(offer);
1160
1161 mediastream_signaling_.SendAudioVideoStream2();
1162 SessionDescriptionInterface* answer =
1163 CreateRemoteAnswer(session_->local_description());
1164 SetRemoteDescriptionWithoutError(answer);
1165
1166 video_channel_ = media_engine_->GetVideoChannel(0);
1167 voice_channel_ = media_engine_->GetVoiceChannel(0);
1168
1169 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1170 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1171
1172 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1173 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1174
1175 ASSERT_EQ(1u, video_channel_->send_streams().size());
1176 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1177 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1178 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1179
1180 // Create new offer without send streams.
1181 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001182 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001183
1184 // Verify the session id is the same and the session version is
1185 // increased.
1186 EXPECT_EQ(session_id_orig, offer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001187 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1188 rtc::FromString<uint64>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001189
1190 SetLocalDescriptionWithoutError(offer);
1191
1192 mediastream_signaling_.SendAudioVideoStream2();
1193 answer = CreateRemoteAnswer(session_->local_description());
1194 SetRemoteDescriptionWithoutError(answer);
1195
1196 EXPECT_EQ(0u, video_channel_->send_streams().size());
1197 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1198
1199 // Make sure the receive streams have not changed.
1200 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1201 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1202 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1203 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1204}
1205
1206// Test receiving offers and creating answers and make sure the
1207// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001208TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001209 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001210 mediastream_signaling_.SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001211 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001212 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001213 SetRemoteDescriptionWithoutError(offer);
1214
1215 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001216 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001217 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001218 SetLocalDescriptionWithoutError(answer);
1219
1220 const std::string session_id_orig = answer->session_id();
1221 const std::string session_version_orig = answer->session_version();
1222
1223 video_channel_ = media_engine_->GetVideoChannel(0);
1224 voice_channel_ = media_engine_->GetVoiceChannel(0);
1225
1226 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1227 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1228
1229 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1230 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1231
1232 ASSERT_EQ(1u, video_channel_->send_streams().size());
1233 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1234 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1235 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1236
1237 mediastream_signaling_.SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001238 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001239 SetRemoteDescriptionWithoutError(offer);
1240
1241 // Answer by turning off all send streams.
1242 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001243 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001244
1245 // Verify the session id is the same and the session version is
1246 // increased.
1247 EXPECT_EQ(session_id_orig, answer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001248 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1249 rtc::FromString<uint64>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001250 SetLocalDescriptionWithoutError(answer);
1251
1252 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1253 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1254 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1255 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1256 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1257 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1258
1259 // Make sure we have no send streams.
1260 EXPECT_EQ(0u, video_channel_->send_streams().size());
1261 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1262}
1263
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001264TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
1265 Init(NULL);
1266 media_engine_->set_fail_create_channel(true);
1267
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001268 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001269 ASSERT_TRUE(offer != NULL);
1270 // SetRemoteDescription and SetLocalDescription will take the ownership of
1271 // the offer.
1272 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001273 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001274 ASSERT_TRUE(offer != NULL);
1275 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1276}
1277
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001278//
1279// Tests for creating/setting SDP under different SDES/DTLS polices:
1280//
1281// --DTLS off and SDES on
1282// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1283// set local/remote offer/answer with crypto --> success
1284// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1285// failure
1286// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1287// failure
1288// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1289// failure
1290//
1291// --DTLS on and SDES off
1292// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1293// set local/remote offer/answer with DTLS fingerprint --> success
1294// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1295// fingerprint --> failure
1296// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1297// --> failure
1298// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1299// --> failure
1300//
1301// --Encryption disabled: DTLS off and SDES off
1302// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1303// answer without SDES or DTLS --> success
1304// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1305// answer without SDES or DTLS --> success
1306//
1307
1308// Test that we return a failure when applying a remote/local offer that doesn't
1309// have cryptos enabled when DTLS is off.
1310TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001311 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001312 cricket::MediaSessionOptions options;
1313 options.has_video = true;
1314 JsepSessionDescription* offer = CreateRemoteOffer(
1315 options, cricket::SEC_DISABLED);
1316 ASSERT_TRUE(offer != NULL);
1317 VerifyNoCryptoParams(offer->description(), false);
1318 // SetRemoteDescription and SetLocalDescription will take the ownership of
1319 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001320 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001321 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1322 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001323 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324}
1325
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001326// Test that we return a failure when applying a local answer that doesn't have
1327// cryptos enabled when DTLS is off.
1328TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
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 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001336 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001337}
1338
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001339// Test we will return fail when apply an remote answer that doesn't have
1340// crypto enabled when DTLS is off.
1341TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001342 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001343 SessionDescriptionInterface* offer = NULL;
1344 SessionDescriptionInterface* answer = NULL;
1345 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1346 // SetRemoteDescription and SetLocalDescription will take the ownership of
1347 // the offer.
1348 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001349 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001350}
1351
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001352// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1353// and that we return an answer with a DTLS fingerprint.
1354TEST_F(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001355 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001356 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001357 InitWithDtls();
1358 SetFactoryDtlsSrtp();
1359 cricket::MediaSessionOptions options;
1360 options.has_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001361 JsepSessionDescription* offer =
1362 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001363 ASSERT_TRUE(offer != NULL);
1364 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001365 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001366
1367 // SetRemoteDescription will take the ownership of the offer.
1368 SetRemoteDescriptionWithoutError(offer);
1369
1370 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001371 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001372 ASSERT_TRUE(answer != NULL);
1373 VerifyFingerprintStatus(answer->description(), true);
1374 // Check that we don't have an a=crypto line in the answer.
1375 VerifyNoCryptoParams(answer->description(), true);
1376
1377 // Now set the local description, which should work, even without a=crypto.
1378 SetLocalDescriptionWithoutError(answer);
1379}
1380
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001381// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1382// and then we accept a remote answer with a DTLS fingerprint successfully.
1383TEST_F(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001384 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001385 mediastream_signaling_.SendAudioVideoStream1();
1386 InitWithDtls();
1387 SetFactoryDtlsSrtp();
1388
1389 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001390 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001391 ASSERT_TRUE(offer != NULL);
1392 VerifyFingerprintStatus(offer->description(), true);
1393 // Check that we don't have an a=crypto line in the offer.
1394 VerifyNoCryptoParams(offer->description(), true);
1395
1396 // Now set the local description, which should work, even without a=crypto.
1397 SetLocalDescriptionWithoutError(offer);
1398
1399 cricket::MediaSessionOptions options;
1400 options.has_video = true;
1401 JsepSessionDescription* answer =
1402 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1403 ASSERT_TRUE(answer != NULL);
1404 VerifyFingerprintStatus(answer->description(), true);
1405 VerifyNoCryptoParams(answer->description(), true);
1406
1407 // SetRemoteDescription will take the ownership of the answer.
1408 SetRemoteDescriptionWithoutError(answer);
1409}
1410
1411// Test that if we support DTLS and the other side didn't offer a fingerprint,
1412// we will fail to set the remote description.
1413TEST_F(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001414 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001415 InitWithDtls();
1416 cricket::MediaSessionOptions options;
1417 options.has_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001418 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001419 JsepSessionDescription* offer = CreateRemoteOffer(
1420 options, cricket::SEC_REQUIRED);
1421 ASSERT_TRUE(offer != NULL);
1422 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001423 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001424
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001425 // SetRemoteDescription will take the ownership of the offer.
1426 SetRemoteDescriptionOfferExpectError(
1427 kSdpWithoutDtlsFingerprint, offer);
1428
1429 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1430 // SetLocalDescription will take the ownership of the offer.
1431 SetLocalDescriptionOfferExpectError(
1432 kSdpWithoutDtlsFingerprint, offer);
1433}
1434
1435// Test that we return a failure when applying a local answer that doesn't have
1436// a DTLS fingerprint when DTLS is required.
1437TEST_F(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001438 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001439 InitWithDtls();
1440 SessionDescriptionInterface* offer = NULL;
1441 SessionDescriptionInterface* answer = NULL;
1442 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1443
1444 // SetRemoteDescription and SetLocalDescription will take the ownership of
1445 // the offer and answer.
1446 SetRemoteDescriptionWithoutError(offer);
1447 SetLocalDescriptionAnswerExpectError(
1448 kSdpWithoutDtlsFingerprint, answer);
1449}
1450
1451// Test that we return a failure when applying a remote answer that doesn't have
1452// a DTLS fingerprint when DTLS is required.
1453TEST_F(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001454 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001455 InitWithDtls();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001456 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001457 cricket::MediaSessionOptions options;
1458 options.has_video = true;
1459 JsepSessionDescription* answer =
1460 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
1461
1462 // SetRemoteDescription and SetLocalDescription will take the ownership of
1463 // the offer and answer.
1464 SetLocalDescriptionWithoutError(offer);
1465 SetRemoteDescriptionAnswerExpectError(
1466 kSdpWithoutDtlsFingerprint, answer);
1467}
1468
1469// Test that we create a local offer without SDES or DTLS and accept a remote
1470// answer without SDES or DTLS when encryption is disabled.
1471TEST_F(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
1472 mediastream_signaling_.SendAudioVideoStream1();
1473 options_.disable_encryption = true;
1474 InitWithDtls();
1475
1476 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001477 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001478 ASSERT_TRUE(offer != NULL);
1479 VerifyFingerprintStatus(offer->description(), false);
1480 // Check that we don't have an a=crypto line in the offer.
1481 VerifyNoCryptoParams(offer->description(), false);
1482
1483 // Now set the local description, which should work, even without a=crypto.
1484 SetLocalDescriptionWithoutError(offer);
1485
1486 cricket::MediaSessionOptions options;
1487 options.has_video = true;
1488 JsepSessionDescription* answer =
1489 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1490 ASSERT_TRUE(answer != NULL);
1491 VerifyFingerprintStatus(answer->description(), false);
1492 VerifyNoCryptoParams(answer->description(), false);
1493
1494 // SetRemoteDescription will take the ownership of the answer.
1495 SetRemoteDescriptionWithoutError(answer);
1496}
1497
1498// Test that we create a local answer without SDES or DTLS and accept a remote
1499// offer without SDES or DTLS when encryption is disabled.
1500TEST_F(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
1501 options_.disable_encryption = true;
1502 InitWithDtls();
1503
1504 cricket::MediaSessionOptions options;
1505 options.has_video = true;
1506 JsepSessionDescription* offer =
1507 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1508 ASSERT_TRUE(offer != NULL);
1509 VerifyFingerprintStatus(offer->description(), false);
1510 VerifyNoCryptoParams(offer->description(), false);
1511
1512 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001513 SetRemoteDescriptionWithoutError(offer);
1514
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001515 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001516 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001517 ASSERT_TRUE(answer != NULL);
1518 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001519 // Check that we don't have an a=crypto line in the answer.
1520 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001521
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001522 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001523 SetLocalDescriptionWithoutError(answer);
1524}
1525
1526TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001527 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001528 mediastream_signaling_.SendNothing();
1529 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001530 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001531 SetLocalDescriptionWithoutError(offer);
1532
1533 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001534 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001535 SetLocalDescriptionWithoutError(offer2);
1536}
1537
1538TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001539 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001540 mediastream_signaling_.SendNothing();
1541 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001542 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001543 SetRemoteDescriptionWithoutError(offer);
1544
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001545 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001546 SetRemoteDescriptionWithoutError(offer2);
1547}
1548
1549TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001550 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001551 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001552 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001553 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001554 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001555 SetRemoteDescriptionOfferExpectError(
1556 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001557}
1558
1559TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001560 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001561 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001562 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001563 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001564 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001565 SetLocalDescriptionOfferExpectError(
1566 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001567}
1568
1569TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001570 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001571 mediastream_signaling_.SendNothing();
1572 SessionDescriptionInterface* offer = CreateRemoteOffer();
1573 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1574
1575 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001576 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001577 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1578 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1579
1580 mediastream_signaling_.SendAudioVideoStream1();
1581 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001582 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001583 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1584
1585 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1586
1587 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001588 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001589 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1590}
1591
1592TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001593 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001594 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001595 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001596 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1597
1598 JsepSessionDescription* pranswer =
1599 CreateRemoteAnswer(session_->local_description());
1600 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1601
1602 SetRemoteDescriptionExpectState(pranswer,
1603 BaseSession::STATE_RECEIVEDPRACCEPT);
1604
1605 mediastream_signaling_.SendAudioVideoStream1();
1606 JsepSessionDescription* pranswer2 =
1607 CreateRemoteAnswer(session_->local_description());
1608 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1609
1610 SetRemoteDescriptionExpectState(pranswer2,
1611 BaseSession::STATE_RECEIVEDPRACCEPT);
1612
1613 mediastream_signaling_.SendAudioVideoStream2();
1614 SessionDescriptionInterface* answer =
1615 CreateRemoteAnswer(session_->local_description());
1616 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1617}
1618
1619TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001620 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001621 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001622 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1623
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001624 SessionDescriptionInterface* answer =
1625 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001626 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1627 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001628}
1629
1630TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001631 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001632 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001633 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1634
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001635 SessionDescriptionInterface* answer =
1636 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001637 SetRemoteDescriptionAnswerExpectError(
1638 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001639}
1640
1641TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001642 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001643 mediastream_signaling_.SendAudioVideoStream1();
1644
1645 cricket::Candidate candidate;
1646 candidate.set_component(1);
1647 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1648
1649 // Fail since we have not set a offer description.
1650 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1651
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001652 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001653 SetLocalDescriptionWithoutError(offer);
1654 // Candidate should be allowed to add before remote description.
1655 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1656 candidate.set_component(2);
1657 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1658 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1659
1660 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1661 session_->local_description());
1662 SetRemoteDescriptionWithoutError(answer);
1663
1664 // Verifying the candidates are copied properly from internal vector.
1665 const SessionDescriptionInterface* remote_desc =
1666 session_->remote_description();
1667 ASSERT_TRUE(remote_desc != NULL);
1668 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1669 const IceCandidateCollection* candidates =
1670 remote_desc->candidates(kMediaContentIndex0);
1671 ASSERT_EQ(2u, candidates->count());
1672 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1673 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1674 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1675 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1676
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001677 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1678 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001679 candidate.set_component(2);
1680 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1681 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001682 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001683
1684 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1685 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1686}
1687
1688// Test that a remote candidate is added to the remote session description and
1689// that it is retained if the remote session description is changed.
1690TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001691 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001692 cricket::Candidate candidate1;
1693 candidate1.set_component(1);
1694 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1695 candidate1);
1696 mediastream_signaling_.SendAudioVideoStream1();
1697 CreateAndSetRemoteOfferAndLocalAnswer();
1698
1699 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1700 const SessionDescriptionInterface* remote_desc =
1701 session_->remote_description();
1702 ASSERT_TRUE(remote_desc != NULL);
1703 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1704 const IceCandidateCollection* candidates =
1705 remote_desc->candidates(kMediaContentIndex0);
1706 ASSERT_EQ(1u, candidates->count());
1707 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1708
1709 // Update the RemoteSessionDescription with a new session description and
1710 // a candidate and check that the new remote session description contains both
1711 // candidates.
1712 SessionDescriptionInterface* offer = CreateRemoteOffer();
1713 cricket::Candidate candidate2;
1714 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1715 candidate2);
1716 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1717 SetRemoteDescriptionWithoutError(offer);
1718
1719 remote_desc = session_->remote_description();
1720 ASSERT_TRUE(remote_desc != NULL);
1721 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1722 candidates = remote_desc->candidates(kMediaContentIndex0);
1723 ASSERT_EQ(2u, candidates->count());
1724 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1725 // Username and password have be updated with the TransportInfo of the
1726 // SessionDescription, won't be equal to the original one.
1727 candidate2.set_username(candidates->at(0)->candidate().username());
1728 candidate2.set_password(candidates->at(0)->candidate().password());
1729 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
1730 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
1731 // No need to verify the username and password.
1732 candidate1.set_username(candidates->at(1)->candidate().username());
1733 candidate1.set_password(candidates->at(1)->candidate().password());
1734 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
1735
1736 // Test that the candidate is ignored if we can add the same candidate again.
1737 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1738}
1739
1740// Test that local candidates are added to the local session description and
1741// that they are retained if the local session description is changed.
1742TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001743 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001744 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001745 mediastream_signaling_.SendAudioVideoStream1();
1746 CreateAndSetRemoteOfferAndLocalAnswer();
1747
1748 const SessionDescriptionInterface* local_desc = session_->local_description();
1749 const IceCandidateCollection* candidates =
1750 local_desc->candidates(kMediaContentIndex0);
1751 ASSERT_TRUE(candidates != NULL);
1752 EXPECT_EQ(0u, candidates->count());
1753
1754 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1755
1756 local_desc = session_->local_description();
1757 candidates = local_desc->candidates(kMediaContentIndex0);
1758 ASSERT_TRUE(candidates != NULL);
1759 EXPECT_LT(0u, candidates->count());
1760 candidates = local_desc->candidates(1);
1761 ASSERT_TRUE(candidates != NULL);
1762 EXPECT_LT(0u, candidates->count());
1763
1764 // Update the session descriptions.
1765 mediastream_signaling_.SendAudioVideoStream1();
1766 CreateAndSetRemoteOfferAndLocalAnswer();
1767
1768 local_desc = session_->local_description();
1769 candidates = local_desc->candidates(kMediaContentIndex0);
1770 ASSERT_TRUE(candidates != NULL);
1771 EXPECT_LT(0u, candidates->count());
1772 candidates = local_desc->candidates(1);
1773 ASSERT_TRUE(candidates != NULL);
1774 EXPECT_LT(0u, candidates->count());
1775}
1776
1777// Test that we can set a remote session description with remote candidates.
1778TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001779 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001780
1781 cricket::Candidate candidate1;
1782 candidate1.set_component(1);
1783 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
1784 candidate1);
1785 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001786 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787
1788 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
1789 SetRemoteDescriptionWithoutError(offer);
1790
1791 const SessionDescriptionInterface* remote_desc =
1792 session_->remote_description();
1793 ASSERT_TRUE(remote_desc != NULL);
1794 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1795 const IceCandidateCollection* candidates =
1796 remote_desc->candidates(kMediaContentIndex0);
1797 ASSERT_EQ(1u, candidates->count());
1798 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1799
wu@webrtc.org91053e72013-08-10 07:18:04 +00001800 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001801 SetLocalDescriptionWithoutError(answer);
1802}
1803
1804// Test that offers and answers contains ice candidates when Ice candidates have
1805// been gathered.
1806TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001807 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001808 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001809 mediastream_signaling_.SendAudioVideoStream1();
1810 // Ice is started but candidates are not provided until SetLocalDescription
1811 // is called.
1812 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1813 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1814 CreateAndSetRemoteOfferAndLocalAnswer();
1815 // Wait until at least one local candidate has been collected.
1816 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
1817 kIceCandidatesTimeout);
1818 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
1819 kIceCandidatesTimeout);
1820
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001821 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
1822
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001823 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
1824 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
1825 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
1826 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
1827
1828 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
1829 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001830 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001831 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
1832 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
1833 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
1834 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
1835 SetLocalDescriptionWithoutError(answer);
1836}
1837
1838// Verifies TransportProxy and media channels are created with content names
1839// present in the SessionDescription.
1840TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001841 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001842 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001843 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001844
1845 // CreateOffer creates session description with the content names "audio" and
1846 // "video". Goal is to modify these content names and verify transport channel
1847 // proxy in the BaseSession, as proxies are created with the content names
1848 // present in SDP.
1849 std::string sdp;
1850 EXPECT_TRUE(offer->ToString(&sdp));
1851 const std::string kAudioMid = "a=mid:audio";
1852 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
1853 const std::string kVideoMid = "a=mid:video";
1854 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
1855
1856 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001857 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001858 kAudioMidReplaceStr.c_str(),
1859 kAudioMidReplaceStr.length(),
1860 &sdp);
1861 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001862 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001863 kVideoMidReplaceStr.c_str(),
1864 kVideoMidReplaceStr.length(),
1865 &sdp);
1866
1867 SessionDescriptionInterface* modified_offer =
1868 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
1869
1870 SetRemoteDescriptionWithoutError(modified_offer);
1871
1872 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00001873 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001874 SetLocalDescriptionWithoutError(answer);
1875
1876 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
1877 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
1878 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
1879 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
1880}
1881
1882// Test that an offer contains the correct media content descriptions based on
1883// the send streams when no constraints have been set.
1884TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001885 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001886 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1887
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001888 ASSERT_TRUE(offer != NULL);
1889 const cricket::ContentInfo* content =
1890 cricket::GetFirstAudioContent(offer->description());
1891 EXPECT_TRUE(content != NULL);
1892 content = cricket::GetFirstVideoContent(offer->description());
1893 EXPECT_TRUE(content == NULL);
1894}
1895
1896// Test that an offer contains the correct media content descriptions based on
1897// the send streams when no constraints have been set.
1898TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001899 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001900 // Test Audio only offer.
1901 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001902 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1903
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001904 const cricket::ContentInfo* content =
1905 cricket::GetFirstAudioContent(offer->description());
1906 EXPECT_TRUE(content != NULL);
1907 content = cricket::GetFirstVideoContent(offer->description());
1908 EXPECT_TRUE(content == NULL);
1909
1910 // Test Audio / Video offer.
1911 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001912 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001913 content = cricket::GetFirstAudioContent(offer->description());
1914 EXPECT_TRUE(content != NULL);
1915 content = cricket::GetFirstVideoContent(offer->description());
1916 EXPECT_TRUE(content != NULL);
1917}
1918
1919// Test that an offer contains no media content descriptions if
1920// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
1921TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001922 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001923 PeerConnectionInterface::RTCOfferAnswerOptions options;
1924 options.offer_to_receive_audio = 0;
1925 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001926
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001927 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001928 CreateOffer(options));
1929
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001930 ASSERT_TRUE(offer != NULL);
1931 const cricket::ContentInfo* content =
1932 cricket::GetFirstAudioContent(offer->description());
1933 EXPECT_TRUE(content == NULL);
1934 content = cricket::GetFirstVideoContent(offer->description());
1935 EXPECT_TRUE(content == NULL);
1936}
1937
1938// Test that an offer contains only audio media content descriptions if
1939// kOfferToReceiveAudio constraints are set to true.
1940TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001941 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001942 PeerConnectionInterface::RTCOfferAnswerOptions options;
1943 options.offer_to_receive_audio =
1944 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
1945
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001946 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001947 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001948
1949 const cricket::ContentInfo* content =
1950 cricket::GetFirstAudioContent(offer->description());
1951 EXPECT_TRUE(content != NULL);
1952 content = cricket::GetFirstVideoContent(offer->description());
1953 EXPECT_TRUE(content == NULL);
1954}
1955
1956// Test that an offer contains audio and video media content descriptions if
1957// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
1958TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001959 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001960 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001961 PeerConnectionInterface::RTCOfferAnswerOptions options;
1962 options.offer_to_receive_audio =
1963 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
1964 options.offer_to_receive_video =
1965 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
1966
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001967 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001968 CreateOffer(options));
1969
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001970 const cricket::ContentInfo* content =
1971 cricket::GetFirstAudioContent(offer->description());
1972
1973 EXPECT_TRUE(content != NULL);
1974 content = cricket::GetFirstVideoContent(offer->description());
1975 EXPECT_TRUE(content != NULL);
1976
1977 // TODO(perkj): Should the direction be set to SEND_ONLY if
1978 // The constraints is set to not receive audio or video but a track is added?
1979}
1980
1981// Test that an answer can not be created if the last remote description is not
1982// an offer.
1983TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00001984 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001985 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001986 SetLocalDescriptionWithoutError(offer);
1987 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
1988 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001989 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001990}
1991
1992// Test that an answer contains the correct media content descriptions when no
1993// constraints have been set.
1994TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
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 and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001997 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001998 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001999 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002000 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002001 const cricket::ContentInfo* content =
2002 cricket::GetFirstAudioContent(answer->description());
2003 ASSERT_TRUE(content != NULL);
2004 EXPECT_FALSE(content->rejected);
2005
2006 content = cricket::GetFirstVideoContent(answer->description());
2007 ASSERT_TRUE(content != NULL);
2008 EXPECT_FALSE(content->rejected);
2009}
2010
2011// Test that an answer contains the correct media content descriptions when no
2012// constraints have been set and the offer only contain audio.
2013TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002014 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002015 // Create a remote offer with audio only.
2016 cricket::MediaSessionOptions options;
2017 options.has_audio = true;
2018 options.has_video = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002019 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020 CreateRemoteOffer(options));
2021 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2022 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2023
2024 SetRemoteDescriptionWithoutError(offer.release());
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 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2033}
2034
2035// Test that an answer contains the correct media content descriptions when no
2036// constraints have been set.
2037TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002038 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002039 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002040 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002041 SetRemoteDescriptionWithoutError(offer.release());
2042 // Test with a stream with tracks.
2043 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002044 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002045 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002046 const cricket::ContentInfo* content =
2047 cricket::GetFirstAudioContent(answer->description());
2048 ASSERT_TRUE(content != NULL);
2049 EXPECT_FALSE(content->rejected);
2050
2051 content = cricket::GetFirstVideoContent(answer->description());
2052 ASSERT_TRUE(content != NULL);
2053 EXPECT_FALSE(content->rejected);
2054}
2055
2056// Test that an answer contains the correct media content descriptions when
2057// constraints have been set but no stream is sent.
2058TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002059 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002060 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002061 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002062 SetRemoteDescriptionWithoutError(offer.release());
2063
2064 webrtc::FakeConstraints constraints_no_receive;
2065 constraints_no_receive.SetMandatoryReceiveAudio(false);
2066 constraints_no_receive.SetMandatoryReceiveVideo(false);
2067
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002068 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002069 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002070 const cricket::ContentInfo* content =
2071 cricket::GetFirstAudioContent(answer->description());
2072 ASSERT_TRUE(content != NULL);
2073 EXPECT_TRUE(content->rejected);
2074
2075 content = cricket::GetFirstVideoContent(answer->description());
2076 ASSERT_TRUE(content != NULL);
2077 EXPECT_TRUE(content->rejected);
2078}
2079
2080// Test that an answer contains the correct media content descriptions when
2081// constraints have been set and streams are sent.
2082TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002083 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002084 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002085 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002086 SetRemoteDescriptionWithoutError(offer.release());
2087
2088 webrtc::FakeConstraints constraints_no_receive;
2089 constraints_no_receive.SetMandatoryReceiveAudio(false);
2090 constraints_no_receive.SetMandatoryReceiveVideo(false);
2091
2092 // Test with a stream with tracks.
2093 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002094 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002095 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002096
2097 // TODO(perkj): Should the direction be set to SEND_ONLY?
2098 const cricket::ContentInfo* content =
2099 cricket::GetFirstAudioContent(answer->description());
2100 ASSERT_TRUE(content != NULL);
2101 EXPECT_FALSE(content->rejected);
2102
2103 // TODO(perkj): Should the direction be set to SEND_ONLY?
2104 content = cricket::GetFirstVideoContent(answer->description());
2105 ASSERT_TRUE(content != NULL);
2106 EXPECT_FALSE(content->rejected);
2107}
2108
2109TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2110 AddCNCodecs();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002111 Init(NULL);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002112 PeerConnectionInterface::RTCOfferAnswerOptions options;
2113 options.offer_to_receive_audio =
2114 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2115 options.voice_activity_detection = false;
2116
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002117 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002118 CreateOffer(options));
2119
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002120 const cricket::ContentInfo* content =
2121 cricket::GetFirstAudioContent(offer->description());
2122 EXPECT_TRUE(content != NULL);
2123 EXPECT_TRUE(VerifyNoCNCodecs(content));
2124}
2125
2126TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2127 AddCNCodecs();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002128 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002130 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002131 SetRemoteDescriptionWithoutError(offer.release());
2132
2133 webrtc::FakeConstraints constraints;
2134 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002135 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002136 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002137 const cricket::ContentInfo* content =
2138 cricket::GetFirstAudioContent(answer->description());
2139 ASSERT_TRUE(content != NULL);
2140 EXPECT_TRUE(VerifyNoCNCodecs(content));
2141}
2142
2143// This test verifies the call setup when remote answer with audio only and
2144// later updates with video.
2145TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002146 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002147 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2148 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2149
2150 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002151 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002152
2153 cricket::MediaSessionOptions options;
2154 options.has_video = false;
2155 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2156
2157 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2158 // and answer;
2159 SetLocalDescriptionWithoutError(offer);
2160 SetRemoteDescriptionWithoutError(answer);
2161
2162 video_channel_ = media_engine_->GetVideoChannel(0);
2163 voice_channel_ = media_engine_->GetVoiceChannel(0);
2164
2165 ASSERT_TRUE(video_channel_ == NULL);
2166
2167 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2168 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2169 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2170
2171 // Let the remote end update the session descriptions, with Audio and Video.
2172 mediastream_signaling_.SendAudioVideoStream2();
2173 CreateAndSetRemoteOfferAndLocalAnswer();
2174
2175 video_channel_ = media_engine_->GetVideoChannel(0);
2176 voice_channel_ = media_engine_->GetVoiceChannel(0);
2177
2178 ASSERT_TRUE(video_channel_ != NULL);
2179 ASSERT_TRUE(voice_channel_ != NULL);
2180
2181 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2182 ASSERT_EQ(1u, video_channel_->send_streams().size());
2183 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2184 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2185 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2186 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2187 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2188 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2189
2190 // Change session back to audio only.
2191 mediastream_signaling_.UseOptionsAudioOnly();
2192 CreateAndSetRemoteOfferAndLocalAnswer();
2193
2194 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2195 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2196 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2197 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2198 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2199}
2200
2201// This test verifies the call setup when remote answer with video only and
2202// later updates with audio.
2203TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002204 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002205 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2206 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2207 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002208 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002209
2210 cricket::MediaSessionOptions options;
2211 options.has_audio = false;
2212 options.has_video = true;
2213 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2214 offer, options, cricket::SEC_ENABLED);
2215
2216 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2217 // and answer.
2218 SetLocalDescriptionWithoutError(offer);
2219 SetRemoteDescriptionWithoutError(answer);
2220
2221 video_channel_ = media_engine_->GetVideoChannel(0);
2222 voice_channel_ = media_engine_->GetVoiceChannel(0);
2223
2224 ASSERT_TRUE(voice_channel_ == NULL);
2225 ASSERT_TRUE(video_channel_ != NULL);
2226
2227 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2228 ASSERT_EQ(1u, video_channel_->send_streams().size());
2229 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2230
2231 // Update the session descriptions, with Audio and Video.
2232 mediastream_signaling_.SendAudioVideoStream2();
2233 CreateAndSetRemoteOfferAndLocalAnswer();
2234
2235 voice_channel_ = media_engine_->GetVoiceChannel(0);
2236 ASSERT_TRUE(voice_channel_ != NULL);
2237
2238 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2239 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2240 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2241 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2242
2243 // Change session back to video only.
2244 mediastream_signaling_.UseOptionsVideoOnly();
2245 CreateAndSetRemoteOfferAndLocalAnswer();
2246
2247 video_channel_ = media_engine_->GetVideoChannel(0);
2248 voice_channel_ = media_engine_->GetVoiceChannel(0);
2249
2250 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2251 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2252 ASSERT_EQ(1u, video_channel_->send_streams().size());
2253 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2254}
2255
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002256TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002257 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002258 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002259 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002260 VerifyCryptoParams(offer->description());
2261 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002262 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002263 VerifyCryptoParams(answer->description());
2264}
2265
2266TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002267 options_.disable_encryption = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00002268 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002269 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002270 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002271 VerifyNoCryptoParams(offer->description(), false);
2272}
2273
2274TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002275 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002276 VerifyAnswerFromNonCryptoOffer();
2277}
2278
2279TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002280 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002281 VerifyAnswerFromCryptoOffer();
2282}
2283
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002284// This test verifies that setLocalDescription fails if
2285// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2286TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
2287 Init(NULL);
2288 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002289 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2290
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002291 std::string sdp;
2292 RemoveIceUfragPwdLines(offer.get(), &sdp);
2293 SessionDescriptionInterface* modified_offer =
2294 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002295 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002296}
2297
2298// This test verifies that setRemoteDescription fails if
2299// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2300TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
2301 Init(NULL);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002302 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002303 std::string sdp;
2304 RemoveIceUfragPwdLines(offer.get(), &sdp);
2305 SessionDescriptionInterface* modified_offer =
2306 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002307 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002308}
2309
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002310// This test verifies that setLocalDescription fails if local offer has
2311// too short ice ufrag and pwd strings.
2312TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
2313 Init(NULL);
2314 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
2315 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002316 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2317
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002318 std::string sdp;
2319 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2320 // recommended values of 4 and 22 bytes respectively.
2321 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2322 SessionDescriptionInterface* modified_offer =
2323 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2324 std::string error;
2325 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2326
2327 // Test with string greater than 256.
2328 sdp.clear();
2329 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2330 &sdp);
2331 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2332 NULL);
2333 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2334}
2335
2336// This test verifies that setRemoteDescription fails if remote offer has
2337// too short ice ufrag and pwd strings.
2338TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
2339 Init(NULL);
2340 tdesc_factory_->set_protocol(cricket::ICEPROTO_RFC5245);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002341 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002342 std::string sdp;
2343 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2344 // recommended values of 4 and 22 bytes respectively.
2345 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2346 SessionDescriptionInterface* modified_offer =
2347 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2348 std::string error;
2349 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2350
2351 sdp.clear();
2352 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2353 &sdp);
2354 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2355 NULL);
2356 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2357}
2358
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002359TEST_F(WebRtcSessionTest, VerifyBundleFlagInPA) {
2360 // This test verifies BUNDLE flag in PortAllocator, if BUNDLE information in
2361 // local description is removed by the application, BUNDLE flag should be
2362 // disabled in PortAllocator. By default BUNDLE is enabled in the WebRtc.
wu@webrtc.org91053e72013-08-10 07:18:04 +00002363 Init(NULL);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002364 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2365 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002366 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2367
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002368 cricket::SessionDescription* offer_copy =
2369 offer->description()->Copy();
2370 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2371 JsepSessionDescription* modified_offer =
2372 new JsepSessionDescription(JsepSessionDescription::kOffer);
2373 modified_offer->Initialize(offer_copy, "1", "1");
2374
2375 SetLocalDescriptionWithoutError(modified_offer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002376 EXPECT_FALSE(allocator_->flags() & cricket::PORTALLOCATOR_ENABLE_BUNDLE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002377}
2378
2379TEST_F(WebRtcSessionTest, TestDisabledBundleInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002380 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002381 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002382 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2383 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002384
2385 PeerConnectionInterface::RTCOfferAnswerOptions options;
2386 options.use_rtp_mux = true;
2387
2388 SessionDescriptionInterface* offer = CreateOffer(options);
2389
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002390 SetLocalDescriptionWithoutError(offer);
2391 mediastream_signaling_.SendAudioVideoStream2();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002392 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002393 CreateRemoteAnswer(session_->local_description()));
2394 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2395 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2396 JsepSessionDescription* modified_answer =
2397 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2398 modified_answer->Initialize(answer_copy, "1", "1");
2399 SetRemoteDescriptionWithoutError(modified_answer);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002400 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2401 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002402
2403 video_channel_ = media_engine_->GetVideoChannel(0);
2404 voice_channel_ = media_engine_->GetVoiceChannel(0);
2405
2406 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2407 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
2408
2409 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2410 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
2411
2412 ASSERT_EQ(1u, video_channel_->send_streams().size());
2413 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
2414 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2415 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
2416}
2417
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002418// This test verifies that SetLocalDescription and SetRemoteDescription fails
2419// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2420TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002421 WebRtcSessionTest::Init(NULL);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002422 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002423 EXPECT_TRUE((cricket::PORTALLOCATOR_ENABLE_BUNDLE &
2424 allocator_->flags()) == cricket::PORTALLOCATOR_ENABLE_BUNDLE);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002425
2426 PeerConnectionInterface::RTCOfferAnswerOptions options;
2427 options.use_rtp_mux = true;
2428
2429 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002430 std::string offer_str;
2431 offer->ToString(&offer_str);
2432 // Disable rtcp-mux
2433 const std::string rtcp_mux = "rtcp-mux";
2434 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002435 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002436 xrtcp_mux.c_str(), xrtcp_mux.length(),
2437 &offer_str);
2438 JsepSessionDescription *local_offer =
2439 new JsepSessionDescription(JsepSessionDescription::kOffer);
2440 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002441 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002442 JsepSessionDescription *remote_offer =
2443 new JsepSessionDescription(JsepSessionDescription::kOffer);
2444 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002445 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002446 // Trying unmodified SDP.
2447 SetLocalDescriptionWithoutError(offer);
2448}
2449
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002450TEST_F(WebRtcSessionTest, SetAudioPlayout) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002451 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002452 mediastream_signaling_.SendAudioVideoStream1();
2453 CreateAndSetRemoteOfferAndLocalAnswer();
2454 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2455 ASSERT_TRUE(channel != NULL);
2456 ASSERT_EQ(1u, channel->recv_streams().size());
2457 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2458 double left_vol, right_vol;
2459 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2460 EXPECT_EQ(1, left_vol);
2461 EXPECT_EQ(1, right_vol);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002462 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002463 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002464 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2465 EXPECT_EQ(0, left_vol);
2466 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002467 EXPECT_EQ(0, renderer->channel_id());
2468 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002469 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
2470 EXPECT_EQ(1, left_vol);
2471 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002472 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002473}
2474
2475TEST_F(WebRtcSessionTest, SetAudioSend) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002476 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002477 mediastream_signaling_.SendAudioVideoStream1();
2478 CreateAndSetRemoteOfferAndLocalAnswer();
2479 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2480 ASSERT_TRUE(channel != NULL);
2481 ASSERT_EQ(1u, channel->send_streams().size());
2482 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2483 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2484
2485 cricket::AudioOptions options;
2486 options.echo_cancellation.Set(true);
2487
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002488 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002489 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002490 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2491 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002492 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002493 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002494
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002495 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002496 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002497 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2498 bool value;
2499 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
2500 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002501 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002502 EXPECT_TRUE(renderer->sink() == NULL);
2503}
2504
2505TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
2506 Init(NULL);
2507 mediastream_signaling_.SendAudioVideoStream1();
2508 CreateAndSetRemoteOfferAndLocalAnswer();
2509 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2510 ASSERT_TRUE(channel != NULL);
2511 ASSERT_EQ(1u, channel->send_streams().size());
2512 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2513
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002514 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00002515 cricket::AudioOptions options;
2516 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
2517 EXPECT_TRUE(renderer->sink() != NULL);
2518
2519 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
2520 // will invalidate the |renderer_| pointer in the sink and prevent getting a
2521 // SetSink(NULL) callback afterwards.
2522 renderer.reset();
2523
2524 // This will trigger SetSink(NULL) if no OnClose() callback.
2525 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002526}
2527
2528TEST_F(WebRtcSessionTest, SetVideoPlayout) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002529 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002530 mediastream_signaling_.SendAudioVideoStream1();
2531 CreateAndSetRemoteOfferAndLocalAnswer();
2532 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2533 ASSERT_TRUE(channel != NULL);
2534 ASSERT_LT(0u, channel->renderers().size());
2535 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2536 ASSERT_EQ(1u, channel->recv_streams().size());
2537 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
2538 cricket::FakeVideoRenderer renderer;
2539 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
2540 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
2541 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
2542 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
2543}
2544
2545TEST_F(WebRtcSessionTest, SetVideoSend) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002546 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002547 mediastream_signaling_.SendAudioVideoStream1();
2548 CreateAndSetRemoteOfferAndLocalAnswer();
2549 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
2550 ASSERT_TRUE(channel != NULL);
2551 ASSERT_EQ(1u, channel->send_streams().size());
2552 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2553 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2554 cricket::VideoOptions* options = NULL;
2555 session_->SetVideoSend(send_ssrc, false, options);
2556 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
2557 session_->SetVideoSend(send_ssrc, true, options);
2558 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
2559}
2560
2561TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
2562 TestCanInsertDtmf(false);
2563}
2564
2565TEST_F(WebRtcSessionTest, CanInsertDtmf) {
2566 TestCanInsertDtmf(true);
2567}
2568
2569TEST_F(WebRtcSessionTest, InsertDtmf) {
2570 // Setup
wu@webrtc.org91053e72013-08-10 07:18:04 +00002571 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002572 mediastream_signaling_.SendAudioVideoStream1();
2573 CreateAndSetRemoteOfferAndLocalAnswer();
2574 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
2575 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
2576
2577 // Insert DTMF
2578 const int expected_flags = DF_SEND;
2579 const int expected_duration = 90;
2580 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
2581 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
2582 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
2583
2584 // Verify
2585 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
2586 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
2587 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
2588 expected_duration, expected_flags));
2589 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
2590 expected_duration, expected_flags));
2591 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
2592 expected_duration, expected_flags));
2593}
2594
2595// This test verifies the |initiator| flag when session initiates the call.
2596TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002597 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002598 EXPECT_FALSE(session_->initiator());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002599 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002600 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2601 SetLocalDescriptionWithoutError(offer);
2602 EXPECT_TRUE(session_->initiator());
2603 SetRemoteDescriptionWithoutError(answer);
2604 EXPECT_TRUE(session_->initiator());
2605}
2606
2607// This test verifies the |initiator| flag when session receives the call.
2608TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002609 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002610 EXPECT_FALSE(session_->initiator());
2611 SessionDescriptionInterface* offer = CreateRemoteOffer();
2612 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002613 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002614
2615 EXPECT_FALSE(session_->initiator());
2616 SetLocalDescriptionWithoutError(answer);
2617 EXPECT_FALSE(session_->initiator());
2618}
2619
2620// This test verifies the ice protocol type at initiator of the call
2621// if |a=ice-options:google-ice| is present in answer.
2622TEST_F(WebRtcSessionTest, TestInitiatorGIceInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002623 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002624 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002625 SessionDescriptionInterface* offer = CreateOffer();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002626 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002627 CreateRemoteAnswer(offer));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002628 SetLocalDescriptionWithoutError(offer);
2629 std::string sdp;
2630 EXPECT_TRUE(answer->ToString(&sdp));
2631 // Adding ice-options to the session level.
2632 InjectAfter("t=0 0\r\n",
2633 "a=ice-options:google-ice\r\n",
2634 &sdp);
2635 SessionDescriptionInterface* answer_with_gice =
2636 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2637 SetRemoteDescriptionWithoutError(answer_with_gice);
2638 VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE);
2639 VerifyTransportType("video", cricket::ICEPROTO_GOOGLE);
2640}
2641
2642// This test verifies the ice protocol type at initiator of the call
2643// if ICE RFC5245 is supported in answer.
2644TEST_F(WebRtcSessionTest, TestInitiatorIceInAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002645 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002646 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002647 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002648 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2649 SetLocalDescriptionWithoutError(offer);
2650
2651 SetRemoteDescriptionWithoutError(answer);
2652 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2653 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2654}
2655
2656// This test verifies the ice protocol type at receiver side of the call if
2657// receiver decides to use google-ice.
2658TEST_F(WebRtcSessionTest, TestReceiverGIceInOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002659 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002660 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002661 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002662 SetRemoteDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002663 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002664 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002665 std::string sdp;
2666 EXPECT_TRUE(answer->ToString(&sdp));
2667 // Adding ice-options to the session level.
2668 InjectAfter("t=0 0\r\n",
2669 "a=ice-options:google-ice\r\n",
2670 &sdp);
2671 SessionDescriptionInterface* answer_with_gice =
2672 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2673 SetLocalDescriptionWithoutError(answer_with_gice);
2674 VerifyTransportType("audio", cricket::ICEPROTO_GOOGLE);
2675 VerifyTransportType("video", cricket::ICEPROTO_GOOGLE);
2676}
2677
2678// This test verifies the ice protocol type at receiver side of the call if
2679// receiver decides to use ice RFC 5245.
2680TEST_F(WebRtcSessionTest, TestReceiverIceInOffer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002681 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002682 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002683 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002684 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002685 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002686 SetLocalDescriptionWithoutError(answer);
2687 VerifyTransportType("audio", cricket::ICEPROTO_RFC5245);
2688 VerifyTransportType("video", cricket::ICEPROTO_RFC5245);
2689}
2690
2691// This test verifies the session state when ICE RFC5245 in offer and
2692// ICE google-ice in answer.
2693TEST_F(WebRtcSessionTest, TestIceOfferGIceOnlyAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002694 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002695 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002696 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2697
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002698 std::string offer_str;
2699 offer->ToString(&offer_str);
2700 // Disable google-ice
2701 const std::string gice_option = "google-ice";
2702 const std::string xgoogle_xice = "xgoogle-xice";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002703 rtc::replace_substrs(gice_option.c_str(), gice_option.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002704 xgoogle_xice.c_str(), xgoogle_xice.length(),
2705 &offer_str);
2706 JsepSessionDescription *ice_only_offer =
2707 new JsepSessionDescription(JsepSessionDescription::kOffer);
2708 EXPECT_TRUE((ice_only_offer)->Initialize(offer_str, NULL));
2709 SetLocalDescriptionWithoutError(ice_only_offer);
2710 std::string original_offer_sdp;
2711 EXPECT_TRUE(offer->ToString(&original_offer_sdp));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002712 SessionDescriptionInterface* pranswer_with_gice =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002713 CreateSessionDescription(JsepSessionDescription::kPrAnswer,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002714 original_offer_sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002715 SetRemoteDescriptionPranswerExpectError(kPushDownTDFailed,
2716 pranswer_with_gice);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002717 SessionDescriptionInterface* answer_with_gice =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002718 CreateSessionDescription(JsepSessionDescription::kAnswer,
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002719 original_offer_sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002720 SetRemoteDescriptionAnswerExpectError(kPushDownTDFailed,
2721 answer_with_gice);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002722}
2723
2724// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
2725TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002726 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002727 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002728 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002729 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002730 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002731 CreateRemoteAnswer(session_->local_description()));
2732
2733 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2734 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002735 JsepSessionDescription* modified_answer =
2736 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002737
2738 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2739 answer->session_id(),
2740 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002741 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002742
wu@webrtc.org4e393072014-04-07 17:04:35 +00002743 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002744 std::string sdp;
2745 EXPECT_TRUE(answer->ToString(&sdp));
2746 const std::string kAudioMid = "a=mid:audio";
2747 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002748 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002749 kAudioMidReplaceStr.c_str(),
2750 kAudioMidReplaceStr.length(),
2751 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002752 SessionDescriptionInterface* modified_answer1 =
2753 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002754 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002755
wu@webrtc.org4e393072014-04-07 17:04:35 +00002756 // Different media types.
2757 EXPECT_TRUE(answer->ToString(&sdp));
2758 const std::string kAudioMline = "m=audio";
2759 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002760 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00002761 kAudioMlineReplaceStr.c_str(),
2762 kAudioMlineReplaceStr.length(),
2763 &sdp);
2764 SessionDescriptionInterface* modified_answer2 =
2765 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
2766 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
2767
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002768 SetRemoteDescriptionWithoutError(answer.release());
2769}
2770
2771// Verifying remote offer and local answer have matching m-lines as per
2772// RFC 3264.
2773TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002774 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002775 mediastream_signaling_.SendAudioVideoStream1();
2776 SessionDescriptionInterface* offer = CreateRemoteOffer();
2777 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002778 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002779
2780 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2781 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002782 JsepSessionDescription* modified_answer =
2783 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002784
2785 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2786 answer->session_id(),
2787 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002788 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002789 SetLocalDescriptionWithoutError(answer);
2790}
2791
2792// This test verifies that WebRtcSession does not start candidate allocation
2793// before SetLocalDescription is called.
2794TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002795 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002796 mediastream_signaling_.SendAudioVideoStream1();
2797 SessionDescriptionInterface* offer = CreateRemoteOffer();
2798 cricket::Candidate candidate;
2799 candidate.set_component(1);
2800 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2801 candidate);
2802 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2803 cricket::Candidate candidate1;
2804 candidate1.set_component(1);
2805 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2806 candidate1);
2807 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
2808 SetRemoteDescriptionWithoutError(offer);
2809 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
2810 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
2811
2812 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002813 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002814 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
2815 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
2816
wu@webrtc.org91053e72013-08-10 07:18:04 +00002817 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002818 SetLocalDescriptionWithoutError(answer);
2819 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
2820 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
2821 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2822}
2823
2824// This test verifies that crypto parameter is updated in local session
2825// description as per security policy set in MediaSessionDescriptionFactory.
2826TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002827 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002828 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002829 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002830
2831 // Making sure SetLocalDescription correctly sets crypto value in
2832 // SessionDescription object after de-serialization of sdp string. The value
2833 // will be set as per MediaSessionDescriptionFactory.
2834 std::string offer_str;
2835 offer->ToString(&offer_str);
2836 SessionDescriptionInterface* jsep_offer_str =
2837 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
2838 SetLocalDescriptionWithoutError(jsep_offer_str);
2839 EXPECT_TRUE(session_->voice_channel()->secure_required());
2840 EXPECT_TRUE(session_->video_channel()->secure_required());
2841}
2842
2843// This test verifies the crypto parameter when security is disabled.
2844TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002845 options_.disable_encryption = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00002846 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002847 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002848 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002849
2850 // Making sure SetLocalDescription correctly sets crypto value in
2851 // SessionDescription object after de-serialization of sdp string. The value
2852 // will be set as per MediaSessionDescriptionFactory.
2853 std::string offer_str;
2854 offer->ToString(&offer_str);
2855 SessionDescriptionInterface *jsep_offer_str =
2856 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
2857 SetLocalDescriptionWithoutError(jsep_offer_str);
2858 EXPECT_FALSE(session_->voice_channel()->secure_required());
2859 EXPECT_FALSE(session_->video_channel()->secure_required());
2860}
2861
2862// This test verifies that an answer contains new ufrag and password if an offer
2863// with new ufrag and password is received.
2864TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002865 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002866 cricket::MediaSessionOptions options;
2867 options.has_audio = true;
2868 options.has_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002869 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002870 CreateRemoteOffer(options));
2871 SetRemoteDescriptionWithoutError(offer.release());
2872
2873 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002874 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002875 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002876 SetLocalDescriptionWithoutError(answer.release());
2877
2878 // Receive an offer with new ufrag and password.
2879 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002880 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002881 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002882 SetRemoteDescriptionWithoutError(updated_offer1.release());
2883
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002884 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002885 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002886
2887 CompareIceUfragAndPassword(updated_answer1->description(),
2888 session_->local_description()->description(),
2889 false);
2890
2891 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002892}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002893
wu@webrtc.org91053e72013-08-10 07:18:04 +00002894// This test verifies that an answer contains old ufrag and password if an offer
2895// with old ufrag and password is received.
2896TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
2897 Init(NULL);
2898 cricket::MediaSessionOptions options;
2899 options.has_audio = true;
2900 options.has_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002901 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002902 CreateRemoteOffer(options));
2903 SetRemoteDescriptionWithoutError(offer.release());
2904
2905 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002906 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002907 CreateAnswer(NULL));
2908 SetLocalDescriptionWithoutError(answer.release());
2909
2910 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002911 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002912 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002913 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002914 SetRemoteDescriptionWithoutError(updated_offer2.release());
2915
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002916 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002917 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002918
2919 CompareIceUfragAndPassword(updated_answer2->description(),
2920 session_->local_description()->description(),
2921 true);
2922
2923 SetLocalDescriptionWithoutError(updated_answer2.release());
2924}
2925
2926TEST_F(WebRtcSessionTest, TestSessionContentError) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002927 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002928 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002929 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002930 const std::string session_id_orig = offer->session_id();
2931 const std::string session_version_orig = offer->session_version();
2932 SetLocalDescriptionWithoutError(offer);
2933
2934 video_channel_ = media_engine_->GetVideoChannel(0);
2935 video_channel_->set_fail_set_send_codecs(true);
2936
2937 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002938 SessionDescriptionInterface* answer =
2939 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002940 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002941}
2942
2943// Runs the loopback call test with BUNDLE and STUN disabled.
2944TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
2945 // Lets try with only UDP ports.
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002946 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002947 cricket::PORTALLOCATOR_DISABLE_TCP |
2948 cricket::PORTALLOCATOR_DISABLE_STUN |
2949 cricket::PORTALLOCATOR_DISABLE_RELAY);
2950 TestLoopbackCall();
2951}
2952
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00002953// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00002954TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00002955 allocator_->set_flags(cricket::PORTALLOCATOR_ENABLE_SHARED_UFRAG |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00002956 cricket::PORTALLOCATOR_ENABLE_BUNDLE |
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00002957 cricket::PORTALLOCATOR_DISABLE_TCP |
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00002958 cricket::PORTALLOCATOR_DISABLE_RELAY);
2959 TestLoopbackCall();
2960}
2961
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002962TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
wu@webrtc.org91053e72013-08-10 07:18:04 +00002963 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002964 cricket::MediaSessionOptions options;
2965 options.has_audio = true;
2966 options.has_video = true;
2967
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002968 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
2969 std::string error_code_str = "ERROR_CONTENT";
2970 std::string error_desc = "Fake session error description.";
2971 session_->SetError(error_code, error_desc);
2972
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002973 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
2974 SessionDescriptionInterface* answer =
2975 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002976
2977 std::string action;
2978 std::ostringstream session_error_msg;
2979 session_error_msg << kSessionError << error_code_str << ". ";
2980 session_error_msg << kSessionErrorDesc << error_desc << ".";
2981 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
2982 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002983}
2984
2985TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
2986 constraints_.reset(new FakeConstraints());
2987 constraints_->AddOptional(
2988 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002989 Init(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002990
2991 SetLocalDescriptionWithDataChannel();
2992 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
2993}
2994
2995TEST_F(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002996 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002997
2998 constraints_.reset(new FakeConstraints());
2999 constraints_->AddOptional(
3000 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003001 options_.disable_sctp_data_channels = false;
3002
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003003 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003004
3005 SetLocalDescriptionWithDataChannel();
3006 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3007}
3008
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003009TEST_F(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003010 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003011
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003012 InitWithDtls();
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003013
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003014 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003015 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003016 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3017}
3018
3019TEST_F(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003020 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003021 SetFactoryDtlsSrtp();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003022 InitWithDtls();
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003023
3024 // Create remote offer with SCTP.
3025 cricket::MediaSessionOptions options;
3026 options.data_channel_type = cricket::DCT_SCTP;
3027 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003028 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003029 SetRemoteDescriptionWithoutError(offer);
3030
3031 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003032 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003033 EXPECT_TRUE(answer != NULL);
3034 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3035 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003036}
3037
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003038TEST_F(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
3039 constraints_.reset(new FakeConstraints());
3040 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003041 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003042 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003043
3044 SetLocalDescriptionWithDataChannel();
3045 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3046}
3047
3048TEST_F(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003049 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003050
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003051 InitWithDtls();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003052
3053 SetLocalDescriptionWithDataChannel();
3054 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3055}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003056
wu@webrtc.org97077a32013-10-25 21:18:33 +00003057TEST_F(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003058 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003059 options_.disable_sctp_data_channels = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003060 InitWithDtls();
wu@webrtc.org97077a32013-10-25 21:18:33 +00003061
3062 SetLocalDescriptionWithDataChannel();
3063 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3064}
3065
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003066TEST_F(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003067 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003068 const int new_send_port = 9998;
3069 const int new_recv_port = 7775;
3070
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003071 InitWithDtls();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003072 SetFactoryDtlsSrtp();
3073
3074 // By default, don't actually add the codecs to desc_factory_; they don't
3075 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3076 // let the session description get parsed. That'll get the proper codecs
3077 // into the stream.
3078 cricket::MediaSessionOptions options;
3079 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3080 "stream1", new_send_port, options);
3081
3082 // SetRemoteDescription will take the ownership of the offer.
3083 SetRemoteDescriptionWithoutError(offer);
3084
3085 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3086 new_recv_port, CreateAnswer(NULL));
3087 ASSERT_TRUE(answer != NULL);
3088
3089 // Now set the local description, which'll take ownership of the answer.
3090 SetLocalDescriptionWithoutError(answer);
3091
3092 // TEST PLAN: Set the port number to something new, set it in the SDP,
3093 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003094 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003095 dci.reliable = true;
3096 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003097 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003098 session_->CreateDataChannel("datachannel", &dci);
3099
3100 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3101 int portnum = -1;
3102 ASSERT_TRUE(ch != NULL);
3103 ASSERT_EQ(1UL, ch->send_codecs().size());
3104 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
3105 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3106 ch->send_codecs()[0].name.c_str()));
3107 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3108 &portnum));
3109 EXPECT_EQ(new_send_port, portnum);
3110
3111 ASSERT_EQ(1UL, ch->recv_codecs().size());
3112 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
3113 EXPECT_TRUE(!strcmp(cricket::kGoogleSctpDataCodecName,
3114 ch->recv_codecs()[0].name.c_str()));
3115 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3116 &portnum));
3117 EXPECT_EQ(new_recv_port, portnum);
3118}
3119
wu@webrtc.org91053e72013-08-10 07:18:04 +00003120// Verifies that CreateOffer succeeds when CreateOffer is called before async
3121// identity generation is finished.
3122TEST_F(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003123 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003124 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003125
3126 EXPECT_TRUE(session_->waiting_for_identity());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003127 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003128 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3129
wu@webrtc.org91053e72013-08-10 07:18:04 +00003130 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003131 VerifyNoCryptoParams(offer->description(), true);
3132 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003133}
3134
3135// Verifies that CreateAnswer succeeds when CreateOffer is called before async
3136// identity generation is finished.
3137TEST_F(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003138 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003139 InitWithDtls();
3140 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003141
3142 cricket::MediaSessionOptions options;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003143 options.has_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003144 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003145 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003146 ASSERT_TRUE(offer.get() != NULL);
3147 SetRemoteDescriptionWithoutError(offer.release());
3148
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003149 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003150 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003151 VerifyNoCryptoParams(answer->description(), true);
3152 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003153}
3154
3155// Verifies that CreateOffer succeeds when CreateOffer is called after async
3156// identity generation is finished.
3157TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003158 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003159 InitWithDtls();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003160
3161 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003162
3163 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003164 EXPECT_TRUE(offer != NULL);
3165}
3166
3167// Verifies that CreateOffer fails when CreateOffer is called after async
3168// identity generation fails.
3169TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003170 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org7666db72013-08-22 14:45:42 +00003171 InitWithDtls(true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003172
3173 EXPECT_TRUE_WAIT(!session_->waiting_for_identity(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003174
3175 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003176 EXPECT_TRUE(offer == NULL);
3177}
3178
3179// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3180// before async identity generation is finished.
3181TEST_F(WebRtcSessionTest,
3182 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003183 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003184 VerifyMultipleAsyncCreateDescription(
3185 true, CreateSessionDescriptionRequest::kOffer);
3186}
3187
3188// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3189// before async identity generation fails.
3190TEST_F(WebRtcSessionTest,
3191 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003192 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003193 VerifyMultipleAsyncCreateDescription(
3194 false, CreateSessionDescriptionRequest::kOffer);
3195}
3196
3197// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3198// before async identity generation is finished.
3199TEST_F(WebRtcSessionTest,
3200 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003201 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003202 VerifyMultipleAsyncCreateDescription(
3203 true, CreateSessionDescriptionRequest::kAnswer);
3204}
3205
3206// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3207// before async identity generation fails.
3208TEST_F(WebRtcSessionTest,
3209 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003210 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003211 VerifyMultipleAsyncCreateDescription(
3212 false, CreateSessionDescriptionRequest::kAnswer);
3213}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003214
3215// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3216// offer has no SDES crypto but only DTLS fingerprint.
3217TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3218 // Init without DTLS.
3219 Init(NULL);
3220 // Create a remote offer with secured transport disabled.
3221 cricket::MediaSessionOptions options;
3222 JsepSessionDescription* offer(CreateRemoteOffer(
3223 options, cricket::SEC_DISABLED));
3224 // Adds a DTLS fingerprint to the remote offer.
3225 cricket::SessionDescription* sdp = offer->description();
3226 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3227 ASSERT_TRUE(audio != NULL);
3228 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3229 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003230 rtc::SSLFingerprint::CreateFromRfc4572(
3231 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003232 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003233 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003234}
3235
wu@webrtc.orgde305012013-10-31 15:40:38 +00003236// This test verifies DSCP is properly applied on the media channels.
3237TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3238 constraints_.reset(new FakeConstraints());
3239 constraints_->AddOptional(
3240 webrtc::MediaConstraintsInterface::kEnableDscp, true);
3241 Init(NULL);
3242 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003243 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003244
3245 SetLocalDescriptionWithoutError(offer);
3246
3247 video_channel_ = media_engine_->GetVideoChannel(0);
3248 voice_channel_ = media_engine_->GetVoiceChannel(0);
3249
3250 ASSERT_TRUE(video_channel_ != NULL);
3251 ASSERT_TRUE(voice_channel_ != NULL);
3252 cricket::AudioOptions audio_options;
3253 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3254 cricket::VideoOptions video_options;
3255 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3256 EXPECT_TRUE(audio_options.dscp.IsSet());
3257 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3258 EXPECT_TRUE(video_options.dscp.IsSet());
3259 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3260}
3261
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003262TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3263 constraints_.reset(new FakeConstraints());
3264 constraints_->AddOptional(
3265 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3266 true);
3267 Init(NULL);
3268 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003269 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003270
3271 SetLocalDescriptionWithoutError(offer);
3272
3273 video_channel_ = media_engine_->GetVideoChannel(0);
3274
3275 ASSERT_TRUE(video_channel_ != NULL);
3276 cricket::VideoOptions video_options;
3277 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3278 EXPECT_TRUE(
3279 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3280}
3281
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003282// Tests that we can renegotiate new media content with ICE candidates in the
3283// new remote SDP.
3284TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003285 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003286 InitWithDtls();
3287 SetFactoryDtlsSrtp();
3288
3289 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003290 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003291 SetLocalDescriptionWithoutError(offer);
3292
3293 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3294 SetRemoteDescriptionWithoutError(answer);
3295
3296 cricket::MediaSessionOptions options;
3297 options.has_video = true;
3298 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3299
3300 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003301 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003302 candidate1.set_component(1);
3303 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3304 candidate1);
3305 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3306 SetRemoteDescriptionWithoutError(offer);
3307
3308 answer = CreateAnswer(NULL);
3309 SetLocalDescriptionWithoutError(answer);
3310}
3311
3312// Tests that we can renegotiate new media content with ICE candidates separated
3313// from the remote SDP.
3314TEST_F(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003315 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003316 InitWithDtls();
3317 SetFactoryDtlsSrtp();
3318
3319 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003320 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003321 SetLocalDescriptionWithoutError(offer);
3322
3323 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3324 SetRemoteDescriptionWithoutError(answer);
3325
3326 cricket::MediaSessionOptions options;
3327 options.has_video = true;
3328 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3329 SetRemoteDescriptionWithoutError(offer);
3330
3331 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003332 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003333 candidate1.set_component(1);
3334 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3335 candidate1);
3336 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3337
3338 answer = CreateAnswer(NULL);
3339 SetLocalDescriptionWithoutError(answer);
3340}
3341
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003342// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
3343// currently fails because upon disconnection and reconnection OnIceComplete is
3344// called more than once without returning to IceGatheringGathering.