blob: 582bdc63565e778b11844c4d252dbe24f9643154 [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.
Henrik Boström3a14bf32015-08-31 09:27:58 +0200565 tdesc_factory_->set_certificate(rtc::RTCCertificate::Create(
566 rtc::scoped_ptr<rtc::SSLIdentity>(rtc::SSLIdentity::Generate(
567 identity_name, rtc::KT_DEFAULT)).Pass()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000568 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
569 }
570
571 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
572 bool expected) {
573 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
574 ASSERT_TRUE(audio != NULL);
575 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000576 const TransportInfo* video = sdp->GetTransportInfoByName("video");
577 ASSERT_TRUE(video != NULL);
578 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000579 }
580
581 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000582 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000583 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000584 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000585 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000586 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000587 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000588 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000589 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
590 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000591 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000592 // Answer should be NULL as no crypto params in offer.
593 ASSERT_TRUE(answer == NULL);
594 }
595
596 void VerifyAnswerFromCryptoOffer() {
597 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000598 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000599 options.bundle_enabled = true;
600 scoped_ptr<JsepSessionDescription> offer(
601 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
602 ASSERT_TRUE(offer.get() != NULL);
603 VerifyCryptoParams(offer->description());
604 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000605 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000606 ASSERT_TRUE(answer.get() != NULL);
607 VerifyCryptoParams(answer->description());
608 }
609
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000610 void SetAndVerifyNumUnsignalledRecvStreams(
611 int value_set, int value_expected) {
612 constraints_.reset(new FakeConstraints());
613 constraints_->AddOptional(
614 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
615 value_set);
616 session_.reset();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000617 Init();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000618 mediastream_signaling_.SendAudioVideoStream1();
619 SessionDescriptionInterface* offer = CreateOffer();
620
621 SetLocalDescriptionWithoutError(offer);
622
623 video_channel_ = media_engine_->GetVideoChannel(0);
624
625 ASSERT_TRUE(video_channel_ != NULL);
626 cricket::VideoOptions video_options;
627 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
628 EXPECT_EQ(value_expected,
629 video_options.unsignalled_recv_stream_limit.GetWithDefaultIfUnset(-1));
630 }
631
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000632 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
633 const cricket::SessionDescription* desc2,
634 bool expect_equal) {
635 if (desc1->contents().size() != desc2->contents().size()) {
636 EXPECT_FALSE(expect_equal);
637 return;
638 }
639
640 const cricket::ContentInfos& contents = desc1->contents();
641 cricket::ContentInfos::const_iterator it = contents.begin();
642
643 for (; it != contents.end(); ++it) {
644 const cricket::TransportDescription* transport_desc1 =
645 desc1->GetTransportDescriptionByName(it->name);
646 const cricket::TransportDescription* transport_desc2 =
647 desc2->GetTransportDescriptionByName(it->name);
648 if (!transport_desc1 || !transport_desc2) {
649 EXPECT_FALSE(expect_equal);
650 return;
651 }
652 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
653 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
654 EXPECT_FALSE(expect_equal);
655 return;
656 }
657 }
658 EXPECT_TRUE(expect_equal);
659 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000660
661 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
662 std::string *sdp) {
663 const cricket::SessionDescription* desc = current_desc->description();
664 EXPECT_TRUE(current_desc->ToString(sdp));
665
666 const cricket::ContentInfos& contents = desc->contents();
667 cricket::ContentInfos::const_iterator it = contents.begin();
668 // Replace ufrag and pwd lines with empty strings.
669 for (; it != contents.end(); ++it) {
670 const cricket::TransportDescription* transport_desc =
671 desc->GetTransportDescriptionByName(it->name);
672 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
673 + "\r\n";
674 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
675 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000676 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000677 "", 0,
678 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000679 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000680 "", 0,
681 sdp);
682 }
683 }
684
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000685 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
686 const std::string& modified_ice_ufrag,
687 const std::string& modified_ice_pwd,
688 std::string* sdp) {
689 const cricket::SessionDescription* desc = current_desc->description();
690 EXPECT_TRUE(current_desc->ToString(sdp));
691
692 const cricket::ContentInfos& contents = desc->contents();
693 cricket::ContentInfos::const_iterator it = contents.begin();
694 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
695 // |modified_ice_pwd| strings.
696 for (; it != contents.end(); ++it) {
697 const cricket::TransportDescription* transport_desc =
698 desc->GetTransportDescriptionByName(it->name);
699 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
700 + "\r\n";
701 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
702 + "\r\n";
703 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
704 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000705 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000706 mod_ufrag.c_str(), mod_ufrag.length(),
707 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000708 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000709 mod_pwd.c_str(), mod_pwd.length(),
710 sdp);
711 }
712 }
713
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000714 // Creates a remote offer and and applies it as a remote description,
715 // creates a local answer and applies is as a local description.
716 // Call mediastream_signaling_.UseOptionsWithStreamX() before this function
717 // to decide which local and remote streams to create.
718 void CreateAndSetRemoteOfferAndLocalAnswer() {
719 SessionDescriptionInterface* offer = CreateRemoteOffer();
720 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000721 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000722 SetLocalDescriptionWithoutError(answer);
723 }
724 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
725 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
726 }
727 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
728 BaseSession::State expected_state) {
729 SetLocalDescriptionWithoutError(desc);
730 EXPECT_EQ(expected_state, session_->state());
731 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000732 void SetLocalDescriptionExpectError(const std::string& action,
733 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000734 SessionDescriptionInterface* desc) {
735 std::string error;
736 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000737 std::string sdp_type = "local ";
738 sdp_type.append(action);
739 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000740 EXPECT_NE(std::string::npos, error.find(expected_error));
741 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000742 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
743 SessionDescriptionInterface* desc) {
744 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
745 expected_error, desc);
746 }
747 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
748 SessionDescriptionInterface* desc) {
749 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
750 expected_error, desc);
751 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000752 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
753 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
754 }
755 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
756 BaseSession::State expected_state) {
757 SetRemoteDescriptionWithoutError(desc);
758 EXPECT_EQ(expected_state, session_->state());
759 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000760 void SetRemoteDescriptionExpectError(const std::string& action,
761 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000762 SessionDescriptionInterface* desc) {
763 std::string error;
764 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000765 std::string sdp_type = "remote ";
766 sdp_type.append(action);
767 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000768 EXPECT_NE(std::string::npos, error.find(expected_error));
769 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000770 void SetRemoteDescriptionOfferExpectError(
771 const std::string& expected_error, SessionDescriptionInterface* desc) {
772 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
773 expected_error, desc);
774 }
775 void SetRemoteDescriptionPranswerExpectError(
776 const std::string& expected_error, SessionDescriptionInterface* desc) {
777 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
778 expected_error, desc);
779 }
780 void SetRemoteDescriptionAnswerExpectError(
781 const std::string& expected_error, SessionDescriptionInterface* desc) {
782 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
783 expected_error, desc);
784 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000785
786 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
787 SessionDescriptionInterface** nocrypto_answer) {
788 // Create a SDP without Crypto.
789 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000790 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000791 options.bundle_enabled = true;
792 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
793 ASSERT_TRUE(*offer != NULL);
794 VerifyCryptoParams((*offer)->description());
795
796 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
797 cricket::SEC_DISABLED);
798 EXPECT_TRUE(*nocrypto_answer != NULL);
799 }
800
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000801 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
802 SessionDescriptionInterface** nodtls_answer) {
803 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000804 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000805 options.bundle_enabled = true;
806
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000807 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000808 CreateRemoteOffer(options, cricket::SEC_ENABLED));
809
810 *nodtls_answer =
811 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
812 EXPECT_TRUE(*nodtls_answer != NULL);
813 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
814 VerifyCryptoParams((*nodtls_answer)->description());
815
816 SetFactoryDtlsSrtp();
817 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
818 ASSERT_TRUE(*offer != NULL);
819 VerifyFingerprintStatus((*offer)->description(), true);
820 VerifyCryptoParams((*offer)->description());
821 }
822
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000823 JsepSessionDescription* CreateRemoteOfferWithVersion(
824 cricket::MediaSessionOptions options,
825 cricket::SecurePolicy secure_policy,
826 const std::string& session_version,
827 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000828 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000829 const cricket::SessionDescription* cricket_desc = NULL;
830 if (current_desc) {
831 cricket_desc = current_desc->description();
832 session_id = current_desc->session_id();
833 }
834
835 desc_factory_->set_secure(secure_policy);
836 JsepSessionDescription* offer(
837 new JsepSessionDescription(JsepSessionDescription::kOffer));
838 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
839 session_id, session_version)) {
840 delete offer;
841 offer = NULL;
842 }
843 return offer;
844 }
845 JsepSessionDescription* CreateRemoteOffer(
846 cricket::MediaSessionOptions options) {
847 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
848 kSessionVersion, NULL);
849 }
850 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000851 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
852 return CreateRemoteOfferWithVersion(
853 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000854 }
855 JsepSessionDescription* CreateRemoteOffer(
856 cricket::MediaSessionOptions options,
857 const SessionDescriptionInterface* current_desc) {
858 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
859 kSessionVersion, current_desc);
860 }
861
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000862 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
863 const char* sctp_stream_name, int new_port,
864 cricket::MediaSessionOptions options) {
865 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000866 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
867 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000868 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
869 }
870
871 // Takes ownership of offer_basis (and deletes it).
872 JsepSessionDescription* ChangeSDPSctpPort(
873 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
874 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
875 // SessionDescription from the mutated string.
876 const char* default_port_str = "5000";
877 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000878 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000879 std::string offer_str;
880 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000881 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000882 new_port_str, strlen(new_port_str),
883 &offer_str);
884 JsepSessionDescription* offer = new JsepSessionDescription(
885 offer_basis->type());
886 delete offer_basis;
887 offer->Initialize(offer_str, NULL);
888 return offer;
889 }
890
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000891 // Create a remote offer. Call mediastream_signaling_.UseOptionsWithStreamX()
892 // before this function to decide which streams to create.
893 JsepSessionDescription* CreateRemoteOffer() {
894 cricket::MediaSessionOptions options;
895 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
896 return CreateRemoteOffer(options, session_->remote_description());
897 }
898
899 JsepSessionDescription* CreateRemoteAnswer(
900 const SessionDescriptionInterface* offer,
901 cricket::MediaSessionOptions options,
902 cricket::SecurePolicy policy) {
903 desc_factory_->set_secure(policy);
904 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000905 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000906 JsepSessionDescription* answer(
907 new JsepSessionDescription(JsepSessionDescription::kAnswer));
908 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
909 options, NULL),
910 session_id, kSessionVersion)) {
911 delete answer;
912 answer = NULL;
913 }
914 return answer;
915 }
916
917 JsepSessionDescription* CreateRemoteAnswer(
918 const SessionDescriptionInterface* offer,
919 cricket::MediaSessionOptions options) {
920 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
921 }
922
923 // Creates an answer session description with streams based on
924 // |mediastream_signaling_|. Call
925 // mediastream_signaling_.UseOptionsWithStreamX() before this function
926 // to decide which streams to create.
927 JsepSessionDescription* CreateRemoteAnswer(
928 const SessionDescriptionInterface* offer) {
929 cricket::MediaSessionOptions options;
930 mediastream_signaling_.GetOptionsForAnswer(NULL, &options);
931 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
932 }
933
934 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000935 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000936 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000937 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000938
939 PeerConnectionInterface::RTCOfferAnswerOptions options;
940 options.use_rtp_mux = bundle;
941
942 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000943 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
944 // and answer.
945 SetLocalDescriptionWithoutError(offer);
946
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000947 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000948 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000949 std::string sdp;
950 EXPECT_TRUE(answer->ToString(&sdp));
951
952 size_t expected_candidate_num = 2;
953 if (!rtcp_mux) {
954 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
955 // for rtp and rtcp.
956 expected_candidate_num = 4;
957 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000958 const std::string kRtcpMux = "a=rtcp-mux";
959 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000960 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000961 kXRtcpMux.c_str(), kXRtcpMux.length(),
962 &sdp);
963 }
964
965 SessionDescriptionInterface* new_answer = CreateSessionDescription(
966 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000967
968 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +0000969 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000970 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
971 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
972 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
973 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
974 cricket::Candidate c0 = observer_.mline_0_candidates_[i];
975 cricket::Candidate c1 = observer_.mline_1_candidates_[i];
976 if (bundle) {
977 EXPECT_TRUE(c0.IsEquivalent(c1));
978 } else {
979 EXPECT_FALSE(c0.IsEquivalent(c1));
980 }
981 }
982 }
983 // Tests that we can only send DTMF when the dtmf codec is supported.
984 void TestCanInsertDtmf(bool can) {
985 if (can) {
986 InitWithDtmfCodec();
987 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000988 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000989 }
990 mediastream_signaling_.SendAudioVideoStream1();
991 CreateAndSetRemoteOfferAndLocalAnswer();
992 EXPECT_FALSE(session_->CanInsertDtmf(""));
993 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
994 }
995
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000996 // Helper class to configure loopback network and verify Best
997 // Connection using right IP protocol for TestLoopbackCall
998 // method. LoopbackNetworkManager applies firewall rules to block
999 // all ping traffic once ICE completed, and remove them to observe
1000 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1001 // verifies the best connection is using the right IP protocol after
1002 // initial ICE convergences.
1003
1004 class LoopbackNetworkConfiguration {
1005 public:
1006 LoopbackNetworkConfiguration()
1007 : test_ipv6_network_(false),
1008 test_extra_ipv4_network_(false),
1009 best_connection_after_initial_ice_converged_(1, 0) {}
1010
1011 // Used to track the expected best connection count in each IP protocol.
1012 struct ExpectedBestConnection {
1013 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1014 : ipv4_count_(ipv4_count),
1015 ipv6_count_(ipv6_count) {}
1016
1017 int ipv4_count_;
1018 int ipv6_count_;
1019 };
1020
1021 bool test_ipv6_network_;
1022 bool test_extra_ipv4_network_;
1023 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1024
1025 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001026 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001027 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1028 }
1029
1030 private:
jbauchac8869e2015-07-03 01:36:14 -07001031 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001032 const ExpectedBestConnection& expected) const {
1033 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001034 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1035 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001036 expected.ipv4_count_);
1037 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001038 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1039 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001040 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001041 // This is used in the loopback call so there is only single host to host
1042 // candidate pair.
1043 EXPECT_EQ(metrics_observer->GetEnumCounter(
1044 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1045 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001046 0);
1047 EXPECT_EQ(metrics_observer->GetEnumCounter(
1048 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1049 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001050 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001051 }
1052 };
1053
1054 class LoopbackNetworkManager {
1055 public:
1056 LoopbackNetworkManager(WebRtcSessionTest* session,
1057 const LoopbackNetworkConfiguration& config)
1058 : config_(config) {
1059 session->AddInterface(
1060 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1061 if (config_.test_extra_ipv4_network_) {
1062 session->AddInterface(
1063 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1064 }
1065 if (config_.test_ipv6_network_) {
1066 session->AddInterface(
1067 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1068 }
1069 }
1070
1071 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1072 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1073 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1074 if (config_.test_extra_ipv4_network_) {
1075 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1076 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1077 }
1078 if (config_.test_ipv6_network_) {
1079 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1080 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1081 }
1082 }
1083
1084 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1085
1086 private:
1087 LoopbackNetworkConfiguration config_;
1088 };
1089
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001090 // The method sets up a call from the session to itself, in a loopback
1091 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001092 // disconnection, and then a permanent disconnection.
1093 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001094 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1095 // While running the call, this method also checks if the session goes through
1096 // the correct sequence of ICE states when a connection is established,
1097 // broken, and re-established.
1098 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001099 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1100 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001101 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001102
1103 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1104 LoopbackNetworkManager loopback_network_manager(this, config);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001105 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001106 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001107 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001108
1109 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1110 observer_.ice_gathering_state_);
1111 SetLocalDescriptionWithoutError(offer);
1112 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1113 observer_.ice_connection_state_);
1114 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
1115 observer_.ice_gathering_state_,
1116 kIceCandidatesTimeout);
1117 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1118 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
1119 observer_.ice_gathering_state_,
1120 kIceCandidatesTimeout);
1121
1122 std::string sdp;
1123 offer->ToString(&sdp);
1124 SessionDescriptionInterface* desc =
jbauchfabe2c92015-07-16 13:43:14 -07001125 webrtc::CreateSessionDescription(
1126 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001127 ASSERT_TRUE(desc != NULL);
1128 SetRemoteDescriptionWithoutError(desc);
1129
1130 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
1131 observer_.ice_connection_state_,
1132 kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001133
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001134 // The ice connection state is "Connected" too briefly to catch in a test.
1135 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001136 observer_.ice_connection_state_,
1137 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001138
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001139 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001140 // Adding firewall rule to block ping requests, which should cause
1141 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001142
1143 loopback_network_manager.ApplyFirewallRules(fss_.get());
1144
1145 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001146 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1147 observer_.ice_connection_state_,
1148 kIceCandidatesTimeout);
1149
jbauchac8869e2015-07-03 01:36:14 -07001150 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001151
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001152 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001153 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001154 // Session is automatically calling OnSignalingReady after creation of
1155 // new portallocator session which will allocate new set of candidates.
1156
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001157 LOG(LS_INFO) << "Firewall Rules cleared";
1158
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001159 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001160 observer_.ice_connection_state_,
1161 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001162
1163 // Now we block ping requests and wait until the ICE connection transitions
1164 // to the Failed state. This will take at least 30 seconds because it must
1165 // wait for the Port to timeout.
1166 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001167
1168 loopback_network_manager.ApplyFirewallRules(fss_.get());
1169 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001170 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001171 observer_.ice_connection_state_,
1172 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001173 }
1174
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001175 void TestLoopbackCall() {
1176 LoopbackNetworkConfiguration config;
1177 TestLoopbackCall(config);
1178 }
1179
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001180 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1181 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001182 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1183 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1184
1185 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001186 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1187 codecs.push_back(kCNCodec1);
1188 codecs.push_back(kCNCodec2);
1189 media_engine_->SetAudioCodecs(codecs);
1190 desc_factory_->set_audio_codecs(codecs);
1191 }
1192
1193 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1194 const cricket::ContentDescription* description = content->description;
1195 ASSERT(description != NULL);
1196 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001197 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001198 ASSERT(audio_content_desc != NULL);
1199 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1200 if (audio_content_desc->codecs()[i].name == "CN")
1201 return false;
1202 }
1203 return true;
1204 }
1205
1206 void SetLocalDescriptionWithDataChannel() {
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00001207 webrtc::InternalDataChannelInit dci;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001208 dci.reliable = false;
1209 session_->CreateDataChannel("datachannel", &dci);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001210 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001211 SetLocalDescriptionWithoutError(offer);
1212 }
1213
wu@webrtc.org91053e72013-08-10 07:18:04 +00001214 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001215 RTCCertificateGenerationMethod cert_gen_method,
1216 CreateSessionDescriptionRequest::Type type) {
1217 InitWithDtls(cert_gen_method);
1218 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1219 }
1220
1221 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1222 CreateSessionDescriptionRequest::Type type) {
1223 InitWithDtlsIdentityGenFail();
1224 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1225 }
1226
1227 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001228 bool success, CreateSessionDescriptionRequest::Type type) {
Henrik Boström87713d02015-08-25 09:53:21 +02001229 CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001230 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001231 if (type == CreateSessionDescriptionRequest::kAnswer) {
1232 cricket::MediaSessionOptions options;
1233 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001234 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001235 ASSERT_TRUE(offer.get() != NULL);
1236 SetRemoteDescriptionWithoutError(offer.release());
1237 }
1238
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001239 PeerConnectionInterface::RTCOfferAnswerOptions options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001240 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001241 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001242 observers[kNumber];
1243 for (int i = 0; i < kNumber; ++i) {
1244 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1245 if (type == CreateSessionDescriptionRequest::kOffer) {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001246 session_->CreateOffer(observers[i], options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001247 } else {
1248 session_->CreateAnswer(observers[i], NULL);
1249 }
1250 }
1251
1252 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1253 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1254 WebRtcSessionCreateSDPObserverForTest::kFailed;
1255
1256 for (int i = 0; i < kNumber; ++i) {
1257 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1258 if (success) {
1259 EXPECT_TRUE(observers[i]->description() != NULL);
1260 } else {
1261 EXPECT_TRUE(observers[i]->description() == NULL);
1262 }
1263 }
1264 }
1265
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001266 void ConfigureAllocatorWithTurn() {
1267 cricket::RelayServerConfig relay_server(cricket::RELAY_TURN);
1268 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
1269 relay_server.credentials = credentials;
1270 relay_server.ports.push_back(cricket::ProtocolAddress(
1271 kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1272 allocator_->AddRelay(relay_server);
1273 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher2159b892015-08-21 20:46:05 -07001274 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001275 }
1276
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001277 cricket::FakeMediaEngine* media_engine_;
1278 cricket::FakeDataEngine* data_engine_;
1279 cricket::FakeDeviceManager* device_manager_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001280 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
1281 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001282 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1283 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1284 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1285 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1286 rtc::SocketServerScope ss_scope_;
1287 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001288 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001289 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001290 rtc::FakeNetworkManager network_manager_;
1291 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001292 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001293 rtc::scoped_ptr<FakeConstraints> constraints_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001294 FakeMediaStreamSignaling mediastream_signaling_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001295 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001296 MockIceObserver observer_;
1297 cricket::FakeVideoMediaChannel* video_channel_;
1298 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001299 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001300};
1301
Henrik Boström87713d02015-08-25 09:53:21 +02001302TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1303 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001304 // SDES is disabled when DTLS is on.
1305 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001306}
1307
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001308TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001309 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001310 // SDES is required if DTLS is off.
1311 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001312}
1313
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001314TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1315 TestSessionCandidatesWithBundleRtcpMux(false, false);
1316}
1317
1318// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1319// with rtcp-mux and/or bundle.
1320TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1321 TestSessionCandidatesWithBundleRtcpMux(false, true);
1322}
1323
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1325 TestSessionCandidatesWithBundleRtcpMux(true, true);
1326}
1327
1328TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001329 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1330 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001331 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001332 mediastream_signaling_.SendAudioVideoStream1();
1333 InitiateCall();
1334 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1335 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1336 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1337}
1338
1339TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001340 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1341 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001342 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001343 rtc::FP_UDP,
1344 rtc::FD_ANY,
1345 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001346 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001347 mediastream_signaling_.SendAudioVideoStream1();
1348 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001349 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001350 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1351 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1352 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1353}
1354
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001355// Test session delivers no candidates gathered when constraint set to "none".
1356TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1357 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001358 InitWithIceTransport(PeerConnectionInterface::kNone);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001359 mediastream_signaling_.SendAudioVideoStream1();
1360 InitiateCall();
1361 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1362 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1363 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1364}
1365
1366// Test session delivers only relay candidates gathered when constaint set to
1367// "relay".
1368TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1369 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1370 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001371 InitWithIceTransport(PeerConnectionInterface::kRelay);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001372 mediastream_signaling_.SendAudioVideoStream1();
1373 InitiateCall();
1374 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1375 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1376 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1377 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1378 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1379 observer_.mline_0_candidates_[i].type());
1380 }
1381 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1382 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1383 observer_.mline_1_candidates_[i].type());
1384 }
1385}
1386
1387// Test session delivers all candidates gathered when constaint set to "all".
1388TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1389 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001390 InitWithIceTransport(PeerConnectionInterface::kAll);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001391 mediastream_signaling_.SendAudioVideoStream1();
1392 InitiateCall();
1393 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1394 // Host + STUN. By default allocator is disabled to gather relay candidates.
1395 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1396 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1397}
1398
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001399TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001400 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001401 SessionDescriptionInterface* offer = NULL;
1402 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1403 std::string unknown_action;
1404 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1405 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1406}
1407
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001408// Test creating offers and receive answers and make sure the
1409// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001410TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001411 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001412 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001413 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001414 const std::string session_id_orig = offer->session_id();
1415 const std::string session_version_orig = offer->session_version();
1416 SetLocalDescriptionWithoutError(offer);
1417
1418 mediastream_signaling_.SendAudioVideoStream2();
1419 SessionDescriptionInterface* answer =
1420 CreateRemoteAnswer(session_->local_description());
1421 SetRemoteDescriptionWithoutError(answer);
1422
1423 video_channel_ = media_engine_->GetVideoChannel(0);
1424 voice_channel_ = media_engine_->GetVoiceChannel(0);
1425
1426 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1427 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1428
1429 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1430 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1431
1432 ASSERT_EQ(1u, video_channel_->send_streams().size());
1433 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1434 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1435 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1436
1437 // Create new offer without send streams.
1438 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001439 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001440
1441 // Verify the session id is the same and the session version is
1442 // increased.
1443 EXPECT_EQ(session_id_orig, offer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001444 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1445 rtc::FromString<uint64>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001446
1447 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001448 EXPECT_EQ(0u, video_channel_->send_streams().size());
1449 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001450
1451 mediastream_signaling_.SendAudioVideoStream2();
1452 answer = CreateRemoteAnswer(session_->local_description());
1453 SetRemoteDescriptionWithoutError(answer);
1454
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001455 // Make sure the receive streams have not changed.
1456 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1457 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1458 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1459 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1460}
1461
1462// Test receiving offers and creating answers and make sure the
1463// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001464TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001465 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001466 mediastream_signaling_.SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001467 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001468 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001469 SetRemoteDescriptionWithoutError(offer);
1470
1471 mediastream_signaling_.SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001472 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001473 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001474 SetLocalDescriptionWithoutError(answer);
1475
1476 const std::string session_id_orig = answer->session_id();
1477 const std::string session_version_orig = answer->session_version();
1478
1479 video_channel_ = media_engine_->GetVideoChannel(0);
1480 voice_channel_ = media_engine_->GetVoiceChannel(0);
1481
1482 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1483 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1484
1485 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1486 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1487
1488 ASSERT_EQ(1u, video_channel_->send_streams().size());
1489 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1490 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1491 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1492
1493 mediastream_signaling_.SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001494 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001495 SetRemoteDescriptionWithoutError(offer);
1496
1497 // Answer by turning off all send streams.
1498 mediastream_signaling_.SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001499 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001500
1501 // Verify the session id is the same and the session version is
1502 // increased.
1503 EXPECT_EQ(session_id_orig, answer->session_id());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001504 EXPECT_LT(rtc::FromString<uint64>(session_version_orig),
1505 rtc::FromString<uint64>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001506 SetLocalDescriptionWithoutError(answer);
1507
1508 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1509 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1510 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1511 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1512 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1513 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1514
1515 // Make sure we have no send streams.
1516 EXPECT_EQ(0u, video_channel_->send_streams().size());
1517 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1518}
1519
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001520TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001521 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001522 media_engine_->set_fail_create_channel(true);
1523
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001524 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001525 ASSERT_TRUE(offer != NULL);
1526 // SetRemoteDescription and SetLocalDescription will take the ownership of
1527 // the offer.
1528 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001529 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001530 ASSERT_TRUE(offer != NULL);
1531 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1532}
1533
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001534//
1535// Tests for creating/setting SDP under different SDES/DTLS polices:
1536//
1537// --DTLS off and SDES on
1538// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1539// set local/remote offer/answer with crypto --> success
1540// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1541// failure
1542// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1543// failure
1544// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1545// failure
1546//
1547// --DTLS on and SDES off
1548// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1549// set local/remote offer/answer with DTLS fingerprint --> success
1550// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1551// fingerprint --> failure
1552// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1553// --> failure
1554// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1555// --> failure
1556//
1557// --Encryption disabled: DTLS off and SDES off
1558// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1559// answer without SDES or DTLS --> success
1560// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1561// answer without SDES or DTLS --> success
1562//
1563
1564// Test that we return a failure when applying a remote/local offer that doesn't
1565// have cryptos enabled when DTLS is off.
1566TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001567 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001568 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001569 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001570 JsepSessionDescription* offer = CreateRemoteOffer(
1571 options, cricket::SEC_DISABLED);
1572 ASSERT_TRUE(offer != NULL);
1573 VerifyNoCryptoParams(offer->description(), false);
1574 // SetRemoteDescription and SetLocalDescription will take the ownership of
1575 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001576 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001577 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1578 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001579 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001580}
1581
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001582// Test that we return a failure when applying a local answer that doesn't have
1583// cryptos enabled when DTLS is off.
1584TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001585 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001586 SessionDescriptionInterface* offer = NULL;
1587 SessionDescriptionInterface* answer = NULL;
1588 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1589 // SetRemoteDescription and SetLocalDescription will take the ownership of
1590 // the offer.
1591 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001592 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001593}
1594
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001595// Test we will return fail when apply an remote answer that doesn't have
1596// crypto enabled when DTLS is off.
1597TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001598 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001599 SessionDescriptionInterface* offer = NULL;
1600 SessionDescriptionInterface* answer = NULL;
1601 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1602 // SetRemoteDescription and SetLocalDescription will take the ownership of
1603 // the offer.
1604 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001605 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001606}
1607
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001608// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1609// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001610TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001611 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001612 mediastream_signaling_.SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001613 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001614 SetFactoryDtlsSrtp();
1615 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001616 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001617 JsepSessionDescription* offer =
1618 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001619 ASSERT_TRUE(offer != NULL);
1620 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001621 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001622
1623 // SetRemoteDescription will take the ownership of the offer.
1624 SetRemoteDescriptionWithoutError(offer);
1625
1626 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001627 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001628 ASSERT_TRUE(answer != NULL);
1629 VerifyFingerprintStatus(answer->description(), true);
1630 // Check that we don't have an a=crypto line in the answer.
1631 VerifyNoCryptoParams(answer->description(), true);
1632
1633 // Now set the local description, which should work, even without a=crypto.
1634 SetLocalDescriptionWithoutError(answer);
1635}
1636
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001637// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1638// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001639TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001640 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001641 mediastream_signaling_.SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001642 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001643 SetFactoryDtlsSrtp();
1644
1645 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001646 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001647 ASSERT_TRUE(offer != NULL);
1648 VerifyFingerprintStatus(offer->description(), true);
1649 // Check that we don't have an a=crypto line in the offer.
1650 VerifyNoCryptoParams(offer->description(), true);
1651
1652 // Now set the local description, which should work, even without a=crypto.
1653 SetLocalDescriptionWithoutError(offer);
1654
1655 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001656 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001657 JsepSessionDescription* answer =
1658 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1659 ASSERT_TRUE(answer != NULL);
1660 VerifyFingerprintStatus(answer->description(), true);
1661 VerifyNoCryptoParams(answer->description(), true);
1662
1663 // SetRemoteDescription will take the ownership of the answer.
1664 SetRemoteDescriptionWithoutError(answer);
1665}
1666
1667// Test that if we support DTLS and the other side didn't offer a fingerprint,
1668// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001669TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001670 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001671 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001672 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001673 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001674 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001675 JsepSessionDescription* offer = CreateRemoteOffer(
1676 options, cricket::SEC_REQUIRED);
1677 ASSERT_TRUE(offer != NULL);
1678 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001679 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001680
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001681 // SetRemoteDescription will take the ownership of the offer.
1682 SetRemoteDescriptionOfferExpectError(
1683 kSdpWithoutDtlsFingerprint, offer);
1684
1685 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1686 // SetLocalDescription will take the ownership of the offer.
1687 SetLocalDescriptionOfferExpectError(
1688 kSdpWithoutDtlsFingerprint, offer);
1689}
1690
1691// Test that we return a failure when applying a local answer that doesn't have
1692// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001693TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001694 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001695 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001696 SessionDescriptionInterface* offer = NULL;
1697 SessionDescriptionInterface* answer = NULL;
1698 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1699
1700 // SetRemoteDescription and SetLocalDescription will take the ownership of
1701 // the offer and answer.
1702 SetRemoteDescriptionWithoutError(offer);
1703 SetLocalDescriptionAnswerExpectError(
1704 kSdpWithoutDtlsFingerprint, answer);
1705}
1706
1707// Test that we return a failure when applying a remote answer that doesn't have
1708// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001709TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001710 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeeff3938292015-07-15 12:20:53 -07001711 // Enable both SDES and DTLS, so that offer won't be outright rejected as a
1712 // result of using the "UDP/TLS/RTP/SAVPF" profile.
Henrik Boström87713d02015-08-25 09:53:21 +02001713 InitWithDtls(GetParam());
deadbeeff3938292015-07-15 12:20:53 -07001714 session_->SetSdesPolicy(cricket::SEC_ENABLED);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001715 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001716 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001717 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001718 JsepSessionDescription* answer =
1719 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
1720
1721 // SetRemoteDescription and SetLocalDescription will take the ownership of
1722 // the offer and answer.
1723 SetLocalDescriptionWithoutError(offer);
1724 SetRemoteDescriptionAnswerExpectError(
1725 kSdpWithoutDtlsFingerprint, answer);
1726}
1727
1728// Test that we create a local offer without SDES or DTLS and accept a remote
1729// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001730TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001731 mediastream_signaling_.SendAudioVideoStream1();
1732 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001733 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001734
1735 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001736 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001737 ASSERT_TRUE(offer != NULL);
1738 VerifyFingerprintStatus(offer->description(), false);
1739 // Check that we don't have an a=crypto line in the offer.
1740 VerifyNoCryptoParams(offer->description(), false);
1741
1742 // Now set the local description, which should work, even without a=crypto.
1743 SetLocalDescriptionWithoutError(offer);
1744
1745 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001746 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001747 JsepSessionDescription* answer =
1748 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1749 ASSERT_TRUE(answer != NULL);
1750 VerifyFingerprintStatus(answer->description(), false);
1751 VerifyNoCryptoParams(answer->description(), false);
1752
1753 // SetRemoteDescription will take the ownership of the answer.
1754 SetRemoteDescriptionWithoutError(answer);
1755}
1756
1757// Test that we create a local answer without SDES or DTLS and accept a remote
1758// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001759TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001760 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001761 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001762
1763 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001764 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001765 JsepSessionDescription* offer =
1766 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1767 ASSERT_TRUE(offer != NULL);
1768 VerifyFingerprintStatus(offer->description(), false);
1769 VerifyNoCryptoParams(offer->description(), false);
1770
1771 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001772 SetRemoteDescriptionWithoutError(offer);
1773
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001774 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001775 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776 ASSERT_TRUE(answer != NULL);
1777 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001778 // Check that we don't have an a=crypto line in the answer.
1779 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001780
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001781 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001782 SetLocalDescriptionWithoutError(answer);
1783}
1784
1785TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001786 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001787 mediastream_signaling_.SendNothing();
1788 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001789 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001790 SetLocalDescriptionWithoutError(offer);
1791
1792 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001793 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001794 SetLocalDescriptionWithoutError(offer2);
1795}
1796
1797TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001798 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001799 mediastream_signaling_.SendNothing();
1800 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001801 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001802 SetRemoteDescriptionWithoutError(offer);
1803
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001804 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001805 SetRemoteDescriptionWithoutError(offer2);
1806}
1807
1808TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001809 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001811 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001812 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001813 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001814 SetRemoteDescriptionOfferExpectError(
1815 "Called in wrong state: STATE_SENTINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001816}
1817
1818TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001819 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001820 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001821 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001822 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001823 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001824 SetLocalDescriptionOfferExpectError(
1825 "Called in wrong state: STATE_RECEIVEDINITIATE", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001826}
1827
1828TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001829 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001830 mediastream_signaling_.SendNothing();
1831 SessionDescriptionInterface* offer = CreateRemoteOffer();
1832 SetRemoteDescriptionExpectState(offer, BaseSession::STATE_RECEIVEDINITIATE);
1833
1834 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001835 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001836 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1837 SetLocalDescriptionExpectState(pranswer, BaseSession::STATE_SENTPRACCEPT);
1838
1839 mediastream_signaling_.SendAudioVideoStream1();
1840 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001841 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001842 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1843
1844 SetLocalDescriptionExpectState(pranswer2, BaseSession::STATE_SENTPRACCEPT);
1845
1846 mediastream_signaling_.SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001847 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001848 SetLocalDescriptionExpectState(answer, BaseSession::STATE_SENTACCEPT);
1849}
1850
1851TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001852 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001853 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001854 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001855 SetLocalDescriptionExpectState(offer, BaseSession::STATE_SENTINITIATE);
1856
1857 JsepSessionDescription* pranswer =
1858 CreateRemoteAnswer(session_->local_description());
1859 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1860
1861 SetRemoteDescriptionExpectState(pranswer,
1862 BaseSession::STATE_RECEIVEDPRACCEPT);
1863
1864 mediastream_signaling_.SendAudioVideoStream1();
1865 JsepSessionDescription* pranswer2 =
1866 CreateRemoteAnswer(session_->local_description());
1867 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1868
1869 SetRemoteDescriptionExpectState(pranswer2,
1870 BaseSession::STATE_RECEIVEDPRACCEPT);
1871
1872 mediastream_signaling_.SendAudioVideoStream2();
1873 SessionDescriptionInterface* answer =
1874 CreateRemoteAnswer(session_->local_description());
1875 SetRemoteDescriptionExpectState(answer, BaseSession::STATE_RECEIVEDACCEPT);
1876}
1877
1878TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001879 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001880 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001881 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1882
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001883 SessionDescriptionInterface* answer =
1884 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001885 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1886 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001887}
1888
1889TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001890 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001891 mediastream_signaling_.SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001892 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
1893
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001894 SessionDescriptionInterface* answer =
1895 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001896 SetRemoteDescriptionAnswerExpectError(
1897 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001898}
1899
1900TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001901 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001902 mediastream_signaling_.SendAudioVideoStream1();
1903
1904 cricket::Candidate candidate;
1905 candidate.set_component(1);
1906 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
1907
1908 // Fail since we have not set a offer description.
1909 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
1910
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001911 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001912 SetLocalDescriptionWithoutError(offer);
1913 // Candidate should be allowed to add before remote description.
1914 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1915 candidate.set_component(2);
1916 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
1917 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1918
1919 SessionDescriptionInterface* answer = CreateRemoteAnswer(
1920 session_->local_description());
1921 SetRemoteDescriptionWithoutError(answer);
1922
1923 // Verifying the candidates are copied properly from internal vector.
1924 const SessionDescriptionInterface* remote_desc =
1925 session_->remote_description();
1926 ASSERT_TRUE(remote_desc != NULL);
1927 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1928 const IceCandidateCollection* candidates =
1929 remote_desc->candidates(kMediaContentIndex0);
1930 ASSERT_EQ(2u, candidates->count());
1931 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1932 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
1933 EXPECT_EQ(1, candidates->at(0)->candidate().component());
1934 EXPECT_EQ(2, candidates->at(1)->candidate().component());
1935
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001936 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
1937 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001938 candidate.set_component(2);
1939 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
1940 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00001941 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001942
1943 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
1944 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
1945}
1946
1947// Test that a remote candidate is added to the remote session description and
1948// that it is retained if the remote session description is changed.
1949TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001950 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001951 cricket::Candidate candidate1;
1952 candidate1.set_component(1);
1953 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
1954 candidate1);
1955 mediastream_signaling_.SendAudioVideoStream1();
1956 CreateAndSetRemoteOfferAndLocalAnswer();
1957
1958 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
1959 const SessionDescriptionInterface* remote_desc =
1960 session_->remote_description();
1961 ASSERT_TRUE(remote_desc != NULL);
1962 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1963 const IceCandidateCollection* candidates =
1964 remote_desc->candidates(kMediaContentIndex0);
1965 ASSERT_EQ(1u, candidates->count());
1966 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1967
1968 // Update the RemoteSessionDescription with a new session description and
1969 // a candidate and check that the new remote session description contains both
1970 // candidates.
1971 SessionDescriptionInterface* offer = CreateRemoteOffer();
1972 cricket::Candidate candidate2;
1973 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
1974 candidate2);
1975 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
1976 SetRemoteDescriptionWithoutError(offer);
1977
1978 remote_desc = session_->remote_description();
1979 ASSERT_TRUE(remote_desc != NULL);
1980 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
1981 candidates = remote_desc->candidates(kMediaContentIndex0);
1982 ASSERT_EQ(2u, candidates->count());
1983 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
1984 // Username and password have be updated with the TransportInfo of the
1985 // SessionDescription, won't be equal to the original one.
1986 candidate2.set_username(candidates->at(0)->candidate().username());
1987 candidate2.set_password(candidates->at(0)->candidate().password());
1988 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
1989 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
1990 // No need to verify the username and password.
1991 candidate1.set_username(candidates->at(1)->candidate().username());
1992 candidate1.set_password(candidates->at(1)->candidate().password());
1993 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
1994
1995 // Test that the candidate is ignored if we can add the same candidate again.
1996 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
1997}
1998
1999// Test that local candidates are added to the local session description and
2000// that they are retained if the local session description is changed.
2001TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002002 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002003 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002004 mediastream_signaling_.SendAudioVideoStream1();
2005 CreateAndSetRemoteOfferAndLocalAnswer();
2006
2007 const SessionDescriptionInterface* local_desc = session_->local_description();
2008 const IceCandidateCollection* candidates =
2009 local_desc->candidates(kMediaContentIndex0);
2010 ASSERT_TRUE(candidates != NULL);
2011 EXPECT_EQ(0u, candidates->count());
2012
2013 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2014
2015 local_desc = session_->local_description();
2016 candidates = local_desc->candidates(kMediaContentIndex0);
2017 ASSERT_TRUE(candidates != NULL);
2018 EXPECT_LT(0u, candidates->count());
2019 candidates = local_desc->candidates(1);
2020 ASSERT_TRUE(candidates != NULL);
2021 EXPECT_LT(0u, candidates->count());
2022
2023 // Update the session descriptions.
2024 mediastream_signaling_.SendAudioVideoStream1();
2025 CreateAndSetRemoteOfferAndLocalAnswer();
2026
2027 local_desc = session_->local_description();
2028 candidates = local_desc->candidates(kMediaContentIndex0);
2029 ASSERT_TRUE(candidates != NULL);
2030 EXPECT_LT(0u, candidates->count());
2031 candidates = local_desc->candidates(1);
2032 ASSERT_TRUE(candidates != NULL);
2033 EXPECT_LT(0u, candidates->count());
2034}
2035
2036// Test that we can set a remote session description with remote candidates.
2037TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002038 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002039
2040 cricket::Candidate candidate1;
2041 candidate1.set_component(1);
2042 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2043 candidate1);
2044 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002045 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002046
2047 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2048 SetRemoteDescriptionWithoutError(offer);
2049
2050 const SessionDescriptionInterface* remote_desc =
2051 session_->remote_description();
2052 ASSERT_TRUE(remote_desc != NULL);
2053 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2054 const IceCandidateCollection* candidates =
2055 remote_desc->candidates(kMediaContentIndex0);
2056 ASSERT_EQ(1u, candidates->count());
2057 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2058
wu@webrtc.org91053e72013-08-10 07:18:04 +00002059 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002060 SetLocalDescriptionWithoutError(answer);
2061}
2062
2063// Test that offers and answers contains ice candidates when Ice candidates have
2064// been gathered.
2065TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002066 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002067 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002068 mediastream_signaling_.SendAudioVideoStream1();
2069 // Ice is started but candidates are not provided until SetLocalDescription
2070 // is called.
2071 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2072 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2073 CreateAndSetRemoteOfferAndLocalAnswer();
2074 // Wait until at least one local candidate has been collected.
2075 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2076 kIceCandidatesTimeout);
2077 EXPECT_TRUE_WAIT(0u < observer_.mline_1_candidates_.size(),
2078 kIceCandidatesTimeout);
2079
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002080 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2081
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002082 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2083 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
2084 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex1) != NULL);
2085 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex1)->count());
2086
2087 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2088 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002089 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002090 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2091 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
2092 ASSERT_TRUE(answer->candidates(kMediaContentIndex1) != NULL);
2093 EXPECT_LT(0u, answer->candidates(kMediaContentIndex1)->count());
2094 SetLocalDescriptionWithoutError(answer);
2095}
2096
2097// Verifies TransportProxy and media channels are created with content names
2098// present in the SessionDescription.
2099TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002100 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002101 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002102 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002103
2104 // CreateOffer creates session description with the content names "audio" and
2105 // "video". Goal is to modify these content names and verify transport channel
2106 // proxy in the BaseSession, as proxies are created with the content names
2107 // present in SDP.
2108 std::string sdp;
2109 EXPECT_TRUE(offer->ToString(&sdp));
2110 const std::string kAudioMid = "a=mid:audio";
2111 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2112 const std::string kVideoMid = "a=mid:video";
2113 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2114
2115 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002116 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002117 kAudioMidReplaceStr.c_str(),
2118 kAudioMidReplaceStr.length(),
2119 &sdp);
2120 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002121 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002122 kVideoMidReplaceStr.c_str(),
2123 kVideoMidReplaceStr.length(),
2124 &sdp);
2125
2126 SessionDescriptionInterface* modified_offer =
2127 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2128
2129 SetRemoteDescriptionWithoutError(modified_offer);
2130
2131 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002132 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002133 SetLocalDescriptionWithoutError(answer);
2134
2135 EXPECT_TRUE(session_->GetTransportProxy("audio_content_name") != NULL);
2136 EXPECT_TRUE(session_->GetTransportProxy("video_content_name") != NULL);
2137 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2138 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2139}
2140
2141// Test that an offer contains the correct media content descriptions based on
2142// the send streams when no constraints have been set.
2143TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002144 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002145 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2146
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002147 ASSERT_TRUE(offer != NULL);
2148 const cricket::ContentInfo* content =
2149 cricket::GetFirstAudioContent(offer->description());
2150 EXPECT_TRUE(content != NULL);
2151 content = cricket::GetFirstVideoContent(offer->description());
2152 EXPECT_TRUE(content == NULL);
2153}
2154
2155// Test that an offer contains the correct media content descriptions based on
2156// the send streams when no constraints have been set.
2157TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002158 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002159 // Test Audio only offer.
2160 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002161 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2162
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002163 const cricket::ContentInfo* content =
2164 cricket::GetFirstAudioContent(offer->description());
2165 EXPECT_TRUE(content != NULL);
2166 content = cricket::GetFirstVideoContent(offer->description());
2167 EXPECT_TRUE(content == NULL);
2168
2169 // Test Audio / Video offer.
2170 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002171 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002172 content = cricket::GetFirstAudioContent(offer->description());
2173 EXPECT_TRUE(content != NULL);
2174 content = cricket::GetFirstVideoContent(offer->description());
2175 EXPECT_TRUE(content != NULL);
2176}
2177
2178// Test that an offer contains no media content descriptions if
2179// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2180TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002181 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002182 PeerConnectionInterface::RTCOfferAnswerOptions options;
2183 options.offer_to_receive_audio = 0;
2184 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002185
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002186 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002187 CreateOffer(options));
2188
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002189 ASSERT_TRUE(offer != NULL);
2190 const cricket::ContentInfo* content =
2191 cricket::GetFirstAudioContent(offer->description());
2192 EXPECT_TRUE(content == NULL);
2193 content = cricket::GetFirstVideoContent(offer->description());
2194 EXPECT_TRUE(content == NULL);
2195}
2196
2197// Test that an offer contains only audio media content descriptions if
2198// kOfferToReceiveAudio constraints are set to true.
2199TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002200 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002201 PeerConnectionInterface::RTCOfferAnswerOptions options;
2202 options.offer_to_receive_audio =
2203 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2204
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002205 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002206 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002207
2208 const cricket::ContentInfo* content =
2209 cricket::GetFirstAudioContent(offer->description());
2210 EXPECT_TRUE(content != NULL);
2211 content = cricket::GetFirstVideoContent(offer->description());
2212 EXPECT_TRUE(content == NULL);
2213}
2214
2215// Test that an offer contains audio and video media content descriptions if
2216// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2217TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002218 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002219 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002220 PeerConnectionInterface::RTCOfferAnswerOptions options;
2221 options.offer_to_receive_audio =
2222 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2223 options.offer_to_receive_video =
2224 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2225
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002226 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002227 CreateOffer(options));
2228
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002229 const cricket::ContentInfo* content =
2230 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002231 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002232
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002233 content = cricket::GetFirstVideoContent(offer->description());
2234 EXPECT_TRUE(content != NULL);
2235
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002236 // Sets constraints to false and verifies that audio/video contents are
2237 // removed.
2238 options.offer_to_receive_audio = 0;
2239 options.offer_to_receive_video = 0;
2240 offer.reset(CreateOffer(options));
2241
2242 content = cricket::GetFirstAudioContent(offer->description());
2243 EXPECT_TRUE(content == NULL);
2244 content = cricket::GetFirstVideoContent(offer->description());
2245 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002246}
2247
2248// Test that an answer can not be created if the last remote description is not
2249// an offer.
2250TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002251 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002252 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002253 SetLocalDescriptionWithoutError(offer);
2254 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2255 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002256 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002257}
2258
2259// Test that an answer contains the correct media content descriptions when no
2260// constraints have been set.
2261TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002262 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002263 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002264 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002265 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002266 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002267 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002268 const cricket::ContentInfo* content =
2269 cricket::GetFirstAudioContent(answer->description());
2270 ASSERT_TRUE(content != NULL);
2271 EXPECT_FALSE(content->rejected);
2272
2273 content = cricket::GetFirstVideoContent(answer->description());
2274 ASSERT_TRUE(content != NULL);
2275 EXPECT_FALSE(content->rejected);
2276}
2277
2278// Test that an answer contains the correct media content descriptions when no
2279// constraints have been set and the offer only contain audio.
2280TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002281 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002282 // Create a remote offer with audio only.
2283 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002284
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002285 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002286 CreateRemoteOffer(options));
2287 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2288 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2289
2290 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002291 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002292 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002293 const cricket::ContentInfo* content =
2294 cricket::GetFirstAudioContent(answer->description());
2295 ASSERT_TRUE(content != NULL);
2296 EXPECT_FALSE(content->rejected);
2297
2298 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2299}
2300
2301// Test that an answer contains the correct media content descriptions when no
2302// constraints have been set.
2303TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002304 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002305 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002306 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002307 SetRemoteDescriptionWithoutError(offer.release());
2308 // Test with a stream with tracks.
2309 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002310 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002311 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002312 const cricket::ContentInfo* content =
2313 cricket::GetFirstAudioContent(answer->description());
2314 ASSERT_TRUE(content != NULL);
2315 EXPECT_FALSE(content->rejected);
2316
2317 content = cricket::GetFirstVideoContent(answer->description());
2318 ASSERT_TRUE(content != NULL);
2319 EXPECT_FALSE(content->rejected);
2320}
2321
2322// Test that an answer contains the correct media content descriptions when
2323// constraints have been set but no stream is sent.
2324TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002325 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002326 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002327 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002328 SetRemoteDescriptionWithoutError(offer.release());
2329
2330 webrtc::FakeConstraints constraints_no_receive;
2331 constraints_no_receive.SetMandatoryReceiveAudio(false);
2332 constraints_no_receive.SetMandatoryReceiveVideo(false);
2333
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002334 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002335 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002336 const cricket::ContentInfo* content =
2337 cricket::GetFirstAudioContent(answer->description());
2338 ASSERT_TRUE(content != NULL);
2339 EXPECT_TRUE(content->rejected);
2340
2341 content = cricket::GetFirstVideoContent(answer->description());
2342 ASSERT_TRUE(content != NULL);
2343 EXPECT_TRUE(content->rejected);
2344}
2345
2346// Test that an answer contains the correct media content descriptions when
2347// constraints have been set and streams are sent.
2348TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002349 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002350 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002351 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002352 SetRemoteDescriptionWithoutError(offer.release());
2353
2354 webrtc::FakeConstraints constraints_no_receive;
2355 constraints_no_receive.SetMandatoryReceiveAudio(false);
2356 constraints_no_receive.SetMandatoryReceiveVideo(false);
2357
2358 // Test with a stream with tracks.
2359 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002360 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002361 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002362
2363 // TODO(perkj): Should the direction be set to SEND_ONLY?
2364 const cricket::ContentInfo* content =
2365 cricket::GetFirstAudioContent(answer->description());
2366 ASSERT_TRUE(content != NULL);
2367 EXPECT_FALSE(content->rejected);
2368
2369 // TODO(perkj): Should the direction be set to SEND_ONLY?
2370 content = cricket::GetFirstVideoContent(answer->description());
2371 ASSERT_TRUE(content != NULL);
2372 EXPECT_FALSE(content->rejected);
2373}
2374
2375TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2376 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002377 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002378 PeerConnectionInterface::RTCOfferAnswerOptions options;
2379 options.offer_to_receive_audio =
2380 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2381 options.voice_activity_detection = false;
2382
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002383 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002384 CreateOffer(options));
2385
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002386 const cricket::ContentInfo* content =
2387 cricket::GetFirstAudioContent(offer->description());
2388 EXPECT_TRUE(content != NULL);
2389 EXPECT_TRUE(VerifyNoCNCodecs(content));
2390}
2391
2392TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2393 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002394 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002395 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002396 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002397 SetRemoteDescriptionWithoutError(offer.release());
2398
2399 webrtc::FakeConstraints constraints;
2400 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002401 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002402 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002403 const cricket::ContentInfo* content =
2404 cricket::GetFirstAudioContent(answer->description());
2405 ASSERT_TRUE(content != NULL);
2406 EXPECT_TRUE(VerifyNoCNCodecs(content));
2407}
2408
2409// This test verifies the call setup when remote answer with audio only and
2410// later updates with video.
2411TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002412 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002413 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2414 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2415
2416 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002417 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002418
2419 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002420 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2421
2422 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2423 // and answer;
2424 SetLocalDescriptionWithoutError(offer);
2425 SetRemoteDescriptionWithoutError(answer);
2426
2427 video_channel_ = media_engine_->GetVideoChannel(0);
2428 voice_channel_ = media_engine_->GetVoiceChannel(0);
2429
2430 ASSERT_TRUE(video_channel_ == NULL);
2431
2432 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2433 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2434 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2435
2436 // Let the remote end update the session descriptions, with Audio and Video.
2437 mediastream_signaling_.SendAudioVideoStream2();
2438 CreateAndSetRemoteOfferAndLocalAnswer();
2439
2440 video_channel_ = media_engine_->GetVideoChannel(0);
2441 voice_channel_ = media_engine_->GetVoiceChannel(0);
2442
2443 ASSERT_TRUE(video_channel_ != NULL);
2444 ASSERT_TRUE(voice_channel_ != NULL);
2445
2446 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2447 ASSERT_EQ(1u, video_channel_->send_streams().size());
2448 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2449 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2450 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2451 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2452 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2453 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2454
2455 // Change session back to audio only.
2456 mediastream_signaling_.UseOptionsAudioOnly();
2457 CreateAndSetRemoteOfferAndLocalAnswer();
2458
2459 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2460 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2461 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2462 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2463 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2464}
2465
2466// This test verifies the call setup when remote answer with video only and
2467// later updates with audio.
2468TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002469 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002470 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2471 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2472 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002473 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002474
2475 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002476 options.recv_audio = false;
2477 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002478 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2479 offer, options, cricket::SEC_ENABLED);
2480
2481 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2482 // and answer.
2483 SetLocalDescriptionWithoutError(offer);
2484 SetRemoteDescriptionWithoutError(answer);
2485
2486 video_channel_ = media_engine_->GetVideoChannel(0);
2487 voice_channel_ = media_engine_->GetVoiceChannel(0);
2488
2489 ASSERT_TRUE(voice_channel_ == NULL);
2490 ASSERT_TRUE(video_channel_ != NULL);
2491
2492 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2493 ASSERT_EQ(1u, video_channel_->send_streams().size());
2494 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2495
2496 // Update the session descriptions, with Audio and Video.
2497 mediastream_signaling_.SendAudioVideoStream2();
2498 CreateAndSetRemoteOfferAndLocalAnswer();
2499
2500 voice_channel_ = media_engine_->GetVoiceChannel(0);
2501 ASSERT_TRUE(voice_channel_ != NULL);
2502
2503 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2504 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2505 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2506 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2507
2508 // Change session back to video only.
2509 mediastream_signaling_.UseOptionsVideoOnly();
2510 CreateAndSetRemoteOfferAndLocalAnswer();
2511
2512 video_channel_ = media_engine_->GetVideoChannel(0);
2513 voice_channel_ = media_engine_->GetVoiceChannel(0);
2514
2515 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2516 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2517 ASSERT_EQ(1u, video_channel_->send_streams().size());
2518 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2519}
2520
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002521TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002522 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002523 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002524 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002525 VerifyCryptoParams(offer->description());
2526 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002527 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002528 VerifyCryptoParams(answer->description());
2529}
2530
2531TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002532 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002533 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002534 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002535 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002536 VerifyNoCryptoParams(offer->description(), false);
2537}
2538
2539TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002540 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002541 VerifyAnswerFromNonCryptoOffer();
2542}
2543
2544TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002545 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002546 VerifyAnswerFromCryptoOffer();
2547}
2548
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002549// This test verifies that setLocalDescription fails if
2550// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2551TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002552 Init();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002553 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002554 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2555
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002556 std::string sdp;
2557 RemoveIceUfragPwdLines(offer.get(), &sdp);
2558 SessionDescriptionInterface* modified_offer =
2559 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002560 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002561}
2562
2563// This test verifies that setRemoteDescription fails if
2564// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2565TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002566 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002567 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002568 std::string sdp;
2569 RemoveIceUfragPwdLines(offer.get(), &sdp);
2570 SessionDescriptionInterface* modified_offer =
2571 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002572 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002573}
2574
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002575// This test verifies that setLocalDescription fails if local offer has
2576// too short ice ufrag and pwd strings.
2577TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002578 Init();
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002579 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002580 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2581
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002582 std::string sdp;
2583 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2584 // recommended values of 4 and 22 bytes respectively.
2585 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2586 SessionDescriptionInterface* modified_offer =
2587 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2588 std::string error;
2589 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2590
2591 // Test with string greater than 256.
2592 sdp.clear();
2593 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2594 &sdp);
2595 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2596 NULL);
2597 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2598}
2599
2600// This test verifies that setRemoteDescription fails if remote offer has
2601// too short ice ufrag and pwd strings.
2602TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002603 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002604 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002605 std::string sdp;
2606 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2607 // recommended values of 4 and 22 bytes respectively.
2608 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2609 SessionDescriptionInterface* modified_offer =
2610 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2611 std::string error;
2612 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2613
2614 sdp.clear();
2615 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2616 &sdp);
2617 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2618 NULL);
2619 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2620}
2621
honghaiz503726c2015-07-31 12:37:38 -07002622// Test that if the remote description indicates the peer requested ICE restart
2623// (via a new ufrag or pwd), the old ICE candidates are not copied,
2624// and vice versa.
2625TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithIceRestart) {
2626 Init();
2627 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2628
2629 // Create the first offer.
2630 std::string sdp;
2631 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2632 "abcdefghijklmnopqrstuvwx", &sdp);
2633 SessionDescriptionInterface* offer1 =
2634 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2635 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2636 0, "", "", "relay", 0, "");
2637 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2638 candidate1);
2639 EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1));
2640 SetRemoteDescriptionWithoutError(offer1);
2641 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2642
2643 // The second offer has the same ufrag and pwd but different address.
2644 sdp.clear();
2645 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2646 "abcdefghijklmnopqrstuvwx", &sdp);
2647 SessionDescriptionInterface* offer2 =
2648 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2649 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2650 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2651 candidate1);
2652 EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2));
2653 SetRemoteDescriptionWithoutError(offer2);
2654 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2655
2656 // The third offer has a different ufrag and different address.
2657 sdp.clear();
2658 ModifyIceUfragPwdLines(offer.get(), "0123456789012333",
2659 "abcdefghijklmnopqrstuvwx", &sdp);
2660 SessionDescriptionInterface* offer3 =
2661 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2662 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2663 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2664 candidate1);
2665 EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3));
2666 SetRemoteDescriptionWithoutError(offer3);
2667 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2668
2669 // The fourth offer has no candidate but a different ufrag/pwd.
2670 sdp.clear();
2671 ModifyIceUfragPwdLines(offer.get(), "0123456789012444",
2672 "abcdefghijklmnopqrstuvyz", &sdp);
2673 SessionDescriptionInterface* offer4 =
2674 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2675 SetRemoteDescriptionWithoutError(offer4);
2676 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2677}
2678
Donald Curtisd4f769d2015-05-28 09:48:21 -07002679// Test that candidates sent to the "video" transport do not get pushed down to
2680// the "audio" transport channel when bundling using TransportProxy.
2681TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2682 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2683
2684 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2685 mediastream_signaling_.SendAudioVideoStream1();
2686
2687 PeerConnectionInterface::RTCOfferAnswerOptions options;
2688 options.use_rtp_mux = true;
2689
2690 SessionDescriptionInterface* offer = CreateRemoteOffer();
2691 SetRemoteDescriptionWithoutError(offer);
2692
2693 SessionDescriptionInterface* answer = CreateAnswer(NULL);
2694 SetLocalDescriptionWithoutError(answer);
2695
2696 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2697 session_->GetTransportProxy("video")->impl());
2698
2699 cricket::Transport* t = session_->GetTransport("audio");
2700
2701 // Checks if one of the transport channels contains a connection using a given
2702 // port.
2703 auto connection_with_remote_port = [t](int port) {
2704 cricket::TransportStats stats;
2705 t->GetStats(&stats);
2706 for (auto& chan_stat : stats.channel_stats) {
2707 for (auto& conn_info : chan_stat.connection_infos) {
2708 if (conn_info.remote_candidate.address().port() == port) {
2709 return true;
2710 }
2711 }
2712 }
2713 return false;
2714 };
2715
2716 EXPECT_FALSE(connection_with_remote_port(5000));
2717 EXPECT_FALSE(connection_with_remote_port(5001));
2718 EXPECT_FALSE(connection_with_remote_port(6000));
2719
2720 // The way the *_WAIT checks work is they only wait if the condition fails,
2721 // which does not help in the case where state is not changing. This is
2722 // problematic in this test since we want to verify that adding a video
2723 // candidate does _not_ change state. So we interleave candidates and assume
2724 // that messages are executed in the order they were posted.
2725
2726 // First audio candidate.
2727 cricket::Candidate candidate0;
2728 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2729 candidate0.set_component(1);
2730 candidate0.set_protocol("udp");
2731 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2732 candidate0);
2733 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2734
2735 // Video candidate.
2736 cricket::Candidate candidate1;
2737 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2738 candidate1.set_component(1);
2739 candidate1.set_protocol("udp");
2740 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2741 candidate1);
2742 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2743
2744 // Second audio candidate.
2745 cricket::Candidate candidate2;
2746 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
2747 candidate2.set_component(1);
2748 candidate2.set_protocol("udp");
2749 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2750 candidate2);
2751 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2752
2753 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
2754 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
2755
2756 // No need here for a _WAIT check since we are checking that state hasn't
2757 // changed: if this is false we would be doing waits for nothing and if this
2758 // is true then there will be no messages processed anyways.
2759 EXPECT_FALSE(connection_with_remote_port(6000));
2760}
2761
Peter Thatcher4eddf182015-04-30 10:55:59 -07002762// kBundlePolicyBalanced bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002763TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
2764 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002765 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002766
2767 PeerConnectionInterface::RTCOfferAnswerOptions options;
2768 options.use_rtp_mux = true;
2769
2770 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002771 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07002772
2773 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2774 session_->GetTransportProxy("video")->impl());
2775
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002776 mediastream_signaling_.SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002777 SessionDescriptionInterface* answer =
2778 CreateRemoteAnswer(session_->local_description());
2779 SetRemoteDescriptionWithoutError(answer);
2780
2781 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2782 session_->GetTransportProxy("video")->impl());
2783}
2784
2785// kBundlePolicyBalanced bundle policy but no BUNDLE in the answer.
2786TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
2787 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
2788 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002789
Donald Curtis0e209b02015-03-24 09:29:54 -07002790 PeerConnectionInterface::RTCOfferAnswerOptions options;
2791 options.use_rtp_mux = true;
2792
2793 SessionDescriptionInterface* offer = CreateOffer(options);
2794 SetLocalDescriptionWithoutError(offer);
2795
2796 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2797 session_->GetTransportProxy("video")->impl());
2798
2799 mediastream_signaling_.SendAudioVideoStream2();
2800
2801 // Remove BUNDLE from the answer.
2802 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2803 CreateRemoteAnswer(session_->local_description()));
2804 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2805 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2806 JsepSessionDescription* modified_answer =
2807 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2808 modified_answer->Initialize(answer_copy, "1", "1");
2809 SetRemoteDescriptionWithoutError(modified_answer); //
2810
2811 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2812 session_->GetTransportProxy("video")->impl());
2813}
2814
2815// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
2816TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
2817 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2818 mediastream_signaling_.SendAudioVideoStream1();
2819
2820 PeerConnectionInterface::RTCOfferAnswerOptions options;
2821 options.use_rtp_mux = true;
2822
2823 SessionDescriptionInterface* offer = CreateOffer(options);
2824 SetLocalDescriptionWithoutError(offer);
2825
2826 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2827 session_->GetTransportProxy("video")->impl());
2828
2829 mediastream_signaling_.SendAudioVideoStream2();
2830 SessionDescriptionInterface* answer =
2831 CreateRemoteAnswer(session_->local_description());
2832 SetRemoteDescriptionWithoutError(answer);
2833
2834 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2835 session_->GetTransportProxy("video")->impl());
2836}
2837
2838// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
2839TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
2840 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2841 mediastream_signaling_.SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002842
Donald Curtis0e209b02015-03-24 09:29:54 -07002843 PeerConnectionInterface::RTCOfferAnswerOptions options;
2844 options.use_rtp_mux = true;
2845
2846 SessionDescriptionInterface* offer = CreateOffer(options);
2847 SetLocalDescriptionWithoutError(offer);
2848
2849 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2850 session_->GetTransportProxy("video")->impl());
2851
2852 mediastream_signaling_.SendAudioVideoStream2();
2853
2854 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002855 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002856 CreateRemoteAnswer(session_->local_description()));
2857 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2858 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2859 JsepSessionDescription* modified_answer =
2860 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2861 modified_answer->Initialize(answer_copy, "1", "1");
2862 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002863
Donald Curtis0e209b02015-03-24 09:29:54 -07002864 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2865 session_->GetTransportProxy("video")->impl());
2866}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002867
Peter Thatcher4eddf182015-04-30 10:55:59 -07002868// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002869TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
2870 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2871 mediastream_signaling_.SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002872
Donald Curtis0e209b02015-03-24 09:29:54 -07002873 PeerConnectionInterface::RTCOfferAnswerOptions options;
2874 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002875
Donald Curtis0e209b02015-03-24 09:29:54 -07002876 SessionDescriptionInterface* offer = CreateOffer(options);
2877 SetLocalDescriptionWithoutError(offer);
2878
2879 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2880 session_->GetTransportProxy("video")->impl());
2881
2882 mediastream_signaling_.SendAudioVideoStream2();
2883 SessionDescriptionInterface* answer =
2884 CreateRemoteAnswer(session_->local_description());
2885 SetRemoteDescriptionWithoutError(answer);
2886
2887 // This should lead to an audio-only call but isn't implemented
2888 // correctly yet.
2889 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2890 session_->GetTransportProxy("video")->impl());
2891}
2892
2893// kBundlePolicyMaxCompat bundle policy but no BUNDLE in the answer.
2894TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
2895 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
2896 mediastream_signaling_.SendAudioVideoStream1();
2897 PeerConnectionInterface::RTCOfferAnswerOptions options;
2898 options.use_rtp_mux = true;
2899
2900 SessionDescriptionInterface* offer = CreateOffer(options);
2901 SetLocalDescriptionWithoutError(offer);
2902
2903 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2904 session_->GetTransportProxy("video")->impl());
2905
2906 mediastream_signaling_.SendAudioVideoStream2();
2907
2908 // Remove BUNDLE from the answer.
2909 rtc::scoped_ptr<SessionDescriptionInterface> answer(
2910 CreateRemoteAnswer(session_->local_description()));
2911 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2912 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2913 JsepSessionDescription* modified_answer =
2914 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2915 modified_answer->Initialize(answer_copy, "1", "1");
2916 SetRemoteDescriptionWithoutError(modified_answer); //
2917
2918 EXPECT_NE(session_->GetTransportProxy("audio")->impl(),
2919 session_->GetTransportProxy("video")->impl());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002920}
2921
Peter Thatcher4eddf182015-04-30 10:55:59 -07002922// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
2923TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
2924 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
2925 mediastream_signaling_.SendAudioVideoStream1();
2926
2927 PeerConnectionInterface::RTCOfferAnswerOptions options;
2928 options.use_rtp_mux = true;
2929
2930 SessionDescriptionInterface* offer = CreateOffer(options);
2931 SetRemoteDescriptionWithoutError(offer);
2932
2933 EXPECT_EQ(session_->GetTransportProxy("audio")->impl(),
2934 session_->GetTransportProxy("video")->impl());
2935}
2936
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002937TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
2938 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
2939 mediastream_signaling_.SendAudioVideoStream1();
2940
2941 PeerConnectionInterface::RTCOfferAnswerOptions options;
2942 SessionDescriptionInterface* offer = CreateOffer(options);
2943 SetLocalDescriptionWithoutError(offer);
2944
2945 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2946 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2947
2948 mediastream_signaling_.SendAudioVideoStream2();
2949 SessionDescriptionInterface* answer =
2950 CreateRemoteAnswer(session_->local_description());
2951 SetRemoteDescriptionWithoutError(answer);
2952
2953 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2954 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2955}
2956
2957TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
2958 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
2959 mediastream_signaling_.SendAudioVideoStream1();
2960
2961 PeerConnectionInterface::RTCOfferAnswerOptions options;
2962 SessionDescriptionInterface* offer = CreateOffer(options);
2963 SetLocalDescriptionWithoutError(offer);
2964
2965 EXPECT_TRUE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2966 EXPECT_TRUE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2967
2968 mediastream_signaling_.SendAudioVideoStream2();
2969 SessionDescriptionInterface* answer =
2970 CreateRemoteAnswer(session_->local_description());
2971 SetRemoteDescriptionWithoutError(answer);
2972
2973 EXPECT_FALSE(session_->GetTransportProxy("audio")->impl()->HasChannel(2));
2974 EXPECT_FALSE(session_->GetTransportProxy("video")->impl()->HasChannel(2));
2975}
2976
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002977// This test verifies that SetLocalDescription and SetRemoteDescription fails
2978// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2979TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002980 Init();
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002981 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002982
2983 PeerConnectionInterface::RTCOfferAnswerOptions options;
2984 options.use_rtp_mux = true;
2985
2986 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002987 std::string offer_str;
2988 offer->ToString(&offer_str);
2989 // Disable rtcp-mux
2990 const std::string rtcp_mux = "rtcp-mux";
2991 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002992 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002993 xrtcp_mux.c_str(), xrtcp_mux.length(),
2994 &offer_str);
2995 JsepSessionDescription *local_offer =
2996 new JsepSessionDescription(JsepSessionDescription::kOffer);
2997 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002998 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002999 JsepSessionDescription *remote_offer =
3000 new JsepSessionDescription(JsepSessionDescription::kOffer);
3001 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003002 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003003 // Trying unmodified SDP.
3004 SetLocalDescriptionWithoutError(offer);
3005}
3006
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003007TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003008 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003009 mediastream_signaling_.SendAudioVideoStream1();
3010 CreateAndSetRemoteOfferAndLocalAnswer();
3011 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3012 ASSERT_TRUE(channel != NULL);
3013 ASSERT_EQ(1u, channel->recv_streams().size());
3014 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
3015 double left_vol, right_vol;
3016 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
3017 EXPECT_EQ(1, left_vol);
3018 EXPECT_EQ(1, right_vol);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003019 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003020 session_->SetAudioPlayout(receive_ssrc, false, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003021 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
3022 EXPECT_EQ(0, left_vol);
3023 EXPECT_EQ(0, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003024 EXPECT_EQ(0, renderer->channel_id());
3025 session_->SetAudioPlayout(receive_ssrc, true, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003026 EXPECT_TRUE(channel->GetOutputScaling(receive_ssrc, &left_vol, &right_vol));
3027 EXPECT_EQ(1, left_vol);
3028 EXPECT_EQ(1, right_vol);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003029 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003030}
3031
3032TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003033 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003034 mediastream_signaling_.SendAudioVideoStream1();
3035 CreateAndSetRemoteOfferAndLocalAnswer();
3036 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3037 ASSERT_TRUE(channel != NULL);
3038 ASSERT_EQ(1u, channel->send_streams().size());
3039 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3040 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3041
3042 cricket::AudioOptions options;
3043 options.echo_cancellation.Set(true);
3044
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003045 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003046 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003047 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3048 EXPECT_FALSE(channel->options().echo_cancellation.IsSet());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003049 EXPECT_EQ(0, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003050 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003051
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003052 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003053 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003054 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3055 bool value;
3056 EXPECT_TRUE(channel->options().echo_cancellation.Get(&value));
3057 EXPECT_TRUE(value);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003058 EXPECT_EQ(-1, renderer->channel_id());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003059 EXPECT_TRUE(renderer->sink() == NULL);
3060}
3061
3062TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003063 Init();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003064 mediastream_signaling_.SendAudioVideoStream1();
3065 CreateAndSetRemoteOfferAndLocalAnswer();
3066 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3067 ASSERT_TRUE(channel != NULL);
3068 ASSERT_EQ(1u, channel->send_streams().size());
3069 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3070
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003071 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003072 cricket::AudioOptions options;
3073 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3074 EXPECT_TRUE(renderer->sink() != NULL);
3075
3076 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3077 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3078 // SetSink(NULL) callback afterwards.
3079 renderer.reset();
3080
3081 // This will trigger SetSink(NULL) if no OnClose() callback.
3082 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003083}
3084
3085TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003086 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003087 mediastream_signaling_.SendAudioVideoStream1();
3088 CreateAndSetRemoteOfferAndLocalAnswer();
3089 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3090 ASSERT_TRUE(channel != NULL);
3091 ASSERT_LT(0u, channel->renderers().size());
3092 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3093 ASSERT_EQ(1u, channel->recv_streams().size());
3094 uint32 receive_ssrc = channel->recv_streams()[0].first_ssrc();
3095 cricket::FakeVideoRenderer renderer;
3096 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
3097 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
3098 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
3099 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3100}
3101
3102TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003103 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003104 mediastream_signaling_.SendAudioVideoStream1();
3105 CreateAndSetRemoteOfferAndLocalAnswer();
3106 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3107 ASSERT_TRUE(channel != NULL);
3108 ASSERT_EQ(1u, channel->send_streams().size());
3109 uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3110 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3111 cricket::VideoOptions* options = NULL;
3112 session_->SetVideoSend(send_ssrc, false, options);
3113 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3114 session_->SetVideoSend(send_ssrc, true, options);
3115 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3116}
3117
3118TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3119 TestCanInsertDtmf(false);
3120}
3121
3122TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3123 TestCanInsertDtmf(true);
3124}
3125
3126TEST_F(WebRtcSessionTest, InsertDtmf) {
3127 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003128 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003129 mediastream_signaling_.SendAudioVideoStream1();
3130 CreateAndSetRemoteOfferAndLocalAnswer();
3131 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3132 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3133
3134 // Insert DTMF
3135 const int expected_flags = DF_SEND;
3136 const int expected_duration = 90;
3137 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3138 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3139 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3140
3141 // Verify
3142 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
3143 const uint32 send_ssrc = channel->send_streams()[0].first_ssrc();
3144 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
3145 expected_duration, expected_flags));
3146 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
3147 expected_duration, expected_flags));
3148 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
3149 expected_duration, expected_flags));
3150}
3151
3152// This test verifies the |initiator| flag when session initiates the call.
3153TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003154 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003155 EXPECT_FALSE(session_->initiator());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003156 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003157 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3158 SetLocalDescriptionWithoutError(offer);
3159 EXPECT_TRUE(session_->initiator());
3160 SetRemoteDescriptionWithoutError(answer);
3161 EXPECT_TRUE(session_->initiator());
3162}
3163
3164// This test verifies the |initiator| flag when session receives the call.
3165TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003166 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003167 EXPECT_FALSE(session_->initiator());
3168 SessionDescriptionInterface* offer = CreateRemoteOffer();
3169 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003170 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003171
3172 EXPECT_FALSE(session_->initiator());
3173 SetLocalDescriptionWithoutError(answer);
3174 EXPECT_FALSE(session_->initiator());
3175}
3176
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003177// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3178TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003179 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003180 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003181 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003182 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003183 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003184 CreateRemoteAnswer(session_->local_description()));
3185
3186 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3187 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003188 JsepSessionDescription* modified_answer =
3189 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003190
3191 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3192 answer->session_id(),
3193 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003194 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003195
wu@webrtc.org4e393072014-04-07 17:04:35 +00003196 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003197 std::string sdp;
3198 EXPECT_TRUE(answer->ToString(&sdp));
3199 const std::string kAudioMid = "a=mid:audio";
3200 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003201 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003202 kAudioMidReplaceStr.c_str(),
3203 kAudioMidReplaceStr.length(),
3204 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003205 SessionDescriptionInterface* modified_answer1 =
3206 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003207 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003208
wu@webrtc.org4e393072014-04-07 17:04:35 +00003209 // Different media types.
3210 EXPECT_TRUE(answer->ToString(&sdp));
3211 const std::string kAudioMline = "m=audio";
3212 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003213 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003214 kAudioMlineReplaceStr.c_str(),
3215 kAudioMlineReplaceStr.length(),
3216 &sdp);
3217 SessionDescriptionInterface* modified_answer2 =
3218 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3219 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3220
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003221 SetRemoteDescriptionWithoutError(answer.release());
3222}
3223
3224// Verifying remote offer and local answer have matching m-lines as per
3225// RFC 3264.
3226TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003227 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003228 mediastream_signaling_.SendAudioVideoStream1();
3229 SessionDescriptionInterface* offer = CreateRemoteOffer();
3230 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003231 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003232
3233 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3234 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003235 JsepSessionDescription* modified_answer =
3236 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003237
3238 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3239 answer->session_id(),
3240 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003241 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003242 SetLocalDescriptionWithoutError(answer);
3243}
3244
3245// This test verifies that WebRtcSession does not start candidate allocation
3246// before SetLocalDescription is called.
3247TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003248 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003249 mediastream_signaling_.SendAudioVideoStream1();
3250 SessionDescriptionInterface* offer = CreateRemoteOffer();
3251 cricket::Candidate candidate;
3252 candidate.set_component(1);
3253 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3254 candidate);
3255 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3256 cricket::Candidate candidate1;
3257 candidate1.set_component(1);
3258 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3259 candidate1);
3260 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3261 SetRemoteDescriptionWithoutError(offer);
3262 ASSERT_TRUE(session_->GetTransportProxy("audio") != NULL);
3263 ASSERT_TRUE(session_->GetTransportProxy("video") != NULL);
3264
3265 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003266 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003267 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3268 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3269
wu@webrtc.org91053e72013-08-10 07:18:04 +00003270 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003271 SetLocalDescriptionWithoutError(answer);
3272 EXPECT_TRUE(session_->GetTransportProxy("audio")->negotiated());
3273 EXPECT_TRUE(session_->GetTransportProxy("video")->negotiated());
3274 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3275}
3276
3277// This test verifies that crypto parameter is updated in local session
3278// description as per security policy set in MediaSessionDescriptionFactory.
3279TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003280 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003281 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003282 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003283
3284 // Making sure SetLocalDescription correctly sets crypto value in
3285 // SessionDescription object after de-serialization of sdp string. The value
3286 // will be set as per MediaSessionDescriptionFactory.
3287 std::string offer_str;
3288 offer->ToString(&offer_str);
3289 SessionDescriptionInterface* jsep_offer_str =
3290 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3291 SetLocalDescriptionWithoutError(jsep_offer_str);
3292 EXPECT_TRUE(session_->voice_channel()->secure_required());
3293 EXPECT_TRUE(session_->video_channel()->secure_required());
3294}
3295
3296// This test verifies the crypto parameter when security is disabled.
3297TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003298 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003299 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003300 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003301 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003302
3303 // Making sure SetLocalDescription correctly sets crypto value in
3304 // SessionDescription object after de-serialization of sdp string. The value
3305 // will be set as per MediaSessionDescriptionFactory.
3306 std::string offer_str;
3307 offer->ToString(&offer_str);
3308 SessionDescriptionInterface *jsep_offer_str =
3309 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3310 SetLocalDescriptionWithoutError(jsep_offer_str);
3311 EXPECT_FALSE(session_->voice_channel()->secure_required());
3312 EXPECT_FALSE(session_->video_channel()->secure_required());
3313}
3314
3315// This test verifies that an answer contains new ufrag and password if an offer
3316// with new ufrag and password is received.
3317TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003318 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003319 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003320 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003321 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003322 CreateRemoteOffer(options));
3323 SetRemoteDescriptionWithoutError(offer.release());
3324
3325 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003326 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003327 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003328 SetLocalDescriptionWithoutError(answer.release());
3329
3330 // Receive an offer with new ufrag and password.
3331 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003332 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003333 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003334 SetRemoteDescriptionWithoutError(updated_offer1.release());
3335
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003336 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003337 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003338
3339 CompareIceUfragAndPassword(updated_answer1->description(),
3340 session_->local_description()->description(),
3341 false);
3342
3343 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003344}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003345
wu@webrtc.org91053e72013-08-10 07:18:04 +00003346// This test verifies that an answer contains old ufrag and password if an offer
3347// with old ufrag and password is received.
3348TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003349 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003350 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003351 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003352 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003353 CreateRemoteOffer(options));
3354 SetRemoteDescriptionWithoutError(offer.release());
3355
3356 mediastream_signaling_.SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003357 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003358 CreateAnswer(NULL));
3359 SetLocalDescriptionWithoutError(answer.release());
3360
3361 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003362 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003363 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003364 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003365 SetRemoteDescriptionWithoutError(updated_offer2.release());
3366
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003367 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003368 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003369
3370 CompareIceUfragAndPassword(updated_answer2->description(),
3371 session_->local_description()->description(),
3372 true);
3373
3374 SetLocalDescriptionWithoutError(updated_answer2.release());
3375}
3376
3377TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003378 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003379 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003380 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003381 const std::string session_id_orig = offer->session_id();
3382 const std::string session_version_orig = offer->session_version();
3383 SetLocalDescriptionWithoutError(offer);
3384
3385 video_channel_ = media_engine_->GetVideoChannel(0);
3386 video_channel_->set_fail_set_send_codecs(true);
3387
3388 mediastream_signaling_.SendAudioVideoStream2();
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003389 SessionDescriptionInterface* answer =
3390 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003391 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003392}
3393
3394// Runs the loopback call test with BUNDLE and STUN disabled.
3395TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3396 // Lets try with only UDP ports.
Peter Thatcher2159b892015-08-21 20:46:05 -07003397 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003398 cricket::PORTALLOCATOR_DISABLE_STUN |
3399 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003400 TestLoopbackCall();
3401}
3402
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003403TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher2159b892015-08-21 20:46:05 -07003404 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003405 cricket::PORTALLOCATOR_DISABLE_STUN |
3406 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3407 cricket::PORTALLOCATOR_DISABLE_RELAY);
3408
3409 // best connection is IPv6 since it has higher network preference.
3410 LoopbackNetworkConfiguration config;
3411 config.test_ipv6_network_ = true;
3412 config.best_connection_after_initial_ice_converged_ =
3413 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3414
3415 TestLoopbackCall(config);
3416}
3417
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003418// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003419TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher2159b892015-08-21 20:46:05 -07003420 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3421 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003422 TestLoopbackCall();
3423}
3424
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003425TEST_F(WebRtcSessionTest, SetSdpFailedOnSessionError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003426 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003427 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003428 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003429
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003430 cricket::BaseSession::Error error_code = cricket::BaseSession::ERROR_CONTENT;
3431 std::string error_code_str = "ERROR_CONTENT";
3432 std::string error_desc = "Fake session error description.";
3433 session_->SetError(error_code, error_desc);
3434
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003435 SessionDescriptionInterface* offer = CreateRemoteOffer(options);
3436 SessionDescriptionInterface* answer =
3437 CreateRemoteAnswer(offer, options);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003438
3439 std::string action;
3440 std::ostringstream session_error_msg;
3441 session_error_msg << kSessionError << error_code_str << ". ";
3442 session_error_msg << kSessionErrorDesc << error_desc << ".";
3443 SetRemoteDescriptionExpectError(action, session_error_msg.str(), offer);
3444 SetLocalDescriptionExpectError(action, session_error_msg.str(), answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003445}
3446
3447TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3448 constraints_.reset(new FakeConstraints());
3449 constraints_->AddOptional(
3450 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003451 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003452
3453 SetLocalDescriptionWithDataChannel();
3454 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3455}
3456
Henrik Boström87713d02015-08-25 09:53:21 +02003457TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003458 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003459
3460 constraints_.reset(new FakeConstraints());
3461 constraints_->AddOptional(
3462 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003463 options_.disable_sctp_data_channels = false;
3464
Henrik Boström87713d02015-08-25 09:53:21 +02003465 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003466
3467 SetLocalDescriptionWithDataChannel();
3468 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3469}
3470
Henrik Boström87713d02015-08-25 09:53:21 +02003471TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003472 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003473
Henrik Boström87713d02015-08-25 09:53:21 +02003474 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003475
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003476 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003477 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003478 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3479}
3480
Henrik Boström87713d02015-08-25 09:53:21 +02003481TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003482 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003483 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003484 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003485
3486 // Create remote offer with SCTP.
3487 cricket::MediaSessionOptions options;
3488 options.data_channel_type = cricket::DCT_SCTP;
3489 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003490 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003491 SetRemoteDescriptionWithoutError(offer);
3492
3493 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003494 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003495 EXPECT_TRUE(answer != NULL);
3496 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3497 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003498}
3499
Henrik Boström87713d02015-08-25 09:53:21 +02003500TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003501 constraints_.reset(new FakeConstraints());
3502 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003503 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
Henrik Boström87713d02015-08-25 09:53:21 +02003504 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003505
3506 SetLocalDescriptionWithDataChannel();
3507 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3508}
3509
Henrik Boström87713d02015-08-25 09:53:21 +02003510TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003511 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003512
Henrik Boström87713d02015-08-25 09:53:21 +02003513 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003514
3515 SetLocalDescriptionWithDataChannel();
3516 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3517}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003518
Henrik Boström87713d02015-08-25 09:53:21 +02003519TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003520 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003521 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003522 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003523
3524 SetLocalDescriptionWithDataChannel();
3525 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3526}
3527
Henrik Boström87713d02015-08-25 09:53:21 +02003528TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003529 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003530 const int new_send_port = 9998;
3531 const int new_recv_port = 7775;
3532
Henrik Boström87713d02015-08-25 09:53:21 +02003533 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003534 SetFactoryDtlsSrtp();
3535
3536 // By default, don't actually add the codecs to desc_factory_; they don't
3537 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3538 // let the session description get parsed. That'll get the proper codecs
3539 // into the stream.
3540 cricket::MediaSessionOptions options;
3541 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3542 "stream1", new_send_port, options);
3543
3544 // SetRemoteDescription will take the ownership of the offer.
3545 SetRemoteDescriptionWithoutError(offer);
3546
3547 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3548 new_recv_port, CreateAnswer(NULL));
3549 ASSERT_TRUE(answer != NULL);
3550
3551 // Now set the local description, which'll take ownership of the answer.
3552 SetLocalDescriptionWithoutError(answer);
3553
3554 // TEST PLAN: Set the port number to something new, set it in the SDP,
3555 // and pass it all the way down.
henrika@webrtc.orgaebb1ad2014-01-14 10:00:58 +00003556 webrtc::InternalDataChannelInit dci;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003557 dci.reliable = true;
3558 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003559 rtc::scoped_refptr<webrtc::DataChannel> dc =
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003560 session_->CreateDataChannel("datachannel", &dci);
3561
3562 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3563 int portnum = -1;
3564 ASSERT_TRUE(ch != NULL);
3565 ASSERT_EQ(1UL, ch->send_codecs().size());
3566 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003567 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003568 ch->send_codecs()[0].name.c_str()));
3569 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3570 &portnum));
3571 EXPECT_EQ(new_send_port, portnum);
3572
3573 ASSERT_EQ(1UL, ch->recv_codecs().size());
3574 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003575 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003576 ch->recv_codecs()[0].name.c_str()));
3577 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3578 &portnum));
3579 EXPECT_EQ(new_recv_port, portnum);
3580}
3581
Henrik Boströmd8281982015-08-27 10:12:24 +02003582TEST_F(WebRtcSessionTest, TestUsesProvidedCertificate) {
3583 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
3584 FakeDtlsIdentityStore::GenerateCertificate();
3585
3586 PeerConnectionInterface::RTCConfiguration configuration;
3587 configuration.certificates.push_back(certificate);
3588 Init(nullptr, configuration);
3589 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3590
3591 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3592}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003593
Henrik Boström87713d02015-08-25 09:53:21 +02003594// Verifies that CreateOffer succeeds when CreateOffer is called before async
3595// identity generation is finished (even if a certificate is provided this is
3596// an async op).
3597TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3598 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3599 InitWithDtls(GetParam());
3600
Henrik Boströmd8281982015-08-27 10:12:24 +02003601 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003602 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003603 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3604
wu@webrtc.org91053e72013-08-10 07:18:04 +00003605 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003606 VerifyNoCryptoParams(offer->description(), true);
3607 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003608}
3609
3610// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02003611// identity generation is finished (even if a certificate is provided this is
3612// an async op).
3613TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003614 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003615 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003616 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003617
3618 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003619 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003620 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003621 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003622 ASSERT_TRUE(offer.get() != NULL);
3623 SetRemoteDescriptionWithoutError(offer.release());
3624
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003625 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003626 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003627 VerifyNoCryptoParams(answer->description(), true);
3628 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003629}
3630
3631// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02003632// identity generation is finished (even if a certificate is provided this is
3633// an async op).
3634TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003635 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003636 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003637
Henrik Boströmd8281982015-08-27 10:12:24 +02003638 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003639
3640 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003641 EXPECT_TRUE(offer != NULL);
3642}
3643
3644// Verifies that CreateOffer fails when CreateOffer is called after async
3645// identity generation fails.
3646TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003647 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003648 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003649
Henrik Boströmd8281982015-08-27 10:12:24 +02003650 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003651
3652 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003653 EXPECT_TRUE(offer == NULL);
3654}
3655
3656// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3657// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003658TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003659 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003660 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003661 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02003662 GetParam(), CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003663}
3664
3665// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3666// before async identity generation fails.
3667TEST_F(WebRtcSessionTest,
3668 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003669 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003670 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
3671 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003672}
3673
3674// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3675// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003676TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003677 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003678 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003679 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02003680 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003681}
3682
3683// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
3684// before async identity generation fails.
3685TEST_F(WebRtcSessionTest,
3686 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003687 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003688 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
3689 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003690}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003691
3692// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
3693// offer has no SDES crypto but only DTLS fingerprint.
3694TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
3695 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003696 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003697 // Create a remote offer with secured transport disabled.
3698 cricket::MediaSessionOptions options;
3699 JsepSessionDescription* offer(CreateRemoteOffer(
3700 options, cricket::SEC_DISABLED));
3701 // Adds a DTLS fingerprint to the remote offer.
3702 cricket::SessionDescription* sdp = offer->description();
3703 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
3704 ASSERT_TRUE(audio != NULL);
3705 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
3706 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003707 rtc::SSLFingerprint::CreateFromRfc4572(
3708 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003709 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003710 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00003711}
3712
wu@webrtc.orgde305012013-10-31 15:40:38 +00003713// This test verifies DSCP is properly applied on the media channels.
3714TEST_F(WebRtcSessionTest, TestDscpConstraint) {
3715 constraints_.reset(new FakeConstraints());
3716 constraints_->AddOptional(
3717 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003718 Init();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003719 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003720 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00003721
3722 SetLocalDescriptionWithoutError(offer);
3723
3724 video_channel_ = media_engine_->GetVideoChannel(0);
3725 voice_channel_ = media_engine_->GetVoiceChannel(0);
3726
3727 ASSERT_TRUE(video_channel_ != NULL);
3728 ASSERT_TRUE(voice_channel_ != NULL);
3729 cricket::AudioOptions audio_options;
3730 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3731 cricket::VideoOptions video_options;
3732 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3733 EXPECT_TRUE(audio_options.dscp.IsSet());
3734 EXPECT_TRUE(audio_options.dscp.GetWithDefaultIfUnset(false));
3735 EXPECT_TRUE(video_options.dscp.IsSet());
3736 EXPECT_TRUE(video_options.dscp.GetWithDefaultIfUnset(false));
3737}
3738
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003739TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
3740 constraints_.reset(new FakeConstraints());
3741 constraints_->AddOptional(
3742 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
3743 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003744 Init();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003745 mediastream_signaling_.SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003746 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00003747
3748 SetLocalDescriptionWithoutError(offer);
3749
3750 video_channel_ = media_engine_->GetVideoChannel(0);
3751
3752 ASSERT_TRUE(video_channel_ != NULL);
3753 cricket::VideoOptions video_options;
3754 EXPECT_TRUE(video_channel_->GetOptions(&video_options));
3755 EXPECT_TRUE(
3756 video_options.suspend_below_min_bitrate.GetWithDefaultIfUnset(false));
3757}
3758
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00003759TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
3760 // Number of unsignalled receiving streams should be between 0 and
3761 // kMaxUnsignalledRecvStreams.
3762 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
3763 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
3764 kMaxUnsignalledRecvStreams);
3765 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
3766}
3767
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003768TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
3769 constraints_.reset(new FakeConstraints());
3770 constraints_->AddOptional(
3771 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
3772 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003773 Init();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00003774 mediastream_signaling_.SendAudioVideoStream1();
3775 SessionDescriptionInterface* offer = CreateOffer();
3776
3777 SetLocalDescriptionWithoutError(offer);
3778
3779 voice_channel_ = media_engine_->GetVoiceChannel(0);
3780
3781 ASSERT_TRUE(voice_channel_ != NULL);
3782 cricket::AudioOptions audio_options;
3783 EXPECT_TRUE(voice_channel_->GetOptions(&audio_options));
3784 EXPECT_TRUE(
3785 audio_options.combined_audio_video_bwe.GetWithDefaultIfUnset(false));
3786}
3787
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003788// Tests that we can renegotiate new media content with ICE candidates in the
3789// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02003790TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003791 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003792 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003793 SetFactoryDtlsSrtp();
3794
3795 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003796 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003797 SetLocalDescriptionWithoutError(offer);
3798
3799 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3800 SetRemoteDescriptionWithoutError(answer);
3801
3802 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003803 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003804 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3805
3806 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003807 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003808 candidate1.set_component(1);
3809 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3810 candidate1);
3811 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3812 SetRemoteDescriptionWithoutError(offer);
3813
3814 answer = CreateAnswer(NULL);
3815 SetLocalDescriptionWithoutError(answer);
3816}
3817
3818// Tests that we can renegotiate new media content with ICE candidates separated
3819// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02003820TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003821 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003822 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003823 SetFactoryDtlsSrtp();
3824
3825 mediastream_signaling_.UseOptionsAudioOnly();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003826 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003827 SetLocalDescriptionWithoutError(offer);
3828
3829 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3830 SetRemoteDescriptionWithoutError(answer);
3831
3832 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003833 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003834 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
3835 SetRemoteDescriptionWithoutError(offer);
3836
3837 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003838 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003839 candidate1.set_component(1);
3840 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
3841 candidate1);
3842 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
3843
3844 answer = CreateAnswer(NULL);
3845 SetLocalDescriptionWithoutError(answer);
3846}
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00003847// Tests that RTX codec is removed from the answer when it isn't supported
3848// by local side.
3849TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
3850 Init();
3851 mediastream_signaling_.SendAudioVideoStream1();
3852 std::string offer_sdp(kSdpWithRtx);
3853
3854 SessionDescriptionInterface* offer =
3855 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
3856 EXPECT_TRUE(offer->ToString(&offer_sdp));
3857
3858 // Offer SDP contains the RTX codec.
3859 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
3860 SetRemoteDescriptionWithoutError(offer);
3861
3862 SessionDescriptionInterface* answer = CreateAnswer(NULL);
3863 std::string answer_sdp;
3864 answer->ToString(&answer_sdp);
3865 // Answer SDP removes the unsupported RTX codec.
3866 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
3867 SetLocalDescriptionWithoutError(answer);
3868}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00003869
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00003870// This verifies that the voice channel after bundle has both options from video
3871// and voice channels.
3872TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
3873 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
3874 mediastream_signaling_.SendAudioVideoStream1();
3875
3876 PeerConnectionInterface::RTCOfferAnswerOptions options;
3877 options.use_rtp_mux = true;
3878
3879 SessionDescriptionInterface* offer = CreateOffer(options);
3880 SetLocalDescriptionWithoutError(offer);
3881
3882 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3883 rtc::Socket::Option::OPT_SNDBUF, 4000);
3884
3885 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
3886 rtc::Socket::Option::OPT_RCVBUF, 8000);
3887
3888 int option_val;
3889 EXPECT_TRUE(session_->video_channel()->transport_channel()->GetOption(
3890 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3891 EXPECT_EQ(4000, option_val);
3892 EXPECT_FALSE(session_->voice_channel()->transport_channel()->GetOption(
3893 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3894
3895 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3896 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3897 EXPECT_EQ(8000, option_val);
3898 EXPECT_FALSE(session_->video_channel()->transport_channel()->GetOption(
3899 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3900
3901 EXPECT_NE(session_->voice_channel()->transport_channel(),
3902 session_->video_channel()->transport_channel());
3903
3904 mediastream_signaling_.SendAudioVideoStream2();
3905 SessionDescriptionInterface* answer =
3906 CreateRemoteAnswer(session_->local_description());
3907 SetRemoteDescriptionWithoutError(answer);
3908
3909 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3910 rtc::Socket::Option::OPT_SNDBUF, &option_val));
3911 EXPECT_EQ(4000, option_val);
3912
3913 EXPECT_TRUE(session_->voice_channel()->transport_channel()->GetOption(
3914 rtc::Socket::Option::OPT_RCVBUF, &option_val));
3915 EXPECT_EQ(8000, option_val);
3916}
3917
tommi0f620f42015-07-09 03:25:02 -07003918// Test creating a session, request multiple offers, destroy the session
3919// and make sure we got success/failure callbacks for all of the requests.
3920// Background: crbug.com/507307
3921TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
3922 Init();
3923
3924 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
3925 PeerConnectionInterface::RTCOfferAnswerOptions options;
3926 options.offer_to_receive_audio =
3927 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
3928
3929 for (auto& o : observers) {
3930 o = new WebRtcSessionCreateSDPObserverForTest();
3931 session_->CreateOffer(o, options);
3932 }
3933
3934 session_.reset();
3935
tommi0f620f42015-07-09 03:25:02 -07003936 for (auto& o : observers) {
3937 // We expect to have received a notification now even if the session was
3938 // terminated. The offer creation may or may not have succeeded, but we
3939 // must have received a notification which, so the only invalid state
3940 // is kInit.
3941 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
3942 }
3943}
3944
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003945// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
3946// currently fails because upon disconnection and reconnection OnIceComplete is
3947// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02003948
3949INSTANTIATE_TEST_CASE_P(
3950 WebRtcSessionTests, WebRtcSessionTest,
3951 testing::Values(ALREADY_GENERATED, DTLS_IDENTITY_STORE));