blob: 2c52d1301e515c47f1dcc366df1c9c3ffcbc4d8c [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2012 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
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"
jbauchac8869e2015-07-03 01:36:14 -070029#include "talk/app/webrtc/fakemetricsobserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030#include "talk/app/webrtc/jsepicecandidate.h"
31#include "talk/app/webrtc/jsepsessiondescription.h"
32#include "talk/app/webrtc/mediastreamsignaling.h"
33#include "talk/app/webrtc/streamcollection.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000034#include "talk/app/webrtc/test/fakeconstraints.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020035#include "talk/app/webrtc/test/fakedtlsidentitystore.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000036#include "talk/app/webrtc/test/fakemediastreamsignaling.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000037#include "talk/app/webrtc/videotrack.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038#include "talk/app/webrtc/webrtcsession.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000039#include "talk/app/webrtc/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000040#include "talk/media/base/fakemediaengine.h"
41#include "talk/media/base/fakevideorenderer.h"
42#include "talk/media/base/mediachannel.h"
43#include "talk/media/devices/fakedevicemanager.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000044#include "webrtc/p2p/base/stunserver.h"
45#include "webrtc/p2p/base/teststunserver.h"
46#include "webrtc/p2p/base/testturnserver.h"
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +000047#include "webrtc/p2p/base/transportchannel.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000048#include "webrtc/p2p/client/basicportallocator.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000049#include "talk/session/media/channelmanager.h"
50#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000051#include "webrtc/base/fakenetwork.h"
52#include "webrtc/base/firewallsocketserver.h"
53#include "webrtc/base/gunit.h"
54#include "webrtc/base/logging.h"
55#include "webrtc/base/network.h"
56#include "webrtc/base/physicalsocketserver.h"
57#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020058#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000059#include "webrtc/base/sslstreamadapter.h"
60#include "webrtc/base/stringutils.h"
61#include "webrtc/base/thread.h"
62#include "webrtc/base/virtualsocketserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063
64#define MAYBE_SKIP_TEST(feature) \
65 if (!(feature())) { \
66 LOG(LS_INFO) << "Feature disabled... skipping"; \
67 return; \
68 }
69
70using cricket::BaseSession;
71using cricket::DF_PLAY;
72using cricket::DF_SEND;
73using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000075using rtc::SocketAddress;
76using rtc::scoped_ptr;
77using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000079using webrtc::CreateSessionDescriptionObserver;
80using webrtc::CreateSessionDescriptionRequest;
Henrik Boström5e56c592015-08-11 10:33:13 +020081using webrtc::DtlsIdentityStoreInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082using webrtc::FakeConstraints;
jbauchac8869e2015-07-03 01:36:14 -070083using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084using webrtc::IceCandidateCollection;
85using webrtc::JsepIceCandidate;
86using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000087using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088using webrtc::PeerConnectionInterface;
89using webrtc::SessionDescriptionInterface;
90using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000091using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000092using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000093using webrtc::kCreateChannelFailed;
94using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000096using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000097using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000098using webrtc::kSdpWithoutDtlsFingerprint;
99using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000101using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000102using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000104typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
105
wu@webrtc.org364f2042013-11-20 21:49:41 +0000106static const int kClientAddrPort = 0;
107static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000108static const char kClientIPv6AddrHost1[] =
109 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +0000110static const char kClientAddrHost2[] = "22.22.22.22";
111static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000112static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
113static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000114static const char kTurnUsername[] = "test";
115static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116
117static const char kSessionVersion[] = "1";
118
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000119// Media index of candidates belonging to the first media content.
120static const int kMediaContentIndex0 = 0;
121static const char kMediaContentName0[] = "audio";
122
123// Media index of candidates belonging to the second media content.
124static const int kMediaContentIndex1 = 1;
125static const char kMediaContentName1[] = "video";
126
127static const int kIceCandidatesTimeout = 10000;
128
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000129static const char kFakeDtlsFingerprint[] =
130 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
131 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
132
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000133static const char kTooLongIceUfragPwd[] =
134 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
135 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
136 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
137 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
138
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000139static const char kSdpWithRtx[] =
140 "v=0\r\n"
141 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
142 "s=-\r\n"
143 "t=0 0\r\n"
144 "a=msid-semantic: WMS stream1\r\n"
145 "m=video 9 RTP/SAVPF 0 96\r\n"
146 "c=IN IP4 0.0.0.0\r\n"
147 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
148 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
149 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
150 "a=mid:video\r\n"
151 "a=sendrecv\r\n"
152 "a=rtcp-mux\r\n"
153 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
154 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
155 "a=rtpmap:0 fake_video_codec/90000\r\n"
156 "a=rtpmap:96 rtx/90000\r\n"
157 "a=fmtp:96 apt=0\r\n";
158
Henrik Boström87713d02015-08-25 09:53:21 +0200159enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
160
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000161// Add some extra |newlines| to the |message| after |line|.
162static void InjectAfter(const std::string& line,
163 const std::string& newlines,
164 std::string* message) {
165 const std::string tmp = line + newlines;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000166 rtc::replace_substrs(line.c_str(), line.length(),
Henrik Boström87713d02015-08-25 09:53:21 +0200167 tmp.c_str(), tmp.length(), message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000168}
169
170class MockIceObserver : public webrtc::IceObserver {
171 public:
172 MockIceObserver()
173 : oncandidatesready_(false),
174 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
175 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
176 }
177
178 virtual void OnIceConnectionChange(
179 PeerConnectionInterface::IceConnectionState new_state) {
180 ice_connection_state_ = new_state;
181 }
182 virtual void OnIceGatheringChange(
183 PeerConnectionInterface::IceGatheringState new_state) {
184 // We can never transition back to "new".
185 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
186 ice_gathering_state_ = new_state;
187
188 // oncandidatesready_ really means "ICE gathering is complete".
189 // This if statement ensures that this value remains correct when we
190 // transition from kIceGatheringComplete to kIceGatheringGathering.
191 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
192 oncandidatesready_ = false;
193 }
194 }
195
196 // Found a new candidate.
197 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000198 switch (candidate->sdp_mline_index()) {
199 case kMediaContentIndex0:
200 mline_0_candidates_.push_back(candidate->candidate());
201 break;
202 case kMediaContentIndex1:
203 mline_1_candidates_.push_back(candidate->candidate());
204 break;
205 default:
206 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000207 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000208
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000209 // The ICE gathering state should always be Gathering when a candidate is
210 // received (or possibly Completed in the case of the final candidate).
211 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
212 }
213
214 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
215 virtual void OnIceComplete() {
216 EXPECT_FALSE(oncandidatesready_);
217 oncandidatesready_ = true;
218
219 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
220 // be called approximately simultaneously. For ease of testing, this
221 // check additionally requires that they be called in the above order.
222 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
223 ice_gathering_state_);
224 }
225
226 bool oncandidatesready_;
227 std::vector<cricket::Candidate> mline_0_candidates_;
228 std::vector<cricket::Candidate> mline_1_candidates_;
229 PeerConnectionInterface::IceConnectionState ice_connection_state_;
230 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
231};
232
233class WebRtcSessionForTest : public webrtc::WebRtcSession {
234 public:
235 WebRtcSessionForTest(cricket::ChannelManager* cmgr,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000236 rtc::Thread* signaling_thread,
237 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000238 cricket::PortAllocator* port_allocator,
239 webrtc::IceObserver* ice_observer,
240 webrtc::MediaStreamSignaling* mediastream_signaling)
241 : WebRtcSession(cmgr, signaling_thread, worker_thread, port_allocator,
242 mediastream_signaling) {
243 RegisterIceObserver(ice_observer);
244 }
245 virtual ~WebRtcSessionForTest() {}
246
247 using cricket::BaseSession::GetTransportProxy;
248 using webrtc::WebRtcSession::SetAudioPlayout;
249 using webrtc::WebRtcSession::SetAudioSend;
250 using webrtc::WebRtcSession::SetCaptureDevice;
251 using webrtc::WebRtcSession::SetVideoPlayout;
252 using webrtc::WebRtcSession::SetVideoSend;
253};
254
wu@webrtc.org91053e72013-08-10 07:18:04 +0000255class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000256 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000258 enum State {
259 kInit,
260 kFailed,
261 kSucceeded,
262 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000263 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000264
265 // CreateSessionDescriptionObserver implementation.
266 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000267 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000268 state_ = kSucceeded;
269 }
270 virtual void OnFailure(const std::string& error) {
271 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000272 }
273
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000274 SessionDescriptionInterface* description() { return description_.get(); }
275
276 SessionDescriptionInterface* ReleaseDescription() {
277 return description_.release();
278 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000279
wu@webrtc.org91053e72013-08-10 07:18:04 +0000280 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000281
wu@webrtc.org91053e72013-08-10 07:18:04 +0000282 protected:
283 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000284
285 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000286 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000287 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000288};
289
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000290class FakeAudioRenderer : public cricket::AudioRenderer {
291 public:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000292 FakeAudioRenderer() : channel_id_(-1), sink_(NULL) {}
293 virtual ~FakeAudioRenderer() {
294 if (sink_)
295 sink_->OnClose();
296 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000297
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000298 void AddChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000299 ASSERT(channel_id_ == -1);
300 channel_id_ = channel_id;
301 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000302 void RemoveChannel(int channel_id) override {
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000303 ASSERT(channel_id == channel_id_);
304 channel_id_ = -1;
305 }
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000306 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000307
308 int channel_id() const { return channel_id_; }
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000309 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000310 private:
311 int channel_id_;
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000312 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000313};
314
Henrik Boström87713d02015-08-25 09:53:21 +0200315class WebRtcSessionTest
316 : public testing::TestWithParam<RTCCertificateGenerationMethod> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000317 protected:
318 // TODO Investigate why ChannelManager crashes, if it's created
319 // after stun_server.
320 WebRtcSessionTest()
321 : media_engine_(new cricket::FakeMediaEngine()),
322 data_engine_(new cricket::FakeDataEngine()),
323 device_manager_(new cricket::FakeDeviceManager()),
324 channel_manager_(new cricket::ChannelManager(
325 media_engine_, data_engine_, device_manager_,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000326 new cricket::CaptureManager(), rtc::Thread::Current())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327 tdesc_factory_(new cricket::TransportDescriptionFactory()),
328 desc_factory_(new cricket::MediaSessionDescriptionFactory(
329 channel_manager_.get(), tdesc_factory_.get())),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000330 pss_(new rtc::PhysicalSocketServer),
331 vss_(new rtc::VirtualSocketServer(pss_.get())),
332 fss_(new rtc::FirewallSocketServer(vss_.get())),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000333 ss_scope_(fss_.get()),
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000334 stun_socket_addr_(rtc::SocketAddress(kStunAddrHost,
wu@webrtc.org364f2042013-11-20 21:49:41 +0000335 cricket::STUN_SERVER_PORT)),
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +0000336 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
337 stun_socket_addr_)),
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000338 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
jbauchac8869e2015-07-03 01:36:14 -0700339 mediastream_signaling_(channel_manager_.get()),
340 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000341 cricket::ServerAddresses stun_servers;
342 stun_servers.insert(stun_socket_addr_);
343 allocator_.reset(new cricket::BasicPortAllocator(
344 &network_manager_,
345 stun_servers,
346 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000347 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher2159b892015-08-21 20:46:05 -0700348 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000349 EXPECT_TRUE(channel_manager_->Init());
350 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000351 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000352 }
353
354 void AddInterface(const SocketAddress& addr) {
355 network_manager_.AddInterface(addr);
356 }
357
Henrik Boström87713d02015-08-25 09:53:21 +0200358 // If |dtls_identity_store| != null or |rtc_configuration| contains
359 // |certificates| then DTLS will be enabled unless explicitly disabled by
360 // |rtc_configuration| options. When DTLS is enabled a certificate will be
361 // used if provided, otherwise one will be generated using the
362 // |dtls_identity_store|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000363 void Init(
Henrik Boström5e56c592015-08-11 10:33:13 +0200364 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store,
Henrik Lundin64dad832015-05-11 12:44:23 +0200365 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000366 ASSERT_TRUE(session_.get() == NULL);
367 session_.reset(new WebRtcSessionForTest(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000368 channel_manager_.get(), rtc::Thread::Current(),
369 rtc::Thread::Current(), allocator_.get(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000370 &observer_,
371 &mediastream_signaling_));
372
373 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
374 observer_.ice_connection_state_);
375 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
376 observer_.ice_gathering_state_);
377
Henrik Boström5e56c592015-08-11 10:33:13 +0200378 EXPECT_TRUE(session_->Initialize(
379 options_, constraints_.get(), dtls_identity_store.Pass(),
380 rtc_configuration));
jbauchac8869e2015-07-03 01:36:14 -0700381 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000382 }
383
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000384 void Init() {
Henrik Lundin64dad832015-05-11 12:44:23 +0200385 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200386 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000387 }
388
389 void InitWithIceTransport(
390 PeerConnectionInterface::IceTransportsType ice_transport_type) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200391 PeerConnectionInterface::RTCConfiguration configuration;
392 configuration.type = ice_transport_type;
Henrik Boström5e56c592015-08-11 10:33:13 +0200393 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000394 }
395
396 void InitWithBundlePolicy(
397 PeerConnectionInterface::BundlePolicy bundle_policy) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200398 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Lundin64dad832015-05-11 12:44:23 +0200399 configuration.bundle_policy = bundle_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200400 Init(nullptr, configuration);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700401 }
402
403 void InitWithRtcpMuxPolicy(
404 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
405 PeerConnectionInterface::RTCConfiguration configuration;
406 configuration.rtcp_mux_policy = rtcp_mux_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200407 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000408 }
409
Henrik Boström87713d02015-08-25 09:53:21 +0200410 // Successfully init with DTLS; with a certificate generated and supplied or
411 // with a store that generates it for us.
412 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
413 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store;
414 PeerConnectionInterface::RTCConfiguration configuration;
415 if (cert_gen_method == ALREADY_GENERATED) {
416 configuration.certificates.push_back(
417 FakeDtlsIdentityStore::GenerateCertificate());
418 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
419 dtls_identity_store.reset(new FakeDtlsIdentityStore());
420 dtls_identity_store->set_should_fail(false);
421 } else {
422 CHECK(false);
423 }
424 Init(dtls_identity_store.Pass(), configuration);
425 }
426
427 // Init with DTLS with a store that will fail to generate a certificate.
428 void InitWithDtlsIdentityGenFail() {
Henrik Boström5e56c592015-08-11 10:33:13 +0200429 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
430 new FakeDtlsIdentityStore());
Henrik Boström87713d02015-08-25 09:53:21 +0200431 dtls_identity_store->set_should_fail(true);
Henrik Lundin64dad832015-05-11 12:44:23 +0200432 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200433 Init(dtls_identity_store.Pass(), configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000434 }
435
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000436 void InitWithDtmfCodec() {
437 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000438 const cricket::AudioCodec kTelephoneEventCodec(
439 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000440 std::vector<cricket::AudioCodec> codecs;
441 codecs.push_back(kTelephoneEventCodec);
442 media_engine_->SetAudioCodecs(codecs);
443 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000444 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000445 }
446
447 // Creates a local offer and applies it. Starts ice.
448 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
449 // to decide which streams to create.
450 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000451 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000452 SetLocalDescriptionWithoutError(offer);
453 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
454 observer_.ice_gathering_state_,
455 kIceCandidatesTimeout);
456 }
457
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000458 SessionDescriptionInterface* CreateOffer() {
459 PeerConnectionInterface::RTCOfferAnswerOptions options;
460 options.offer_to_receive_audio =
461 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
462
463 return CreateOffer(options);
464 }
465
wu@webrtc.org91053e72013-08-10 07:18:04 +0000466 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000467 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000468 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000469 observer = new WebRtcSessionCreateSDPObserverForTest();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000470 session_->CreateOffer(observer, options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000471 EXPECT_TRUE_WAIT(
472 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000473 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000474 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000475 }
476
477 SessionDescriptionInterface* CreateAnswer(
478 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000479 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000480 = new WebRtcSessionCreateSDPObserverForTest();
481 session_->CreateAnswer(observer, constraints);
482 EXPECT_TRUE_WAIT(
483 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000484 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000485 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000486 }
487
wu@webrtc.org364f2042013-11-20 21:49:41 +0000488 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000489 return (session_->voice_channel() != NULL &&
490 session_->video_channel() != NULL);
491 }
492
wu@webrtc.org364f2042013-11-20 21:49:41 +0000493 void CheckTransportChannels() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000494 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 1) != NULL);
495 EXPECT_TRUE(session_->GetChannel(cricket::CN_AUDIO, 2) != NULL);
496 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 1) != NULL);
497 EXPECT_TRUE(session_->GetChannel(cricket::CN_VIDEO, 2) != NULL);
498 }
499
500 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
501 ASSERT_TRUE(session_.get() != NULL);
502 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
503 ASSERT_TRUE(content != NULL);
504 const cricket::AudioContentDescription* audio_content =
505 static_cast<const cricket::AudioContentDescription*>(
506 content->description);
507 ASSERT_TRUE(audio_content != NULL);
508 ASSERT_EQ(1U, audio_content->cryptos().size());
509 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
510 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
511 audio_content->cryptos()[0].cipher_suite);
512 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
513 audio_content->protocol());
514
515 content = cricket::GetFirstVideoContent(sdp);
516 ASSERT_TRUE(content != NULL);
517 const cricket::VideoContentDescription* video_content =
518 static_cast<const cricket::VideoContentDescription*>(
519 content->description);
520 ASSERT_TRUE(video_content != NULL);
521 ASSERT_EQ(1U, video_content->cryptos().size());
522 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
523 video_content->cryptos()[0].cipher_suite);
524 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
525 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
526 video_content->protocol());
527 }
528
529 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
530 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
531 ASSERT_TRUE(content != NULL);
532 const cricket::AudioContentDescription* audio_content =
533 static_cast<const cricket::AudioContentDescription*>(
534 content->description);
535 ASSERT_TRUE(audio_content != NULL);
536 ASSERT_EQ(0U, audio_content->cryptos().size());
537
538 content = cricket::GetFirstVideoContent(sdp);
539 ASSERT_TRUE(content != NULL);
540 const cricket::VideoContentDescription* video_content =
541 static_cast<const cricket::VideoContentDescription*>(
542 content->description);
543 ASSERT_TRUE(video_content != NULL);
544 ASSERT_EQ(0U, video_content->cryptos().size());
545
546 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700547 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000548 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700549 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000550 video_content->protocol());
551 } else {
552 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
553 audio_content->protocol());
554 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
555 video_content->protocol());
556 }
557 }
558
559 // Set the internal fake description factories to do DTLS-SRTP.
560 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000561 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000562 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000563 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200564 // Confirmed to work with KT_RSA and KT_ECDSA.
565 identity_.reset(rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT));
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000566 tdesc_factory_->set_identity(identity_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000567 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
568 }
569
570 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
571 bool expected) {
572 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
573 ASSERT_TRUE(audio != NULL);
574 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000575 const TransportInfo* video = sdp->GetTransportInfoByName("video");
576 ASSERT_TRUE(video != NULL);
577 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000578 }
579
580 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000581 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000582 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000583 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000584 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000585 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000586 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000587 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000588 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
589 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000590 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000591 // Answer should be NULL as no crypto params in offer.
592 ASSERT_TRUE(answer == NULL);
593 }
594
595 void VerifyAnswerFromCryptoOffer() {
596 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000597 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000598 options.bundle_enabled = true;
599 scoped_ptr<JsepSessionDescription> offer(
600 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
601 ASSERT_TRUE(offer.get() != NULL);
602 VerifyCryptoParams(offer->description());
603 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000604 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000605 ASSERT_TRUE(answer.get() != NULL);
606 VerifyCryptoParams(answer->description());
607 }
608
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000609 void SetAndVerifyNumUnsignalledRecvStreams(
610 int value_set, int value_expected) {
611 constraints_.reset(new FakeConstraints());
612 constraints_->AddOptional(
613 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
614 value_set);
615 session_.reset();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000616 Init();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000617 mediastream_signaling_.SendAudioVideoStream1();
618 SessionDescriptionInterface* offer = CreateOffer();
619
620 SetLocalDescriptionWithoutError(offer);
621
622 video_channel_ = media_engine_->GetVideoChannel(0);
623
624 ASSERT_TRUE(video_channel_ != NULL);
625 cricket::VideoOptions video_options;
626 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
627 EXPECT_EQ(value_expected,
628 video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1));
629 }
630
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000631 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
632 const cricket::SessionDescription* desc2,
633 bool expect_equal) {
634 if (desc1->contents().size() != desc2->contents().size()) {
635 EXPECT_FALSE(expect_equal);
636 return;
637 }
638
639 const cricket::ContentInfos& contents = desc1->contents();
640 cricket::ContentInfos::const_iterator it = contents.begin();
641
642 for (; it != contents.end(); ++it) {
643 const cricket::TransportDescription* transport_desc1 =
644 desc1->GetTransportDescriptionByName(it->name);
645 const cricket::TransportDescription* transport_desc2 =
646 desc2->GetTransportDescriptionByName(it->name);
647 if (!transport_desc1 || !transport_desc2) {
648 EXPECT_FALSE(expect_equal);
649 return;
650 }
651 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
652 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
653 EXPECT_FALSE(expect_equal);
654 return;
655 }
656 }
657 EXPECT_TRUE(expect_equal);
658 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000659
660 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
661 std::string *sdp) {
662 const cricket::SessionDescription* desc = current_desc->description();
663 EXPECT_TRUE(current_desc->ToString(sdp));
664
665 const cricket::ContentInfos& contents = desc->contents();
666 cricket::ContentInfos::const_iterator it = contents.begin();
667 // Replace ufrag and pwd lines with empty strings.
668 for (; it != contents.end(); ++it) {
669 const cricket::TransportDescription* transport_desc =
670 desc->GetTransportDescriptionByName(it->name);
671 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
672 + "\r\n";
673 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
674 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000675 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000676 "", 0,
677 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000678 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000679 "", 0,
680 sdp);
681 }
682 }
683
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000684 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
685 const std::string& modified_ice_ufrag,
686 const std::string& modified_ice_pwd,
687 std::string* sdp) {
688 const cricket::SessionDescription* desc = current_desc->description();
689 EXPECT_TRUE(current_desc->ToString(sdp));
690
691 const cricket::ContentInfos& contents = desc->contents();
692 cricket::ContentInfos::const_iterator it = contents.begin();
693 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
694 // |modified_ice_pwd| strings.
695 for (; it != contents.end(); ++it) {
696 const cricket::TransportDescription* transport_desc =
697 desc->GetTransportDescriptionByName(it->name);
698 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
699 + "\r\n";
700 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
701 + "\r\n";
702 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
703 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000704 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000705 mod_ufrag.c_str(), mod_ufrag.length(),
706 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000707 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000708 mod_pwd.c_str(), mod_pwd.length(),
709 sdp);
710 }
711 }
712
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000713 // Creates a remote offer and and applies it as a remote description,
714 // creates a local answer and applies is as a local description.
715 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
716 // to decide which local and remote streams to create.
717 void CreateAndSetRemoteOfferAndLocalAnswer() {
718 SessionDescriptionInterface* offer = CreateRemoteOffer();
719 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000720 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000721 SetLocalDescriptionWithoutError(answer);
722 }
723 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
724 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
725 }
726 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
727 BaseSession::State expected_state) {
728 SetLocalDescriptionWithoutError(desc);
729 EXPECT_EQ(expected_state, session_->state());
730 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000731 void SetLocalDescriptionExpectError(const std::string& action,
732 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000733 SessionDescriptionInterface* desc) {
734 std::string error;
735 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000736 std::string sdp_type = "local ";
737 sdp_type.append(action);
738 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000739 EXPECT_NE(std::string::npos, error.find(expected_error));
740 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000741 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
742 SessionDescriptionInterface* desc) {
743 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
744 expected_error, desc);
745 }
746 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
747 SessionDescriptionInterface* desc) {
748 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
749 expected_error, desc);
750 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000751 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
752 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
753 }
754 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
755 BaseSession::State expected_state) {
756 SetRemoteDescriptionWithoutError(desc);
757 EXPECT_EQ(expected_state, session_->state());
758 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000759 void SetRemoteDescriptionExpectError(const std::string& action,
760 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000761 SessionDescriptionInterface* desc) {
762 std::string error;
763 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000764 std::string sdp_type = "remote ";
765 sdp_type.append(action);
766 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000767 EXPECT_NE(std::string::npos, error.find(expected_error));
768 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000769 void SetRemoteDescriptionOfferExpectError(
770 const std::string& expected_error, SessionDescriptionInterface* desc) {
771 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
772 expected_error, desc);
773 }
774 void SetRemoteDescriptionPranswerExpectError(
775 const std::string& expected_error, SessionDescriptionInterface* desc) {
776 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
777 expected_error, desc);
778 }
779 void SetRemoteDescriptionAnswerExpectError(
780 const std::string& expected_error, SessionDescriptionInterface* desc) {
781 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
782 expected_error, desc);
783 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000784
785 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
786 SessionDescriptionInterface** nocrypto_answer) {
787 // Create a SDP without Crypto.
788 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000789 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000790 options.bundle_enabled = true;
791 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
792 ASSERT_TRUE(*offer != NULL);
793 VerifyCryptoParams((*offer)->description());
794
795 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
796 cricket::SEC_DISABLED);
797 EXPECT_TRUE(*nocrypto_answer != NULL);
798 }
799
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000800 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
801 SessionDescriptionInterface** nodtls_answer) {
802 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000803 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000804 options.bundle_enabled = true;
805
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000806 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000807 CreateRemoteOffer(options, cricket::SEC_ENABLED));
808
809 *nodtls_answer =
810 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
811 EXPECT_TRUE(*nodtls_answer != NULL);
812 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
813 VerifyCryptoParams((*nodtls_answer)->description());
814
815 SetFactoryDtlsSrtp();
816 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
817 ASSERT_TRUE(*offer != NULL);
818 VerifyFingerprintStatus((*offer)->description(), true);
819 VerifyCryptoParams((*offer)->description());
820 }
821
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822 JsepSessionDescription* CreateRemoteOfferWithVersion(
823 cricket::MediaSessionOptions options,
824 cricket::SecurePolicy secure_policy,
825 const std::string& session_version,
826 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000827 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000828 const cricket::SessionDescription* cricket_desc = NULL;
829 if (current_desc) {
830 cricket_desc = current_desc->description();
831 session_id = current_desc->session_id();
832 }
833
834 desc_factory_->set_secure(secure_policy);
835 JsepSessionDescription* offer(
836 new JsepSessionDescription(JsepSessionDescription::kOffer));
837 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
838 session_id, session_version)) {
839 delete offer;
840 offer = NULL;
841 }
842 return offer;
843 }
844 JsepSessionDescription* CreateRemoteOffer(
845 cricket::MediaSessionOptions options) {
846 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
847 kSessionVersion, NULL);
848 }
849 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000850 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
851 return CreateRemoteOfferWithVersion(
852 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853 }
854 JsepSessionDescription* CreateRemoteOffer(
855 cricket::MediaSessionOptions options,
856 const SessionDescriptionInterface* current_desc) {
857 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
858 kSessionVersion, current_desc);
859 }
860
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000861 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
862 const char* sctp_stream_name, int new_port,
863 cricket::MediaSessionOptions options) {
864 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000865 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
866 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000867 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
868 }
869
870 // Takes ownership of offer_basis (and deletes it).
871 JsepSessionDescription* ChangeSDPSctpPort(
872 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
873 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
874 // SessionDescription from the mutated string.
875 const char* default_port_str = "5000";
876 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000877 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000878 std::string offer_str;
879 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000880 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000881 new_port_str, strlen(new_port_str),
882 &offer_str);
883 JsepSessionDescription* offer = new JsepSessionDescription(
884 offer_basis->type());
885 delete offer_basis;
886 offer->Initialize(offer_str, NULL);
887 return offer;
888 }
889
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000890 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
891 // before this function to decide which streams to create.
892 JsepSessionDescription* CreateRemoteOffer() {
893 cricket::MediaSessionOptions options;
894 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
895 return CreateRemoteOffer(options, session_->remote_description());
896 }
897
898 JsepSessionDescription* CreateRemoteAnswer(
899 const SessionDescriptionInterface* offer,
900 cricket::MediaSessionOptions options,
901 cricket::SecurePolicy policy) {
902 desc_factory_->set_secure(policy);
903 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000904 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000905 JsepSessionDescription* answer(
906 new JsepSessionDescription(JsepSessionDescription::kAnswer));
907 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
908 options, NULL),
909 session_id, kSessionVersion)) {
910 delete answer;
911 answer = NULL;
912 }
913 return answer;
914 }
915
916 JsepSessionDescription* CreateRemoteAnswer(
917 const SessionDescriptionInterface* offer,
918 cricket::MediaSessionOptions options) {
919 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
920 }
921
922 // Creates an answer session description with streams based on
923 // |mediastream_signaling_|. Call
924 // mediastream_signaling_.UseOptionsWithStreamX() before this function
925 // to decide which streams to create.
926 JsepSessionDescription* CreateRemoteAnswer(
927 const SessionDescriptionInterface* offer) {
928 cricket::MediaSessionOptions options;
929 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
930 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
931 }
932
933 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000934 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000935 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000936 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000937
938 PeerConnectionInterface::RTCOfferAnswerOptions options;
939 options.use_rtp_mux = bundle;
940
941 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000942 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
943 // and answer.
944 SetLocalDescriptionWithoutError(offer);
945
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000946 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000947 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000948 std::string sdp;
949 EXPECT_TRUE(answer->ToString(&sdp));
950
951 size_t expected_candidate_num = 2;
952 if (!rtcp_mux) {
953 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
954 // for rtp and rtcp.
955 expected_candidate_num = 4;
956 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000957 const std::string kRtcpMux = "a=rtcp-mux";
958 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000959 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000960 kXRtcpMux.c_str(), kXRtcpMux.length(),
961 &sdp);
962 }
963
964 SessionDescriptionInterface* new_answer = CreateSessionDescription(
965 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000966
967 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000968 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000969 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
970 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
971 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
972 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
973 cricket::Candidate c0 = observer_.mline_0_candidates_[i];
974 cricket::Candidate c1 = observer_.mline_1_candidates_[i];
975 if (bundle) {
976 EXPECT_TRUE(c0.IsEquivalent(c1));
977 } else {
978 EXPECT_FALSE(c0.IsEquivalent(c1));
979 }
980 }
981 }
982 // Tests that we can only send DTMF when the dtmf codec is supported.
983 void TestCanInsertDtmf(bool can) {
984 if (can) {
985 InitWithDtmfCodec();
986 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000987 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000988 }
989 mediastream_signaling_.SendAudioVideoStream1();
990 CreateAndSetRemoteOfferAndLocalAnswer();
991 EXPECT_FALSE(session_->CanInsertDtmf(""));
992 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
993 }
994
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000995 // Helper class to configure loopback network and verify Best
996 // Connection using right IP protocol for TestLoopbackCall
997 // method. LoopbackNetworkManager applies firewall rules to block
998 // all ping traffic once ICE completed, and remove them to observe
999 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1000 // verifies the best connection is using the right IP protocol after
1001 // initial ICE convergences.
1002
1003 class LoopbackNetworkConfiguration {
1004 public:
1005 LoopbackNetworkConfiguration()
1006 : test_ipv6_network_(false),
1007 test_extra_ipv4_network_(false),
1008 best_connection_after_initial_ice_converged_(1, 0) {}
1009
1010 // Used to track the expected best connection count in each IP protocol.
1011 struct ExpectedBestConnection {
1012 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1013 : ipv4_count_(ipv4_count),
1014 ipv6_count_(ipv6_count) {}
1015
1016 int ipv4_count_;
1017 int ipv6_count_;
1018 };
1019
1020 bool test_ipv6_network_;
1021 bool test_extra_ipv4_network_;
1022 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1023
1024 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001025 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001026 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1027 }
1028
1029 private:
jbauchac8869e2015-07-03 01:36:14 -07001030 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001031 const ExpectedBestConnection& expected) const {
1032 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001033 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1034 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001035 expected.ipv4_count_);
1036 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001037 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1038 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001039 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001040 // This is used in the loopback call so there is only single host to host
1041 // candidate pair.
1042 EXPECT_EQ(metrics_observer->GetEnumCounter(
1043 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1044 webrtc::kIceCandidatePairHostHost),
1045 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001046 }
1047 };
1048
1049 class LoopbackNetworkManager {
1050 public:
1051 LoopbackNetworkManager(WebRtcSessionTest* session,
1052 const LoopbackNetworkConfiguration& config)
1053 : config_(config) {
1054 session->AddInterface(
1055 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1056 if (config_.test_extra_ipv4_network_) {
1057 session->AddInterface(
1058 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1059 }
1060 if (config_.test_ipv6_network_) {
1061 session->AddInterface(
1062 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1063 }
1064 }
1065
1066 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1067 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1068 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1069 if (config_.test_extra_ipv4_network_) {
1070 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1071 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1072 }
1073 if (config_.test_ipv6_network_) {
1074 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1075 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1076 }
1077 }
1078
1079 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1080
1081 private:
1082 LoopbackNetworkConfiguration config_;
1083 };
1084
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001085 // The method sets up a call from the session to itself, in a loopback
1086 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001087 // disconnection, and then a permanent disconnection.
1088 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001089 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1090 // While running the call, this method also checks if the session goes through
1091 // the correct sequence of ICE states when a connection is established,
1092 // broken, and re-established.
1093 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001094 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1095 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001096 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001097
1098 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1099 LoopbackNetworkManager loopback_network_manager(this, config);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001100 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001101 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001102 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001103
1104 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1105 observer_.ice_gathering_state_);
1106 SetLocalDescriptionWithoutError(offer);
1107 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1108 observer_.ice_connection_state_);
1109 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
1110 observer_.ice_gathering_state_,
1111 kIceCandidatesTimeout);
1112 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1113 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
1114 observer_.ice_gathering_state_,
1115 kIceCandidatesTimeout);
1116
1117 std::string sdp;
1118 offer->ToString(&sdp);
1119 SessionDescriptionInterface* desc =
jbauchfabe2c92015-07-16 13:43:14 -07001120 webrtc::CreateSessionDescription(
1121 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001122 ASSERT_TRUE(desc != NULL);
1123 SetRemoteDescriptionWithoutError(desc);
1124
1125 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
1126 observer_.ice_connection_state_,
1127 kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001128
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001129 // The ice connection state is "Connected" too briefly to catch in a test.
1130 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001131 observer_.ice_connection_state_,
1132 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001133
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001134 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001135 // Adding firewall rule to block ping requests, which should cause
1136 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001137
1138 loopback_network_manager.ApplyFirewallRules(fss_.get());
1139
1140 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001141 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1142 observer_.ice_connection_state_,
1143 kIceCandidatesTimeout);
1144
jbauchac8869e2015-07-03 01:36:14 -07001145 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001146
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001147 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001148 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001149 // Session is automatically calling OnSignalingReady after creation of
1150 // new portallocator session which will allocate new set of candidates.
1151
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001152 LOG(LS_INFO) << "Firewall Rules cleared";
1153
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001154 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001155 observer_.ice_connection_state_,
1156 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001157
1158 // Now we block ping requests and wait until the ICE connection transitions
1159 // to the Failed state. This will take at least 30 seconds because it must
1160 // wait for the Port to timeout.
1161 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001162
1163 loopback_network_manager.ApplyFirewallRules(fss_.get());
1164 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001165 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001166 observer_.ice_connection_state_,
1167 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001168 }
1169
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001170 void TestLoopbackCall() {
1171 LoopbackNetworkConfiguration config;
1172 TestLoopbackCall(config);
1173 }
1174
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001175 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1176 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001177 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1178 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1179
1180 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001181 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1182 codecs.push_back(kCNCodec1);
1183 codecs.push_back(kCNCodec2);
1184 media_engine_->SetAudioCodecs(codecs);
1185 desc_factory_->set_audio_codecs(codecs);
1186 }
1187
1188 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1189 const cricket::ContentDescription* description = content->description;
1190 ASSERT(description != NULL);
1191 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001192 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001193 ASSERT(audio_content_desc != NULL);
1194 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1195 if (audio_content_desc->codecs()[i].name == "CN")
1196 return false;
1197 }
1198 return true;
1199 }
1200
1201 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001202 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001203 dci.reliable = false;
1204 session_->CreateDataChannel("datachannel", &dci);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001205 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001206 SetLocalDescriptionWithoutError(offer);
1207 }
1208
wu@webrtc.org91053e72013-08-10 07:18:04 +00001209 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001210 RTCCertificateGenerationMethod cert_gen_method,
1211 CreateSessionDescriptionRequest::Type type) {
1212 InitWithDtls(cert_gen_method);
1213 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1214 }
1215
1216 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1217 CreateSessionDescriptionRequest::Type type) {
1218 InitWithDtlsIdentityGenFail();
1219 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1220 }
1221
1222 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001223 bool success, CreateSessionDescriptionRequest::Type type) {
Henrik Boström87713d02015-08-25 09:53:21 +02001224 CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001225 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001226 if (type == CreateSessionDescriptionRequest::kAnswer) {
1227 cricket::MediaSessionOptions options;
1228 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001229 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001230 ASSERT_TRUE(offer.get() != NULL);
1231 SetRemoteDescriptionWithoutError(offer.release());
1232 }
1233
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001234 PeerConnectionInterface::RTCOfferAnswerOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001235 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001236 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001237 observers[kNumber];
1238 for (int i = 0; i < kNumber; ++i) {
1239 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1240 if (type == CreateSessionDescriptionRequest::kOffer) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001241 session_->CreateOffer(observers[i], options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001242 } else {
1243 session_->CreateAnswer(observers[i], NULL);
1244 }
1245 }
1246
1247 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1248 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1249 WebRtcSessionCreateSDPObserverForTest::kFailed;
1250
1251 for (int i = 0; i < kNumber; ++i) {
1252 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1253 if (success) {
1254 EXPECT_TRUE(observers[i]->description() != NULL);
1255 } else {
1256 EXPECT_TRUE(observers[i]->description() == NULL);
1257 }
1258 }
1259 }
1260
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001261 void ConfigureAllocatorWithTurn() {
1262 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1263 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
1264 relay_server.credentials = credentials;
1265 relay_server.ports.push_back(cricket::ProtocolAddress(
1266 kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1267 allocator_->AddRelay(relay_server);
1268 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher2159b892015-08-21 20:46:05 -07001269 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001270 }
1271
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001272 cricket::FakeMediaEngine* media_engine_;
1273 cricket::FakeDataEngine* data_engine_;
1274 cricket::FakeDeviceManager* device_manager_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001275 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
1276 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1277 rtc::scoped_ptr<rtc::SSLIdentity> identity_;
1278 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1279 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1280 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1281 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1282 rtc::SocketServerScope ss_scope_;
1283 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001284 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001285 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001286 rtc::FakeNetworkManager network_manager_;
1287 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001288 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001289 rtc::scoped_ptr<FakeConstraints> constraints_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290 FakeMediaStreamSignaling mediastream_signaling_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001291 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001292 MockIceObserver observer_;
1293 cricket::FakeVideoMediaChannel* video_channel_;
1294 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001295 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001296};
1297
Henrik Boström87713d02015-08-25 09:53:21 +02001298TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1299 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001300 // SDES is disabled when DTLS is on.
1301 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001302}
1303
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001304TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001305 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001306 // SDES is required if DTLS is off.
1307 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001308}
1309
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001310TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1311 TestSessionCandidatesWithBundleRtcpMux(false, false);
1312}
1313
1314// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1315// with rtcp-mux and/or bundle.
1316TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1317 TestSessionCandidatesWithBundleRtcpMux(false, true);
1318}
1319
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001320TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1321 TestSessionCandidatesWithBundleRtcpMux(true, true);
1322}
1323
1324TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001325 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1326 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001327 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001328 mediastream_signaling_.SendAudioVideoStream1();
1329 InitiateCall();
1330 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1331 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1332 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1333}
1334
1335TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001336 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1337 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001338 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001339 rtc::FP_UDP,
1340 rtc::FD_ANY,
1341 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001342 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001343 mediastream_signaling_.SendAudioVideoStream1();
1344 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001345 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001346 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1347 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1348 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1349}
1350
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001351// Test session delivers no candidates gathered when constraint set to "none".
1352TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1353 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001354 InitWithIceTransport(PeerConnectionInterface::kNone);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001355 mediastream_signaling_.SendAudioVideoStream1();
1356 InitiateCall();
1357 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1358 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1359 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1360}
1361
1362// Test session delivers only relay candidates gathered when constaint set to
1363// "relay".
1364TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1365 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1366 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001367 InitWithIceTransport(PeerConnectionInterface::kRelay);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001368 mediastream_signaling_.SendAudioVideoStream1();
1369 InitiateCall();
1370 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1371 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1372 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1373 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1374 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1375 observer_.mline_0_candidates_[i].type());
1376 }
1377 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1378 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1379 observer_.mline_1_candidates_[i].type());
1380 }
1381}
1382
1383// Test session delivers all candidates gathered when constaint set to "all".
1384TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1385 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001386 InitWithIceTransport(PeerConnectionInterface::kAll);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001387 mediastream_signaling_.SendAudioVideoStream1();
1388 InitiateCall();
1389 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1390 // Host + STUN. By default allocator is disabled to gather relay candidates.
1391 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1392 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1393}
1394
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001395TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001396 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001397 SessionDescriptionInterface* offer = NULL;
1398 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1399 std::string unknown_action;
1400 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1401 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1402}
1403
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001404// Test creating offers and receive answers and make sure the
1405// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001406TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001407 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001408 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001409 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001410 const std::string session_id_orig = offer->session_id();
1411 const std::string session_version_orig = offer->session_version();
1412 SetLocalDescriptionWithoutError(offer);
1413
1414 mediastream_signaling_.SendAudioVideoStream2();
1415 SessionDescriptionInterface* answer =
1416 CreateRemoteAnswer(session_->local_description());
1417 SetRemoteDescriptionWithoutError(answer);
1418
1419 video_channel_ = media_engine_->GetVideoChannel(0);
1420 voice_channel_ = media_engine_->GetVoiceChannel(0);
1421
1422 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1423 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1424
1425 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1426 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1427
1428 ASSERT_EQ(1u, video_channel_->send_streams().size());
1429 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1430 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1431 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1432
1433 // Create new offer without send streams.
1434 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001435 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001436
1437 // Verify the session id is the same and the session version is
1438 // increased.
1439 EXPECT_EQ(session_id_orig, offer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001440 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1441 rtc::FromString<uint64>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001442
1443 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001444 EXPECT_EQ(0u, video_channel_->send_streams().size());
1445 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001446
1447 mediastream_signaling_.SendAudioVideoStream2();
1448 answer = CreateRemoteAnswer(session_->local_description());
1449 SetRemoteDescriptionWithoutError(answer);
1450
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001451 // Make sure the receive streams have not changed.
1452 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1453 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1454 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1455 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1456}
1457
1458// Test receiving offers and creating answers and make sure the
1459// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001460TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001461 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001462 mediastream_signaling_.SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001463 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001464 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001465 SetRemoteDescriptionWithoutError(offer);
1466
1467 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001468 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001469 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001470 SetLocalDescriptionWithoutError(answer);
1471
1472 const std::string session_id_orig = answer->session_id();
1473 const std::string session_version_orig = answer->session_version();
1474
1475 video_channel_ = media_engine_->GetVideoChannel(0);
1476 voice_channel_ = media_engine_->GetVoiceChannel(0);
1477
1478 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1479 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1480
1481 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1482 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1483
1484 ASSERT_EQ(1u, video_channel_->send_streams().size());
1485 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1486 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1487 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1488
1489 mediastream_signaling_.SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001490 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001491 SetRemoteDescriptionWithoutError(offer);
1492
1493 // Answer by turning off all send streams.
1494 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001495 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001496
1497 // Verify the session id is the same and the session version is
1498 // increased.
1499 EXPECT_EQ(session_id_orig, answer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001500 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1501 rtc::FromString<uint64>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001502 SetLocalDescriptionWithoutError(answer);
1503
1504 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1505 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1506 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1507 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1508 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1509 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1510
1511 // Make sure we have no send streams.
1512 EXPECT_EQ(0u, video_channel_->send_streams().size());
1513 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1514}
1515
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001516TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001517 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001518 media_engine_->set_fail_create_channel(true);
1519
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001520 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001521 ASSERT_TRUE(offer != NULL);
1522 // SetRemoteDescription and SetLocalDescription will take the ownership of
1523 // the offer.
1524 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001525 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001526 ASSERT_TRUE(offer != NULL);
1527 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1528}
1529
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001530//
1531// Tests for creating/setting SDP under different SDES/DTLS polices:
1532//
1533// --DTLS off and SDES on
1534// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1535// set local/remote offer/answer with crypto --> success
1536// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1537// failure
1538// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1539// failure
1540// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1541// failure
1542//
1543// --DTLS on and SDES off
1544// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1545// set local/remote offer/answer with DTLS fingerprint --> success
1546// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1547// fingerprint --> failure
1548// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1549// --> failure
1550// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1551// --> failure
1552//
1553// --Encryption disabled: DTLS off and SDES off
1554// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1555// answer without SDES or DTLS --> success
1556// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1557// answer without SDES or DTLS --> success
1558//
1559
1560// Test that we return a failure when applying a remote/local offer that doesn't
1561// have cryptos enabled when DTLS is off.
1562TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001563 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001564 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001565 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001566 JsepSessionDescription* offer = CreateRemoteOffer(
1567 options, cricket::SEC_DISABLED);
1568 ASSERT_TRUE(offer != NULL);
1569 VerifyNoCryptoParams(offer->description(), false);
1570 // SetRemoteDescription and SetLocalDescription will take the ownership of
1571 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001572 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001573 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1574 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001575 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001576}
1577
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001578// Test that we return a failure when applying a local answer that doesn't have
1579// cryptos enabled when DTLS is off.
1580TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001581 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001582 SessionDescriptionInterface* offer = NULL;
1583 SessionDescriptionInterface* answer = NULL;
1584 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1585 // SetRemoteDescription and SetLocalDescription will take the ownership of
1586 // the offer.
1587 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001588 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001589}
1590
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001591// Test we will return fail when apply an remote answer that doesn't have
1592// crypto enabled when DTLS is off.
1593TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001594 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001595 SessionDescriptionInterface* offer = NULL;
1596 SessionDescriptionInterface* answer = NULL;
1597 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1598 // SetRemoteDescription and SetLocalDescription will take the ownership of
1599 // the offer.
1600 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001601 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001602}
1603
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001604// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1605// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001606TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001607 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001608 mediastream_signaling_.SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001609 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001610 SetFactoryDtlsSrtp();
1611 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001612 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001613 JsepSessionDescription* offer =
1614 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001615 ASSERT_TRUE(offer != NULL);
1616 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001617 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001618
1619 // SetRemoteDescription will take the ownership of the offer.
1620 SetRemoteDescriptionWithoutError(offer);
1621
1622 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001623 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001624 ASSERT_TRUE(answer != NULL);
1625 VerifyFingerprintStatus(answer->description(), true);
1626 // Check that we don't have an a=crypto line in the answer.
1627 VerifyNoCryptoParams(answer->description(), true);
1628
1629 // Now set the local description, which should work, even without a=crypto.
1630 SetLocalDescriptionWithoutError(answer);
1631}
1632
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001633// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1634// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001635TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001636 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001637 mediastream_signaling_.SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001638 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001639 SetFactoryDtlsSrtp();
1640
1641 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001642 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001643 ASSERT_TRUE(offer != NULL);
1644 VerifyFingerprintStatus(offer->description(), true);
1645 // Check that we don't have an a=crypto line in the offer.
1646 VerifyNoCryptoParams(offer->description(), true);
1647
1648 // Now set the local description, which should work, even without a=crypto.
1649 SetLocalDescriptionWithoutError(offer);
1650
1651 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001652 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001653 JsepSessionDescription* answer =
1654 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1655 ASSERT_TRUE(answer != NULL);
1656 VerifyFingerprintStatus(answer->description(), true);
1657 VerifyNoCryptoParams(answer->description(), true);
1658
1659 // SetRemoteDescription will take the ownership of the answer.
1660 SetRemoteDescriptionWithoutError(answer);
1661}
1662
1663// Test that if we support DTLS and the other side didn't offer a fingerprint,
1664// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001665TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001666 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001667 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001668 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001669 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001670 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001671 JsepSessionDescription* offer = CreateRemoteOffer(
1672 options, cricket::SEC_REQUIRED);
1673 ASSERT_TRUE(offer != NULL);
1674 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001675 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001676
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001677 // SetRemoteDescription will take the ownership of the offer.
1678 SetRemoteDescriptionOfferExpectError(
1679 kSdpWithoutDtlsFingerprint, offer);
1680
1681 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1682 // SetLocalDescription will take the ownership of the offer.
1683 SetLocalDescriptionOfferExpectError(
1684 kSdpWithoutDtlsFingerprint, offer);
1685}
1686
1687// Test that we return a failure when applying a local answer that doesn't have
1688// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001689TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001690 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001691 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001692 SessionDescriptionInterface* offer = NULL;
1693 SessionDescriptionInterface* answer = NULL;
1694 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1695
1696 // SetRemoteDescription and SetLocalDescription will take the ownership of
1697 // the offer and answer.
1698 SetRemoteDescriptionWithoutError(offer);
1699 SetLocalDescriptionAnswerExpectError(
1700 kSdpWithoutDtlsFingerprint, answer);
1701}
1702
1703// Test that we return a failure when applying a remote answer that doesn't have
1704// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001705TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001706 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeeff3938292015-07-15 12:20:53 -07001707 // Enable both SDES and DTLS, so that offer won't be outright rejected as a
1708 // result of using the "UDP/TLS/RTP/SAVPF" profile.
Henrik Boström87713d02015-08-25 09:53:21 +02001709 InitWithDtls(GetParam());
deadbeeff3938292015-07-15 12:20:53 -07001710 session_->SetSdesPolicy(cricket::SEC_ENABLED);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001711 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001712 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001713 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001714 JsepSessionDescription* answer =
1715 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
1716
1717 // SetRemoteDescription and SetLocalDescription will take the ownership of
1718 // the offer and answer.
1719 SetLocalDescriptionWithoutError(offer);
1720 SetRemoteDescriptionAnswerExpectError(
1721 kSdpWithoutDtlsFingerprint, answer);
1722}
1723
1724// Test that we create a local offer without SDES or DTLS and accept a remote
1725// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001726TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001727 mediastream_signaling_.SendAudioVideoStream1();
1728 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001729 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001730
1731 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001732 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001733 ASSERT_TRUE(offer != NULL);
1734 VerifyFingerprintStatus(offer->description(), false);
1735 // Check that we don't have an a=crypto line in the offer.
1736 VerifyNoCryptoParams(offer->description(), false);
1737
1738 // Now set the local description, which should work, even without a=crypto.
1739 SetLocalDescriptionWithoutError(offer);
1740
1741 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001742 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001743 JsepSessionDescription* answer =
1744 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1745 ASSERT_TRUE(answer != NULL);
1746 VerifyFingerprintStatus(answer->description(), false);
1747 VerifyNoCryptoParams(answer->description(), false);
1748
1749 // SetRemoteDescription will take the ownership of the answer.
1750 SetRemoteDescriptionWithoutError(answer);
1751}
1752
1753// Test that we create a local answer without SDES or DTLS and accept a remote
1754// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001755TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001756 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001757 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001758
1759 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001760 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001761 JsepSessionDescription* offer =
1762 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1763 ASSERT_TRUE(offer != NULL);
1764 VerifyFingerprintStatus(offer->description(), false);
1765 VerifyNoCryptoParams(offer->description(), false);
1766
1767 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001768 SetRemoteDescriptionWithoutError(offer);
1769
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001770 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001771 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772 ASSERT_TRUE(answer != NULL);
1773 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001774 // Check that we don't have an a=crypto line in the answer.
1775 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001777 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778 SetLocalDescriptionWithoutError(answer);
1779}
1780
1781TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001782 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001783 mediastream_signaling_.SendNothing();
1784 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001785 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001786 SetLocalDescriptionWithoutError(offer);
1787
1788 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001789 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001790 SetLocalDescriptionWithoutError(offer2);
1791}
1792
1793TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001794 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001795 mediastream_signaling_.SendNothing();
1796 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001797 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001798 SetRemoteDescriptionWithoutError(offer);
1799
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001800 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001801 SetRemoteDescriptionWithoutError(offer2);
1802}
1803
1804TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001805 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001806 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001807 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001808 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001809 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001810 SetRemoteDescriptionOfferExpectError(
1811 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001812}
1813
1814TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001815 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001816 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001817 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001818 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001819 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001820 SetLocalDescriptionOfferExpectError(
1821 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001822}
1823
1824TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001825 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001826 mediastream_signaling_.SendNothing();
1827 SessionDescriptionInterface* offer = CreateRemoteOffer();
1828 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1829
1830 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001831 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001832 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1833 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1834
1835 mediastream_signaling_.SendAudioVideoStream1();
1836 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001837 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001838 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1839
1840 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1841
1842 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001843 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001844 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1845}
1846
1847TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001848 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001849 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001850 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001851 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1852
1853 JsepSessionDescription* pranswer =
1854 CreateRemoteAnswer(session_->local_description());
1855 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1856
1857 SetRemoteDescriptionExpectState(pranswer,
1858 BaseSession::STATE_RECEIVEDPRACCEPT);
1859
1860 mediastream_signaling_.SendAudioVideoStream1();
1861 JsepSessionDescription* pranswer2 =
1862 CreateRemoteAnswer(session_->local_description());
1863 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1864
1865 SetRemoteDescriptionExpectState(pranswer2,
1866 BaseSession::STATE_RECEIVEDPRACCEPT);
1867
1868 mediastream_signaling_.SendAudioVideoStream2();
1869 SessionDescriptionInterface* answer =
1870 CreateRemoteAnswer(session_->local_description());
1871 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1872}
1873
1874TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001875 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001876 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001877 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1878
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001879 SessionDescriptionInterface* answer =
1880 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001881 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1882 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001883}
1884
1885TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001886 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001887 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001888 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1889
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001890 SessionDescriptionInterface* answer =
1891 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001892 SetRemoteDescriptionAnswerExpectError(
1893 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001894}
1895
1896TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001897 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001898 mediastream_signaling_.SendAudioVideoStream1();
1899
1900 cricket::Candidate candidate;
1901 candidate.set_component(1);
1902 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1903
1904 // Fail since we have not set a offer description.
1905 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1906
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001907 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001908 SetLocalDescriptionWithoutError(offer);
1909 // Candidate should be allowed to add before remote description.
1910 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1911 candidate.set_component(2);
1912 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1913 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1914
1915 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1916 session_->local_description());
1917 SetRemoteDescriptionWithoutError(answer);
1918
1919 // Verifying the candidates are copied properly from internal vector.
1920 const SessionDescriptionInterface* remote_desc =
1921 session_->remote_description();
1922 ASSERT_TRUE(remote_desc != NULL);
1923 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1924 const IceCandidateCollection* candidates =
1925 remote_desc->candidates(kMediaContentIndex0);
1926 ASSERT_EQ(2u, candidates->count());
1927 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1928 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1929 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1930 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1931
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001932 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1933 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001934 candidate.set_component(2);
1935 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1936 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001937 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001938
1939 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1940 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1941}
1942
1943// Test that a remote candidate is added to the remote session description and
1944// that it is retained if the remote session description is changed.
1945TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001946 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001947 cricket::Candidate candidate1;
1948 candidate1.set_component(1);
1949 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1950 candidate1);
1951 mediastream_signaling_.SendAudioVideoStream1();
1952 CreateAndSetRemoteOfferAndLocalAnswer();
1953
1954 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1955 const SessionDescriptionInterface* remote_desc =
1956 session_->remote_description();
1957 ASSERT_TRUE(remote_desc != NULL);
1958 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1959 const IceCandidateCollection* candidates =
1960 remote_desc->candidates(kMediaContentIndex0);
1961 ASSERT_EQ(1u, candidates->count());
1962 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1963
1964 // Update the RemoteSessionDescription with a new session description and
1965 // a candidate and check that the new remote session description contains both
1966 // candidates.
1967 SessionDescriptionInterface* offer = CreateRemoteOffer();
1968 cricket::Candidate candidate2;
1969 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1970 candidate2);
1971 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1972 SetRemoteDescriptionWithoutError(offer);
1973
1974 remote_desc = session_->remote_description();
1975 ASSERT_TRUE(remote_desc != NULL);
1976 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1977 candidates = remote_desc->candidates(kMediaContentIndex0);
1978 ASSERT_EQ(2u, candidates->count());
1979 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1980 // Username and password have be updated with the TransportInfo of the
1981 // SessionDescription, won't be equal to the original one.
1982 candidate2.set_username(candidates->at(0)->candidate().username());
1983 candidate2.set_password(candidates->at(0)->candidate().password());
1984 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
1985 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
1986 // No need to verify the username and password.
1987 candidate1.set_username(candidates->at(1)->candidate().username());
1988 candidate1.set_password(candidates->at(1)->candidate().password());
1989 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
1990
1991 // Test that the candidate is ignored if we can add the same candidate again.
1992 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1993}
1994
1995// Test that local candidates are added to the local session description and
1996// that they are retained if the local session description is changed.
1997TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001998 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001999 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002000 mediastream_signaling_.SendAudioVideoStream1();
2001 CreateAndSetRemoteOfferAndLocalAnswer();
2002
2003 const SessionDescriptionInterface* local_desc = session_->local_description();
2004 const IceCandidateCollection* candidates =
2005 local_desc->candidates(kMediaContentIndex0);
2006 ASSERT_TRUE(candidates != NULL);
2007 EXPECT_EQ(0u, candidates->count());
2008
2009 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2010
2011 local_desc = session_->local_description();
2012 candidates = local_desc->candidates(kMediaContentIndex0);
2013 ASSERT_TRUE(candidates != NULL);
2014 EXPECT_LT(0u, candidates->count());
2015 candidates = local_desc->candidates(1);
2016 ASSERT_TRUE(candidates != NULL);
2017 EXPECT_LT(0u, candidates->count());
2018
2019 // Update the session descriptions.
2020 mediastream_signaling_.SendAudioVideoStream1();
2021 CreateAndSetRemoteOfferAndLocalAnswer();
2022
2023 local_desc = session_->local_description();
2024 candidates = local_desc->candidates(kMediaContentIndex0);
2025 ASSERT_TRUE(candidates != NULL);
2026 EXPECT_LT(0u, candidates->count());
2027 candidates = local_desc->candidates(1);
2028 ASSERT_TRUE(candidates != NULL);
2029 EXPECT_LT(0u, candidates->count());
2030}
2031
2032// Test that we can set a remote session description with remote candidates.
2033TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002034 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002035
2036 cricket::Candidate candidate1;
2037 candidate1.set_component(1);
2038 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2039 candidate1);
2040 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002041 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002042
2043 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2044 SetRemoteDescriptionWithoutError(offer);
2045
2046 const SessionDescriptionInterface* remote_desc =
2047 session_->remote_description();
2048 ASSERT_TRUE(remote_desc != NULL);
2049 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2050 const IceCandidateCollection* candidates =
2051 remote_desc->candidates(kMediaContentIndex0);
2052 ASSERT_EQ(1u, candidates->count());
2053 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2054
wu@webrtc.org91053e72013-08-10 07:18:04 +00002055 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002056 SetLocalDescriptionWithoutError(answer);
2057}
2058
2059// Test that offers and answers contains ice candidates when Ice candidates have
2060// been gathered.
2061TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002062 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002063 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002064 mediastream_signaling_.SendAudioVideoStream1();
2065 // Ice is started but candidates are not provided until SetLocalDescription
2066 // is called.
2067 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2068 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2069 CreateAndSetRemoteOfferAndLocalAnswer();
2070 // Wait until at least one local candidate has been collected.
2071 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2072 kIceCandidatesTimeout);
2073 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
2074 kIceCandidatesTimeout);
2075
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002076 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2077
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002078 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2079 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
2080 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
2081 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
2082
2083 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2084 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002085 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002086 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2087 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
2088 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
2089 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
2090 SetLocalDescriptionWithoutError(answer);
2091}
2092
2093// Verifies TransportProxy and media channels are created with content names
2094// present in the SessionDescription.
2095TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002096 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002097 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002098 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002099
2100 // CreateOffer creates session description with the content names "audio" and
2101 // "video". Goal is to modify these content names and verify transport channel
2102 // proxy in the BaseSession, as proxies are created with the content names
2103 // present in SDP.
2104 std::string sdp;
2105 EXPECT_TRUE(offer->ToString(&sdp));
2106 const std::string kAudioMid = "a=mid:audio";
2107 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2108 const std::string kVideoMid = "a=mid:video";
2109 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2110
2111 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002112 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002113 kAudioMidReplaceStr.c_str(),
2114 kAudioMidReplaceStr.length(),
2115 &sdp);
2116 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002117 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002118 kVideoMidReplaceStr.c_str(),
2119 kVideoMidReplaceStr.length(),
2120 &sdp);
2121
2122 SessionDescriptionInterface* modified_offer =
2123 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2124
2125 SetRemoteDescriptionWithoutError(modified_offer);
2126
2127 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002128 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129 SetLocalDescriptionWithoutError(answer);
2130
2131 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
2132 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
2133 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2134 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2135}
2136
2137// Test that an offer contains the correct media content descriptions based on
2138// the send streams when no constraints have been set.
2139TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002140 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002141 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2142
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002143 ASSERT_TRUE(offer != NULL);
2144 const cricket::ContentInfo* content =
2145 cricket::GetFirstAudioContent(offer->description());
2146 EXPECT_TRUE(content != NULL);
2147 content = cricket::GetFirstVideoContent(offer->description());
2148 EXPECT_TRUE(content == NULL);
2149}
2150
2151// Test that an offer contains the correct media content descriptions based on
2152// the send streams when no constraints have been set.
2153TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002154 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002155 // Test Audio only offer.
2156 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002157 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2158
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002159 const cricket::ContentInfo* content =
2160 cricket::GetFirstAudioContent(offer->description());
2161 EXPECT_TRUE(content != NULL);
2162 content = cricket::GetFirstVideoContent(offer->description());
2163 EXPECT_TRUE(content == NULL);
2164
2165 // Test Audio / Video offer.
2166 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002167 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002168 content = cricket::GetFirstAudioContent(offer->description());
2169 EXPECT_TRUE(content != NULL);
2170 content = cricket::GetFirstVideoContent(offer->description());
2171 EXPECT_TRUE(content != NULL);
2172}
2173
2174// Test that an offer contains no media content descriptions if
2175// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2176TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002177 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002178 PeerConnectionInterface::RTCOfferAnswerOptions options;
2179 options.offer_to_receive_audio = 0;
2180 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002181
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002182 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002183 CreateOffer(options));
2184
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002185 ASSERT_TRUE(offer != NULL);
2186 const cricket::ContentInfo* content =
2187 cricket::GetFirstAudioContent(offer->description());
2188 EXPECT_TRUE(content == NULL);
2189 content = cricket::GetFirstVideoContent(offer->description());
2190 EXPECT_TRUE(content == NULL);
2191}
2192
2193// Test that an offer contains only audio media content descriptions if
2194// kOfferToReceiveAudio constraints are set to true.
2195TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002196 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002197 PeerConnectionInterface::RTCOfferAnswerOptions options;
2198 options.offer_to_receive_audio =
2199 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2200
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002201 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002202 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002203
2204 const cricket::ContentInfo* content =
2205 cricket::GetFirstAudioContent(offer->description());
2206 EXPECT_TRUE(content != NULL);
2207 content = cricket::GetFirstVideoContent(offer->description());
2208 EXPECT_TRUE(content == NULL);
2209}
2210
2211// Test that an offer contains audio and video media content descriptions if
2212// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2213TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002214 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002215 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002216 PeerConnectionInterface::RTCOfferAnswerOptions options;
2217 options.offer_to_receive_audio =
2218 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2219 options.offer_to_receive_video =
2220 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2221
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002222 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002223 CreateOffer(options));
2224
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002225 const cricket::ContentInfo* content =
2226 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002227 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002228
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002229 content = cricket::GetFirstVideoContent(offer->description());
2230 EXPECT_TRUE(content != NULL);
2231
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002232 // Sets constraints to false and verifies that audio/video contents are
2233 // removed.
2234 options.offer_to_receive_audio = 0;
2235 options.offer_to_receive_video = 0;
2236 offer.reset(CreateOffer(options));
2237
2238 content = cricket::GetFirstAudioContent(offer->description());
2239 EXPECT_TRUE(content == NULL);
2240 content = cricket::GetFirstVideoContent(offer->description());
2241 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002242}
2243
2244// Test that an answer can not be created if the last remote description is not
2245// an offer.
2246TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002247 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002248 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002249 SetLocalDescriptionWithoutError(offer);
2250 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2251 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002252 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002253}
2254
2255// Test that an answer contains the correct media content descriptions when no
2256// constraints have been set.
2257TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002258 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002259 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002260 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002261 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002262 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002263 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002264 const cricket::ContentInfo* content =
2265 cricket::GetFirstAudioContent(answer->description());
2266 ASSERT_TRUE(content != NULL);
2267 EXPECT_FALSE(content->rejected);
2268
2269 content = cricket::GetFirstVideoContent(answer->description());
2270 ASSERT_TRUE(content != NULL);
2271 EXPECT_FALSE(content->rejected);
2272}
2273
2274// Test that an answer contains the correct media content descriptions when no
2275// constraints have been set and the offer only contain audio.
2276TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002277 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002278 // Create a remote offer with audio only.
2279 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002280
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002281 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002282 CreateRemoteOffer(options));
2283 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2284 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2285
2286 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002287 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002288 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002289 const cricket::ContentInfo* content =
2290 cricket::GetFirstAudioContent(answer->description());
2291 ASSERT_TRUE(content != NULL);
2292 EXPECT_FALSE(content->rejected);
2293
2294 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2295}
2296
2297// Test that an answer contains the correct media content descriptions when no
2298// constraints have been set.
2299TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002300 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002301 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002302 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002303 SetRemoteDescriptionWithoutError(offer.release());
2304 // Test with a stream with tracks.
2305 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002306 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002307 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002308 const cricket::ContentInfo* content =
2309 cricket::GetFirstAudioContent(answer->description());
2310 ASSERT_TRUE(content != NULL);
2311 EXPECT_FALSE(content->rejected);
2312
2313 content = cricket::GetFirstVideoContent(answer->description());
2314 ASSERT_TRUE(content != NULL);
2315 EXPECT_FALSE(content->rejected);
2316}
2317
2318// Test that an answer contains the correct media content descriptions when
2319// constraints have been set but no stream is sent.
2320TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002321 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002322 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002323 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002324 SetRemoteDescriptionWithoutError(offer.release());
2325
2326 webrtc::FakeConstraints constraints_no_receive;
2327 constraints_no_receive.SetMandatoryReceiveAudio(false);
2328 constraints_no_receive.SetMandatoryReceiveVideo(false);
2329
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002330 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002331 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002332 const cricket::ContentInfo* content =
2333 cricket::GetFirstAudioContent(answer->description());
2334 ASSERT_TRUE(content != NULL);
2335 EXPECT_TRUE(content->rejected);
2336
2337 content = cricket::GetFirstVideoContent(answer->description());
2338 ASSERT_TRUE(content != NULL);
2339 EXPECT_TRUE(content->rejected);
2340}
2341
2342// Test that an answer contains the correct media content descriptions when
2343// constraints have been set and streams are sent.
2344TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002345 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002346 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002347 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002348 SetRemoteDescriptionWithoutError(offer.release());
2349
2350 webrtc::FakeConstraints constraints_no_receive;
2351 constraints_no_receive.SetMandatoryReceiveAudio(false);
2352 constraints_no_receive.SetMandatoryReceiveVideo(false);
2353
2354 // Test with a stream with tracks.
2355 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002356 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002357 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002358
2359 // TODO(perkj): Should the direction be set to SEND_ONLY?
2360 const cricket::ContentInfo* content =
2361 cricket::GetFirstAudioContent(answer->description());
2362 ASSERT_TRUE(content != NULL);
2363 EXPECT_FALSE(content->rejected);
2364
2365 // TODO(perkj): Should the direction be set to SEND_ONLY?
2366 content = cricket::GetFirstVideoContent(answer->description());
2367 ASSERT_TRUE(content != NULL);
2368 EXPECT_FALSE(content->rejected);
2369}
2370
2371TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2372 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002373 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002374 PeerConnectionInterface::RTCOfferAnswerOptions options;
2375 options.offer_to_receive_audio =
2376 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2377 options.voice_activity_detection = false;
2378
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002379 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002380 CreateOffer(options));
2381
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002382 const cricket::ContentInfo* content =
2383 cricket::GetFirstAudioContent(offer->description());
2384 EXPECT_TRUE(content != NULL);
2385 EXPECT_TRUE(VerifyNoCNCodecs(content));
2386}
2387
2388TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2389 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002390 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002391 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002392 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002393 SetRemoteDescriptionWithoutError(offer.release());
2394
2395 webrtc::FakeConstraints constraints;
2396 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002397 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002398 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002399 const cricket::ContentInfo* content =
2400 cricket::GetFirstAudioContent(answer->description());
2401 ASSERT_TRUE(content != NULL);
2402 EXPECT_TRUE(VerifyNoCNCodecs(content));
2403}
2404
2405// This test verifies the call setup when remote answer with audio only and
2406// later updates with video.
2407TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002408 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002409 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2410 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2411
2412 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002413 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002414
2415 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002416 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2417
2418 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2419 // and answer;
2420 SetLocalDescriptionWithoutError(offer);
2421 SetRemoteDescriptionWithoutError(answer);
2422
2423 video_channel_ = media_engine_->GetVideoChannel(0);
2424 voice_channel_ = media_engine_->GetVoiceChannel(0);
2425
2426 ASSERT_TRUE(video_channel_ == NULL);
2427
2428 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2429 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2430 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2431
2432 // Let the remote end update the session descriptions, with Audio and Video.
2433 mediastream_signaling_.SendAudioVideoStream2();
2434 CreateAndSetRemoteOfferAndLocalAnswer();
2435
2436 video_channel_ = media_engine_->GetVideoChannel(0);
2437 voice_channel_ = media_engine_->GetVoiceChannel(0);
2438
2439 ASSERT_TRUE(video_channel_ != NULL);
2440 ASSERT_TRUE(voice_channel_ != NULL);
2441
2442 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2443 ASSERT_EQ(1u, video_channel_->send_streams().size());
2444 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2445 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2446 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2447 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2448 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2449 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2450
2451 // Change session back to audio only.
2452 mediastream_signaling_.UseOptionsAudioOnly();
2453 CreateAndSetRemoteOfferAndLocalAnswer();
2454
2455 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2456 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2457 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2458 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2459 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2460}
2461
2462// This test verifies the call setup when remote answer with video only and
2463// later updates with audio.
2464TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002465 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002466 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2467 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2468 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002469 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002470
2471 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002472 options.recv_audio = false;
2473 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002474 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2475 offer, options, cricket::SEC_ENABLED);
2476
2477 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2478 // and answer.
2479 SetLocalDescriptionWithoutError(offer);
2480 SetRemoteDescriptionWithoutError(answer);
2481
2482 video_channel_ = media_engine_->GetVideoChannel(0);
2483 voice_channel_ = media_engine_->GetVoiceChannel(0);
2484
2485 ASSERT_TRUE(voice_channel_ == NULL);
2486 ASSERT_TRUE(video_channel_ != NULL);
2487
2488 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2489 ASSERT_EQ(1u, video_channel_->send_streams().size());
2490 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2491
2492 // Update the session descriptions, with Audio and Video.
2493 mediastream_signaling_.SendAudioVideoStream2();
2494 CreateAndSetRemoteOfferAndLocalAnswer();
2495
2496 voice_channel_ = media_engine_->GetVoiceChannel(0);
2497 ASSERT_TRUE(voice_channel_ != NULL);
2498
2499 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2500 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2501 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2502 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2503
2504 // Change session back to video only.
2505 mediastream_signaling_.UseOptionsVideoOnly();
2506 CreateAndSetRemoteOfferAndLocalAnswer();
2507
2508 video_channel_ = media_engine_->GetVideoChannel(0);
2509 voice_channel_ = media_engine_->GetVoiceChannel(0);
2510
2511 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2512 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2513 ASSERT_EQ(1u, video_channel_->send_streams().size());
2514 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2515}
2516
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002517TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002518 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002519 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002520 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002521 VerifyCryptoParams(offer->description());
2522 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002523 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002524 VerifyCryptoParams(answer->description());
2525}
2526
2527TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002528 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002529 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002530 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002531 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002532 VerifyNoCryptoParams(offer->description(), false);
2533}
2534
2535TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002536 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002537 VerifyAnswerFromNonCryptoOffer();
2538}
2539
2540TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002541 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002542 VerifyAnswerFromCryptoOffer();
2543}
2544
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002545// This test verifies that setLocalDescription fails if
2546// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2547TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002548 Init();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002549 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002550 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2551
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002552 std::string sdp;
2553 RemoveIceUfragPwdLines(offer.get(), &sdp);
2554 SessionDescriptionInterface* modified_offer =
2555 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002556 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002557}
2558
2559// This test verifies that setRemoteDescription fails if
2560// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2561TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002562 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002563 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002564 std::string sdp;
2565 RemoveIceUfragPwdLines(offer.get(), &sdp);
2566 SessionDescriptionInterface* modified_offer =
2567 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002568 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002569}
2570
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002571// This test verifies that setLocalDescription fails if local offer has
2572// too short ice ufrag and pwd strings.
2573TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002574 Init();
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002575 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002576 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2577
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002578 std::string sdp;
2579 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2580 // recommended values of 4 and 22 bytes respectively.
2581 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2582 SessionDescriptionInterface* modified_offer =
2583 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2584 std::string error;
2585 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2586
2587 // Test with string greater than 256.
2588 sdp.clear();
2589 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2590 &sdp);
2591 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2592 NULL);
2593 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2594}
2595
2596// This test verifies that setRemoteDescription fails if remote offer has
2597// too short ice ufrag and pwd strings.
2598TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002599 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002600 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002601 std::string sdp;
2602 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2603 // recommended values of 4 and 22 bytes respectively.
2604 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2605 SessionDescriptionInterface* modified_offer =
2606 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2607 std::string error;
2608 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2609
2610 sdp.clear();
2611 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2612 &sdp);
2613 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2614 NULL);
2615 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2616}
2617
honghaiz503726c2015-07-31 12:37:38 -07002618// Test that if the remote description indicates the peer requested ICE restart
2619// (via a new ufrag or pwd), the old ICE candidates are not copied,
2620// and vice versa.
2621TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithIceRestart) {
2622 Init();
2623 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2624
2625 // Create the first offer.
2626 std::string sdp;
2627 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2628 "abcdefghijklmnopqrstuvwx", &sdp);
2629 SessionDescriptionInterface* offer1 =
2630 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2631 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2632 0, "", "", "relay", 0, "");
2633 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2634 candidate1);
2635 EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1));
2636 SetRemoteDescriptionWithoutError(offer1);
2637 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2638
2639 // The second offer has the same ufrag and pwd but different address.
2640 sdp.clear();
2641 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2642 "abcdefghijklmnopqrstuvwx", &sdp);
2643 SessionDescriptionInterface* offer2 =
2644 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2645 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2646 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2647 candidate1);
2648 EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2));
2649 SetRemoteDescriptionWithoutError(offer2);
2650 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2651
2652 // The third offer has a different ufrag and different address.
2653 sdp.clear();
2654 ModifyIceUfragPwdLines(offer.get(), "0123456789012333",
2655 "abcdefghijklmnopqrstuvwx", &sdp);
2656 SessionDescriptionInterface* offer3 =
2657 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2658 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2659 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2660 candidate1);
2661 EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3));
2662 SetRemoteDescriptionWithoutError(offer3);
2663 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2664
2665 // The fourth offer has no candidate but a different ufrag/pwd.
2666 sdp.clear();
2667 ModifyIceUfragPwdLines(offer.get(), "0123456789012444",
2668 "abcdefghijklmnopqrstuvyz", &sdp);
2669 SessionDescriptionInterface* offer4 =
2670 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2671 SetRemoteDescriptionWithoutError(offer4);
2672 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2673}
2674
Donald Curtisd4f769d2015-05-28 09:48:21 -07002675// Test that candidates sent to the "video" transport do not get pushed down to
2676// the "audio" transport channel when bundling using TransportProxy.
2677TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2678 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2679
2680 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2681 mediastream_signaling_.SendAudioVideoStream1();
2682
2683 PeerConnectionInterface::RTCOfferAnswerOptions options;
2684 options.use_rtp_mux = true;
2685
2686 SessionDescriptionInterface* offer = CreateRemoteOffer();
2687 SetRemoteDescriptionWithoutError(offer);
2688
2689 SessionDescriptionInterface* answer = CreateAnswer(NULL);
2690 SetLocalDescriptionWithoutError(answer);
2691
2692 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2693 session_->GetTransportProxy("video")->impl());
2694
2695 cricket::Transport* t = session_->GetTransport("audio");
2696
2697 // Checks if one of the transport channels contains a connection using a given
2698 // port.
2699 auto connection_with_remote_port = [t](int port) {
2700 cricket::TransportStats stats;
2701 t->GetStats(&stats);
2702 for (auto& chan_stat : stats.channel_stats) {
2703 for (auto& conn_info : chan_stat.connection_infos) {
2704 if (conn_info.remote_candidate.address().port() == port) {
2705 return true;
2706 }
2707 }
2708 }
2709 return false;
2710 };
2711
2712 EXPECT_FALSE(connection_with_remote_port(5000));
2713 EXPECT_FALSE(connection_with_remote_port(5001));
2714 EXPECT_FALSE(connection_with_remote_port(6000));
2715
2716 // The way the *_WAIT checks work is they only wait if the condition fails,
2717 // which does not help in the case where state is not changing. This is
2718 // problematic in this test since we want to verify that adding a video
2719 // candidate does _not_ change state. So we interleave candidates and assume
2720 // that messages are executed in the order they were posted.
2721
2722 // First audio candidate.
2723 cricket::Candidate candidate0;
2724 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2725 candidate0.set_component(1);
2726 candidate0.set_protocol("udp");
2727 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2728 candidate0);
2729 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2730
2731 // Video candidate.
2732 cricket::Candidate candidate1;
2733 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2734 candidate1.set_component(1);
2735 candidate1.set_protocol("udp");
2736 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2737 candidate1);
2738 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2739
2740 // Second audio candidate.
2741 cricket::Candidate candidate2;
2742 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
2743 candidate2.set_component(1);
2744 candidate2.set_protocol("udp");
2745 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2746 candidate2);
2747 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2748
2749 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
2750 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
2751
2752 // No need here for a _WAIT check since we are checking that state hasn't
2753 // changed: if this is false we would be doing waits for nothing and if this
2754 // is true then there will be no messages processed anyways.
2755 EXPECT_FALSE(connection_with_remote_port(6000));
2756}
2757
Peter Thatcher4eddf182015-04-30 10:55:59 -07002758// kBundlePolicyBalanced bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002759TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
2760 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002761 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002762
2763 PeerConnectionInterface::RTCOfferAnswerOptions options;
2764 options.use_rtp_mux = true;
2765
2766 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002767 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07002768
2769 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2770 session_->GetTransportProxy("video")->impl());
2771
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002772 mediastream_signaling_.SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002773 SessionDescriptionInterface* answer =
2774 CreateRemoteAnswer(session_->local_description());
2775 SetRemoteDescriptionWithoutError(answer);
2776
2777 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2778 session_->GetTransportProxy("video")->impl());
2779}
2780
2781// kBundlePolicyBalanced bundle policy but no BUNDLE in the answer.
2782TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
2783 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2784 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002785
Donald Curtis0e209b02015-03-24 09:29:54 -07002786 PeerConnectionInterface::RTCOfferAnswerOptions options;
2787 options.use_rtp_mux = true;
2788
2789 SessionDescriptionInterface* offer = CreateOffer(options);
2790 SetLocalDescriptionWithoutError(offer);
2791
2792 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2793 session_->GetTransportProxy("video")->impl());
2794
2795 mediastream_signaling_.SendAudioVideoStream2();
2796
2797 // Remove BUNDLE from the answer.
2798 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2799 CreateRemoteAnswer(session_->local_description()));
2800 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2801 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2802 JsepSessionDescription* modified_answer =
2803 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2804 modified_answer->Initialize(answer_copy, "1", "1");
2805 SetRemoteDescriptionWithoutError(modified_answer); //
2806
2807 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2808 session_->GetTransportProxy("video")->impl());
2809}
2810
2811// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
2812TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
2813 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2814 mediastream_signaling_.SendAudioVideoStream1();
2815
2816 PeerConnectionInterface::RTCOfferAnswerOptions options;
2817 options.use_rtp_mux = true;
2818
2819 SessionDescriptionInterface* offer = CreateOffer(options);
2820 SetLocalDescriptionWithoutError(offer);
2821
2822 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2823 session_->GetTransportProxy("video")->impl());
2824
2825 mediastream_signaling_.SendAudioVideoStream2();
2826 SessionDescriptionInterface* answer =
2827 CreateRemoteAnswer(session_->local_description());
2828 SetRemoteDescriptionWithoutError(answer);
2829
2830 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2831 session_->GetTransportProxy("video")->impl());
2832}
2833
2834// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
2835TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
2836 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2837 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002838
Donald Curtis0e209b02015-03-24 09:29:54 -07002839 PeerConnectionInterface::RTCOfferAnswerOptions options;
2840 options.use_rtp_mux = true;
2841
2842 SessionDescriptionInterface* offer = CreateOffer(options);
2843 SetLocalDescriptionWithoutError(offer);
2844
2845 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2846 session_->GetTransportProxy("video")->impl());
2847
2848 mediastream_signaling_.SendAudioVideoStream2();
2849
2850 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002851 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002852 CreateRemoteAnswer(session_->local_description()));
2853 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2854 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2855 JsepSessionDescription* modified_answer =
2856 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2857 modified_answer->Initialize(answer_copy, "1", "1");
2858 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002859
Donald Curtis0e209b02015-03-24 09:29:54 -07002860 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2861 session_->GetTransportProxy("video")->impl());
2862}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002863
Peter Thatcher4eddf182015-04-30 10:55:59 -07002864// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002865TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
2866 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2867 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002868
Donald Curtis0e209b02015-03-24 09:29:54 -07002869 PeerConnectionInterface::RTCOfferAnswerOptions options;
2870 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002871
Donald Curtis0e209b02015-03-24 09:29:54 -07002872 SessionDescriptionInterface* offer = CreateOffer(options);
2873 SetLocalDescriptionWithoutError(offer);
2874
2875 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2876 session_->GetTransportProxy("video")->impl());
2877
2878 mediastream_signaling_.SendAudioVideoStream2();
2879 SessionDescriptionInterface* answer =
2880 CreateRemoteAnswer(session_->local_description());
2881 SetRemoteDescriptionWithoutError(answer);
2882
2883 // This should lead to an audio-only call but isn't implemented
2884 // correctly yet.
2885 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2886 session_->GetTransportProxy("video")->impl());
2887}
2888
2889// kBundlePolicyMaxCompat bundle policy but no BUNDLE in the answer.
2890TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
2891 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2892 mediastream_signaling_.SendAudioVideoStream1();
2893 PeerConnectionInterface::RTCOfferAnswerOptions options;
2894 options.use_rtp_mux = true;
2895
2896 SessionDescriptionInterface* offer = CreateOffer(options);
2897 SetLocalDescriptionWithoutError(offer);
2898
2899 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2900 session_->GetTransportProxy("video")->impl());
2901
2902 mediastream_signaling_.SendAudioVideoStream2();
2903
2904 // Remove BUNDLE from the answer.
2905 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2906 CreateRemoteAnswer(session_->local_description()));
2907 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2908 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2909 JsepSessionDescription* modified_answer =
2910 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2911 modified_answer->Initialize(answer_copy, "1", "1");
2912 SetRemoteDescriptionWithoutError(modified_answer); //
2913
2914 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2915 session_->GetTransportProxy("video")->impl());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002916}
2917
Peter Thatcher4eddf182015-04-30 10:55:59 -07002918// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
2919TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
2920 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2921 mediastream_signaling_.SendAudioVideoStream1();
2922
2923 PeerConnectionInterface::RTCOfferAnswerOptions options;
2924 options.use_rtp_mux = true;
2925
2926 SessionDescriptionInterface* offer = CreateOffer(options);
2927 SetRemoteDescriptionWithoutError(offer);
2928
2929 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2930 session_->GetTransportProxy("video")->impl());
2931}
2932
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002933TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
2934 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
2935 mediastream_signaling_.SendAudioVideoStream1();
2936
2937 PeerConnectionInterface::RTCOfferAnswerOptions options;
2938 SessionDescriptionInterface* offer = CreateOffer(options);
2939 SetLocalDescriptionWithoutError(offer);
2940
2941 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2942 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2943
2944 mediastream_signaling_.SendAudioVideoStream2();
2945 SessionDescriptionInterface* answer =
2946 CreateRemoteAnswer(session_->local_description());
2947 SetRemoteDescriptionWithoutError(answer);
2948
2949 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2950 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2951}
2952
2953TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
2954 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
2955 mediastream_signaling_.SendAudioVideoStream1();
2956
2957 PeerConnectionInterface::RTCOfferAnswerOptions options;
2958 SessionDescriptionInterface* offer = CreateOffer(options);
2959 SetLocalDescriptionWithoutError(offer);
2960
2961 EXPECT_TRUE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2962 EXPECT_TRUE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2963
2964 mediastream_signaling_.SendAudioVideoStream2();
2965 SessionDescriptionInterface* answer =
2966 CreateRemoteAnswer(session_->local_description());
2967 SetRemoteDescriptionWithoutError(answer);
2968
2969 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2970 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2971}
2972
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002973// This test verifies that SetLocalDescription and SetRemoteDescription fails
2974// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2975TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002976 Init();
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002977 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002978
2979 PeerConnectionInterface::RTCOfferAnswerOptions options;
2980 options.use_rtp_mux = true;
2981
2982 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002983 std::string offer_str;
2984 offer->ToString(&offer_str);
2985 // Disable rtcp-mux
2986 const std::string rtcp_mux = "rtcp-mux";
2987 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002988 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002989 xrtcp_mux.c_str(), xrtcp_mux.length(),
2990 &offer_str);
2991 JsepSessionDescription *local_offer =
2992 new JsepSessionDescription(JsepSessionDescription::kOffer);
2993 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002994 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002995 JsepSessionDescription *remote_offer =
2996 new JsepSessionDescription(JsepSessionDescription::kOffer);
2997 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002998 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002999 // Trying unmodified SDP.
3000 SetLocalDescriptionWithoutError(offer);
3001}
3002
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003003TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003004 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003005 mediastream_signaling_.SendAudioVideoStream1();
3006 CreateAndSetRemoteOfferAndLocalAnswer();
3007 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3008 ASSERT_TRUE(channel != NULL);
3009 ASSERT_EQ(1u, channel->recv_streams().size());
3010 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
3011 double left_vol, right_vol;
3012 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
3013 EXPECT_EQ(1, left_vol);
3014 EXPECT_EQ(1, right_vol);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003015 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003016 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003017 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
3018 EXPECT_EQ(0, left_vol);
3019 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003020 EXPECT_EQ(0, renderer->channel_id());
3021 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003022 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
3023 EXPECT_EQ(1, left_vol);
3024 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003025 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003026}
3027
3028TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003029 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003030 mediastream_signaling_.SendAudioVideoStream1();
3031 CreateAndSetRemoteOfferAndLocalAnswer();
3032 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3033 ASSERT_TRUE(channel != NULL);
3034 ASSERT_EQ(1u, channel->send_streams().size());
3035 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3036 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3037
3038 cricket::AudioOptions options;
3039 options.echo_cancellation.Set(true);
3040
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003041 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003042 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003043 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3044 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003045 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003046 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003047
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003048 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003049 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003050 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3051 bool value;
3052 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
3053 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003054 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003055 EXPECT_TRUE(renderer->sink() == NULL);
3056}
3057
3058TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003059 Init();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003060 mediastream_signaling_.SendAudioVideoStream1();
3061 CreateAndSetRemoteOfferAndLocalAnswer();
3062 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3063 ASSERT_TRUE(channel != NULL);
3064 ASSERT_EQ(1u, channel->send_streams().size());
3065 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3066
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003067 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003068 cricket::AudioOptions options;
3069 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3070 EXPECT_TRUE(renderer->sink() != NULL);
3071
3072 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3073 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3074 // SetSink(NULL) callback afterwards.
3075 renderer.reset();
3076
3077 // This will trigger SetSink(NULL) if no OnClose() callback.
3078 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003079}
3080
3081TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003082 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003083 mediastream_signaling_.SendAudioVideoStream1();
3084 CreateAndSetRemoteOfferAndLocalAnswer();
3085 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3086 ASSERT_TRUE(channel != NULL);
3087 ASSERT_LT(0u, channel->renderers().size());
3088 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3089 ASSERT_EQ(1u, channel->recv_streams().size());
3090 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
3091 cricket::FakeVideoRenderer renderer;
3092 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
3093 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
3094 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
3095 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3096}
3097
3098TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003099 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003100 mediastream_signaling_.SendAudioVideoStream1();
3101 CreateAndSetRemoteOfferAndLocalAnswer();
3102 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3103 ASSERT_TRUE(channel != NULL);
3104 ASSERT_EQ(1u, channel->send_streams().size());
3105 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3106 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3107 cricket::VideoOptions* options = NULL;
3108 session_->SetVideoSend(send_ssrc, false, options);
3109 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3110 session_->SetVideoSend(send_ssrc, true, options);
3111 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3112}
3113
3114TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3115 TestCanInsertDtmf(false);
3116}
3117
3118TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3119 TestCanInsertDtmf(true);
3120}
3121
3122TEST_F(WebRtcSessionTest, InsertDtmf) {
3123 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003124 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003125 mediastream_signaling_.SendAudioVideoStream1();
3126 CreateAndSetRemoteOfferAndLocalAnswer();
3127 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3128 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3129
3130 // Insert DTMF
3131 const int expected_flags = DF_SEND;
3132 const int expected_duration = 90;
3133 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3134 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3135 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3136
3137 // Verify
3138 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
3139 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3140 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
3141 expected_duration, expected_flags));
3142 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
3143 expected_duration, expected_flags));
3144 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
3145 expected_duration, expected_flags));
3146}
3147
3148// This test verifies the |initiator| flag when session initiates the call.
3149TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003150 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003151 EXPECT_FALSE(session_->initiator());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003152 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003153 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3154 SetLocalDescriptionWithoutError(offer);
3155 EXPECT_TRUE(session_->initiator());
3156 SetRemoteDescriptionWithoutError(answer);
3157 EXPECT_TRUE(session_->initiator());
3158}
3159
3160// This test verifies the |initiator| flag when session receives the call.
3161TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003162 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003163 EXPECT_FALSE(session_->initiator());
3164 SessionDescriptionInterface* offer = CreateRemoteOffer();
3165 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003166 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003167
3168 EXPECT_FALSE(session_->initiator());
3169 SetLocalDescriptionWithoutError(answer);
3170 EXPECT_FALSE(session_->initiator());
3171}
3172
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003173// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3174TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003175 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003176 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003177 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003178 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003179 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003180 CreateRemoteAnswer(session_->local_description()));
3181
3182 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3183 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003184 JsepSessionDescription* modified_answer =
3185 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003186
3187 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3188 answer->session_id(),
3189 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003190 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003191
wu@webrtc.org4e393072014-04-07 17:04:35 +00003192 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003193 std::string sdp;
3194 EXPECT_TRUE(answer->ToString(&sdp));
3195 const std::string kAudioMid = "a=mid:audio";
3196 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003197 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003198 kAudioMidReplaceStr.c_str(),
3199 kAudioMidReplaceStr.length(),
3200 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003201 SessionDescriptionInterface* modified_answer1 =
3202 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003203 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003204
wu@webrtc.org4e393072014-04-07 17:04:35 +00003205 // Different media types.
3206 EXPECT_TRUE(answer->ToString(&sdp));
3207 const std::string kAudioMline = "m=audio";
3208 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003209 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003210 kAudioMlineReplaceStr.c_str(),
3211 kAudioMlineReplaceStr.length(),
3212 &sdp);
3213 SessionDescriptionInterface* modified_answer2 =
3214 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3215 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3216
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003217 SetRemoteDescriptionWithoutError(answer.release());
3218}
3219
3220// Verifying remote offer and local answer have matching m-lines as per
3221// RFC 3264.
3222TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003223 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003224 mediastream_signaling_.SendAudioVideoStream1();
3225 SessionDescriptionInterface* offer = CreateRemoteOffer();
3226 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003227 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003228
3229 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3230 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003231 JsepSessionDescription* modified_answer =
3232 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003233
3234 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3235 answer->session_id(),
3236 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003237 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003238 SetLocalDescriptionWithoutError(answer);
3239}
3240
3241// This test verifies that WebRtcSession does not start candidate allocation
3242// before SetLocalDescription is called.
3243TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003244 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003245 mediastream_signaling_.SendAudioVideoStream1();
3246 SessionDescriptionInterface* offer = CreateRemoteOffer();
3247 cricket::Candidate candidate;
3248 candidate.set_component(1);
3249 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3250 candidate);
3251 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3252 cricket::Candidate candidate1;
3253 candidate1.set_component(1);
3254 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3255 candidate1);
3256 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3257 SetRemoteDescriptionWithoutError(offer);
3258 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
3259 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
3260
3261 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003262 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003263 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3264 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3265
wu@webrtc.org91053e72013-08-10 07:18:04 +00003266 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003267 SetLocalDescriptionWithoutError(answer);
3268 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
3269 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
3270 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3271}
3272
3273// This test verifies that crypto parameter is updated in local session
3274// description as per security policy set in MediaSessionDescriptionFactory.
3275TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003276 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003277 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003278 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003279
3280 // Making sure SetLocalDescription correctly sets crypto value in
3281 // SessionDescription object after de-serialization of sdp string. The value
3282 // will be set as per MediaSessionDescriptionFactory.
3283 std::string offer_str;
3284 offer->ToString(&offer_str);
3285 SessionDescriptionInterface* jsep_offer_str =
3286 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3287 SetLocalDescriptionWithoutError(jsep_offer_str);
3288 EXPECT_TRUE(session_->voice_channel()->secure_required());
3289 EXPECT_TRUE(session_->video_channel()->secure_required());
3290}
3291
3292// This test verifies the crypto parameter when security is disabled.
3293TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003294 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003295 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003296 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003297 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003298
3299 // Making sure SetLocalDescription correctly sets crypto value in
3300 // SessionDescription object after de-serialization of sdp string. The value
3301 // will be set as per MediaSessionDescriptionFactory.
3302 std::string offer_str;
3303 offer->ToString(&offer_str);
3304 SessionDescriptionInterface *jsep_offer_str =
3305 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3306 SetLocalDescriptionWithoutError(jsep_offer_str);
3307 EXPECT_FALSE(session_->voice_channel()->secure_required());
3308 EXPECT_FALSE(session_->video_channel()->secure_required());
3309}
3310
3311// This test verifies that an answer contains new ufrag and password if an offer
3312// with new ufrag and password is received.
3313TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003314 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003315 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003316 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003317 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003318 CreateRemoteOffer(options));
3319 SetRemoteDescriptionWithoutError(offer.release());
3320
3321 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003322 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003323 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003324 SetLocalDescriptionWithoutError(answer.release());
3325
3326 // Receive an offer with new ufrag and password.
3327 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003328 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003329 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003330 SetRemoteDescriptionWithoutError(updated_offer1.release());
3331
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003332 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003333 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003334
3335 CompareIceUfragAndPassword(updated_answer1->description(),
3336 session_->local_description()->description(),
3337 false);
3338
3339 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003340}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003341
wu@webrtc.org91053e72013-08-10 07:18:04 +00003342// This test verifies that an answer contains old ufrag and password if an offer
3343// with old ufrag and password is received.
3344TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003345 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003346 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003347 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003348 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003349 CreateRemoteOffer(options));
3350 SetRemoteDescriptionWithoutError(offer.release());
3351
3352 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003353 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003354 CreateAnswer(NULL));
3355 SetLocalDescriptionWithoutError(answer.release());
3356
3357 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003358 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003359 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003360 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003361 SetRemoteDescriptionWithoutError(updated_offer2.release());
3362
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003363 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003364 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003365
3366 CompareIceUfragAndPassword(updated_answer2->description(),
3367 session_->local_description()->description(),
3368 true);
3369
3370 SetLocalDescriptionWithoutError(updated_answer2.release());
3371}
3372
3373TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003374 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003375 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003376 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003377 const std::string session_id_orig = offer->session_id();
3378 const std::string session_version_orig = offer->session_version();
3379 SetLocalDescriptionWithoutError(offer);
3380
3381 video_channel_ = media_engine_->GetVideoChannel(0);
3382 video_channel_->set_fail_set_send_codecs(true);
3383
3384 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003385 SessionDescriptionInterface* answer =
3386 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003387 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003388}
3389
3390// Runs the loopback call test with BUNDLE and STUN disabled.
3391TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3392 // Lets try with only UDP ports.
Peter Thatcher2159b892015-08-21 20:46:05 -07003393 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003394 cricket::PORTALLOCATOR_DISABLE_STUN |
3395 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003396 TestLoopbackCall();
3397}
3398
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003399TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher2159b892015-08-21 20:46:05 -07003400 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003401 cricket::PORTALLOCATOR_DISABLE_STUN |
3402 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3403 cricket::PORTALLOCATOR_DISABLE_RELAY);
3404
3405 // best connection is IPv6 since it has higher network preference.
3406 LoopbackNetworkConfiguration config;
3407 config.test_ipv6_network_ = true;
3408 config.best_connection_after_initial_ice_converged_ =
3409 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3410
3411 TestLoopbackCall(config);
3412}
3413
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003414// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003415TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher2159b892015-08-21 20:46:05 -07003416 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3417 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003418 TestLoopbackCall();
3419}
3420
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003421TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003422 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003423 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003424 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003425
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003426 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
3427 std::string error_code_str = "ERROR_CONTENT";
3428 std::string error_desc = "Fake session error description.";
3429 session_->SetError(error_code, error_desc);
3430
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003431 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
3432 SessionDescriptionInterface* answer =
3433 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003434
3435 std::string action;
3436 std::ostringstream session_error_msg;
3437 session_error_msg << kSessionError << error_code_str << ". ";
3438 session_error_msg << kSessionErrorDesc << error_desc << ".";
3439 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
3440 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003441}
3442
3443TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3444 constraints_.reset(new FakeConstraints());
3445 constraints_->AddOptional(
3446 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003447 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003448
3449 SetLocalDescriptionWithDataChannel();
3450 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3451}
3452
Henrik Boström87713d02015-08-25 09:53:21 +02003453TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003454 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003455
3456 constraints_.reset(new FakeConstraints());
3457 constraints_->AddOptional(
3458 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003459 options_.disable_sctp_data_channels = false;
3460
Henrik Boström87713d02015-08-25 09:53:21 +02003461 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003462
3463 SetLocalDescriptionWithDataChannel();
3464 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3465}
3466
Henrik Boström87713d02015-08-25 09:53:21 +02003467TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003468 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003469
Henrik Boström87713d02015-08-25 09:53:21 +02003470 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003471
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003472 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003473 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003474 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3475}
3476
Henrik Boström87713d02015-08-25 09:53:21 +02003477TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003478 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003479 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003480 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003481
3482 // Create remote offer with SCTP.
3483 cricket::MediaSessionOptions options;
3484 options.data_channel_type = cricket::DCT_SCTP;
3485 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003486 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003487 SetRemoteDescriptionWithoutError(offer);
3488
3489 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003490 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003491 EXPECT_TRUE(answer != NULL);
3492 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3493 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003494}
3495
Henrik Boström87713d02015-08-25 09:53:21 +02003496TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003497 constraints_.reset(new FakeConstraints());
3498 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003499 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
Henrik Boström87713d02015-08-25 09:53:21 +02003500 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003501
3502 SetLocalDescriptionWithDataChannel();
3503 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3504}
3505
Henrik Boström87713d02015-08-25 09:53:21 +02003506TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003507 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003508
Henrik Boström87713d02015-08-25 09:53:21 +02003509 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003510
3511 SetLocalDescriptionWithDataChannel();
3512 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3513}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003514
Henrik Boström87713d02015-08-25 09:53:21 +02003515TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003516 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003517 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003518 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003519
3520 SetLocalDescriptionWithDataChannel();
3521 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3522}
3523
Henrik Boström87713d02015-08-25 09:53:21 +02003524TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003525 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003526 const int new_send_port = 9998;
3527 const int new_recv_port = 7775;
3528
Henrik Boström87713d02015-08-25 09:53:21 +02003529 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003530 SetFactoryDtlsSrtp();
3531
3532 // By default, don't actually add the codecs to desc_factory_; they don't
3533 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3534 // let the session description get parsed. That'll get the proper codecs
3535 // into the stream.
3536 cricket::MediaSessionOptions options;
3537 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3538 "stream1", new_send_port, options);
3539
3540 // SetRemoteDescription will take the ownership of the offer.
3541 SetRemoteDescriptionWithoutError(offer);
3542
3543 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3544 new_recv_port, CreateAnswer(NULL));
3545 ASSERT_TRUE(answer != NULL);
3546
3547 // Now set the local description, which'll take ownership of the answer.
3548 SetLocalDescriptionWithoutError(answer);
3549
3550 // TEST PLAN: Set the port number to something new, set it in the SDP,
3551 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003552 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003553 dci.reliable = true;
3554 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003555 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003556 session_->CreateDataChannel("datachannel", &dci);
3557
3558 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3559 int portnum = -1;
3560 ASSERT_TRUE(ch != NULL);
3561 ASSERT_EQ(1UL, ch->send_codecs().size());
3562 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003563 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003564 ch->send_codecs()[0].name.c_str()));
3565 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3566 &portnum));
3567 EXPECT_EQ(new_send_port, portnum);
3568
3569 ASSERT_EQ(1UL, ch->recv_codecs().size());
3570 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003571 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003572 ch->recv_codecs()[0].name.c_str()));
3573 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3574 &portnum));
3575 EXPECT_EQ(new_recv_port, portnum);
3576}
3577
Henrik Boströmd8281982015-08-27 10:12:24 +02003578TEST_F(WebRtcSessionTest, TestUsesProvidedCertificate) {
3579 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
3580 FakeDtlsIdentityStore::GenerateCertificate();
3581
3582 PeerConnectionInterface::RTCConfiguration configuration;
3583 configuration.certificates.push_back(certificate);
3584 Init(nullptr, configuration);
3585 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3586
3587 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3588}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003589
Henrik Boström87713d02015-08-25 09:53:21 +02003590// Verifies that CreateOffer succeeds when CreateOffer is called before async
3591// identity generation is finished (even if a certificate is provided this is
3592// an async op).
3593TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3594 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3595 InitWithDtls(GetParam());
3596
Henrik Boströmd8281982015-08-27 10:12:24 +02003597 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003598 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003599 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3600
wu@webrtc.org91053e72013-08-10 07:18:04 +00003601 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003602 VerifyNoCryptoParams(offer->description(), true);
3603 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003604}
3605
3606// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02003607// identity generation is finished (even if a certificate is provided this is
3608// an async op).
3609TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003610 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003611 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003612 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003613
3614 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003615 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003616 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003617 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003618 ASSERT_TRUE(offer.get() != NULL);
3619 SetRemoteDescriptionWithoutError(offer.release());
3620
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003621 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003622 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003623 VerifyNoCryptoParams(answer->description(), true);
3624 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003625}
3626
3627// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02003628// identity generation is finished (even if a certificate is provided this is
3629// an async op).
3630TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003631 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003632 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003633
Henrik Boströmd8281982015-08-27 10:12:24 +02003634 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003635
3636 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003637 EXPECT_TRUE(offer != NULL);
3638}
3639
3640// Verifies that CreateOffer fails when CreateOffer is called after async
3641// identity generation fails.
3642TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003643 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003644 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003645
Henrik Boströmd8281982015-08-27 10:12:24 +02003646 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003647
3648 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003649 EXPECT_TRUE(offer == NULL);
3650}
3651
3652// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3653// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003654TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003655 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003656 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003657 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02003658 GetParam(), CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003659}
3660
3661// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3662// before async identity generation fails.
3663TEST_F(WebRtcSessionTest,
3664 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003665 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003666 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
3667 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003668}
3669
3670// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3671// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003672TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003673 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003674 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003675 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02003676 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003677}
3678
3679// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3680// before async identity generation fails.
3681TEST_F(WebRtcSessionTest,
3682 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003683 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003684 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
3685 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003686}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003687
3688// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3689// offer has no SDES crypto but only DTLS fingerprint.
3690TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3691 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003692 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003693 // Create a remote offer with secured transport disabled.
3694 cricket::MediaSessionOptions options;
3695 JsepSessionDescription* offer(CreateRemoteOffer(
3696 options, cricket::SEC_DISABLED));
3697 // Adds a DTLS fingerprint to the remote offer.
3698 cricket::SessionDescription* sdp = offer->description();
3699 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3700 ASSERT_TRUE(audio != NULL);
3701 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3702 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003703 rtc::SSLFingerprint::CreateFromRfc4572(
3704 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003705 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003706 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003707}
3708
wu@webrtc.orgde305012013-10-31 15:40:38 +00003709// This test verifies DSCP is properly applied on the media channels.
3710TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3711 constraints_.reset(new FakeConstraints());
3712 constraints_->AddOptional(
3713 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003714 Init();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003715 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003716 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003717
3718 SetLocalDescriptionWithoutError(offer);
3719
3720 video_channel_ = media_engine_->GetVideoChannel(0);
3721 voice_channel_ = media_engine_->GetVoiceChannel(0);
3722
3723 ASSERT_TRUE(video_channel_ != NULL);
3724 ASSERT_TRUE(voice_channel_ != NULL);
3725 cricket::AudioOptions audio_options;
3726 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3727 cricket::VideoOptions video_options;
3728 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3729 EXPECT_TRUE(audio_options.dscp.IsSet());
3730 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3731 EXPECT_TRUE(video_options.dscp.IsSet());
3732 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3733}
3734
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003735TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3736 constraints_.reset(new FakeConstraints());
3737 constraints_->AddOptional(
3738 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3739 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003740 Init();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003741 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003742 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003743
3744 SetLocalDescriptionWithoutError(offer);
3745
3746 video_channel_ = media_engine_->GetVideoChannel(0);
3747
3748 ASSERT_TRUE(video_channel_ != NULL);
3749 cricket::VideoOptions video_options;
3750 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3751 EXPECT_TRUE(
3752 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3753}
3754
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00003755TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
3756 // Number of unsignalled receiving streams should be between 0 and
3757 // kMaxUnsignalledRecvStreams.
3758 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
3759 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
3760 kMaxUnsignalledRecvStreams);
3761 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
3762}
3763
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003764TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
3765 constraints_.reset(new FakeConstraints());
3766 constraints_->AddOptional(
3767 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
3768 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003769 Init();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003770 mediastream_signaling_.SendAudioVideoStream1();
3771 SessionDescriptionInterface* offer = CreateOffer();
3772
3773 SetLocalDescriptionWithoutError(offer);
3774
3775 voice_channel_ = media_engine_->GetVoiceChannel(0);
3776
3777 ASSERT_TRUE(voice_channel_ != NULL);
3778 cricket::AudioOptions audio_options;
3779 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3780 EXPECT_TRUE(
3781 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
3782}
3783
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003784// Tests that we can renegotiate new media content with ICE candidates in the
3785// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02003786TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003787 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003788 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003789 SetFactoryDtlsSrtp();
3790
3791 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003792 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003793 SetLocalDescriptionWithoutError(offer);
3794
3795 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3796 SetRemoteDescriptionWithoutError(answer);
3797
3798 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003799 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003800 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3801
3802 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003803 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003804 candidate1.set_component(1);
3805 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3806 candidate1);
3807 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3808 SetRemoteDescriptionWithoutError(offer);
3809
3810 answer = CreateAnswer(NULL);
3811 SetLocalDescriptionWithoutError(answer);
3812}
3813
3814// Tests that we can renegotiate new media content with ICE candidates separated
3815// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02003816TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003817 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003818 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003819 SetFactoryDtlsSrtp();
3820
3821 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003822 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003823 SetLocalDescriptionWithoutError(offer);
3824
3825 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3826 SetRemoteDescriptionWithoutError(answer);
3827
3828 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003829 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003830 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3831 SetRemoteDescriptionWithoutError(offer);
3832
3833 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003834 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003835 candidate1.set_component(1);
3836 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3837 candidate1);
3838 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3839
3840 answer = CreateAnswer(NULL);
3841 SetLocalDescriptionWithoutError(answer);
3842}
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00003843// Tests that RTX codec is removed from the answer when it isn't supported
3844// by local side.
3845TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
3846 Init();
3847 mediastream_signaling_.SendAudioVideoStream1();
3848 std::string offer_sdp(kSdpWithRtx);
3849
3850 SessionDescriptionInterface* offer =
3851 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
3852 EXPECT_TRUE(offer->ToString(&offer_sdp));
3853
3854 // Offer SDP contains the RTX codec.
3855 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
3856 SetRemoteDescriptionWithoutError(offer);
3857
3858 SessionDescriptionInterface* answer = CreateAnswer(NULL);
3859 std::string answer_sdp;
3860 answer->ToString(&answer_sdp);
3861 // Answer SDP removes the unsupported RTX codec.
3862 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
3863 SetLocalDescriptionWithoutError(answer);
3864}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003865
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003866// This verifies that the voice channel after bundle has both options from video
3867// and voice channels.
3868TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
3869 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
3870 mediastream_signaling_.SendAudioVideoStream1();
3871
3872 PeerConnectionInterface::RTCOfferAnswerOptions options;
3873 options.use_rtp_mux = true;
3874
3875 SessionDescriptionInterface* offer = CreateOffer(options);
3876 SetLocalDescriptionWithoutError(offer);
3877
3878 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3879 rtc::Socket::Option::OPT_SNDBUF, 4000);
3880
3881 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3882 rtc::Socket::Option::OPT_RCVBUF, 8000);
3883
3884 int option_val;
3885 EXPECT_TRUE(session_->video_channel()->transport_channel()->GetOption(
3886 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3887 EXPECT_EQ(4000, option_val);
3888 EXPECT_FALSE(session_->voice_channel()->transport_channel()->GetOption(
3889 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3890
3891 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3892 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3893 EXPECT_EQ(8000, option_val);
3894 EXPECT_FALSE(session_->video_channel()->transport_channel()->GetOption(
3895 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3896
3897 EXPECT_NE(session_->voice_channel()->transport_channel(),
3898 session_->video_channel()->transport_channel());
3899
3900 mediastream_signaling_.SendAudioVideoStream2();
3901 SessionDescriptionInterface* answer =
3902 CreateRemoteAnswer(session_->local_description());
3903 SetRemoteDescriptionWithoutError(answer);
3904
3905 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3906 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3907 EXPECT_EQ(4000, option_val);
3908
3909 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3910 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3911 EXPECT_EQ(8000, option_val);
3912}
3913
tommi0f620f42015-07-09 03:25:02 -07003914// Test creating a session, request multiple offers, destroy the session
3915// and make sure we got success/failure callbacks for all of the requests.
3916// Background: crbug.com/507307
3917TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
3918 Init();
3919
3920 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
3921 PeerConnectionInterface::RTCOfferAnswerOptions options;
3922 options.offer_to_receive_audio =
3923 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
3924
3925 for (auto& o : observers) {
3926 o = new WebRtcSessionCreateSDPObserverForTest();
3927 session_->CreateOffer(o, options);
3928 }
3929
3930 session_.reset();
3931
tommi0f620f42015-07-09 03:25:02 -07003932 for (auto& o : observers) {
3933 // We expect to have received a notification now even if the session was
3934 // terminated. The offer creation may or may not have succeeded, but we
3935 // must have received a notification which, so the only invalid state
3936 // is kInit.
3937 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
3938 }
3939}
3940
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003941// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
3942// currently fails because upon disconnection and reconnection OnIceComplete is
3943// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02003944
3945INSTANTIATE_TEST_CASE_P(
3946 WebRtcSessionTests, WebRtcSessionTest,
3947 testing::Values(ALREADY_GENERATED, DTLS_IDENTITY_STORE));