blob: 5997c5328f1e6674aefcb31440c86b29cae995dd [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
kwiberg0eb15ed2015-12-17 03:04:15 -080028#include <utility>
deadbeefcbecd352015-09-23 11:50:27 -070029#include <vector>
30
henrike@webrtc.org28e20752013-07-10 00:45:36 +000031#include "talk/app/webrtc/audiotrack.h"
stefanc1aeaf02015-10-15 07:26:07 -070032#include "talk/app/webrtc/fakemediacontroller.h"
jbauchac8869e2015-07-03 01:36:14 -070033#include "talk/app/webrtc/fakemetricsobserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000034#include "talk/app/webrtc/jsepicecandidate.h"
35#include "talk/app/webrtc/jsepsessiondescription.h"
deadbeefab9b2d12015-10-14 11:33:11 -070036#include "talk/app/webrtc/peerconnection.h"
deadbeefab9b2d12015-10-14 11:33:11 -070037#include "talk/app/webrtc/sctputils.h"
38#include "talk/app/webrtc/streamcollection.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000039#include "talk/app/webrtc/streamcollection.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000040#include "talk/app/webrtc/test/fakeconstraints.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020041#include "talk/app/webrtc/test/fakedtlsidentitystore.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000042#include "talk/app/webrtc/videotrack.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000043#include "talk/app/webrtc/webrtcsession.h"
wu@webrtc.org91053e72013-08-10 07:18:04 +000044#include "talk/app/webrtc/webrtcsessiondescriptionfactory.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000045#include "talk/media/base/fakemediaengine.h"
46#include "talk/media/base/fakevideorenderer.h"
47#include "talk/media/base/mediachannel.h"
stefanc1aeaf02015-10-15 07:26:07 -070048#include "talk/media/webrtc/fakewebrtccall.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000049#include "webrtc/p2p/base/stunserver.h"
50#include "webrtc/p2p/base/teststunserver.h"
51#include "webrtc/p2p/base/testturnserver.h"
pthatcher@webrtc.orgb4aac132015-03-13 18:25:21 +000052#include "webrtc/p2p/base/transportchannel.h"
henrike@webrtc.org269fb4b2014-10-28 22:20:11 +000053#include "webrtc/p2p/client/basicportallocator.h"
buildbot@webrtc.orga09a9992014-08-13 17:26:08 +000054#include "talk/session/media/channelmanager.h"
55#include "talk/session/media/mediasession.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000056#include "webrtc/base/fakenetwork.h"
57#include "webrtc/base/firewallsocketserver.h"
58#include "webrtc/base/gunit.h"
59#include "webrtc/base/logging.h"
60#include "webrtc/base/network.h"
61#include "webrtc/base/physicalsocketserver.h"
62#include "webrtc/base/ssladapter.h"
Henrik Boström5e56c592015-08-11 10:33:13 +020063#include "webrtc/base/sslidentity.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000064#include "webrtc/base/sslstreamadapter.h"
65#include "webrtc/base/stringutils.h"
66#include "webrtc/base/thread.h"
67#include "webrtc/base/virtualsocketserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068
69#define MAYBE_SKIP_TEST(feature) \
70 if (!(feature())) { \
71 LOG(LS_INFO) << "Feature disabled... skipping"; \
72 return; \
73 }
74
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000077using rtc::SocketAddress;
78using rtc::scoped_ptr;
79using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000080using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000081using webrtc::CreateSessionDescriptionObserver;
82using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070083using webrtc::DataChannel;
Henrik Boström5e56c592015-08-11 10:33:13 +020084using webrtc::DtlsIdentityStoreInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000085using webrtc::FakeConstraints;
jbauchac8869e2015-07-03 01:36:14 -070086using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070088using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000089using webrtc::JsepIceCandidate;
90using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000091using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000092using webrtc::PeerConnectionInterface;
93using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070094using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000096using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000097using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000098using webrtc::kCreateChannelFailed;
99using webrtc::kInvalidSdp;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000100using webrtc::kMlineMismatch;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000101using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000102using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000103using webrtc::kSdpWithoutDtlsFingerprint;
104using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000105using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000106using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000107using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000108
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000109typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
110
wu@webrtc.org364f2042013-11-20 21:49:41 +0000111static const int kClientAddrPort = 0;
112static const char kClientAddrHost1[] = "11.11.11.11";
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +0000113static const char kClientIPv6AddrHost1[] =
114 "2620:0:aaaa:bbbb:cccc:dddd:eeee:ffff";
wu@webrtc.org364f2042013-11-20 21:49:41 +0000115static const char kClientAddrHost2[] = "22.22.22.22";
116static const char kStunAddrHost[] = "99.99.99.1";
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000117static const SocketAddress kTurnUdpIntAddr("99.99.99.4", 3478);
118static const SocketAddress kTurnUdpExtAddr("99.99.99.6", 0);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +0000119static const char kTurnUsername[] = "test";
120static const char kTurnPassword[] = "test";
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000121
122static const char kSessionVersion[] = "1";
123
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000124// Media index of candidates belonging to the first media content.
125static const int kMediaContentIndex0 = 0;
126static const char kMediaContentName0[] = "audio";
127
128// Media index of candidates belonging to the second media content.
129static const int kMediaContentIndex1 = 1;
130static const char kMediaContentName1[] = "video";
131
132static const int kIceCandidatesTimeout = 10000;
133
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +0000134static const char kFakeDtlsFingerprint[] =
135 "BB:CD:72:F7:2F:D0:BA:43:F3:68:B1:0C:23:72:B6:4A:"
136 "0F:DE:34:06:BC:E0:FE:01:BC:73:C8:6D:F4:65:D5:24";
137
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000138static const char kTooLongIceUfragPwd[] =
139 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
140 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
141 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag"
142 "IceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfragIceUfrag";
143
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +0000144static const char kSdpWithRtx[] =
145 "v=0\r\n"
146 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
147 "s=-\r\n"
148 "t=0 0\r\n"
149 "a=msid-semantic: WMS stream1\r\n"
150 "m=video 9 RTP/SAVPF 0 96\r\n"
151 "c=IN IP4 0.0.0.0\r\n"
152 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
153 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
154 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
155 "a=mid:video\r\n"
156 "a=sendrecv\r\n"
157 "a=rtcp-mux\r\n"
158 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
159 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
160 "a=rtpmap:0 fake_video_codec/90000\r\n"
161 "a=rtpmap:96 rtx/90000\r\n"
162 "a=fmtp:96 apt=0\r\n";
163
deadbeefab9b2d12015-10-14 11:33:11 -0700164static const char kStream1[] = "stream1";
165static const char kVideoTrack1[] = "video1";
166static const char kAudioTrack1[] = "audio1";
167
168static const char kStream2[] = "stream2";
169static const char kVideoTrack2[] = "video2";
170static const char kAudioTrack2[] = "audio2";
171
Henrik Boström87713d02015-08-25 09:53:21 +0200172enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
173
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000174// Add some extra |newlines| to the |message| after |line|.
175static void InjectAfter(const std::string& line,
176 const std::string& newlines,
177 std::string* message) {
178 const std::string tmp = line + newlines;
deadbeefcbecd352015-09-23 11:50:27 -0700179 rtc::replace_substrs(line.c_str(), line.length(), tmp.c_str(), tmp.length(),
180 message);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000181}
182
183class MockIceObserver : public webrtc::IceObserver {
184 public:
185 MockIceObserver()
186 : oncandidatesready_(false),
187 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
188 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
189 }
190
191 virtual void OnIceConnectionChange(
192 PeerConnectionInterface::IceConnectionState new_state) {
193 ice_connection_state_ = new_state;
194 }
195 virtual void OnIceGatheringChange(
196 PeerConnectionInterface::IceGatheringState new_state) {
197 // We can never transition back to "new".
198 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
199 ice_gathering_state_ = new_state;
200
201 // oncandidatesready_ really means "ICE gathering is complete".
202 // This if statement ensures that this value remains correct when we
203 // transition from kIceGatheringComplete to kIceGatheringGathering.
204 if (new_state == PeerConnectionInterface::kIceGatheringGathering) {
205 oncandidatesready_ = false;
206 }
207 }
208
209 // Found a new candidate.
210 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000211 switch (candidate->sdp_mline_index()) {
212 case kMediaContentIndex0:
213 mline_0_candidates_.push_back(candidate->candidate());
214 break;
215 case kMediaContentIndex1:
216 mline_1_candidates_.push_back(candidate->candidate());
217 break;
218 default:
219 ASSERT(false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000220 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000221
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000222 // The ICE gathering state should always be Gathering when a candidate is
223 // received (or possibly Completed in the case of the final candidate).
224 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
225 }
226
227 // TODO(bemasc): Remove this once callers transition to OnIceGatheringChange.
228 virtual void OnIceComplete() {
229 EXPECT_FALSE(oncandidatesready_);
230 oncandidatesready_ = true;
231
232 // OnIceGatheringChange(IceGatheringCompleted) and OnIceComplete() should
233 // be called approximately simultaneously. For ease of testing, this
234 // check additionally requires that they be called in the above order.
235 EXPECT_EQ(PeerConnectionInterface::kIceGatheringComplete,
236 ice_gathering_state_);
237 }
238
239 bool oncandidatesready_;
240 std::vector<cricket::Candidate> mline_0_candidates_;
241 std::vector<cricket::Candidate> mline_1_candidates_;
242 PeerConnectionInterface::IceConnectionState ice_connection_state_;
243 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
244};
245
246class WebRtcSessionForTest : public webrtc::WebRtcSession {
247 public:
stefanc1aeaf02015-10-15 07:26:07 -0700248 WebRtcSessionForTest(webrtc::MediaControllerInterface* media_controller,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000249 rtc::Thread* signaling_thread,
250 rtc::Thread* worker_thread,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000251 cricket::PortAllocator* port_allocator,
deadbeefab9b2d12015-10-14 11:33:11 -0700252 webrtc::IceObserver* ice_observer)
stefanc1aeaf02015-10-15 07:26:07 -0700253 : WebRtcSession(media_controller,
254 signaling_thread,
255 worker_thread,
256 port_allocator) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000257 RegisterIceObserver(ice_observer);
258 }
259 virtual ~WebRtcSessionForTest() {}
260
deadbeefcbecd352015-09-23 11:50:27 -0700261 // Note that these methods are only safe to use if the signaling thread
262 // is the same as the worker thread
263 cricket::TransportChannel* voice_rtp_transport_channel() {
264 return rtp_transport_channel(voice_channel());
265 }
266
267 cricket::TransportChannel* voice_rtcp_transport_channel() {
268 return rtcp_transport_channel(voice_channel());
269 }
270
271 cricket::TransportChannel* video_rtp_transport_channel() {
272 return rtp_transport_channel(video_channel());
273 }
274
275 cricket::TransportChannel* video_rtcp_transport_channel() {
276 return rtcp_transport_channel(video_channel());
277 }
278
279 cricket::TransportChannel* data_rtp_transport_channel() {
280 return rtp_transport_channel(data_channel());
281 }
282
283 cricket::TransportChannel* data_rtcp_transport_channel() {
284 return rtcp_transport_channel(data_channel());
285 }
286
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000287 using webrtc::WebRtcSession::SetAudioPlayout;
288 using webrtc::WebRtcSession::SetAudioSend;
289 using webrtc::WebRtcSession::SetCaptureDevice;
290 using webrtc::WebRtcSession::SetVideoPlayout;
291 using webrtc::WebRtcSession::SetVideoSend;
deadbeefcbecd352015-09-23 11:50:27 -0700292
293 private:
294 cricket::TransportChannel* rtp_transport_channel(cricket::BaseChannel* ch) {
295 if (!ch) {
296 return nullptr;
297 }
298 return ch->transport_channel();
299 }
300
301 cricket::TransportChannel* rtcp_transport_channel(cricket::BaseChannel* ch) {
302 if (!ch) {
303 return nullptr;
304 }
305 return ch->rtcp_transport_channel();
306 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000307};
308
wu@webrtc.org91053e72013-08-10 07:18:04 +0000309class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000310 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000312 enum State {
313 kInit,
314 kFailed,
315 kSucceeded,
316 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000317 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000318
319 // CreateSessionDescriptionObserver implementation.
320 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000321 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000322 state_ = kSucceeded;
323 }
324 virtual void OnFailure(const std::string& error) {
325 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000326 }
327
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000328 SessionDescriptionInterface* description() { return description_.get(); }
329
330 SessionDescriptionInterface* ReleaseDescription() {
331 return description_.release();
332 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000333
wu@webrtc.org91053e72013-08-10 07:18:04 +0000334 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000335
wu@webrtc.org91053e72013-08-10 07:18:04 +0000336 protected:
337 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000338
339 private:
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000340 rtc::scoped_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000341 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000342};
343
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000344class FakeAudioRenderer : public cricket::AudioRenderer {
345 public:
solenberg98c68862015-10-09 03:27:14 -0700346 FakeAudioRenderer() : sink_(NULL) {}
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000347 virtual ~FakeAudioRenderer() {
348 if (sink_)
349 sink_->OnClose();
350 }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000351
kjellander@webrtc.org14665ff2015-03-04 12:58:35 +0000352 void SetSink(Sink* sink) override { sink_ = sink; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000353
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000354 cricket::AudioRenderer::Sink* sink() const { return sink_; }
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000355 private:
henrike@webrtc.orga7b98182014-02-21 15:51:43 +0000356 cricket::AudioRenderer::Sink* sink_;
henrike@webrtc.org1e09a712013-07-26 19:17:59 +0000357};
358
Henrik Boström87713d02015-08-25 09:53:21 +0200359class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700360 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
361 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000362 protected:
363 // TODO Investigate why ChannelManager crashes, if it's created
364 // after stun_server.
365 WebRtcSessionTest()
stefanc1aeaf02015-10-15 07:26:07 -0700366 : media_engine_(new cricket::FakeMediaEngine()),
367 data_engine_(new cricket::FakeDataEngine()),
368 channel_manager_(
369 new cricket::ChannelManager(media_engine_,
370 data_engine_,
371 new cricket::CaptureManager(),
372 rtc::Thread::Current())),
373 fake_call_(webrtc::Call::Config()),
374 media_controller_(
375 webrtc::MediaControllerInterface::Create(rtc::Thread::Current(),
376 channel_manager_.get())),
377 tdesc_factory_(new cricket::TransportDescriptionFactory()),
378 desc_factory_(
379 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
380 tdesc_factory_.get())),
381 pss_(new rtc::PhysicalSocketServer),
382 vss_(new rtc::VirtualSocketServer(pss_.get())),
383 fss_(new rtc::FirewallSocketServer(vss_.get())),
384 ss_scope_(fss_.get()),
385 stun_socket_addr_(
386 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
387 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
388 stun_socket_addr_)),
389 turn_server_(Thread::Current(), kTurnUdpIntAddr, kTurnUdpExtAddr),
390 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000391 cricket::ServerAddresses stun_servers;
392 stun_servers.insert(stun_socket_addr_);
393 allocator_.reset(new cricket::BasicPortAllocator(
394 &network_manager_,
395 stun_servers,
396 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000397 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700398 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000399 EXPECT_TRUE(channel_manager_->Init());
400 desc_factory_->set_add_legacy_streams(false);
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000401 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000402 }
403
404 void AddInterface(const SocketAddress& addr) {
405 network_manager_.AddInterface(addr);
406 }
407
Henrik Boström87713d02015-08-25 09:53:21 +0200408 // If |dtls_identity_store| != null or |rtc_configuration| contains
409 // |certificates| then DTLS will be enabled unless explicitly disabled by
410 // |rtc_configuration| options. When DTLS is enabled a certificate will be
411 // used if provided, otherwise one will be generated using the
412 // |dtls_identity_store|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000413 void Init(
Henrik Boström5e56c592015-08-11 10:33:13 +0200414 rtc::scoped_ptr<webrtc::DtlsIdentityStoreInterface> dtls_identity_store,
Henrik Lundin64dad832015-05-11 12:44:23 +0200415 const PeerConnectionInterface::RTCConfiguration& rtc_configuration) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000416 ASSERT_TRUE(session_.get() == NULL);
417 session_.reset(new WebRtcSessionForTest(
stefanc1aeaf02015-10-15 07:26:07 -0700418 media_controller_.get(), rtc::Thread::Current(), rtc::Thread::Current(),
deadbeefab9b2d12015-10-14 11:33:11 -0700419 allocator_.get(), &observer_));
420 session_->SignalDataChannelOpenMessage.connect(
421 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000422
423 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
424 observer_.ice_connection_state_);
425 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
426 observer_.ice_gathering_state_);
427
deadbeefcbecd352015-09-23 11:50:27 -0700428 EXPECT_TRUE(session_->Initialize(options_, constraints_.get(),
kwiberg0eb15ed2015-12-17 03:04:15 -0800429 std::move(dtls_identity_store),
deadbeefcbecd352015-09-23 11:50:27 -0700430 rtc_configuration));
jbauchac8869e2015-07-03 01:36:14 -0700431 session_->set_metrics_observer(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000432 }
433
deadbeefab9b2d12015-10-14 11:33:11 -0700434 void OnDataChannelOpenMessage(const std::string& label,
435 const InternalDataChannelInit& config) {
436 last_data_channel_label_ = label;
437 last_data_channel_config_ = config;
438 }
439
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000440 void Init() {
Henrik Lundin64dad832015-05-11 12:44:23 +0200441 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Boström5e56c592015-08-11 10:33:13 +0200442 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000443 }
444
445 void InitWithIceTransport(
446 PeerConnectionInterface::IceTransportsType ice_transport_type) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200447 PeerConnectionInterface::RTCConfiguration configuration;
448 configuration.type = ice_transport_type;
Henrik Boström5e56c592015-08-11 10:33:13 +0200449 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000450 }
451
452 void InitWithBundlePolicy(
453 PeerConnectionInterface::BundlePolicy bundle_policy) {
Henrik Lundin64dad832015-05-11 12:44:23 +0200454 PeerConnectionInterface::RTCConfiguration configuration;
Henrik Lundin64dad832015-05-11 12:44:23 +0200455 configuration.bundle_policy = bundle_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200456 Init(nullptr, configuration);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700457 }
458
459 void InitWithRtcpMuxPolicy(
460 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
461 PeerConnectionInterface::RTCConfiguration configuration;
462 configuration.rtcp_mux_policy = rtcp_mux_policy;
Henrik Boström5e56c592015-08-11 10:33:13 +0200463 Init(nullptr, configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000464 }
465
Henrik Boström87713d02015-08-25 09:53:21 +0200466 // Successfully init with DTLS; with a certificate generated and supplied or
467 // with a store that generates it for us.
468 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
469 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store;
470 PeerConnectionInterface::RTCConfiguration configuration;
471 if (cert_gen_method == ALREADY_GENERATED) {
472 configuration.certificates.push_back(
473 FakeDtlsIdentityStore::GenerateCertificate());
474 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
475 dtls_identity_store.reset(new FakeDtlsIdentityStore());
476 dtls_identity_store->set_should_fail(false);
477 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700478 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200479 }
kwiberg0eb15ed2015-12-17 03:04:15 -0800480 Init(std::move(dtls_identity_store), configuration);
Henrik Boström87713d02015-08-25 09:53:21 +0200481 }
482
483 // Init with DTLS with a store that will fail to generate a certificate.
484 void InitWithDtlsIdentityGenFail() {
Henrik Boström5e56c592015-08-11 10:33:13 +0200485 rtc::scoped_ptr<FakeDtlsIdentityStore> dtls_identity_store(
486 new FakeDtlsIdentityStore());
Henrik Boström87713d02015-08-25 09:53:21 +0200487 dtls_identity_store->set_should_fail(true);
Henrik Lundin64dad832015-05-11 12:44:23 +0200488 PeerConnectionInterface::RTCConfiguration configuration;
kwiberg0eb15ed2015-12-17 03:04:15 -0800489 Init(std::move(dtls_identity_store), configuration);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000490 }
491
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000492 void InitWithDtmfCodec() {
493 // Add kTelephoneEventCodec for dtmf test.
wu@webrtc.org364f2042013-11-20 21:49:41 +0000494 const cricket::AudioCodec kTelephoneEventCodec(
495 106, "telephone-event", 8000, 0, 1, 0);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000496 std::vector<cricket::AudioCodec> codecs;
497 codecs.push_back(kTelephoneEventCodec);
498 media_engine_->SetAudioCodecs(codecs);
499 desc_factory_->set_audio_codecs(codecs);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000500 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000501 }
502
deadbeefab9b2d12015-10-14 11:33:11 -0700503 void SendAudioVideoStream1() {
504 send_stream_1_ = true;
505 send_stream_2_ = false;
506 send_audio_ = true;
507 send_video_ = true;
508 }
509
510 void SendAudioVideoStream2() {
511 send_stream_1_ = false;
512 send_stream_2_ = true;
513 send_audio_ = true;
514 send_video_ = true;
515 }
516
517 void SendAudioVideoStream1And2() {
518 send_stream_1_ = true;
519 send_stream_2_ = true;
520 send_audio_ = true;
521 send_video_ = true;
522 }
523
524 void SendNothing() {
525 send_stream_1_ = false;
526 send_stream_2_ = false;
527 send_audio_ = false;
528 send_video_ = false;
529 }
530
531 void SendAudioOnlyStream2() {
532 send_stream_1_ = false;
533 send_stream_2_ = true;
534 send_audio_ = true;
535 send_video_ = false;
536 }
537
538 void SendVideoOnlyStream2() {
539 send_stream_1_ = false;
540 send_stream_2_ = true;
541 send_audio_ = false;
542 send_video_ = true;
543 }
544
545 void AddStreamsToOptions(cricket::MediaSessionOptions* session_options) {
546 if (send_stream_1_ && send_audio_) {
547 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack1,
548 kStream1);
549 }
550 if (send_stream_1_ && send_video_) {
551 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack1,
552 kStream1);
553 }
554 if (send_stream_2_ && send_audio_) {
555 session_options->AddSendStream(cricket::MEDIA_TYPE_AUDIO, kAudioTrack2,
556 kStream2);
557 }
558 if (send_stream_2_ && send_video_) {
559 session_options->AddSendStream(cricket::MEDIA_TYPE_VIDEO, kVideoTrack2,
560 kStream2);
561 }
562 if (data_channel_ && session_->data_channel_type() == cricket::DCT_RTP) {
563 session_options->AddSendStream(cricket::MEDIA_TYPE_DATA,
564 data_channel_->label(),
565 data_channel_->label());
566 }
567 }
568
569 void GetOptionsForOffer(
570 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
571 cricket::MediaSessionOptions* session_options) {
deadbeefab9b2d12015-10-14 11:33:11 -0700572 ASSERT_TRUE(ConvertRtcOptionsForOffer(rtc_options, session_options));
573
deadbeefc80741f2015-10-22 13:14:45 -0700574 AddStreamsToOptions(session_options);
575 if (rtc_options.offer_to_receive_audio ==
576 RTCOfferAnswerOptions::kUndefined) {
577 session_options->recv_audio =
578 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_AUDIO);
579 }
580 if (rtc_options.offer_to_receive_video ==
581 RTCOfferAnswerOptions::kUndefined) {
582 session_options->recv_video =
583 session_options->HasSendMediaStream(cricket::MEDIA_TYPE_VIDEO);
584 }
585 session_options->bundle_enabled =
586 session_options->bundle_enabled &&
587 (session_options->has_audio() || session_options->has_video() ||
588 session_options->has_data());
589
deadbeefab9b2d12015-10-14 11:33:11 -0700590 if (session_->data_channel_type() == cricket::DCT_SCTP && data_channel_) {
591 session_options->data_channel_type = cricket::DCT_SCTP;
592 }
593 }
594
595 void GetOptionsForAnswer(const webrtc::MediaConstraintsInterface* constraints,
596 cricket::MediaSessionOptions* session_options) {
deadbeefab9b2d12015-10-14 11:33:11 -0700597 session_options->recv_audio = false;
598 session_options->recv_video = false;
599 ASSERT_TRUE(ParseConstraintsForAnswer(constraints, session_options));
600
deadbeefc80741f2015-10-22 13:14:45 -0700601 AddStreamsToOptions(session_options);
602 session_options->bundle_enabled =
603 session_options->bundle_enabled &&
604 (session_options->has_audio() || session_options->has_video() ||
605 session_options->has_data());
606
deadbeefab9b2d12015-10-14 11:33:11 -0700607 if (session_->data_channel_type() == cricket::DCT_SCTP) {
608 session_options->data_channel_type = cricket::DCT_SCTP;
609 }
610 }
611
612 // Creates a local offer and applies it. Starts ICE.
613 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000614 // to decide which streams to create.
615 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000616 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000617 SetLocalDescriptionWithoutError(offer);
618 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
619 observer_.ice_gathering_state_,
620 kIceCandidatesTimeout);
621 }
622
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000623 SessionDescriptionInterface* CreateOffer() {
624 PeerConnectionInterface::RTCOfferAnswerOptions options;
625 options.offer_to_receive_audio =
626 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
627
628 return CreateOffer(options);
629 }
630
wu@webrtc.org91053e72013-08-10 07:18:04 +0000631 SessionDescriptionInterface* CreateOffer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000632 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000633 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000634 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700635 cricket::MediaSessionOptions session_options;
636 GetOptionsForOffer(options, &session_options);
637 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000638 EXPECT_TRUE_WAIT(
639 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000640 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000641 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000642 }
643
644 SessionDescriptionInterface* CreateAnswer(
645 const webrtc::MediaConstraintsInterface* constraints) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000646 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000647 = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700648 cricket::MediaSessionOptions session_options;
649 GetOptionsForAnswer(constraints, &session_options);
650 session_->CreateAnswer(observer, constraints, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000651 EXPECT_TRUE_WAIT(
652 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000653 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000654 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000655 }
656
wu@webrtc.org364f2042013-11-20 21:49:41 +0000657 bool ChannelsExist() const {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000658 return (session_->voice_channel() != NULL &&
659 session_->video_channel() != NULL);
660 }
661
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000662 void VerifyCryptoParams(const cricket::SessionDescription* sdp) {
663 ASSERT_TRUE(session_.get() != NULL);
664 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
665 ASSERT_TRUE(content != NULL);
666 const cricket::AudioContentDescription* audio_content =
667 static_cast<const cricket::AudioContentDescription*>(
668 content->description);
669 ASSERT_TRUE(audio_content != NULL);
670 ASSERT_EQ(1U, audio_content->cryptos().size());
671 ASSERT_EQ(47U, audio_content->cryptos()[0].key_params.size());
672 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
673 audio_content->cryptos()[0].cipher_suite);
674 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
675 audio_content->protocol());
676
677 content = cricket::GetFirstVideoContent(sdp);
678 ASSERT_TRUE(content != NULL);
679 const cricket::VideoContentDescription* video_content =
680 static_cast<const cricket::VideoContentDescription*>(
681 content->description);
682 ASSERT_TRUE(video_content != NULL);
683 ASSERT_EQ(1U, video_content->cryptos().size());
684 ASSERT_EQ("AES_CM_128_HMAC_SHA1_80",
685 video_content->cryptos()[0].cipher_suite);
686 ASSERT_EQ(47U, video_content->cryptos()[0].key_params.size());
687 EXPECT_EQ(std::string(cricket::kMediaProtocolSavpf),
688 video_content->protocol());
689 }
690
691 void VerifyNoCryptoParams(const cricket::SessionDescription* sdp, bool dtls) {
692 const cricket::ContentInfo* content = cricket::GetFirstAudioContent(sdp);
693 ASSERT_TRUE(content != NULL);
694 const cricket::AudioContentDescription* audio_content =
695 static_cast<const cricket::AudioContentDescription*>(
696 content->description);
697 ASSERT_TRUE(audio_content != NULL);
698 ASSERT_EQ(0U, audio_content->cryptos().size());
699
700 content = cricket::GetFirstVideoContent(sdp);
701 ASSERT_TRUE(content != NULL);
702 const cricket::VideoContentDescription* video_content =
703 static_cast<const cricket::VideoContentDescription*>(
704 content->description);
705 ASSERT_TRUE(video_content != NULL);
706 ASSERT_EQ(0U, video_content->cryptos().size());
707
708 if (dtls) {
deadbeeff3938292015-07-15 12:20:53 -0700709 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000710 audio_content->protocol());
deadbeeff3938292015-07-15 12:20:53 -0700711 EXPECT_EQ(std::string(cricket::kMediaProtocolDtlsSavpf),
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000712 video_content->protocol());
713 } else {
714 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
715 audio_content->protocol());
716 EXPECT_EQ(std::string(cricket::kMediaProtocolAvpf),
717 video_content->protocol());
718 }
719 }
720
721 // Set the internal fake description factories to do DTLS-SRTP.
722 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000723 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000724 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000725 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200726 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800727 tdesc_factory_->set_certificate(
728 rtc::RTCCertificate::Create(rtc::scoped_ptr<rtc::SSLIdentity>(
729 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000730 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
731 }
732
733 void VerifyFingerprintStatus(const cricket::SessionDescription* sdp,
734 bool expected) {
735 const TransportInfo* audio = sdp->GetTransportInfoByName("audio");
736 ASSERT_TRUE(audio != NULL);
737 ASSERT_EQ(expected, audio->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000738 const TransportInfo* video = sdp->GetTransportInfoByName("video");
739 ASSERT_TRUE(video != NULL);
740 ASSERT_EQ(expected, video->description.identity_fingerprint.get() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000741 }
742
743 void VerifyAnswerFromNonCryptoOffer() {
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +0000744 // Create an SDP without Crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000745 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000746 options.recv_video = true;
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000747 JsepSessionDescription* offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000748 CreateRemoteOffer(options, cricket::SEC_DISABLED));
henrike@webrtc.org28654cb2013-07-22 21:07:49 +0000749 ASSERT_TRUE(offer != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000750 VerifyNoCryptoParams(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000751 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
752 offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000753 const webrtc::SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000754 // Answer should be NULL as no crypto params in offer.
755 ASSERT_TRUE(answer == NULL);
756 }
757
758 void VerifyAnswerFromCryptoOffer() {
759 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000760 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000761 options.bundle_enabled = true;
762 scoped_ptr<JsepSessionDescription> offer(
763 CreateRemoteOffer(options, cricket::SEC_REQUIRED));
764 ASSERT_TRUE(offer.get() != NULL);
765 VerifyCryptoParams(offer->description());
766 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +0000767 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000768 ASSERT_TRUE(answer.get() != NULL);
769 VerifyCryptoParams(answer->description());
770 }
771
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000772 void SetAndVerifyNumUnsignalledRecvStreams(
773 int value_set, int value_expected) {
774 constraints_.reset(new FakeConstraints());
775 constraints_->AddOptional(
776 webrtc::MediaConstraintsInterface::kNumUnsignalledRecvStreams,
777 value_set);
778 session_.reset();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000779 Init();
deadbeefab9b2d12015-10-14 11:33:11 -0700780 SendAudioVideoStream1();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000781 SessionDescriptionInterface* offer = CreateOffer();
782
783 SetLocalDescriptionWithoutError(offer);
784
785 video_channel_ = media_engine_->GetVideoChannel(0);
786
787 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -0700788 const cricket::VideoOptions& video_options = video_channel_->options();
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000789 EXPECT_EQ(value_expected,
kwiberg102c6a62015-10-30 02:47:38 -0700790 video_options.unsignalled_recv_stream_limit.value_or(-1));
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +0000791 }
792
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000793 void CompareIceUfragAndPassword(const cricket::SessionDescription* desc1,
794 const cricket::SessionDescription* desc2,
795 bool expect_equal) {
796 if (desc1->contents().size() != desc2->contents().size()) {
797 EXPECT_FALSE(expect_equal);
798 return;
799 }
800
801 const cricket::ContentInfos& contents = desc1->contents();
802 cricket::ContentInfos::const_iterator it = contents.begin();
803
804 for (; it != contents.end(); ++it) {
805 const cricket::TransportDescription* transport_desc1 =
806 desc1->GetTransportDescriptionByName(it->name);
807 const cricket::TransportDescription* transport_desc2 =
808 desc2->GetTransportDescriptionByName(it->name);
809 if (!transport_desc1 || !transport_desc2) {
810 EXPECT_FALSE(expect_equal);
811 return;
812 }
813 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
814 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
815 EXPECT_FALSE(expect_equal);
816 return;
817 }
818 }
819 EXPECT_TRUE(expect_equal);
820 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000821
822 void RemoveIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
823 std::string *sdp) {
824 const cricket::SessionDescription* desc = current_desc->description();
825 EXPECT_TRUE(current_desc->ToString(sdp));
826
827 const cricket::ContentInfos& contents = desc->contents();
828 cricket::ContentInfos::const_iterator it = contents.begin();
829 // Replace ufrag and pwd lines with empty strings.
830 for (; it != contents.end(); ++it) {
831 const cricket::TransportDescription* transport_desc =
832 desc->GetTransportDescriptionByName(it->name);
833 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
834 + "\r\n";
835 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
836 + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000837 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000838 "", 0,
839 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000840 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000841 "", 0,
842 sdp);
843 }
844 }
845
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000846 void ModifyIceUfragPwdLines(const SessionDescriptionInterface* current_desc,
847 const std::string& modified_ice_ufrag,
848 const std::string& modified_ice_pwd,
849 std::string* sdp) {
850 const cricket::SessionDescription* desc = current_desc->description();
851 EXPECT_TRUE(current_desc->ToString(sdp));
852
853 const cricket::ContentInfos& contents = desc->contents();
854 cricket::ContentInfos::const_iterator it = contents.begin();
855 // Replace ufrag and pwd lines with |modified_ice_ufrag| and
856 // |modified_ice_pwd| strings.
857 for (; it != contents.end(); ++it) {
858 const cricket::TransportDescription* transport_desc =
859 desc->GetTransportDescriptionByName(it->name);
860 std::string ufrag_line = "a=ice-ufrag:" + transport_desc->ice_ufrag
861 + "\r\n";
862 std::string pwd_line = "a=ice-pwd:" + transport_desc->ice_pwd
863 + "\r\n";
864 std::string mod_ufrag = "a=ice-ufrag:" + modified_ice_ufrag + "\r\n";
865 std::string mod_pwd = "a=ice-pwd:" + modified_ice_pwd + "\r\n";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000866 rtc::replace_substrs(ufrag_line.c_str(), ufrag_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000867 mod_ufrag.c_str(), mod_ufrag.length(),
868 sdp);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000869 rtc::replace_substrs(pwd_line.c_str(), pwd_line.length(),
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +0000870 mod_pwd.c_str(), mod_pwd.length(),
871 sdp);
872 }
873 }
874
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000875 // Creates a remote offer and and applies it as a remote description,
876 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700877 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000878 // to decide which local and remote streams to create.
879 void CreateAndSetRemoteOfferAndLocalAnswer() {
880 SessionDescriptionInterface* offer = CreateRemoteOffer();
881 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000882 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000883 SetLocalDescriptionWithoutError(answer);
884 }
885 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
886 EXPECT_TRUE(session_->SetLocalDescription(desc, NULL));
deadbeefcbecd352015-09-23 11:50:27 -0700887 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888 }
889 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700890 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000891 SetLocalDescriptionWithoutError(desc);
892 EXPECT_EQ(expected_state, session_->state());
893 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000894 void SetLocalDescriptionExpectError(const std::string& action,
895 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000896 SessionDescriptionInterface* desc) {
897 std::string error;
898 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000899 std::string sdp_type = "local ";
900 sdp_type.append(action);
901 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000902 EXPECT_NE(std::string::npos, error.find(expected_error));
903 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000904 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
905 SessionDescriptionInterface* desc) {
906 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
907 expected_error, desc);
908 }
909 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
910 SessionDescriptionInterface* desc) {
911 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
912 expected_error, desc);
913 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000914 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
915 EXPECT_TRUE(session_->SetRemoteDescription(desc, NULL));
916 }
917 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700918 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000919 SetRemoteDescriptionWithoutError(desc);
920 EXPECT_EQ(expected_state, session_->state());
921 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000922 void SetRemoteDescriptionExpectError(const std::string& action,
923 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000924 SessionDescriptionInterface* desc) {
925 std::string error;
926 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000927 std::string sdp_type = "remote ";
928 sdp_type.append(action);
929 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000930 EXPECT_NE(std::string::npos, error.find(expected_error));
931 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000932 void SetRemoteDescriptionOfferExpectError(
933 const std::string& expected_error, SessionDescriptionInterface* desc) {
934 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
935 expected_error, desc);
936 }
937 void SetRemoteDescriptionPranswerExpectError(
938 const std::string& expected_error, SessionDescriptionInterface* desc) {
939 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kPrAnswer,
940 expected_error, desc);
941 }
942 void SetRemoteDescriptionAnswerExpectError(
943 const std::string& expected_error, SessionDescriptionInterface* desc) {
944 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
945 expected_error, desc);
946 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000947
948 void CreateCryptoOfferAndNonCryptoAnswer(SessionDescriptionInterface** offer,
949 SessionDescriptionInterface** nocrypto_answer) {
950 // Create a SDP without Crypto.
951 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000952 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000953 options.bundle_enabled = true;
954 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
955 ASSERT_TRUE(*offer != NULL);
956 VerifyCryptoParams((*offer)->description());
957
958 *nocrypto_answer = CreateRemoteAnswer(*offer, options,
959 cricket::SEC_DISABLED);
960 EXPECT_TRUE(*nocrypto_answer != NULL);
961 }
962
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000963 void CreateDtlsOfferAndNonDtlsAnswer(SessionDescriptionInterface** offer,
964 SessionDescriptionInterface** nodtls_answer) {
965 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +0000966 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000967 options.bundle_enabled = true;
968
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000969 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000970 CreateRemoteOffer(options, cricket::SEC_ENABLED));
971
972 *nodtls_answer =
973 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
974 EXPECT_TRUE(*nodtls_answer != NULL);
975 VerifyFingerprintStatus((*nodtls_answer)->description(), false);
976 VerifyCryptoParams((*nodtls_answer)->description());
977
978 SetFactoryDtlsSrtp();
979 *offer = CreateRemoteOffer(options, cricket::SEC_ENABLED);
980 ASSERT_TRUE(*offer != NULL);
981 VerifyFingerprintStatus((*offer)->description(), true);
982 VerifyCryptoParams((*offer)->description());
983 }
984
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000985 JsepSessionDescription* CreateRemoteOfferWithVersion(
986 cricket::MediaSessionOptions options,
987 cricket::SecurePolicy secure_policy,
988 const std::string& session_version,
989 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000990 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000991 const cricket::SessionDescription* cricket_desc = NULL;
992 if (current_desc) {
993 cricket_desc = current_desc->description();
994 session_id = current_desc->session_id();
995 }
996
997 desc_factory_->set_secure(secure_policy);
998 JsepSessionDescription* offer(
999 new JsepSessionDescription(JsepSessionDescription::kOffer));
1000 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
1001 session_id, session_version)) {
1002 delete offer;
1003 offer = NULL;
1004 }
1005 return offer;
1006 }
1007 JsepSessionDescription* CreateRemoteOffer(
1008 cricket::MediaSessionOptions options) {
1009 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1010 kSessionVersion, NULL);
1011 }
1012 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001013 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
1014 return CreateRemoteOfferWithVersion(
1015 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001016 }
1017 JsepSessionDescription* CreateRemoteOffer(
1018 cricket::MediaSessionOptions options,
1019 const SessionDescriptionInterface* current_desc) {
1020 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
1021 kSessionVersion, current_desc);
1022 }
1023
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001024 JsepSessionDescription* CreateRemoteOfferWithSctpPort(
1025 const char* sctp_stream_name, int new_port,
1026 cricket::MediaSessionOptions options) {
1027 options.data_channel_type = cricket::DCT_SCTP;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001028 options.AddSendStream(cricket::MEDIA_TYPE_DATA, "datachannel",
1029 sctp_stream_name);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001030 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
1031 }
1032
1033 // Takes ownership of offer_basis (and deletes it).
1034 JsepSessionDescription* ChangeSDPSctpPort(
1035 int new_port, webrtc::SessionDescriptionInterface *offer_basis) {
1036 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
1037 // SessionDescription from the mutated string.
1038 const char* default_port_str = "5000";
1039 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001040 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001041 std::string offer_str;
1042 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001043 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00001044 new_port_str, strlen(new_port_str),
1045 &offer_str);
1046 JsepSessionDescription* offer = new JsepSessionDescription(
1047 offer_basis->type());
1048 delete offer_basis;
1049 offer->Initialize(offer_str, NULL);
1050 return offer;
1051 }
1052
deadbeefab9b2d12015-10-14 11:33:11 -07001053 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001054 // before this function to decide which streams to create.
1055 JsepSessionDescription* CreateRemoteOffer() {
1056 cricket::MediaSessionOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001057 GetOptionsForAnswer(NULL, &options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001058 return CreateRemoteOffer(options, session_->remote_description());
1059 }
1060
1061 JsepSessionDescription* CreateRemoteAnswer(
1062 const SessionDescriptionInterface* offer,
1063 cricket::MediaSessionOptions options,
1064 cricket::SecurePolicy policy) {
1065 desc_factory_->set_secure(policy);
1066 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001067 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001068 JsepSessionDescription* answer(
1069 new JsepSessionDescription(JsepSessionDescription::kAnswer));
1070 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
1071 options, NULL),
1072 session_id, kSessionVersion)) {
1073 delete answer;
1074 answer = NULL;
1075 }
1076 return answer;
1077 }
1078
1079 JsepSessionDescription* CreateRemoteAnswer(
1080 const SessionDescriptionInterface* offer,
1081 cricket::MediaSessionOptions options) {
1082 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1083 }
1084
deadbeefab9b2d12015-10-14 11:33:11 -07001085 // Creates an answer session description.
1086 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001087 // to decide which streams to create.
1088 JsepSessionDescription* CreateRemoteAnswer(
1089 const SessionDescriptionInterface* offer) {
1090 cricket::MediaSessionOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001091 GetOptionsForAnswer(NULL, &options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001092 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
1093 }
1094
1095 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001096 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001097 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001098 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001099
1100 PeerConnectionInterface::RTCOfferAnswerOptions options;
1101 options.use_rtp_mux = bundle;
1102
1103 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001104 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1105 // and answer.
1106 SetLocalDescriptionWithoutError(offer);
1107
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001108 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001109 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001110 std::string sdp;
1111 EXPECT_TRUE(answer->ToString(&sdp));
1112
1113 size_t expected_candidate_num = 2;
1114 if (!rtcp_mux) {
1115 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1116 // for rtp and rtcp.
1117 expected_candidate_num = 4;
1118 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001119 const std::string kRtcpMux = "a=rtcp-mux";
1120 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001121 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001122 kXRtcpMux.c_str(), kXRtcpMux.length(),
1123 &sdp);
1124 }
1125
1126 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1127 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001128
1129 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001130 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001131 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1132 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001133 if (bundle) {
1134 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1135 } else {
1136 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001137 }
1138 }
1139 // Tests that we can only send DTMF when the dtmf codec is supported.
1140 void TestCanInsertDtmf(bool can) {
1141 if (can) {
1142 InitWithDtmfCodec();
1143 } else {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001144 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001145 }
deadbeefab9b2d12015-10-14 11:33:11 -07001146 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001147 CreateAndSetRemoteOfferAndLocalAnswer();
1148 EXPECT_FALSE(session_->CanInsertDtmf(""));
1149 EXPECT_EQ(can, session_->CanInsertDtmf(kAudioTrack1));
1150 }
1151
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001152 // Helper class to configure loopback network and verify Best
1153 // Connection using right IP protocol for TestLoopbackCall
1154 // method. LoopbackNetworkManager applies firewall rules to block
1155 // all ping traffic once ICE completed, and remove them to observe
1156 // ICE reconnected again. This LoopbackNetworkConfiguration struct
1157 // verifies the best connection is using the right IP protocol after
1158 // initial ICE convergences.
1159
1160 class LoopbackNetworkConfiguration {
deadbeefcbecd352015-09-23 11:50:27 -07001161 public:
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001162 LoopbackNetworkConfiguration()
1163 : test_ipv6_network_(false),
1164 test_extra_ipv4_network_(false),
1165 best_connection_after_initial_ice_converged_(1, 0) {}
1166
1167 // Used to track the expected best connection count in each IP protocol.
1168 struct ExpectedBestConnection {
1169 ExpectedBestConnection(int ipv4_count, int ipv6_count)
1170 : ipv4_count_(ipv4_count),
1171 ipv6_count_(ipv6_count) {}
1172
1173 int ipv4_count_;
1174 int ipv6_count_;
1175 };
1176
1177 bool test_ipv6_network_;
1178 bool test_extra_ipv4_network_;
1179 ExpectedBestConnection best_connection_after_initial_ice_converged_;
1180
1181 void VerifyBestConnectionAfterIceConverge(
jbauchac8869e2015-07-03 01:36:14 -07001182 const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer) const {
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001183 Verify(metrics_observer, best_connection_after_initial_ice_converged_);
1184 }
1185
1186 private:
jbauchac8869e2015-07-03 01:36:14 -07001187 void Verify(const rtc::scoped_refptr<FakeMetricsObserver> metrics_observer,
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001188 const ExpectedBestConnection& expected) const {
1189 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001190 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1191 webrtc::kBestConnections_IPv4),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001192 expected.ipv4_count_);
1193 EXPECT_EQ(
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001194 metrics_observer->GetEnumCounter(webrtc::kEnumCounterAddressFamily,
1195 webrtc::kBestConnections_IPv6),
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001196 expected.ipv6_count_);
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001197 // This is used in the loopback call so there is only single host to host
1198 // candidate pair.
1199 EXPECT_EQ(metrics_observer->GetEnumCounter(
1200 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1201 webrtc::kIceCandidatePairHostHost),
Guo-wei Shieh3cc834a2015-09-04 15:52:14 -07001202 0);
1203 EXPECT_EQ(metrics_observer->GetEnumCounter(
1204 webrtc::kEnumCounterIceCandidatePairTypeUdp,
1205 webrtc::kIceCandidatePairHostPublicHostPublic),
Guo-wei Shieh3d564c12015-08-19 16:51:15 -07001206 1);
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001207 }
1208 };
1209
1210 class LoopbackNetworkManager {
1211 public:
1212 LoopbackNetworkManager(WebRtcSessionTest* session,
1213 const LoopbackNetworkConfiguration& config)
1214 : config_(config) {
1215 session->AddInterface(
1216 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1217 if (config_.test_extra_ipv4_network_) {
1218 session->AddInterface(
1219 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1220 }
1221 if (config_.test_ipv6_network_) {
1222 session->AddInterface(
1223 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1224 }
1225 }
1226
1227 void ApplyFirewallRules(rtc::FirewallSocketServer* fss) {
1228 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1229 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1230 if (config_.test_extra_ipv4_network_) {
1231 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1232 rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
1233 }
1234 if (config_.test_ipv6_network_) {
1235 fss->AddRule(false, rtc::FP_ANY, rtc::FD_ANY,
1236 rtc::SocketAddress(kClientIPv6AddrHost1, kClientAddrPort));
1237 }
1238 }
1239
1240 void ClearRules(rtc::FirewallSocketServer* fss) { fss->ClearRules(); }
1241
1242 private:
1243 LoopbackNetworkConfiguration config_;
1244 };
1245
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001246 // The method sets up a call from the session to itself, in a loopback
1247 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001248 // disconnection, and then a permanent disconnection.
1249 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001250 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1251 // While running the call, this method also checks if the session goes through
1252 // the correct sequence of ICE states when a connection is established,
1253 // broken, and re-established.
1254 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001255 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1256 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001257 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001258
stefanc1aeaf02015-10-15 07:26:07 -07001259 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001260 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001261 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001262 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001263
1264 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1265 observer_.ice_gathering_state_);
1266 SetLocalDescriptionWithoutError(offer);
1267 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1268 observer_.ice_connection_state_);
1269 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001270 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001271 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1272 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001273 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001274
1275 std::string sdp;
1276 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001277 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1278 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001279 ASSERT_TRUE(desc != NULL);
1280 SetRemoteDescriptionWithoutError(desc);
1281
1282 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001283 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001284
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001285 // The ice connection state is "Connected" too briefly to catch in a test.
1286 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001287 observer_.ice_connection_state_, kIceCandidatesTimeout);
1288 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001289
stefanc1aeaf02015-10-15 07:26:07 -07001290 void TestLoopbackCall(const LoopbackNetworkConfiguration& config) {
1291 LoopbackNetworkManager loopback_network_manager(this, config);
1292 SetupLoopbackCall();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001293 config.VerifyBestConnectionAfterIceConverge(metrics_observer_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001294 // Adding firewall rule to block ping requests, which should cause
1295 // transport channel failure.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001296
1297 loopback_network_manager.ApplyFirewallRules(fss_.get());
1298
1299 LOG(LS_INFO) << "Firewall Rules applied";
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001300 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
1301 observer_.ice_connection_state_,
1302 kIceCandidatesTimeout);
1303
jbauchac8869e2015-07-03 01:36:14 -07001304 metrics_observer_->Reset();
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001305
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001306 // Clearing the rules, session should move back to completed state.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001307 loopback_network_manager.ClearRules(fss_.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001308
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001309 LOG(LS_INFO) << "Firewall Rules cleared";
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001310 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001311 observer_.ice_connection_state_,
1312 kIceCandidatesTimeout);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001313
1314 // Now we block ping requests and wait until the ICE connection transitions
1315 // to the Failed state. This will take at least 30 seconds because it must
1316 // wait for the Port to timeout.
1317 int port_timeout = 30000;
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001318
1319 loopback_network_manager.ApplyFirewallRules(fss_.get());
1320 LOG(LS_INFO) << "Firewall Rules applied again";
jlmiller@webrtc.org804eb462015-02-20 02:20:03 +00001321 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001322 observer_.ice_connection_state_,
1323 kIceCandidatesTimeout + port_timeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324 }
1325
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001326 void TestLoopbackCall() {
1327 LoopbackNetworkConfiguration config;
1328 TestLoopbackCall(config);
1329 }
1330
stefanc1aeaf02015-10-15 07:26:07 -07001331 void TestPacketOptions() {
1332 media_controller_.reset(
1333 new cricket::FakeMediaController(channel_manager_.get(), &fake_call_));
1334 LoopbackNetworkConfiguration config;
1335 LoopbackNetworkManager loopback_network_manager(this, config);
1336
1337 SetupLoopbackCall();
1338
1339 uint8_t test_packet[15] = {0};
1340 rtc::PacketOptions options;
1341 options.packet_id = 10;
1342 media_engine_->GetVideoChannel(0)
1343 ->SendRtp(test_packet, sizeof(test_packet), options);
1344
1345 const int kPacketTimeout = 2000;
1346 EXPECT_EQ_WAIT(fake_call_.last_sent_packet().packet_id, 10, kPacketTimeout);
1347 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1348 }
1349
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001350 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1351 void AddCNCodecs() {
wu@webrtc.org364f2042013-11-20 21:49:41 +00001352 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1, 0);
1353 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1, 0);
1354
1355 // Add kCNCodec for dtmf test.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001356 std::vector<cricket::AudioCodec> codecs = media_engine_->audio_codecs();;
1357 codecs.push_back(kCNCodec1);
1358 codecs.push_back(kCNCodec2);
1359 media_engine_->SetAudioCodecs(codecs);
1360 desc_factory_->set_audio_codecs(codecs);
1361 }
1362
1363 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1364 const cricket::ContentDescription* description = content->description;
1365 ASSERT(description != NULL);
1366 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001367 static_cast<const cricket::AudioContentDescription*>(description);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001368 ASSERT(audio_content_desc != NULL);
1369 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1370 if (audio_content_desc->codecs()[i].name == "CN")
1371 return false;
1372 }
1373 return true;
1374 }
1375
deadbeefab9b2d12015-10-14 11:33:11 -07001376 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001377 webrtc::InternalDataChannelInit dci;
deadbeefab9b2d12015-10-14 11:33:11 -07001378 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1379 data_channel_ = DataChannel::Create(
1380 session_.get(), session_->data_channel_type(), "datachannel", dci);
1381 }
1382
1383 void SetLocalDescriptionWithDataChannel() {
1384 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001385 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001386 SetLocalDescriptionWithoutError(offer);
1387 }
1388
wu@webrtc.org91053e72013-08-10 07:18:04 +00001389 void VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02001390 RTCCertificateGenerationMethod cert_gen_method,
1391 CreateSessionDescriptionRequest::Type type) {
1392 InitWithDtls(cert_gen_method);
1393 VerifyMultipleAsyncCreateDescriptionAfterInit(true, type);
1394 }
1395
1396 void VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
1397 CreateSessionDescriptionRequest::Type type) {
1398 InitWithDtlsIdentityGenFail();
1399 VerifyMultipleAsyncCreateDescriptionAfterInit(false, type);
1400 }
1401
1402 void VerifyMultipleAsyncCreateDescriptionAfterInit(
wu@webrtc.org91053e72013-08-10 07:18:04 +00001403 bool success, CreateSessionDescriptionRequest::Type type) {
henrikg91d6ede2015-09-17 00:24:34 -07001404 RTC_CHECK(session_);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001405 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001406 if (type == CreateSessionDescriptionRequest::kAnswer) {
1407 cricket::MediaSessionOptions options;
1408 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001409 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00001410 ASSERT_TRUE(offer.get() != NULL);
1411 SetRemoteDescriptionWithoutError(offer.release());
1412 }
1413
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001414 PeerConnectionInterface::RTCOfferAnswerOptions options;
deadbeefab9b2d12015-10-14 11:33:11 -07001415 cricket::MediaSessionOptions session_options;
wu@webrtc.org91053e72013-08-10 07:18:04 +00001416 const int kNumber = 3;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001417 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +00001418 observers[kNumber];
1419 for (int i = 0; i < kNumber; ++i) {
1420 observers[i] = new WebRtcSessionCreateSDPObserverForTest();
1421 if (type == CreateSessionDescriptionRequest::kOffer) {
deadbeefab9b2d12015-10-14 11:33:11 -07001422 session_->CreateOffer(observers[i], options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001423 } else {
deadbeefab9b2d12015-10-14 11:33:11 -07001424 session_->CreateAnswer(observers[i], nullptr, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +00001425 }
1426 }
1427
1428 WebRtcSessionCreateSDPObserverForTest::State expected_state =
1429 success ? WebRtcSessionCreateSDPObserverForTest::kSucceeded :
1430 WebRtcSessionCreateSDPObserverForTest::kFailed;
1431
1432 for (int i = 0; i < kNumber; ++i) {
1433 EXPECT_EQ_WAIT(expected_state, observers[i]->state(), 1000);
1434 if (success) {
1435 EXPECT_TRUE(observers[i]->description() != NULL);
1436 } else {
1437 EXPECT_TRUE(observers[i]->description() == NULL);
1438 }
1439 }
1440 }
1441
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001442 void ConfigureAllocatorWithTurn() {
deadbeef653b8e02015-11-11 12:55:10 -08001443 cricket::RelayServerConfig turn_server(cricket::RELAY_TURN);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001444 cricket::RelayCredentials credentials(kTurnUsername, kTurnPassword);
deadbeef653b8e02015-11-11 12:55:10 -08001445 turn_server.credentials = credentials;
1446 turn_server.ports.push_back(
1447 cricket::ProtocolAddress(kTurnUdpIntAddr, cricket::PROTO_UDP, false));
1448 allocator_->AddTurnServer(turn_server);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001449 allocator_->set_step_delay(cricket::kMinimumStepDelay);
Peter Thatcher7cbd1882015-09-17 18:54:52 -07001450 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP);
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001451 }
1452
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001453 cricket::FakeMediaEngine* media_engine_;
1454 cricket::FakeDataEngine* data_engine_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001455 rtc::scoped_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001456 cricket::FakeCall fake_call_;
1457 rtc::scoped_ptr<webrtc::MediaControllerInterface> media_controller_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001458 rtc::scoped_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001459 rtc::scoped_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
1460 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1461 rtc::scoped_ptr<rtc::VirtualSocketServer> vss_;
1462 rtc::scoped_ptr<rtc::FirewallSocketServer> fss_;
1463 rtc::SocketServerScope ss_scope_;
1464 rtc::SocketAddress stun_socket_addr_;
jiayl@webrtc.orgbebc75e2014-09-26 23:01:11 +00001465 rtc::scoped_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.org41451d42014-05-03 05:39:45 +00001466 cricket::TestTurnServer turn_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001467 rtc::FakeNetworkManager network_manager_;
1468 rtc::scoped_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001469 PeerConnectionFactoryInterface::Options options_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001470 rtc::scoped_ptr<FakeConstraints> constraints_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001471 rtc::scoped_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001472 MockIceObserver observer_;
1473 cricket::FakeVideoMediaChannel* video_channel_;
1474 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001475 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001476 // The following flags affect options created for CreateOffer/CreateAnswer.
1477 bool send_stream_1_ = false;
1478 bool send_stream_2_ = false;
1479 bool send_audio_ = false;
1480 bool send_video_ = false;
1481 rtc::scoped_refptr<DataChannel> data_channel_;
1482 // Last values received from data channel creation signal.
1483 std::string last_data_channel_label_;
1484 InternalDataChannelInit last_data_channel_config_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001485};
1486
Henrik Boström87713d02015-08-25 09:53:21 +02001487TEST_P(WebRtcSessionTest, TestInitializeWithDtls) {
1488 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001489 // SDES is disabled when DTLS is on.
1490 EXPECT_EQ(cricket::SEC_DISABLED, session_->SdesPolicy());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001491}
1492
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001493TEST_F(WebRtcSessionTest, TestInitializeWithoutDtls) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001494 Init();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001495 // SDES is required if DTLS is off.
1496 EXPECT_EQ(cricket::SEC_REQUIRED, session_->SdesPolicy());
wu@webrtc.org91053e72013-08-10 07:18:04 +00001497}
1498
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001499TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1500 TestSessionCandidatesWithBundleRtcpMux(false, false);
1501}
1502
1503// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1504// with rtcp-mux and/or bundle.
1505TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1506 TestSessionCandidatesWithBundleRtcpMux(false, true);
1507}
1508
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001509TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1510 TestSessionCandidatesWithBundleRtcpMux(true, true);
1511}
1512
1513TEST_F(WebRtcSessionTest, TestMultihomeCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001514 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1515 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001516 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001517 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001518 InitiateCall();
1519 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1520 EXPECT_EQ(8u, observer_.mline_0_candidates_.size());
1521 EXPECT_EQ(8u, observer_.mline_1_candidates_.size());
1522}
1523
1524TEST_F(WebRtcSessionTest, TestStunError) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001525 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1526 AddInterface(rtc::SocketAddress(kClientAddrHost2, kClientAddrPort));
wu@webrtc.org364f2042013-11-20 21:49:41 +00001527 fss_->AddRule(false,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001528 rtc::FP_UDP,
1529 rtc::FD_ANY,
1530 rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001531 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001532 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001533 InitiateCall();
wu@webrtc.org364f2042013-11-20 21:49:41 +00001534 // Since kClientAddrHost1 is blocked, not expecting stun candidates for it.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001535 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1536 EXPECT_EQ(6u, observer_.mline_0_candidates_.size());
1537 EXPECT_EQ(6u, observer_.mline_1_candidates_.size());
1538}
1539
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001540// Test session delivers no candidates gathered when constraint set to "none".
1541TEST_F(WebRtcSessionTest, TestIceTransportsNone) {
1542 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001543 InitWithIceTransport(PeerConnectionInterface::kNone);
deadbeefab9b2d12015-10-14 11:33:11 -07001544 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001545 InitiateCall();
1546 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1547 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
1548 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
1549}
1550
1551// Test session delivers only relay candidates gathered when constaint set to
1552// "relay".
1553TEST_F(WebRtcSessionTest, TestIceTransportsRelay) {
1554 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
1555 ConfigureAllocatorWithTurn();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001556 InitWithIceTransport(PeerConnectionInterface::kRelay);
deadbeefab9b2d12015-10-14 11:33:11 -07001557 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001558 InitiateCall();
1559 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1560 EXPECT_EQ(2u, observer_.mline_0_candidates_.size());
1561 EXPECT_EQ(2u, observer_.mline_1_candidates_.size());
1562 for (size_t i = 0; i < observer_.mline_0_candidates_.size(); ++i) {
1563 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1564 observer_.mline_0_candidates_[i].type());
1565 }
1566 for (size_t i = 0; i < observer_.mline_1_candidates_.size(); ++i) {
1567 EXPECT_EQ(cricket::RELAY_PORT_TYPE,
1568 observer_.mline_1_candidates_[i].type());
1569 }
1570}
1571
1572// Test session delivers all candidates gathered when constaint set to "all".
1573TEST_F(WebRtcSessionTest, TestIceTransportsAll) {
1574 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001575 InitWithIceTransport(PeerConnectionInterface::kAll);
deadbeefab9b2d12015-10-14 11:33:11 -07001576 SendAudioVideoStream1();
mallinath@webrtc.org3d81b1b2014-09-09 14:38:10 +00001577 InitiateCall();
1578 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1579 // Host + STUN. By default allocator is disabled to gather relay candidates.
1580 EXPECT_EQ(4u, observer_.mline_0_candidates_.size());
1581 EXPECT_EQ(4u, observer_.mline_1_candidates_.size());
1582}
1583
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001584TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001585 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001586 SessionDescriptionInterface* offer = NULL;
1587 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1588 std::string unknown_action;
1589 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1590 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1591}
1592
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001593// Test creating offers and receive answers and make sure the
1594// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001595TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001596 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001597 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001598 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001599 const std::string session_id_orig = offer->session_id();
1600 const std::string session_version_orig = offer->session_version();
1601 SetLocalDescriptionWithoutError(offer);
1602
deadbeefab9b2d12015-10-14 11:33:11 -07001603 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001604 SessionDescriptionInterface* answer =
1605 CreateRemoteAnswer(session_->local_description());
1606 SetRemoteDescriptionWithoutError(answer);
1607
1608 video_channel_ = media_engine_->GetVideoChannel(0);
1609 voice_channel_ = media_engine_->GetVoiceChannel(0);
1610
1611 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1612 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1613
1614 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1615 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1616
1617 ASSERT_EQ(1u, video_channel_->send_streams().size());
1618 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1619 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1620 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1621
1622 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001623 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001624 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001625
1626 // Verify the session id is the same and the session version is
1627 // increased.
1628 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001629 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1630 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001631
1632 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001633 EXPECT_EQ(0u, video_channel_->send_streams().size());
1634 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001635
deadbeefab9b2d12015-10-14 11:33:11 -07001636 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001637 answer = CreateRemoteAnswer(session_->local_description());
1638 SetRemoteDescriptionWithoutError(answer);
1639
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001640 // Make sure the receive streams have not changed.
1641 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1642 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1643 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1644 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1645}
1646
1647// Test receiving offers and creating answers and make sure the
1648// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001649TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001650 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001651 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001652 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001653 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001654 SetRemoteDescriptionWithoutError(offer);
1655
deadbeefab9b2d12015-10-14 11:33:11 -07001656 SendAudioVideoStream1();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001657 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001658 VerifyCryptoParams(answer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001659 SetLocalDescriptionWithoutError(answer);
1660
1661 const std::string session_id_orig = answer->session_id();
1662 const std::string session_version_orig = answer->session_version();
1663
1664 video_channel_ = media_engine_->GetVideoChannel(0);
1665 voice_channel_ = media_engine_->GetVoiceChannel(0);
1666
1667 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1668 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1669
1670 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1671 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1672
1673 ASSERT_EQ(1u, video_channel_->send_streams().size());
1674 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1675 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1676 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1677
deadbeefab9b2d12015-10-14 11:33:11 -07001678 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001679 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001680 SetRemoteDescriptionWithoutError(offer);
1681
1682 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001683 SendNothing();
wu@webrtc.org91053e72013-08-10 07:18:04 +00001684 answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001685
1686 // Verify the session id is the same and the session version is
1687 // increased.
1688 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001689 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1690 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001691 SetLocalDescriptionWithoutError(answer);
1692
1693 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1694 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1695 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1696 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1697 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1698 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1699
1700 // Make sure we have no send streams.
1701 EXPECT_EQ(0u, video_channel_->send_streams().size());
1702 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1703}
1704
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001705TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001706 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001707 media_engine_->set_fail_create_channel(true);
1708
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001709 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001710 ASSERT_TRUE(offer != NULL);
1711 // SetRemoteDescription and SetLocalDescription will take the ownership of
1712 // the offer.
1713 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001714 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001715 ASSERT_TRUE(offer != NULL);
1716 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1717}
1718
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001719//
1720// Tests for creating/setting SDP under different SDES/DTLS polices:
1721//
1722// --DTLS off and SDES on
1723// TestCreateSdesOfferReceiveSdesAnswer/TestReceiveSdesOfferCreateSdesAnswer:
1724// set local/remote offer/answer with crypto --> success
1725// TestSetNonSdesOfferWhenSdesOn: set local/remote offer without crypto --->
1726// failure
1727// TestSetLocalNonSdesAnswerWhenSdesOn: set local answer without crypto -->
1728// failure
1729// TestSetRemoteNonSdesAnswerWhenSdesOn: set remote answer without crypto -->
1730// failure
1731//
1732// --DTLS on and SDES off
1733// TestCreateDtlsOfferReceiveDtlsAnswer/TestReceiveDtlsOfferCreateDtlsAnswer:
1734// set local/remote offer/answer with DTLS fingerprint --> success
1735// TestReceiveNonDtlsOfferWhenDtlsOn: set local/remote offer without DTLS
1736// fingerprint --> failure
1737// TestSetLocalNonDtlsAnswerWhenDtlsOn: set local answer without fingerprint
1738// --> failure
1739// TestSetRemoteNonDtlsAnswerWhenDtlsOn: set remote answer without fingerprint
1740// --> failure
1741//
1742// --Encryption disabled: DTLS off and SDES off
1743// TestCreateOfferReceiveAnswerWithoutEncryption: set local offer and remote
1744// answer without SDES or DTLS --> success
1745// TestCreateAnswerReceiveOfferWithoutEncryption: set remote offer and local
1746// answer without SDES or DTLS --> success
1747//
1748
1749// Test that we return a failure when applying a remote/local offer that doesn't
1750// have cryptos enabled when DTLS is off.
1751TEST_F(WebRtcSessionTest, TestSetNonSdesOfferWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001752 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001753 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001754 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001755 JsepSessionDescription* offer = CreateRemoteOffer(
1756 options, cricket::SEC_DISABLED);
1757 ASSERT_TRUE(offer != NULL);
1758 VerifyNoCryptoParams(offer->description(), false);
1759 // SetRemoteDescription and SetLocalDescription will take the ownership of
1760 // the offer.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001761 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001762 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
1763 ASSERT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001764 SetLocalDescriptionOfferExpectError(kSdpWithoutSdesCrypto, offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001765}
1766
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001767// Test that we return a failure when applying a local answer that doesn't have
1768// cryptos enabled when DTLS is off.
1769TEST_F(WebRtcSessionTest, TestSetLocalNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001770 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001771 SessionDescriptionInterface* offer = NULL;
1772 SessionDescriptionInterface* answer = NULL;
1773 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1774 // SetRemoteDescription and SetLocalDescription will take the ownership of
1775 // the offer.
1776 SetRemoteDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001777 SetLocalDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778}
1779
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001780// Test we will return fail when apply an remote answer that doesn't have
1781// crypto enabled when DTLS is off.
1782TEST_F(WebRtcSessionTest, TestSetRemoteNonSdesAnswerWhenSdesOn) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001783 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001784 SessionDescriptionInterface* offer = NULL;
1785 SessionDescriptionInterface* answer = NULL;
1786 CreateCryptoOfferAndNonCryptoAnswer(&offer, &answer);
1787 // SetRemoteDescription and SetLocalDescription will take the ownership of
1788 // the offer.
1789 SetLocalDescriptionWithoutError(offer);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001790 SetRemoteDescriptionAnswerExpectError(kSdpWithoutSdesCrypto, answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001791}
1792
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001793// Test that we accept an offer with a DTLS fingerprint when DTLS is on
1794// and that we return an answer with a DTLS fingerprint.
Henrik Boström87713d02015-08-25 09:53:21 +02001795TEST_P(WebRtcSessionTest, TestReceiveDtlsOfferCreateDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001796 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001797 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001798 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001799 SetFactoryDtlsSrtp();
1800 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001801 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001802 JsepSessionDescription* offer =
1803 CreateRemoteOffer(options, cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001804 ASSERT_TRUE(offer != NULL);
1805 VerifyFingerprintStatus(offer->description(), true);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001806 VerifyNoCryptoParams(offer->description(), true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001807
1808 // SetRemoteDescription will take the ownership of the offer.
1809 SetRemoteDescriptionWithoutError(offer);
1810
1811 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001812 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001813 ASSERT_TRUE(answer != NULL);
1814 VerifyFingerprintStatus(answer->description(), true);
1815 // Check that we don't have an a=crypto line in the answer.
1816 VerifyNoCryptoParams(answer->description(), true);
1817
1818 // Now set the local description, which should work, even without a=crypto.
1819 SetLocalDescriptionWithoutError(answer);
1820}
1821
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001822// Test that we set a local offer with a DTLS fingerprint when DTLS is on
1823// and then we accept a remote answer with a DTLS fingerprint successfully.
Henrik Boström87713d02015-08-25 09:53:21 +02001824TEST_P(WebRtcSessionTest, TestCreateDtlsOfferReceiveDtlsAnswer) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001825 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefab9b2d12015-10-14 11:33:11 -07001826 SendAudioVideoStream1();
Henrik Boström87713d02015-08-25 09:53:21 +02001827 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001828 SetFactoryDtlsSrtp();
1829
1830 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001831 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001832 ASSERT_TRUE(offer != NULL);
1833 VerifyFingerprintStatus(offer->description(), true);
1834 // Check that we don't have an a=crypto line in the offer.
1835 VerifyNoCryptoParams(offer->description(), true);
1836
1837 // Now set the local description, which should work, even without a=crypto.
1838 SetLocalDescriptionWithoutError(offer);
1839
1840 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001841 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001842 JsepSessionDescription* answer =
1843 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1844 ASSERT_TRUE(answer != NULL);
1845 VerifyFingerprintStatus(answer->description(), true);
1846 VerifyNoCryptoParams(answer->description(), true);
1847
1848 // SetRemoteDescription will take the ownership of the answer.
1849 SetRemoteDescriptionWithoutError(answer);
1850}
1851
1852// Test that if we support DTLS and the other side didn't offer a fingerprint,
1853// we will fail to set the remote description.
Henrik Boström87713d02015-08-25 09:53:21 +02001854TEST_P(WebRtcSessionTest, TestReceiveNonDtlsOfferWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001855 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001856 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001857 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001858 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001859 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001860 JsepSessionDescription* offer = CreateRemoteOffer(
1861 options, cricket::SEC_REQUIRED);
1862 ASSERT_TRUE(offer != NULL);
1863 VerifyFingerprintStatus(offer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001864 VerifyCryptoParams(offer->description());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001865
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001866 // SetRemoteDescription will take the ownership of the offer.
1867 SetRemoteDescriptionOfferExpectError(
1868 kSdpWithoutDtlsFingerprint, offer);
1869
1870 offer = CreateRemoteOffer(options, cricket::SEC_REQUIRED);
1871 // SetLocalDescription will take the ownership of the offer.
1872 SetLocalDescriptionOfferExpectError(
1873 kSdpWithoutDtlsFingerprint, offer);
1874}
1875
1876// Test that we return a failure when applying a local answer that doesn't have
1877// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001878TEST_P(WebRtcSessionTest, TestSetLocalNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001879 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001880 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001881 SessionDescriptionInterface* offer = NULL;
1882 SessionDescriptionInterface* answer = NULL;
1883 CreateDtlsOfferAndNonDtlsAnswer(&offer, &answer);
1884
1885 // SetRemoteDescription and SetLocalDescription will take the ownership of
1886 // the offer and answer.
1887 SetRemoteDescriptionWithoutError(offer);
1888 SetLocalDescriptionAnswerExpectError(
1889 kSdpWithoutDtlsFingerprint, answer);
1890}
1891
1892// Test that we return a failure when applying a remote answer that doesn't have
1893// a DTLS fingerprint when DTLS is required.
Henrik Boström87713d02015-08-25 09:53:21 +02001894TEST_P(WebRtcSessionTest, TestSetRemoteNonDtlsAnswerWhenDtlsOn) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001895 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02001896 InitWithDtls(GetParam());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001897 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001898 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001899 options.recv_video = true;
deadbeefcbecd352015-09-23 11:50:27 -07001900 rtc::scoped_ptr<SessionDescriptionInterface> temp_offer(
1901 CreateRemoteOffer(options, cricket::SEC_ENABLED));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001902 JsepSessionDescription* answer =
deadbeefcbecd352015-09-23 11:50:27 -07001903 CreateRemoteAnswer(temp_offer.get(), options, cricket::SEC_ENABLED);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001904
1905 // SetRemoteDescription and SetLocalDescription will take the ownership of
1906 // the offer and answer.
1907 SetLocalDescriptionWithoutError(offer);
1908 SetRemoteDescriptionAnswerExpectError(
1909 kSdpWithoutDtlsFingerprint, answer);
1910}
1911
1912// Test that we create a local offer without SDES or DTLS and accept a remote
1913// answer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001914TEST_P(WebRtcSessionTest, TestCreateOfferReceiveAnswerWithoutEncryption) {
deadbeefab9b2d12015-10-14 11:33:11 -07001915 SendAudioVideoStream1();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001916 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001917 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001918
1919 // Verify that we get a crypto fingerprint in the answer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001920 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001921 ASSERT_TRUE(offer != NULL);
1922 VerifyFingerprintStatus(offer->description(), false);
1923 // Check that we don't have an a=crypto line in the offer.
1924 VerifyNoCryptoParams(offer->description(), false);
1925
1926 // Now set the local description, which should work, even without a=crypto.
1927 SetLocalDescriptionWithoutError(offer);
1928
1929 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001930 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001931 JsepSessionDescription* answer =
1932 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1933 ASSERT_TRUE(answer != NULL);
1934 VerifyFingerprintStatus(answer->description(), false);
1935 VerifyNoCryptoParams(answer->description(), false);
1936
1937 // SetRemoteDescription will take the ownership of the answer.
1938 SetRemoteDescriptionWithoutError(answer);
1939}
1940
1941// Test that we create a local answer without SDES or DTLS and accept a remote
1942// offer without SDES or DTLS when encryption is disabled.
Henrik Boström87713d02015-08-25 09:53:21 +02001943TEST_P(WebRtcSessionTest, TestCreateAnswerReceiveOfferWithoutEncryption) {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001944 options_.disable_encryption = true;
Henrik Boström87713d02015-08-25 09:53:21 +02001945 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001946
1947 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00001948 options.recv_video = true;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001949 JsepSessionDescription* offer =
1950 CreateRemoteOffer(options, cricket::SEC_DISABLED);
1951 ASSERT_TRUE(offer != NULL);
1952 VerifyFingerprintStatus(offer->description(), false);
1953 VerifyNoCryptoParams(offer->description(), false);
1954
1955 // SetRemoteDescription will take the ownership of the offer.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001956 SetRemoteDescriptionWithoutError(offer);
1957
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001958 // Verify that we get a crypto fingerprint in the answer.
wu@webrtc.org91053e72013-08-10 07:18:04 +00001959 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001960 ASSERT_TRUE(answer != NULL);
1961 VerifyFingerprintStatus(answer->description(), false);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001962 // Check that we don't have an a=crypto line in the answer.
1963 VerifyNoCryptoParams(answer->description(), false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001964
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001965 // Now set the local description, which should work, even without a=crypto.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001966 SetLocalDescriptionWithoutError(answer);
1967}
1968
1969TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001970 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001971 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001972 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001973 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001974 SetLocalDescriptionWithoutError(offer);
1975
1976 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001977 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001978 SetLocalDescriptionWithoutError(offer2);
1979}
1980
1981TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001982 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001983 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001984 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001985 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001986 SetRemoteDescriptionWithoutError(offer);
1987
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001988 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001989 SetRemoteDescriptionWithoutError(offer2);
1990}
1991
1992TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001993 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001994 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001995 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001996 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001997 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07001998 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
1999 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002000}
2001
2002TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002003 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002004 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002005 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002006 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002007 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002008 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07002009 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002010}
2011
2012TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002013 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002014 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002015 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002016 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002017
2018 JsepSessionDescription* pranswer = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002019 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002020 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07002021 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002022
deadbeefab9b2d12015-10-14 11:33:11 -07002023 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002024 JsepSessionDescription* pranswer2 = static_cast<JsepSessionDescription*>(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002025 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002026 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2027
deadbeefd59daf82015-10-14 15:02:44 -07002028 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002029
deadbeefab9b2d12015-10-14 11:33:11 -07002030 SendAudioVideoStream2();
wu@webrtc.org91053e72013-08-10 07:18:04 +00002031 SessionDescriptionInterface* answer = CreateAnswer(NULL);
deadbeefd59daf82015-10-14 15:02:44 -07002032 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002033}
2034
2035TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002036 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002037 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002038 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07002039 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002040
2041 JsepSessionDescription* pranswer =
2042 CreateRemoteAnswer(session_->local_description());
2043 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
2044
2045 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07002046 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002047
deadbeefab9b2d12015-10-14 11:33:11 -07002048 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002049 JsepSessionDescription* pranswer2 =
2050 CreateRemoteAnswer(session_->local_description());
2051 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
2052
2053 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07002054 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002055
deadbeefab9b2d12015-10-14 11:33:11 -07002056 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002057 SessionDescriptionInterface* answer =
2058 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07002059 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002060}
2061
2062TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002063 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002064 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002065 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2066
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002067 SessionDescriptionInterface* answer =
2068 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002069 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
2070 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002071}
2072
2073TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002074 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002075 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002076 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2077
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002078 SessionDescriptionInterface* answer =
2079 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002080 SetRemoteDescriptionAnswerExpectError(
2081 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002082}
2083
2084TEST_F(WebRtcSessionTest, TestAddRemoteCandidate) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002085 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002086 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002087
2088 cricket::Candidate candidate;
2089 candidate.set_component(1);
2090 JsepIceCandidate ice_candidate1(kMediaContentName0, 0, candidate);
2091
deadbeefd59daf82015-10-14 15:02:44 -07002092 // Fail since we have not set a remote description.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002093 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
2094
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002095 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002096 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002097
2098 // Fail since we have not set a remote description.
2099 EXPECT_FALSE(session_->ProcessIceMessage(&ice_candidate1));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002100
2101 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2102 session_->local_description());
2103 SetRemoteDescriptionWithoutError(answer);
2104
deadbeefd59daf82015-10-14 15:02:44 -07002105 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2106 candidate.set_component(2);
2107 JsepIceCandidate ice_candidate2(kMediaContentName0, 0, candidate);
2108 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2109
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002110 // Verifying the candidates are copied properly from internal vector.
2111 const SessionDescriptionInterface* remote_desc =
2112 session_->remote_description();
2113 ASSERT_TRUE(remote_desc != NULL);
2114 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2115 const IceCandidateCollection* candidates =
2116 remote_desc->candidates(kMediaContentIndex0);
2117 ASSERT_EQ(2u, candidates->count());
2118 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2119 EXPECT_EQ(kMediaContentName0, candidates->at(0)->sdp_mid());
2120 EXPECT_EQ(1, candidates->at(0)->candidate().component());
2121 EXPECT_EQ(2, candidates->at(1)->candidate().component());
2122
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002123 // |ice_candidate3| is identical to |ice_candidate2|. It can be added
2124 // successfully, but the total count of candidates will not increase.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002125 candidate.set_component(2);
2126 JsepIceCandidate ice_candidate3(kMediaContentName0, 0, candidate);
2127 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate3));
mallinath@webrtc.org67ee6b92014-02-03 16:57:16 +00002128 ASSERT_EQ(2u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002129
2130 JsepIceCandidate bad_ice_candidate("bad content name", 99, candidate);
2131 EXPECT_FALSE(session_->ProcessIceMessage(&bad_ice_candidate));
2132}
2133
2134// Test that a remote candidate is added to the remote session description and
2135// that it is retained if the remote session description is changed.
2136TEST_F(WebRtcSessionTest, TestRemoteCandidatesAddedToSessionDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002137 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002138 cricket::Candidate candidate1;
2139 candidate1.set_component(1);
2140 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2141 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002142 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002143 CreateAndSetRemoteOfferAndLocalAnswer();
2144
2145 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2146 const SessionDescriptionInterface* remote_desc =
2147 session_->remote_description();
2148 ASSERT_TRUE(remote_desc != NULL);
2149 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2150 const IceCandidateCollection* candidates =
2151 remote_desc->candidates(kMediaContentIndex0);
2152 ASSERT_EQ(1u, candidates->count());
2153 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2154
2155 // Update the RemoteSessionDescription with a new session description and
2156 // a candidate and check that the new remote session description contains both
2157 // candidates.
2158 SessionDescriptionInterface* offer = CreateRemoteOffer();
2159 cricket::Candidate candidate2;
2160 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2161 candidate2);
2162 EXPECT_TRUE(offer->AddCandidate(&ice_candidate2));
2163 SetRemoteDescriptionWithoutError(offer);
2164
2165 remote_desc = session_->remote_description();
2166 ASSERT_TRUE(remote_desc != NULL);
2167 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2168 candidates = remote_desc->candidates(kMediaContentIndex0);
2169 ASSERT_EQ(2u, candidates->count());
2170 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2171 // Username and password have be updated with the TransportInfo of the
2172 // SessionDescription, won't be equal to the original one.
2173 candidate2.set_username(candidates->at(0)->candidate().username());
2174 candidate2.set_password(candidates->at(0)->candidate().password());
2175 EXPECT_TRUE(candidate2.IsEquivalent(candidates->at(0)->candidate()));
2176 EXPECT_EQ(kMediaContentIndex0, candidates->at(1)->sdp_mline_index());
2177 // No need to verify the username and password.
2178 candidate1.set_username(candidates->at(1)->candidate().username());
2179 candidate1.set_password(candidates->at(1)->candidate().password());
2180 EXPECT_TRUE(candidate1.IsEquivalent(candidates->at(1)->candidate()));
2181
2182 // Test that the candidate is ignored if we can add the same candidate again.
2183 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2184}
2185
2186// Test that local candidates are added to the local session description and
2187// that they are retained if the local session description is changed.
2188TEST_F(WebRtcSessionTest, TestLocalCandidatesAddedToSessionDescription) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002189 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002190 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002191 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002192 CreateAndSetRemoteOfferAndLocalAnswer();
2193
2194 const SessionDescriptionInterface* local_desc = session_->local_description();
2195 const IceCandidateCollection* candidates =
2196 local_desc->candidates(kMediaContentIndex0);
2197 ASSERT_TRUE(candidates != NULL);
2198 EXPECT_EQ(0u, candidates->count());
2199
2200 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
2201
2202 local_desc = session_->local_description();
2203 candidates = local_desc->candidates(kMediaContentIndex0);
2204 ASSERT_TRUE(candidates != NULL);
2205 EXPECT_LT(0u, candidates->count());
2206 candidates = local_desc->candidates(1);
2207 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002208 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002209
2210 // Update the session descriptions.
deadbeefab9b2d12015-10-14 11:33:11 -07002211 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002212 CreateAndSetRemoteOfferAndLocalAnswer();
2213
2214 local_desc = session_->local_description();
2215 candidates = local_desc->candidates(kMediaContentIndex0);
2216 ASSERT_TRUE(candidates != NULL);
2217 EXPECT_LT(0u, candidates->count());
2218 candidates = local_desc->candidates(1);
2219 ASSERT_TRUE(candidates != NULL);
deadbeefcbecd352015-09-23 11:50:27 -07002220 EXPECT_EQ(0u, candidates->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002221}
2222
2223// Test that we can set a remote session description with remote candidates.
2224TEST_F(WebRtcSessionTest, TestSetRemoteSessionDescriptionWithCandidates) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002225 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002226
2227 cricket::Candidate candidate1;
2228 candidate1.set_component(1);
2229 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
2230 candidate1);
deadbeefab9b2d12015-10-14 11:33:11 -07002231 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002232 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002233
2234 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
2235 SetRemoteDescriptionWithoutError(offer);
2236
2237 const SessionDescriptionInterface* remote_desc =
2238 session_->remote_description();
2239 ASSERT_TRUE(remote_desc != NULL);
2240 ASSERT_EQ(2u, remote_desc->number_of_mediasections());
2241 const IceCandidateCollection* candidates =
2242 remote_desc->candidates(kMediaContentIndex0);
2243 ASSERT_EQ(1u, candidates->count());
2244 EXPECT_EQ(kMediaContentIndex0, candidates->at(0)->sdp_mline_index());
2245
wu@webrtc.org91053e72013-08-10 07:18:04 +00002246 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002247 SetLocalDescriptionWithoutError(answer);
2248}
2249
2250// Test that offers and answers contains ice candidates when Ice candidates have
2251// been gathered.
2252TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteDescriptionWithCandidates) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002253 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002254 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002255 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002256 // Ice is started but candidates are not provided until SetLocalDescription
2257 // is called.
2258 EXPECT_EQ(0u, observer_.mline_0_candidates_.size());
2259 EXPECT_EQ(0u, observer_.mline_1_candidates_.size());
2260 CreateAndSetRemoteOfferAndLocalAnswer();
2261 // Wait until at least one local candidate has been collected.
2262 EXPECT_TRUE_WAIT(0u < observer_.mline_0_candidates_.size(),
2263 kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002264
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002265 rtc::scoped_ptr<SessionDescriptionInterface> local_offer(CreateOffer());
2266
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002267 ASSERT_TRUE(local_offer->candidates(kMediaContentIndex0) != NULL);
2268 EXPECT_LT(0u, local_offer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002269
2270 SessionDescriptionInterface* remote_offer(CreateRemoteOffer());
2271 SetRemoteDescriptionWithoutError(remote_offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002272 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002273 ASSERT_TRUE(answer->candidates(kMediaContentIndex0) != NULL);
2274 EXPECT_LT(0u, answer->candidates(kMediaContentIndex0)->count());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002275 SetLocalDescriptionWithoutError(answer);
2276}
2277
2278// Verifies TransportProxy and media channels are created with content names
2279// present in the SessionDescription.
2280TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002281 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002282 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002283 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002284
2285 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07002286 // "video". Goal is to modify these content names and verify transport
2287 // channels
2288 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002289 // present in SDP.
2290 std::string sdp;
2291 EXPECT_TRUE(offer->ToString(&sdp));
2292 const std::string kAudioMid = "a=mid:audio";
2293 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
2294 const std::string kVideoMid = "a=mid:video";
2295 const std::string kVideoMidReplaceStr = "a=mid:video_content_name";
2296
2297 // Replacing |audio| with |audio_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002298 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002299 kAudioMidReplaceStr.c_str(),
2300 kAudioMidReplaceStr.length(),
2301 &sdp);
2302 // Replacing |video| with |video_content_name|.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002303 rtc::replace_substrs(kVideoMid.c_str(), kVideoMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002304 kVideoMidReplaceStr.c_str(),
2305 kVideoMidReplaceStr.length(),
2306 &sdp);
2307
2308 SessionDescriptionInterface* modified_offer =
2309 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2310
2311 SetRemoteDescriptionWithoutError(modified_offer);
2312
2313 SessionDescriptionInterface* answer =
wu@webrtc.org91053e72013-08-10 07:18:04 +00002314 CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002315 SetLocalDescriptionWithoutError(answer);
2316
deadbeefcbecd352015-09-23 11:50:27 -07002317 cricket::TransportChannel* voice_transport_channel =
2318 session_->voice_rtp_transport_channel();
2319 EXPECT_TRUE(voice_transport_channel != NULL);
2320 EXPECT_EQ(voice_transport_channel->transport_name(), "audio_content_name");
2321 cricket::TransportChannel* video_transport_channel =
2322 session_->video_rtp_transport_channel();
2323 EXPECT_TRUE(video_transport_channel != NULL);
2324 EXPECT_EQ(video_transport_channel->transport_name(), "video_content_name");
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002325 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
2326 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
2327}
2328
2329// Test that an offer contains the correct media content descriptions based on
2330// the send streams when no constraints have been set.
2331TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002332 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002333 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2334
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002335 ASSERT_TRUE(offer != NULL);
2336 const cricket::ContentInfo* content =
2337 cricket::GetFirstAudioContent(offer->description());
2338 EXPECT_TRUE(content != NULL);
2339 content = cricket::GetFirstVideoContent(offer->description());
2340 EXPECT_TRUE(content == NULL);
2341}
2342
2343// Test that an offer contains the correct media content descriptions based on
2344// the send streams when no constraints have been set.
2345TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002346 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002347 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002348 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002349 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2350
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002351 const cricket::ContentInfo* content =
2352 cricket::GetFirstAudioContent(offer->description());
2353 EXPECT_TRUE(content != NULL);
2354 content = cricket::GetFirstVideoContent(offer->description());
2355 EXPECT_TRUE(content == NULL);
2356
2357 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07002358 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002359 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002360 content = cricket::GetFirstAudioContent(offer->description());
2361 EXPECT_TRUE(content != NULL);
2362 content = cricket::GetFirstVideoContent(offer->description());
2363 EXPECT_TRUE(content != NULL);
2364}
2365
2366// Test that an offer contains no media content descriptions if
2367// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
2368TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002369 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002370 PeerConnectionInterface::RTCOfferAnswerOptions options;
2371 options.offer_to_receive_audio = 0;
2372 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002373
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002374 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002375 CreateOffer(options));
2376
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002377 ASSERT_TRUE(offer != NULL);
2378 const cricket::ContentInfo* content =
2379 cricket::GetFirstAudioContent(offer->description());
2380 EXPECT_TRUE(content == NULL);
2381 content = cricket::GetFirstVideoContent(offer->description());
2382 EXPECT_TRUE(content == NULL);
2383}
2384
2385// Test that an offer contains only audio media content descriptions if
2386// kOfferToReceiveAudio constraints are set to true.
2387TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002388 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002389 PeerConnectionInterface::RTCOfferAnswerOptions options;
2390 options.offer_to_receive_audio =
2391 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2392
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002393 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002394 CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002395
2396 const cricket::ContentInfo* content =
2397 cricket::GetFirstAudioContent(offer->description());
2398 EXPECT_TRUE(content != NULL);
2399 content = cricket::GetFirstVideoContent(offer->description());
2400 EXPECT_TRUE(content == NULL);
2401}
2402
2403// Test that an offer contains audio and video media content descriptions if
2404// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
2405TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002406 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002407 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002408 PeerConnectionInterface::RTCOfferAnswerOptions options;
2409 options.offer_to_receive_audio =
2410 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2411 options.offer_to_receive_video =
2412 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2413
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002414 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002415 CreateOffer(options));
2416
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002417 const cricket::ContentInfo* content =
2418 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00002419 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002420
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002421 content = cricket::GetFirstVideoContent(offer->description());
2422 EXPECT_TRUE(content != NULL);
2423
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002424 // Sets constraints to false and verifies that audio/video contents are
2425 // removed.
2426 options.offer_to_receive_audio = 0;
2427 options.offer_to_receive_video = 0;
2428 offer.reset(CreateOffer(options));
2429
2430 content = cricket::GetFirstAudioContent(offer->description());
2431 EXPECT_TRUE(content == NULL);
2432 content = cricket::GetFirstVideoContent(offer->description());
2433 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002434}
2435
2436// Test that an answer can not be created if the last remote description is not
2437// an offer.
2438TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002439 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002440 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002441 SetLocalDescriptionWithoutError(offer);
2442 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2443 SetRemoteDescriptionWithoutError(answer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00002444 EXPECT_TRUE(CreateAnswer(NULL) == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002445}
2446
2447// Test that an answer contains the correct media content descriptions when no
2448// constraints have been set.
2449TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002450 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002451 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002452 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002453 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002454 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002455 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002456 const cricket::ContentInfo* content =
2457 cricket::GetFirstAudioContent(answer->description());
2458 ASSERT_TRUE(content != NULL);
2459 EXPECT_FALSE(content->rejected);
2460
2461 content = cricket::GetFirstVideoContent(answer->description());
2462 ASSERT_TRUE(content != NULL);
2463 EXPECT_FALSE(content->rejected);
2464}
2465
2466// Test that an answer contains the correct media content descriptions when no
2467// constraints have been set and the offer only contain audio.
2468TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002469 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002470 // Create a remote offer with audio only.
2471 cricket::MediaSessionOptions options;
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00002472
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002473 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002474 CreateRemoteOffer(options));
2475 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
2476 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
2477
2478 SetRemoteDescriptionWithoutError(offer.release());
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002479 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002480 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002481 const cricket::ContentInfo* content =
2482 cricket::GetFirstAudioContent(answer->description());
2483 ASSERT_TRUE(content != NULL);
2484 EXPECT_FALSE(content->rejected);
2485
2486 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
2487}
2488
2489// Test that an answer contains the correct media content descriptions when no
2490// constraints have been set.
2491TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002492 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002493 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002494 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002495 SetRemoteDescriptionWithoutError(offer.release());
2496 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002497 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002498 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002499 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002500 const cricket::ContentInfo* content =
2501 cricket::GetFirstAudioContent(answer->description());
2502 ASSERT_TRUE(content != NULL);
2503 EXPECT_FALSE(content->rejected);
2504
2505 content = cricket::GetFirstVideoContent(answer->description());
2506 ASSERT_TRUE(content != NULL);
2507 EXPECT_FALSE(content->rejected);
2508}
2509
2510// Test that an answer contains the correct media content descriptions when
2511// constraints have been set but no stream is sent.
2512TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002513 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002514 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002515 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002516 SetRemoteDescriptionWithoutError(offer.release());
2517
2518 webrtc::FakeConstraints constraints_no_receive;
2519 constraints_no_receive.SetMandatoryReceiveAudio(false);
2520 constraints_no_receive.SetMandatoryReceiveVideo(false);
2521
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002522 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002523 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002524 const cricket::ContentInfo* content =
2525 cricket::GetFirstAudioContent(answer->description());
2526 ASSERT_TRUE(content != NULL);
2527 EXPECT_TRUE(content->rejected);
2528
2529 content = cricket::GetFirstVideoContent(answer->description());
2530 ASSERT_TRUE(content != NULL);
2531 EXPECT_TRUE(content->rejected);
2532}
2533
2534// Test that an answer contains the correct media content descriptions when
2535// constraints have been set and streams are sent.
2536TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002537 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002538 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002539 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002540 SetRemoteDescriptionWithoutError(offer.release());
2541
2542 webrtc::FakeConstraints constraints_no_receive;
2543 constraints_no_receive.SetMandatoryReceiveAudio(false);
2544 constraints_no_receive.SetMandatoryReceiveVideo(false);
2545
2546 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07002547 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002548 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002549 CreateAnswer(&constraints_no_receive));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002550
2551 // TODO(perkj): Should the direction be set to SEND_ONLY?
2552 const cricket::ContentInfo* content =
2553 cricket::GetFirstAudioContent(answer->description());
2554 ASSERT_TRUE(content != NULL);
2555 EXPECT_FALSE(content->rejected);
2556
2557 // TODO(perkj): Should the direction be set to SEND_ONLY?
2558 content = cricket::GetFirstVideoContent(answer->description());
2559 ASSERT_TRUE(content != NULL);
2560 EXPECT_FALSE(content->rejected);
2561}
2562
2563TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
2564 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002565 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002566 PeerConnectionInterface::RTCOfferAnswerOptions options;
2567 options.offer_to_receive_audio =
2568 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
2569 options.voice_activity_detection = false;
2570
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002571 rtc::scoped_ptr<SessionDescriptionInterface> offer(
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002572 CreateOffer(options));
2573
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002574 const cricket::ContentInfo* content =
2575 cricket::GetFirstAudioContent(offer->description());
2576 EXPECT_TRUE(content != NULL);
2577 EXPECT_TRUE(VerifyNoCNCodecs(content));
2578}
2579
2580TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
2581 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002582 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002583 // Create a remote offer with audio and video content.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002584 rtc::scoped_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002585 SetRemoteDescriptionWithoutError(offer.release());
2586
2587 webrtc::FakeConstraints constraints;
2588 constraints.SetOptionalVAD(false);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002589 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00002590 CreateAnswer(&constraints));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002591 const cricket::ContentInfo* content =
2592 cricket::GetFirstAudioContent(answer->description());
2593 ASSERT_TRUE(content != NULL);
2594 EXPECT_TRUE(VerifyNoCNCodecs(content));
2595}
2596
2597// This test verifies the call setup when remote answer with audio only and
2598// later updates with video.
2599TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002600 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002601 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2602 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
2603
deadbeefab9b2d12015-10-14 11:33:11 -07002604 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002605 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002606
2607 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002608 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
2609
2610 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2611 // and answer;
2612 SetLocalDescriptionWithoutError(offer);
2613 SetRemoteDescriptionWithoutError(answer);
2614
2615 video_channel_ = media_engine_->GetVideoChannel(0);
2616 voice_channel_ = media_engine_->GetVoiceChannel(0);
2617
2618 ASSERT_TRUE(video_channel_ == NULL);
2619
2620 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
2621 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2622 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
2623
2624 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002625 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002626 CreateAndSetRemoteOfferAndLocalAnswer();
2627
2628 video_channel_ = media_engine_->GetVideoChannel(0);
2629 voice_channel_ = media_engine_->GetVoiceChannel(0);
2630
2631 ASSERT_TRUE(video_channel_ != NULL);
2632 ASSERT_TRUE(voice_channel_ != NULL);
2633
2634 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2635 ASSERT_EQ(1u, video_channel_->send_streams().size());
2636 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2637 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2638 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2639 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2640 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2641 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2642
2643 // Change session back to audio only.
deadbeefab9b2d12015-10-14 11:33:11 -07002644 SendAudioOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002645 CreateAndSetRemoteOfferAndLocalAnswer();
2646
2647 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2648 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2649 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2650 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2651 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2652}
2653
2654// This test verifies the call setup when remote answer with video only and
2655// later updates with audio.
2656TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002657 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002658 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
2659 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07002660 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002661 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002662
2663 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00002664 options.recv_audio = false;
2665 options.recv_video = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002666 SessionDescriptionInterface* answer = CreateRemoteAnswer(
2667 offer, options, cricket::SEC_ENABLED);
2668
2669 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
2670 // and answer.
2671 SetLocalDescriptionWithoutError(offer);
2672 SetRemoteDescriptionWithoutError(answer);
2673
2674 video_channel_ = media_engine_->GetVideoChannel(0);
2675 voice_channel_ = media_engine_->GetVoiceChannel(0);
2676
2677 ASSERT_TRUE(voice_channel_ == NULL);
2678 ASSERT_TRUE(video_channel_ != NULL);
2679
2680 EXPECT_EQ(0u, video_channel_->recv_streams().size());
2681 ASSERT_EQ(1u, video_channel_->send_streams().size());
2682 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
2683
2684 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07002685 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002686 CreateAndSetRemoteOfferAndLocalAnswer();
2687
2688 voice_channel_ = media_engine_->GetVoiceChannel(0);
2689 ASSERT_TRUE(voice_channel_ != NULL);
2690
2691 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
2692 ASSERT_EQ(1u, voice_channel_->send_streams().size());
2693 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
2694 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
2695
2696 // Change session back to video only.
deadbeefab9b2d12015-10-14 11:33:11 -07002697 SendVideoOnlyStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002698 CreateAndSetRemoteOfferAndLocalAnswer();
2699
2700 video_channel_ = media_engine_->GetVideoChannel(0);
2701 voice_channel_ = media_engine_->GetVoiceChannel(0);
2702
2703 ASSERT_EQ(1u, video_channel_->recv_streams().size());
2704 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
2705 ASSERT_EQ(1u, video_channel_->send_streams().size());
2706 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
2707}
2708
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002709TEST_F(WebRtcSessionTest, VerifyCryptoParamsInSDP) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002710 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002711 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002712 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002713 VerifyCryptoParams(offer->description());
2714 SetRemoteDescriptionWithoutError(offer.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00002715 scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002716 VerifyCryptoParams(answer->description());
2717}
2718
2719TEST_F(WebRtcSessionTest, VerifyNoCryptoParamsInSDP) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002720 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002721 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002722 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002723 scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002724 VerifyNoCryptoParams(offer->description(), false);
2725}
2726
2727TEST_F(WebRtcSessionTest, VerifyAnswerFromNonCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002728 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002729 VerifyAnswerFromNonCryptoOffer();
2730}
2731
2732TEST_F(WebRtcSessionTest, VerifyAnswerFromCryptoOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002733 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002734 VerifyAnswerFromCryptoOffer();
2735}
2736
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002737// This test verifies that setLocalDescription fails if
2738// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2739TEST_F(WebRtcSessionTest, TestSetLocalDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002740 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002741 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002742 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2743
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002744 std::string sdp;
2745 RemoveIceUfragPwdLines(offer.get(), &sdp);
2746 SessionDescriptionInterface* modified_offer =
2747 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002748 SetLocalDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002749}
2750
2751// This test verifies that setRemoteDescription fails if
2752// no a=ice-ufrag and a=ice-pwd lines are present in the SDP.
2753TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionWithoutIce) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002754 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002755 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002756 std::string sdp;
2757 RemoveIceUfragPwdLines(offer.get(), &sdp);
2758 SessionDescriptionInterface* modified_offer =
2759 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002760 SetRemoteDescriptionOfferExpectError(kSdpWithoutIceUfragPwd, modified_offer);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002761}
2762
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002763// This test verifies that setLocalDescription fails if local offer has
2764// too short ice ufrag and pwd strings.
2765TEST_F(WebRtcSessionTest, TestSetLocalDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002766 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002767 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002768 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
2769
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002770 std::string sdp;
2771 // Modifying ice ufrag and pwd in local offer with strings smaller than the
2772 // recommended values of 4 and 22 bytes respectively.
2773 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2774 SessionDescriptionInterface* modified_offer =
2775 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2776 std::string error;
2777 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2778
2779 // Test with string greater than 256.
2780 sdp.clear();
2781 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2782 &sdp);
2783 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2784 NULL);
2785 EXPECT_FALSE(session_->SetLocalDescription(modified_offer, &error));
2786}
2787
2788// This test verifies that setRemoteDescription fails if remote offer has
2789// too short ice ufrag and pwd strings.
2790TEST_F(WebRtcSessionTest, TestSetRemoteDescriptionInvalidIceCredentials) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002791 Init();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002792 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
buildbot@webrtc.org7aa1a472014-05-23 17:33:05 +00002793 std::string sdp;
2794 // Modifying ice ufrag and pwd in remote offer with strings smaller than the
2795 // recommended values of 4 and 22 bytes respectively.
2796 ModifyIceUfragPwdLines(offer.get(), "ice", "icepwd", &sdp);
2797 SessionDescriptionInterface* modified_offer =
2798 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2799 std::string error;
2800 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2801
2802 sdp.clear();
2803 ModifyIceUfragPwdLines(offer.get(), kTooLongIceUfragPwd, kTooLongIceUfragPwd,
2804 &sdp);
2805 modified_offer = CreateSessionDescription(JsepSessionDescription::kOffer, sdp,
2806 NULL);
2807 EXPECT_FALSE(session_->SetRemoteDescription(modified_offer, &error));
2808}
2809
Honghai Zhang04e91462015-12-11 14:26:22 -08002810// Test that if the remote offer indicates the peer requested ICE restart (via
2811// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2812TEST_F(WebRtcSessionTest, TestSetRemoteOfferWithIceRestart) {
honghaiz503726c2015-07-31 12:37:38 -07002813 Init();
2814 scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
2815
2816 // Create the first offer.
2817 std::string sdp;
2818 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2819 "abcdefghijklmnopqrstuvwx", &sdp);
2820 SessionDescriptionInterface* offer1 =
2821 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2822 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2823 0, "", "", "relay", 0, "");
2824 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2825 candidate1);
2826 EXPECT_TRUE(offer1->AddCandidate(&ice_candidate1));
2827 SetRemoteDescriptionWithoutError(offer1);
2828 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2829
2830 // The second offer has the same ufrag and pwd but different address.
2831 sdp.clear();
2832 ModifyIceUfragPwdLines(offer.get(), "0123456789012345",
2833 "abcdefghijklmnopqrstuvwx", &sdp);
2834 SessionDescriptionInterface* offer2 =
2835 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2836 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2837 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2838 candidate1);
2839 EXPECT_TRUE(offer2->AddCandidate(&ice_candidate2));
2840 SetRemoteDescriptionWithoutError(offer2);
2841 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2842
2843 // The third offer has a different ufrag and different address.
2844 sdp.clear();
2845 ModifyIceUfragPwdLines(offer.get(), "0123456789012333",
2846 "abcdefghijklmnopqrstuvwx", &sdp);
2847 SessionDescriptionInterface* offer3 =
2848 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2849 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2850 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2851 candidate1);
2852 EXPECT_TRUE(offer3->AddCandidate(&ice_candidate3));
2853 SetRemoteDescriptionWithoutError(offer3);
2854 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2855
2856 // The fourth offer has no candidate but a different ufrag/pwd.
2857 sdp.clear();
2858 ModifyIceUfragPwdLines(offer.get(), "0123456789012444",
2859 "abcdefghijklmnopqrstuvyz", &sdp);
2860 SessionDescriptionInterface* offer4 =
2861 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
2862 SetRemoteDescriptionWithoutError(offer4);
2863 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2864}
2865
Honghai Zhang04e91462015-12-11 14:26:22 -08002866// Test that if the remote answer indicates the peer requested ICE restart (via
2867// a new ufrag or pwd), the old ICE candidates are not copied, and vice versa.
2868TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithIceRestart) {
2869 Init();
2870 SessionDescriptionInterface* offer = CreateOffer();
2871 SetLocalDescriptionWithoutError(offer);
2872 scoped_ptr<SessionDescriptionInterface> answer(CreateRemoteAnswer(offer));
2873
2874 // Create the first answer.
2875 std::string sdp;
2876 ModifyIceUfragPwdLines(answer.get(), "0123456789012345",
2877 "abcdefghijklmnopqrstuvwx", &sdp);
2878 SessionDescriptionInterface* answer1 =
2879 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2880 cricket::Candidate candidate1(1, "udp", rtc::SocketAddress("1.1.1.1", 5000),
2881 0, "", "", "relay", 0, "");
2882 JsepIceCandidate ice_candidate1(kMediaContentName0, kMediaContentIndex0,
2883 candidate1);
2884 EXPECT_TRUE(answer1->AddCandidate(&ice_candidate1));
2885 SetRemoteDescriptionWithoutError(answer1);
2886 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2887
2888 // The second answer has the same ufrag and pwd but different address.
2889 sdp.clear();
2890 ModifyIceUfragPwdLines(answer.get(), "0123456789012345",
2891 "abcdefghijklmnopqrstuvwx", &sdp);
2892 SessionDescriptionInterface* answer2 =
2893 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2894 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2895 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2896 candidate1);
2897 EXPECT_TRUE(answer2->AddCandidate(&ice_candidate2));
2898 SetRemoteDescriptionWithoutError(answer2);
2899 EXPECT_EQ(2, session_->remote_description()->candidates(0)->count());
2900
2901 // The third answer has a different ufrag and different address.
2902 sdp.clear();
2903 ModifyIceUfragPwdLines(answer.get(), "0123456789012333",
2904 "abcdefghijklmnopqrstuvwx", &sdp);
2905 SessionDescriptionInterface* answer3 =
2906 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2907 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 7000));
2908 JsepIceCandidate ice_candidate3(kMediaContentName0, kMediaContentIndex0,
2909 candidate1);
2910 EXPECT_TRUE(answer3->AddCandidate(&ice_candidate3));
2911 SetRemoteDescriptionWithoutError(answer3);
2912 EXPECT_EQ(1, session_->remote_description()->candidates(0)->count());
2913
2914 // The fourth answer has no candidate but a different ufrag/pwd.
2915 sdp.clear();
2916 ModifyIceUfragPwdLines(answer.get(), "0123456789012444",
2917 "abcdefghijklmnopqrstuvyz", &sdp);
2918 SessionDescriptionInterface* offer4 =
2919 CreateSessionDescription(JsepSessionDescription::kPrAnswer, sdp, NULL);
2920 SetRemoteDescriptionWithoutError(offer4);
2921 EXPECT_EQ(0, session_->remote_description()->candidates(0)->count());
2922}
2923
Donald Curtisd4f769d2015-05-28 09:48:21 -07002924// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002925// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002926TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2927 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2928
2929 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002930 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002931
2932 PeerConnectionInterface::RTCOfferAnswerOptions options;
2933 options.use_rtp_mux = true;
2934
2935 SessionDescriptionInterface* offer = CreateRemoteOffer();
2936 SetRemoteDescriptionWithoutError(offer);
2937
2938 SessionDescriptionInterface* answer = CreateAnswer(NULL);
2939 SetLocalDescriptionWithoutError(answer);
2940
deadbeefcbecd352015-09-23 11:50:27 -07002941 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2942 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002943
deadbeefcbecd352015-09-23 11:50:27 -07002944 cricket::BaseChannel* voice_channel = session_->voice_channel();
2945 ASSERT(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002946
2947 // Checks if one of the transport channels contains a connection using a given
2948 // port.
deadbeefcbecd352015-09-23 11:50:27 -07002949 auto connection_with_remote_port = [this, voice_channel](int port) {
deadbeefd59daf82015-10-14 15:02:44 -07002950 SessionStats stats;
deadbeefcbecd352015-09-23 11:50:27 -07002951 session_->GetChannelTransportStats(voice_channel, &stats);
2952 for (auto& kv : stats.transport_stats) {
2953 for (auto& chan_stat : kv.second.channel_stats) {
2954 for (auto& conn_info : chan_stat.connection_infos) {
2955 if (conn_info.remote_candidate.address().port() == port) {
2956 return true;
2957 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002958 }
2959 }
2960 }
2961 return false;
2962 };
2963
2964 EXPECT_FALSE(connection_with_remote_port(5000));
2965 EXPECT_FALSE(connection_with_remote_port(5001));
2966 EXPECT_FALSE(connection_with_remote_port(6000));
2967
2968 // The way the *_WAIT checks work is they only wait if the condition fails,
2969 // which does not help in the case where state is not changing. This is
2970 // problematic in this test since we want to verify that adding a video
2971 // candidate does _not_ change state. So we interleave candidates and assume
2972 // that messages are executed in the order they were posted.
2973
2974 // First audio candidate.
2975 cricket::Candidate candidate0;
2976 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2977 candidate0.set_component(1);
2978 candidate0.set_protocol("udp");
2979 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2980 candidate0);
2981 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2982
2983 // Video candidate.
2984 cricket::Candidate candidate1;
2985 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2986 candidate1.set_component(1);
2987 candidate1.set_protocol("udp");
2988 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2989 candidate1);
2990 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2991
2992 // Second audio candidate.
2993 cricket::Candidate candidate2;
2994 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
2995 candidate2.set_component(1);
2996 candidate2.set_protocol("udp");
2997 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2998 candidate2);
2999 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
3000
3001 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
3002 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
3003
3004 // No need here for a _WAIT check since we are checking that state hasn't
3005 // changed: if this is false we would be doing waits for nothing and if this
3006 // is true then there will be no messages processed anyways.
3007 EXPECT_FALSE(connection_with_remote_port(6000));
3008}
3009
deadbeefcbecd352015-09-23 11:50:27 -07003010// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003011TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
3012 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003013 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003014
3015 PeerConnectionInterface::RTCOfferAnswerOptions options;
3016 options.use_rtp_mux = true;
3017
3018 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003019 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003020
deadbeefcbecd352015-09-23 11:50:27 -07003021 EXPECT_NE(session_->voice_rtp_transport_channel(),
3022 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003023
deadbeefab9b2d12015-10-14 11:33:11 -07003024 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003025 SessionDescriptionInterface* answer =
3026 CreateRemoteAnswer(session_->local_description());
3027 SetRemoteDescriptionWithoutError(answer);
3028
deadbeefcbecd352015-09-23 11:50:27 -07003029 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3030 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003031}
3032
deadbeefcbecd352015-09-23 11:50:27 -07003033// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003034TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
3035 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07003036 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003037
Donald Curtis0e209b02015-03-24 09:29:54 -07003038 PeerConnectionInterface::RTCOfferAnswerOptions options;
3039 options.use_rtp_mux = true;
3040
3041 SessionDescriptionInterface* offer = CreateOffer(options);
3042 SetLocalDescriptionWithoutError(offer);
3043
deadbeefcbecd352015-09-23 11:50:27 -07003044 EXPECT_NE(session_->voice_rtp_transport_channel(),
3045 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003046
deadbeefab9b2d12015-10-14 11:33:11 -07003047 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003048
3049 // Remove BUNDLE from the answer.
3050 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3051 CreateRemoteAnswer(session_->local_description()));
3052 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3053 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3054 JsepSessionDescription* modified_answer =
3055 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3056 modified_answer->Initialize(answer_copy, "1", "1");
3057 SetRemoteDescriptionWithoutError(modified_answer); //
3058
deadbeefcbecd352015-09-23 11:50:27 -07003059 EXPECT_NE(session_->voice_rtp_transport_channel(),
3060 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003061}
3062
3063// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
3064TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
3065 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003066 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003067
3068 PeerConnectionInterface::RTCOfferAnswerOptions options;
3069 options.use_rtp_mux = true;
3070
3071 SessionDescriptionInterface* offer = CreateOffer(options);
3072 SetLocalDescriptionWithoutError(offer);
3073
deadbeefcbecd352015-09-23 11:50:27 -07003074 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3075 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003076
deadbeefab9b2d12015-10-14 11:33:11 -07003077 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003078 SessionDescriptionInterface* answer =
3079 CreateRemoteAnswer(session_->local_description());
3080 SetRemoteDescriptionWithoutError(answer);
3081
deadbeefcbecd352015-09-23 11:50:27 -07003082 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3083 session_->video_rtp_transport_channel());
3084}
3085
3086// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
3087// audio content in the answer.
3088TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
3089 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003090 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003091
3092 PeerConnectionInterface::RTCOfferAnswerOptions options;
3093 options.use_rtp_mux = true;
3094
3095 SessionDescriptionInterface* offer = CreateOffer(options);
3096 SetLocalDescriptionWithoutError(offer);
3097
3098 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3099 session_->video_rtp_transport_channel());
3100
deadbeefab9b2d12015-10-14 11:33:11 -07003101 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003102 cricket::MediaSessionOptions recv_options;
3103 recv_options.recv_audio = false;
3104 recv_options.recv_video = true;
3105 SessionDescriptionInterface* answer =
3106 CreateRemoteAnswer(session_->local_description(), recv_options);
3107 SetRemoteDescriptionWithoutError(answer);
3108
deadbeefd59daf82015-10-14 15:02:44 -07003109 EXPECT_TRUE(nullptr == session_->voice_channel());
3110 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07003111
deadbeefd59daf82015-10-14 15:02:44 -07003112 session_->Close();
3113 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
3114 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
3115 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
3116 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003117}
3118
3119// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
3120TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
3121 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003122 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003123
Donald Curtis0e209b02015-03-24 09:29:54 -07003124 PeerConnectionInterface::RTCOfferAnswerOptions options;
3125 options.use_rtp_mux = true;
3126
3127 SessionDescriptionInterface* offer = CreateOffer(options);
3128 SetLocalDescriptionWithoutError(offer);
3129
deadbeefcbecd352015-09-23 11:50:27 -07003130 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3131 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003132
deadbeefab9b2d12015-10-14 11:33:11 -07003133 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003134
3135 // Remove BUNDLE from the answer.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003136 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003137 CreateRemoteAnswer(session_->local_description()));
3138 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3139 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3140 JsepSessionDescription* modified_answer =
3141 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3142 modified_answer->Initialize(answer_copy, "1", "1");
3143 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003144
deadbeefcbecd352015-09-23 11:50:27 -07003145 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3146 session_->video_rtp_transport_channel());
3147}
3148
3149// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
3150TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
3151 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003152 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003153
3154 SessionDescriptionInterface* offer = CreateRemoteOffer();
3155 SetRemoteDescriptionWithoutError(offer);
3156
3157 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3158 session_->video_rtp_transport_channel());
3159
deadbeefab9b2d12015-10-14 11:33:11 -07003160 SendAudioVideoStream2();
deadbeefcbecd352015-09-23 11:50:27 -07003161 SessionDescriptionInterface* answer = CreateAnswer(nullptr);
3162 SetLocalDescriptionWithoutError(answer);
3163
3164 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3165 session_->video_rtp_transport_channel());
3166}
3167
3168// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
3169TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
3170 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003171 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07003172
3173 // Remove BUNDLE from the offer.
3174 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
3175 cricket::SessionDescription* offer_copy = offer->description()->Copy();
3176 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3177 JsepSessionDescription* modified_offer =
3178 new JsepSessionDescription(JsepSessionDescription::kOffer);
3179 modified_offer->Initialize(offer_copy, "1", "1");
3180
3181 // Expect an error when applying the remote description
3182 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
3183 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07003184}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003185
Peter Thatcher4eddf182015-04-30 10:55:59 -07003186// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07003187TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
3188 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003189 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003190
Donald Curtis0e209b02015-03-24 09:29:54 -07003191 PeerConnectionInterface::RTCOfferAnswerOptions options;
3192 options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003193
Donald Curtis0e209b02015-03-24 09:29:54 -07003194 SessionDescriptionInterface* offer = CreateOffer(options);
3195 SetLocalDescriptionWithoutError(offer);
3196
deadbeefcbecd352015-09-23 11:50:27 -07003197 EXPECT_NE(session_->voice_rtp_transport_channel(),
3198 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003199
deadbeefab9b2d12015-10-14 11:33:11 -07003200 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003201 SessionDescriptionInterface* answer =
3202 CreateRemoteAnswer(session_->local_description());
3203 SetRemoteDescriptionWithoutError(answer);
3204
3205 // This should lead to an audio-only call but isn't implemented
3206 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07003207 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3208 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003209}
3210
deadbeefcbecd352015-09-23 11:50:27 -07003211// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07003212TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
3213 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07003214 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07003215 PeerConnectionInterface::RTCOfferAnswerOptions options;
3216 options.use_rtp_mux = true;
3217
3218 SessionDescriptionInterface* offer = CreateOffer(options);
3219 SetLocalDescriptionWithoutError(offer);
3220
deadbeefcbecd352015-09-23 11:50:27 -07003221 EXPECT_NE(session_->voice_rtp_transport_channel(),
3222 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07003223
deadbeefab9b2d12015-10-14 11:33:11 -07003224 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07003225
3226 // Remove BUNDLE from the answer.
3227 rtc::scoped_ptr<SessionDescriptionInterface> answer(
3228 CreateRemoteAnswer(session_->local_description()));
3229 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3230 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
3231 JsepSessionDescription* modified_answer =
3232 new JsepSessionDescription(JsepSessionDescription::kAnswer);
3233 modified_answer->Initialize(answer_copy, "1", "1");
3234 SetRemoteDescriptionWithoutError(modified_answer); //
3235
deadbeefcbecd352015-09-23 11:50:27 -07003236 EXPECT_NE(session_->voice_rtp_transport_channel(),
3237 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003238}
3239
Peter Thatcher4eddf182015-04-30 10:55:59 -07003240// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
3241TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
3242 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07003243 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07003244
3245 PeerConnectionInterface::RTCOfferAnswerOptions options;
3246 options.use_rtp_mux = true;
3247
3248 SessionDescriptionInterface* offer = CreateOffer(options);
3249 SetRemoteDescriptionWithoutError(offer);
3250
deadbeefcbecd352015-09-23 11:50:27 -07003251 EXPECT_EQ(session_->voice_rtp_transport_channel(),
3252 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07003253}
3254
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003255TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
3256 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07003257 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003258
3259 PeerConnectionInterface::RTCOfferAnswerOptions options;
3260 SessionDescriptionInterface* offer = CreateOffer(options);
3261 SetLocalDescriptionWithoutError(offer);
3262
deadbeefcbecd352015-09-23 11:50:27 -07003263 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3264 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003265
deadbeefab9b2d12015-10-14 11:33:11 -07003266 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003267 SessionDescriptionInterface* answer =
3268 CreateRemoteAnswer(session_->local_description());
3269 SetRemoteDescriptionWithoutError(answer);
3270
deadbeefcbecd352015-09-23 11:50:27 -07003271 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3272 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003273}
3274
3275TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
3276 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07003277 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003278
3279 PeerConnectionInterface::RTCOfferAnswerOptions options;
3280 SessionDescriptionInterface* offer = CreateOffer(options);
3281 SetLocalDescriptionWithoutError(offer);
3282
deadbeefcbecd352015-09-23 11:50:27 -07003283 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
3284 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003285
deadbeefab9b2d12015-10-14 11:33:11 -07003286 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003287 SessionDescriptionInterface* answer =
3288 CreateRemoteAnswer(session_->local_description());
3289 SetRemoteDescriptionWithoutError(answer);
3290
deadbeefcbecd352015-09-23 11:50:27 -07003291 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
3292 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07003293}
3294
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003295// This test verifies that SetLocalDescription and SetRemoteDescription fails
3296// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
3297TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003298 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003299 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003300
3301 PeerConnectionInterface::RTCOfferAnswerOptions options;
3302 options.use_rtp_mux = true;
3303
3304 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003305 std::string offer_str;
3306 offer->ToString(&offer_str);
3307 // Disable rtcp-mux
3308 const std::string rtcp_mux = "rtcp-mux";
3309 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003310 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003311 xrtcp_mux.c_str(), xrtcp_mux.length(),
3312 &offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003313 JsepSessionDescription* local_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003314 new JsepSessionDescription(JsepSessionDescription::kOffer);
3315 EXPECT_TRUE((local_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003316 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
deadbeefcbecd352015-09-23 11:50:27 -07003317 JsepSessionDescription* remote_offer =
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003318 new JsepSessionDescription(JsepSessionDescription::kOffer);
3319 EXPECT_TRUE((remote_offer)->Initialize(offer_str, NULL));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003320 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003321 // Trying unmodified SDP.
3322 SetLocalDescriptionWithoutError(offer);
3323}
3324
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003325TEST_F(WebRtcSessionTest, SetAudioPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003326 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003327 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003328 CreateAndSetRemoteOfferAndLocalAnswer();
3329 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3330 ASSERT_TRUE(channel != NULL);
3331 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003332 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
solenberg4bac9c52015-10-09 02:32:53 -07003333 double volume;
3334 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3335 EXPECT_EQ(1, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003336 session_->SetAudioPlayout(receive_ssrc, false);
solenberg4bac9c52015-10-09 02:32:53 -07003337 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3338 EXPECT_EQ(0, volume);
solenbergd4cec0d2015-10-09 08:55:48 -07003339 session_->SetAudioPlayout(receive_ssrc, true);
solenberg4bac9c52015-10-09 02:32:53 -07003340 EXPECT_TRUE(channel->GetOutputVolume(receive_ssrc, &volume));
3341 EXPECT_EQ(1, volume);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003342}
3343
3344TEST_F(WebRtcSessionTest, SetAudioSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003345 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003346 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003347 CreateAndSetRemoteOfferAndLocalAnswer();
3348 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3349 ASSERT_TRUE(channel != NULL);
3350 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003351 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003352 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3353
3354 cricket::AudioOptions options;
Karl Wibergbe579832015-11-10 22:34:18 +01003355 options.echo_cancellation = rtc::Optional<bool>(true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003356
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003357 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003358 session_->SetAudioSend(send_ssrc, false, options, renderer.get());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003359 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003360 EXPECT_EQ(rtc::Optional<bool>(), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003361 EXPECT_TRUE(renderer->sink() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003362
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003363 // This will trigger SetSink(NULL) to the |renderer|.
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00003364 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003365 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
Karl Wibergbe579832015-11-10 22:34:18 +01003366 EXPECT_EQ(rtc::Optional<bool>(true), channel->options().echo_cancellation);
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003367 EXPECT_TRUE(renderer->sink() == NULL);
3368}
3369
3370TEST_F(WebRtcSessionTest, AudioRendererForLocalStream) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003371 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003372 SendAudioVideoStream1();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003373 CreateAndSetRemoteOfferAndLocalAnswer();
3374 cricket::FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3375 ASSERT_TRUE(channel != NULL);
3376 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003377 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003378
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003379 rtc::scoped_ptr<FakeAudioRenderer> renderer(new FakeAudioRenderer());
henrike@webrtc.orga7b98182014-02-21 15:51:43 +00003380 cricket::AudioOptions options;
3381 session_->SetAudioSend(send_ssrc, true, options, renderer.get());
3382 EXPECT_TRUE(renderer->sink() != NULL);
3383
3384 // Delete the |renderer| and it will trigger OnClose() to the sink, and this
3385 // will invalidate the |renderer_| pointer in the sink and prevent getting a
3386 // SetSink(NULL) callback afterwards.
3387 renderer.reset();
3388
3389 // This will trigger SetSink(NULL) if no OnClose() callback.
3390 session_->SetAudioSend(send_ssrc, true, options, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003391}
3392
3393TEST_F(WebRtcSessionTest, SetVideoPlayout) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003394 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003395 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003396 CreateAndSetRemoteOfferAndLocalAnswer();
3397 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3398 ASSERT_TRUE(channel != NULL);
3399 ASSERT_LT(0u, channel->renderers().size());
3400 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3401 ASSERT_EQ(1u, channel->recv_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003402 uint32_t receive_ssrc = channel->recv_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003403 cricket::FakeVideoRenderer renderer;
3404 session_->SetVideoPlayout(receive_ssrc, true, &renderer);
3405 EXPECT_TRUE(channel->renderers().begin()->second == &renderer);
3406 session_->SetVideoPlayout(receive_ssrc, false, &renderer);
3407 EXPECT_TRUE(channel->renderers().begin()->second == NULL);
3408}
3409
3410TEST_F(WebRtcSessionTest, SetVideoSend) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003411 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003412 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003413 CreateAndSetRemoteOfferAndLocalAnswer();
3414 cricket::FakeVideoMediaChannel* channel = media_engine_->GetVideoChannel(0);
3415 ASSERT_TRUE(channel != NULL);
3416 ASSERT_EQ(1u, channel->send_streams().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003417 uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003418 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3419 cricket::VideoOptions* options = NULL;
3420 session_->SetVideoSend(send_ssrc, false, options);
3421 EXPECT_TRUE(channel->IsStreamMuted(send_ssrc));
3422 session_->SetVideoSend(send_ssrc, true, options);
3423 EXPECT_FALSE(channel->IsStreamMuted(send_ssrc));
3424}
3425
3426TEST_F(WebRtcSessionTest, CanNotInsertDtmf) {
3427 TestCanInsertDtmf(false);
3428}
3429
3430TEST_F(WebRtcSessionTest, CanInsertDtmf) {
3431 TestCanInsertDtmf(true);
3432}
3433
3434TEST_F(WebRtcSessionTest, InsertDtmf) {
3435 // Setup
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003436 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003437 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003438 CreateAndSetRemoteOfferAndLocalAnswer();
3439 FakeVoiceMediaChannel* channel = media_engine_->GetVoiceChannel(0);
3440 EXPECT_EQ(0U, channel->dtmf_info_queue().size());
3441
3442 // Insert DTMF
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003443 const int expected_duration = 90;
3444 session_->InsertDtmf(kAudioTrack1, 0, expected_duration);
3445 session_->InsertDtmf(kAudioTrack1, 1, expected_duration);
3446 session_->InsertDtmf(kAudioTrack1, 2, expected_duration);
3447
3448 // Verify
3449 ASSERT_EQ(3U, channel->dtmf_info_queue().size());
Peter Boström0c4e06b2015-10-07 12:23:21 +02003450 const uint32_t send_ssrc = channel->send_streams()[0].first_ssrc();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003451 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[0], send_ssrc, 0,
solenberg1d63dd02015-12-02 12:35:09 -08003452 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003453 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[1], send_ssrc, 1,
solenberg1d63dd02015-12-02 12:35:09 -08003454 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003455 EXPECT_TRUE(CompareDtmfInfo(channel->dtmf_info_queue()[2], send_ssrc, 2,
solenberg1d63dd02015-12-02 12:35:09 -08003456 expected_duration));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003457}
3458
deadbeefd59daf82015-10-14 15:02:44 -07003459// This test verifies the |initial_offerer| flag when session initiates the
3460// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003461TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003462 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003463 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003464 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003465 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
3466 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07003467 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003468 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003469 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003470}
3471
deadbeefd59daf82015-10-14 15:02:44 -07003472// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003473TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003474 Init();
deadbeefd59daf82015-10-14 15:02:44 -07003475 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003476 SessionDescriptionInterface* offer = CreateRemoteOffer();
3477 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003478 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003479
deadbeefd59daf82015-10-14 15:02:44 -07003480 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003481 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07003482 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003483}
3484
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003485// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
3486TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003487 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003488 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003489 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003490 SetLocalDescriptionWithoutError(offer);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003491 rtc::scoped_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003492 CreateRemoteAnswer(session_->local_description()));
3493
3494 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3495 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003496 JsepSessionDescription* modified_answer =
3497 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003498
3499 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3500 answer->session_id(),
3501 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003502 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003503
wu@webrtc.org4e393072014-04-07 17:04:35 +00003504 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003505 std::string sdp;
3506 EXPECT_TRUE(answer->ToString(&sdp));
3507 const std::string kAudioMid = "a=mid:audio";
3508 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003509 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003510 kAudioMidReplaceStr.c_str(),
3511 kAudioMidReplaceStr.length(),
3512 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003513 SessionDescriptionInterface* modified_answer1 =
3514 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003515 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003516
wu@webrtc.org4e393072014-04-07 17:04:35 +00003517 // Different media types.
3518 EXPECT_TRUE(answer->ToString(&sdp));
3519 const std::string kAudioMline = "m=audio";
3520 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003521 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00003522 kAudioMlineReplaceStr.c_str(),
3523 kAudioMlineReplaceStr.length(),
3524 &sdp);
3525 SessionDescriptionInterface* modified_answer2 =
3526 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
3527 SetRemoteDescriptionAnswerExpectError(kMlineMismatch, modified_answer2);
3528
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003529 SetRemoteDescriptionWithoutError(answer.release());
3530}
3531
3532// Verifying remote offer and local answer have matching m-lines as per
3533// RFC 3264.
3534TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003535 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003536 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003537 SessionDescriptionInterface* offer = CreateRemoteOffer();
3538 SetRemoteDescriptionWithoutError(offer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003539 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003540
3541 cricket::SessionDescription* answer_copy = answer->description()->Copy();
3542 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003543 JsepSessionDescription* modified_answer =
3544 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003545
3546 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
3547 answer->session_id(),
3548 answer->session_version()));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003549 SetLocalDescriptionAnswerExpectError(kMlineMismatch, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003550 SetLocalDescriptionWithoutError(answer);
3551}
3552
3553// This test verifies that WebRtcSession does not start candidate allocation
3554// before SetLocalDescription is called.
3555TEST_F(WebRtcSessionTest, TestIceStartAfterSetLocalDescriptionOnly) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003556 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003557 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003558 SessionDescriptionInterface* offer = CreateRemoteOffer();
3559 cricket::Candidate candidate;
3560 candidate.set_component(1);
3561 JsepIceCandidate ice_candidate(kMediaContentName0, kMediaContentIndex0,
3562 candidate);
3563 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
3564 cricket::Candidate candidate1;
3565 candidate1.set_component(1);
3566 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
3567 candidate1);
3568 EXPECT_TRUE(offer->AddCandidate(&ice_candidate1));
3569 SetRemoteDescriptionWithoutError(offer);
deadbeefcbecd352015-09-23 11:50:27 -07003570 ASSERT_TRUE(session_->voice_rtp_transport_channel() != NULL);
3571 ASSERT_TRUE(session_->video_rtp_transport_channel() != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003572
3573 // Pump for 1 second and verify that no candidates are generated.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003574 rtc::Thread::Current()->ProcessMessages(1000);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003575 EXPECT_TRUE(observer_.mline_0_candidates_.empty());
3576 EXPECT_TRUE(observer_.mline_1_candidates_.empty());
3577
wu@webrtc.org91053e72013-08-10 07:18:04 +00003578 SessionDescriptionInterface* answer = CreateAnswer(NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003579 SetLocalDescriptionWithoutError(answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003580 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
3581}
3582
3583// This test verifies that crypto parameter is updated in local session
3584// description as per security policy set in MediaSessionDescriptionFactory.
3585TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescription) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003586 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003587 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003588 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003589
3590 // Making sure SetLocalDescription correctly sets crypto value in
3591 // SessionDescription object after de-serialization of sdp string. The value
3592 // will be set as per MediaSessionDescriptionFactory.
3593 std::string offer_str;
3594 offer->ToString(&offer_str);
3595 SessionDescriptionInterface* jsep_offer_str =
3596 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3597 SetLocalDescriptionWithoutError(jsep_offer_str);
3598 EXPECT_TRUE(session_->voice_channel()->secure_required());
3599 EXPECT_TRUE(session_->video_channel()->secure_required());
3600}
3601
3602// This test verifies the crypto parameter when security is disabled.
3603TEST_F(WebRtcSessionTest, TestCryptoAfterSetLocalDescriptionWithDisabled) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00003604 options_.disable_encryption = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003605 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003606 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003607 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003608
3609 // Making sure SetLocalDescription correctly sets crypto value in
3610 // SessionDescription object after de-serialization of sdp string. The value
3611 // will be set as per MediaSessionDescriptionFactory.
3612 std::string offer_str;
3613 offer->ToString(&offer_str);
deadbeefcbecd352015-09-23 11:50:27 -07003614 SessionDescriptionInterface* jsep_offer_str =
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003615 CreateSessionDescription(JsepSessionDescription::kOffer, offer_str, NULL);
3616 SetLocalDescriptionWithoutError(jsep_offer_str);
3617 EXPECT_FALSE(session_->voice_channel()->secure_required());
3618 EXPECT_FALSE(session_->video_channel()->secure_required());
3619}
3620
3621// This test verifies that an answer contains new ufrag and password if an offer
3622// with new ufrag and password is received.
3623TEST_F(WebRtcSessionTest, TestCreateAnswerWithNewUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003624 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003625 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003626 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003627 rtc::scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003628 CreateRemoteOffer(options));
3629 SetRemoteDescriptionWithoutError(offer.release());
3630
deadbeefab9b2d12015-10-14 11:33:11 -07003631 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003632 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003633 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003634 SetLocalDescriptionWithoutError(answer.release());
3635
3636 // Receive an offer with new ufrag and password.
3637 options.transport_options.ice_restart = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003638 rtc::scoped_ptr<JsepSessionDescription> updated_offer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003639 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003640 SetRemoteDescriptionWithoutError(updated_offer1.release());
3641
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003642 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer1(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003643 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003644
3645 CompareIceUfragAndPassword(updated_answer1->description(),
3646 session_->local_description()->description(),
3647 false);
3648
3649 SetLocalDescriptionWithoutError(updated_answer1.release());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003650}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003651
wu@webrtc.org91053e72013-08-10 07:18:04 +00003652// This test verifies that an answer contains old ufrag and password if an offer
3653// with old ufrag and password is received.
3654TEST_F(WebRtcSessionTest, TestCreateAnswerWithOldUfragAndPassword) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003655 Init();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003656 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003657 options.recv_video = true;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003658 rtc::scoped_ptr<JsepSessionDescription> offer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003659 CreateRemoteOffer(options));
3660 SetRemoteDescriptionWithoutError(offer.release());
3661
deadbeefab9b2d12015-10-14 11:33:11 -07003662 SendAudioVideoStream1();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003663 rtc::scoped_ptr<SessionDescriptionInterface> answer(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003664 CreateAnswer(NULL));
3665 SetLocalDescriptionWithoutError(answer.release());
3666
3667 // Receive an offer without changed ufrag or password.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003668 options.transport_options.ice_restart = false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003669 rtc::scoped_ptr<JsepSessionDescription> updated_offer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003670 CreateRemoteOffer(options, session_->remote_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003671 SetRemoteDescriptionWithoutError(updated_offer2.release());
3672
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003673 rtc::scoped_ptr<SessionDescriptionInterface> updated_answer2(
wu@webrtc.org91053e72013-08-10 07:18:04 +00003674 CreateAnswer(NULL));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003675
3676 CompareIceUfragAndPassword(updated_answer2->description(),
3677 session_->local_description()->description(),
3678 true);
3679
3680 SetLocalDescriptionWithoutError(updated_answer2.release());
3681}
3682
3683TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003684 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07003685 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003686 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003687 const std::string session_id_orig = offer->session_id();
3688 const std::string session_version_orig = offer->session_version();
3689 SetLocalDescriptionWithoutError(offer);
3690
3691 video_channel_ = media_engine_->GetVideoChannel(0);
3692 video_channel_->set_fail_set_send_codecs(true);
3693
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00003694 SessionDescriptionInterface* answer =
3695 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00003696 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07003697
3698 // Test that after a content error, setting any description will
3699 // result in an error.
3700 video_channel_->set_fail_set_send_codecs(false);
3701 answer = CreateRemoteAnswer(session_->local_description());
3702 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
3703 offer = CreateRemoteOffer();
3704 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003705}
3706
3707// Runs the loopback call test with BUNDLE and STUN disabled.
3708TEST_F(WebRtcSessionTest, TestIceStatesBasic) {
3709 // Lets try with only UDP ports.
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003710 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003711 cricket::PORTALLOCATOR_DISABLE_STUN |
3712 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003713 TestLoopbackCall();
3714}
3715
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003716TEST_F(WebRtcSessionTest, TestIceStatesBasicIPv6) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003717 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00003718 cricket::PORTALLOCATOR_DISABLE_STUN |
3719 cricket::PORTALLOCATOR_ENABLE_IPV6 |
3720 cricket::PORTALLOCATOR_DISABLE_RELAY);
3721
3722 // best connection is IPv6 since it has higher network preference.
3723 LoopbackNetworkConfiguration config;
3724 config.test_ipv6_network_ = true;
3725 config.best_connection_after_initial_ice_converged_ =
3726 LoopbackNetworkConfiguration::ExpectedBestConnection(0, 1);
3727
3728 TestLoopbackCall(config);
3729}
3730
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00003731// Runs the loopback call test with BUNDLE and STUN enabled.
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003732TEST_F(WebRtcSessionTest, TestIceStatesBundle) {
Peter Thatcher7cbd1882015-09-17 18:54:52 -07003733 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
3734 cricket::PORTALLOCATOR_DISABLE_RELAY);
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00003735 TestLoopbackCall();
3736}
3737
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003738TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
3739 constraints_.reset(new FakeConstraints());
3740 constraints_->AddOptional(
3741 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00003742 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003743
3744 SetLocalDescriptionWithDataChannel();
3745 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3746}
3747
Henrik Boström87713d02015-08-25 09:53:21 +02003748TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003749 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003750
3751 constraints_.reset(new FakeConstraints());
3752 constraints_->AddOptional(
3753 webrtc::MediaConstraintsInterface::kEnableRtpDataChannels, true);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003754 options_.disable_sctp_data_channels = false;
3755
Henrik Boström87713d02015-08-25 09:53:21 +02003756 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003757
3758 SetLocalDescriptionWithDataChannel();
3759 EXPECT_EQ(cricket::DCT_RTP, data_engine_->last_channel_type());
3760}
3761
Henrik Boström87713d02015-08-25 09:53:21 +02003762TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003763 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org967bfff2013-09-19 05:49:50 +00003764
Henrik Boström87713d02015-08-25 09:53:21 +02003765 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003766
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003767 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003768 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003769 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
3770}
3771
Henrik Boström87713d02015-08-25 09:53:21 +02003772TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003773 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003774 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02003775 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003776
3777 // Create remote offer with SCTP.
3778 cricket::MediaSessionOptions options;
3779 options.data_channel_type = cricket::DCT_SCTP;
3780 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003781 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003782 SetRemoteDescriptionWithoutError(offer);
3783
3784 // Verifies the answer contains SCTP.
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003785 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00003786 EXPECT_TRUE(answer != NULL);
3787 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
3788 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003789}
3790
Henrik Boström87713d02015-08-25 09:53:21 +02003791TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003792 constraints_.reset(new FakeConstraints());
3793 constraints_->AddOptional(
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00003794 webrtc::MediaConstraintsInterface::kEnableDtlsSrtp, false);
Henrik Boström87713d02015-08-25 09:53:21 +02003795 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003796
3797 SetLocalDescriptionWithDataChannel();
3798 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3799}
3800
Henrik Boström87713d02015-08-25 09:53:21 +02003801TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003802 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003803
Henrik Boström87713d02015-08-25 09:53:21 +02003804 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003805
3806 SetLocalDescriptionWithDataChannel();
3807 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3808}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003809
Henrik Boström87713d02015-08-25 09:53:21 +02003810TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003811 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org97077a32013-10-25 21:18:33 +00003812 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02003813 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00003814
3815 SetLocalDescriptionWithDataChannel();
3816 EXPECT_EQ(cricket::DCT_NONE, data_engine_->last_channel_type());
3817}
3818
Henrik Boström87713d02015-08-25 09:53:21 +02003819TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003820 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003821 const int new_send_port = 9998;
3822 const int new_recv_port = 7775;
3823
Henrik Boström87713d02015-08-25 09:53:21 +02003824 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003825 SetFactoryDtlsSrtp();
3826
3827 // By default, don't actually add the codecs to desc_factory_; they don't
3828 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
3829 // let the session description get parsed. That'll get the proper codecs
3830 // into the stream.
3831 cricket::MediaSessionOptions options;
3832 JsepSessionDescription* offer = CreateRemoteOfferWithSctpPort(
3833 "stream1", new_send_port, options);
3834
3835 // SetRemoteDescription will take the ownership of the offer.
3836 SetRemoteDescriptionWithoutError(offer);
3837
3838 SessionDescriptionInterface* answer = ChangeSDPSctpPort(
3839 new_recv_port, CreateAnswer(NULL));
3840 ASSERT_TRUE(answer != NULL);
3841
3842 // Now set the local description, which'll take ownership of the answer.
3843 SetLocalDescriptionWithoutError(answer);
3844
3845 // TEST PLAN: Set the port number to something new, set it in the SDP,
3846 // and pass it all the way down.
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003847 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
deadbeefab9b2d12015-10-14 11:33:11 -07003848 CreateDataChannel();
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003849
3850 cricket::FakeDataMediaChannel* ch = data_engine_->GetChannel(0);
3851 int portnum = -1;
3852 ASSERT_TRUE(ch != NULL);
3853 ASSERT_EQ(1UL, ch->send_codecs().size());
3854 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->send_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003855 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003856 ch->send_codecs()[0].name.c_str()));
3857 EXPECT_TRUE(ch->send_codecs()[0].GetParam(cricket::kCodecParamPort,
3858 &portnum));
3859 EXPECT_EQ(new_send_port, portnum);
3860
3861 ASSERT_EQ(1UL, ch->recv_codecs().size());
3862 EXPECT_EQ(cricket::kGoogleSctpDataCodecId, ch->recv_codecs()[0].id);
Donald Curtisd4f769d2015-05-28 09:48:21 -07003863 EXPECT_EQ(0, strcmp(cricket::kGoogleSctpDataCodecName,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00003864 ch->recv_codecs()[0].name.c_str()));
3865 EXPECT_TRUE(ch->recv_codecs()[0].GetParam(cricket::kCodecParamPort,
3866 &portnum));
3867 EXPECT_EQ(new_recv_port, portnum);
3868}
3869
deadbeefab9b2d12015-10-14 11:33:11 -07003870// Verifies that when a session's DataChannel receives an OPEN message,
3871// WebRtcSession signals the DataChannel creation request with the expected
3872// config.
3873TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
3874 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3875
3876 InitWithDtls(GetParam());
3877
3878 SetLocalDescriptionWithDataChannel();
3879 EXPECT_EQ(cricket::DCT_SCTP, data_engine_->last_channel_type());
3880
3881 webrtc::DataChannelInit config;
3882 config.id = 1;
3883 rtc::Buffer payload;
3884 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
3885 cricket::ReceiveDataParams params;
3886 params.ssrc = config.id;
3887 params.type = cricket::DMT_CONTROL;
3888
3889 cricket::DataChannel* data_channel = session_->data_channel();
3890 data_channel->SignalDataReceived(data_channel, params, payload);
3891
3892 EXPECT_EQ("a", last_data_channel_label_);
3893 EXPECT_EQ(config.id, last_data_channel_config_.id);
3894 EXPECT_FALSE(last_data_channel_config_.negotiated);
3895 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
3896 last_data_channel_config_.open_handshake_role);
3897}
3898
3899TEST_P(WebRtcSessionTest, TestUsesProvidedCertificate) {
Henrik Boströmd8281982015-08-27 10:12:24 +02003900 rtc::scoped_refptr<rtc::RTCCertificate> certificate =
3901 FakeDtlsIdentityStore::GenerateCertificate();
3902
3903 PeerConnectionInterface::RTCConfiguration configuration;
3904 configuration.certificates.push_back(certificate);
3905 Init(nullptr, configuration);
3906 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
3907
3908 EXPECT_EQ(session_->certificate_for_testing(), certificate);
3909}
wu@webrtc.org91053e72013-08-10 07:18:04 +00003910
Henrik Boström87713d02015-08-25 09:53:21 +02003911// Verifies that CreateOffer succeeds when CreateOffer is called before async
3912// identity generation is finished (even if a certificate is provided this is
3913// an async op).
3914TEST_P(WebRtcSessionTest, TestCreateOfferBeforeIdentityRequestReturnSuccess) {
3915 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
3916 InitWithDtls(GetParam());
3917
Henrik Boströmd8281982015-08-27 10:12:24 +02003918 EXPECT_TRUE(session_->waiting_for_certificate_for_testing());
deadbeefab9b2d12015-10-14 11:33:11 -07003919 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003920 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
3921
wu@webrtc.org91053e72013-08-10 07:18:04 +00003922 EXPECT_TRUE(offer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003923 VerifyNoCryptoParams(offer->description(), true);
3924 VerifyFingerprintStatus(offer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003925}
3926
3927// Verifies that CreateAnswer succeeds when CreateOffer is called before async
Henrik Boström87713d02015-08-25 09:53:21 +02003928// identity generation is finished (even if a certificate is provided this is
3929// an async op).
3930TEST_P(WebRtcSessionTest, TestCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003931 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003932 InitWithDtls(GetParam());
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003933 SetFactoryDtlsSrtp();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003934
3935 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00003936 options.recv_video = true;
wu@webrtc.org91053e72013-08-10 07:18:04 +00003937 scoped_ptr<JsepSessionDescription> offer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003938 CreateRemoteOffer(options, cricket::SEC_DISABLED));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003939 ASSERT_TRUE(offer.get() != NULL);
3940 SetRemoteDescriptionWithoutError(offer.release());
3941
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003942 rtc::scoped_ptr<SessionDescriptionInterface> answer(CreateAnswer(NULL));
wu@webrtc.org91053e72013-08-10 07:18:04 +00003943 EXPECT_TRUE(answer != NULL);
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00003944 VerifyNoCryptoParams(answer->description(), true);
3945 VerifyFingerprintStatus(answer->description(), true);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003946}
3947
3948// Verifies that CreateOffer succeeds when CreateOffer is called after async
Henrik Boström87713d02015-08-25 09:53:21 +02003949// identity generation is finished (even if a certificate is provided this is
3950// an async op).
3951TEST_P(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003952 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003953 InitWithDtls(GetParam());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003954
Henrik Boströmd8281982015-08-27 10:12:24 +02003955 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003956
3957 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003958 EXPECT_TRUE(offer != NULL);
3959}
3960
3961// Verifies that CreateOffer fails when CreateOffer is called after async
3962// identity generation fails.
3963TEST_F(WebRtcSessionTest, TestCreateOfferAfterIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003964 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003965 InitWithDtlsIdentityGenFail();
wu@webrtc.org91053e72013-08-10 07:18:04 +00003966
Henrik Boströmd8281982015-08-27 10:12:24 +02003967 EXPECT_TRUE_WAIT(!session_->waiting_for_certificate_for_testing(), 1000);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00003968
3969 rtc::scoped_ptr<SessionDescriptionInterface> offer(CreateOffer());
wu@webrtc.org91053e72013-08-10 07:18:04 +00003970 EXPECT_TRUE(offer == NULL);
3971}
3972
3973// Verifies that CreateOffer succeeds when Multiple CreateOffer calls are made
3974// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003975TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003976 TestMultipleCreateOfferBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003977 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
deadbeefcbecd352015-09-23 11:50:27 -07003978 VerifyMultipleAsyncCreateDescription(GetParam(),
3979 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003980}
3981
3982// Verifies that CreateOffer fails when Multiple CreateOffer calls are made
3983// before async identity generation fails.
3984TEST_F(WebRtcSessionTest,
3985 TestMultipleCreateOfferBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003986 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02003987 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
3988 CreateSessionDescriptionRequest::kOffer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003989}
3990
3991// Verifies that CreateAnswer succeeds when Multiple CreateAnswer calls are made
3992// before async identity generation is finished.
Henrik Boström87713d02015-08-25 09:53:21 +02003993TEST_P(WebRtcSessionTest,
wu@webrtc.org91053e72013-08-10 07:18:04 +00003994 TestMultipleCreateAnswerBeforeIdentityRequestReturnSuccess) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00003995 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003996 VerifyMultipleAsyncCreateDescription(
Henrik Boström87713d02015-08-25 09:53:21 +02003997 GetParam(), CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00003998}
3999
4000// Verifies that CreateAnswer fails when Multiple CreateAnswer calls are made
4001// before async identity generation fails.
4002TEST_F(WebRtcSessionTest,
4003 TestMultipleCreateAnswerBeforeIdentityRequestReturnFailure) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004004 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004005 VerifyMultipleAsyncCreateDescriptionIdentityGenFailure(
4006 CreateSessionDescriptionRequest::kAnswer);
wu@webrtc.org91053e72013-08-10 07:18:04 +00004007}
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004008
4009// Verifies that setRemoteDescription fails when DTLS is disabled and the remote
4010// offer has no SDES crypto but only DTLS fingerprint.
4011TEST_F(WebRtcSessionTest, TestSetRemoteOfferFailIfDtlsDisabledAndNoCrypto) {
4012 // Init without DTLS.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004013 Init();
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004014 // Create a remote offer with secured transport disabled.
4015 cricket::MediaSessionOptions options;
4016 JsepSessionDescription* offer(CreateRemoteOffer(
4017 options, cricket::SEC_DISABLED));
4018 // Adds a DTLS fingerprint to the remote offer.
4019 cricket::SessionDescription* sdp = offer->description();
4020 TransportInfo* audio = sdp->GetTransportInfoByName("audio");
4021 ASSERT_TRUE(audio != NULL);
4022 ASSERT_TRUE(audio->description.identity_fingerprint.get() == NULL);
4023 audio->description.identity_fingerprint.reset(
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004024 rtc::SSLFingerprint::CreateFromRfc4572(
4025 rtc::DIGEST_SHA_256, kFakeDtlsFingerprint));
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00004026 SetRemoteDescriptionOfferExpectError(kSdpWithoutSdesCrypto,
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00004027 offer);
mallinath@webrtc.orga27be8e2013-09-27 23:04:10 +00004028}
4029
wu@webrtc.orgde305012013-10-31 15:40:38 +00004030// This test verifies DSCP is properly applied on the media channels.
4031TEST_F(WebRtcSessionTest, TestDscpConstraint) {
4032 constraints_.reset(new FakeConstraints());
4033 constraints_->AddOptional(
4034 webrtc::MediaConstraintsInterface::kEnableDscp, true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004035 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004036 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004037 SessionDescriptionInterface* offer = CreateOffer();
wu@webrtc.orgde305012013-10-31 15:40:38 +00004038
4039 SetLocalDescriptionWithoutError(offer);
4040
4041 video_channel_ = media_engine_->GetVideoChannel(0);
4042 voice_channel_ = media_engine_->GetVoiceChannel(0);
4043
4044 ASSERT_TRUE(video_channel_ != NULL);
4045 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004046 const cricket::AudioOptions& audio_options = voice_channel_->options();
4047 const cricket::VideoOptions& video_options = video_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004048 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.dscp);
4049 EXPECT_EQ(rtc::Optional<bool>(true), video_options.dscp);
wu@webrtc.orgde305012013-10-31 15:40:38 +00004050}
4051
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004052TEST_F(WebRtcSessionTest, TestSuspendBelowMinBitrateConstraint) {
4053 constraints_.reset(new FakeConstraints());
4054 constraints_->AddOptional(
4055 webrtc::MediaConstraintsInterface::kEnableVideoSuspendBelowMinBitrate,
4056 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004057 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004058 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004059 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004060
4061 SetLocalDescriptionWithoutError(offer);
4062
4063 video_channel_ = media_engine_->GetVideoChannel(0);
4064
4065 ASSERT_TRUE(video_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004066 const cricket::VideoOptions& video_options = video_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004067 EXPECT_EQ(rtc::Optional<bool>(true), video_options.suspend_below_min_bitrate);
henrike@webrtc.org6e3dbc22014-03-25 17:09:47 +00004068}
4069
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +00004070TEST_F(WebRtcSessionTest, TestNumUnsignalledRecvStreamsConstraint) {
4071 // Number of unsignalled receiving streams should be between 0 and
4072 // kMaxUnsignalledRecvStreams.
4073 SetAndVerifyNumUnsignalledRecvStreams(10, 10);
4074 SetAndVerifyNumUnsignalledRecvStreams(kMaxUnsignalledRecvStreams + 1,
4075 kMaxUnsignalledRecvStreams);
4076 SetAndVerifyNumUnsignalledRecvStreams(-1, 0);
4077}
4078
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004079TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
4080 constraints_.reset(new FakeConstraints());
4081 constraints_->AddOptional(
4082 webrtc::MediaConstraintsInterface::kCombinedAudioVideoBwe,
4083 true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00004084 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004085 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004086 SessionDescriptionInterface* offer = CreateOffer();
4087
4088 SetLocalDescriptionWithoutError(offer);
4089
4090 voice_channel_ = media_engine_->GetVoiceChannel(0);
4091
4092 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07004093 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01004094 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00004095}
4096
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004097// Tests that we can renegotiate new media content with ICE candidates in the
4098// new remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004099TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesInSdp) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004100 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004101 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004102 SetFactoryDtlsSrtp();
4103
deadbeefab9b2d12015-10-14 11:33:11 -07004104 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004105 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004106 SetLocalDescriptionWithoutError(offer);
4107
4108 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4109 SetRemoteDescriptionWithoutError(answer);
4110
4111 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004112 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004113 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4114
4115 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004116 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004117 candidate1.set_component(1);
4118 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4119 candidate1);
4120 EXPECT_TRUE(offer->AddCandidate(&ice_candidate));
4121 SetRemoteDescriptionWithoutError(offer);
4122
4123 answer = CreateAnswer(NULL);
4124 SetLocalDescriptionWithoutError(answer);
4125}
4126
4127// Tests that we can renegotiate new media content with ICE candidates separated
4128// from the remote SDP.
Henrik Boström87713d02015-08-25 09:53:21 +02004129TEST_P(WebRtcSessionTest, TestRenegotiateNewMediaWithCandidatesSeparated) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004130 MAYBE_SKIP_TEST(rtc::SSLStreamAdapter::HaveDtlsSrtp);
Henrik Boström87713d02015-08-25 09:53:21 +02004131 InitWithDtls(GetParam());
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004132 SetFactoryDtlsSrtp();
4133
deadbeefab9b2d12015-10-14 11:33:11 -07004134 SendAudioOnlyStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00004135 SessionDescriptionInterface* offer = CreateOffer();
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004136 SetLocalDescriptionWithoutError(offer);
4137
4138 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
4139 SetRemoteDescriptionWithoutError(answer);
4140
4141 cricket::MediaSessionOptions options;
jiayl@webrtc.org742922b2014-10-07 21:32:43 +00004142 options.recv_video = true;
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004143 offer = CreateRemoteOffer(options, cricket::SEC_DISABLED);
4144 SetRemoteDescriptionWithoutError(offer);
4145
4146 cricket::Candidate candidate1;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00004147 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 5000));
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004148 candidate1.set_component(1);
4149 JsepIceCandidate ice_candidate(kMediaContentName1, kMediaContentIndex1,
4150 candidate1);
4151 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate));
4152
4153 answer = CreateAnswer(NULL);
4154 SetLocalDescriptionWithoutError(answer);
4155}
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004156// Tests that RTX codec is removed from the answer when it isn't supported
4157// by local side.
4158TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
4159 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07004160 SendAudioVideoStream1();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00004161 std::string offer_sdp(kSdpWithRtx);
4162
4163 SessionDescriptionInterface* offer =
4164 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
4165 EXPECT_TRUE(offer->ToString(&offer_sdp));
4166
4167 // Offer SDP contains the RTX codec.
4168 EXPECT_TRUE(offer_sdp.find("rtx") != std::string::npos);
4169 SetRemoteDescriptionWithoutError(offer);
4170
4171 SessionDescriptionInterface* answer = CreateAnswer(NULL);
4172 std::string answer_sdp;
4173 answer->ToString(&answer_sdp);
4174 // Answer SDP removes the unsupported RTX codec.
4175 EXPECT_TRUE(answer_sdp.find("rtx") == std::string::npos);
4176 SetLocalDescriptionWithoutError(answer);
4177}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00004178
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004179// This verifies that the voice channel after bundle has both options from video
4180// and voice channels.
4181TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
4182 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07004183 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004184
4185 PeerConnectionInterface::RTCOfferAnswerOptions options;
4186 options.use_rtp_mux = true;
4187
4188 SessionDescriptionInterface* offer = CreateOffer(options);
4189 SetLocalDescriptionWithoutError(offer);
4190
4191 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4192 rtc::Socket::Option::OPT_SNDBUF, 4000);
4193
4194 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
4195 rtc::Socket::Option::OPT_RCVBUF, 8000);
4196
4197 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07004198 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004199 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4200 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004201 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004202 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4203
deadbeefcbecd352015-09-23 11:50:27 -07004204 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004205 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4206 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07004207 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004208 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4209
deadbeefcbecd352015-09-23 11:50:27 -07004210 EXPECT_NE(session_->voice_rtp_transport_channel(),
4211 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004212
deadbeefab9b2d12015-10-14 11:33:11 -07004213 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004214 SessionDescriptionInterface* answer =
4215 CreateRemoteAnswer(session_->local_description());
4216 SetRemoteDescriptionWithoutError(answer);
4217
deadbeefcbecd352015-09-23 11:50:27 -07004218 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004219 rtc::Socket::Option::OPT_SNDBUF, &option_val));
4220 EXPECT_EQ(4000, option_val);
4221
deadbeefcbecd352015-09-23 11:50:27 -07004222 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00004223 rtc::Socket::Option::OPT_RCVBUF, &option_val));
4224 EXPECT_EQ(8000, option_val);
4225}
4226
tommi0f620f42015-07-09 03:25:02 -07004227// Test creating a session, request multiple offers, destroy the session
4228// and make sure we got success/failure callbacks for all of the requests.
4229// Background: crbug.com/507307
4230TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
4231 Init();
4232
4233 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
4234 PeerConnectionInterface::RTCOfferAnswerOptions options;
4235 options.offer_to_receive_audio =
4236 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07004237 cricket::MediaSessionOptions session_options;
4238 session_options.recv_audio = true;
tommi0f620f42015-07-09 03:25:02 -07004239
4240 for (auto& o : observers) {
4241 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07004242 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07004243 }
4244
4245 session_.reset();
4246
tommi0f620f42015-07-09 03:25:02 -07004247 for (auto& o : observers) {
4248 // We expect to have received a notification now even if the session was
4249 // terminated. The offer creation may or may not have succeeded, but we
4250 // must have received a notification which, so the only invalid state
4251 // is kInit.
4252 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
4253 }
4254}
4255
stefanc1aeaf02015-10-15 07:26:07 -07004256TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
4257 TestPacketOptions();
4258}
4259
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004260// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
4261// currently fails because upon disconnection and reconnection OnIceComplete is
4262// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02004263
deadbeefcbecd352015-09-23 11:50:27 -07004264INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
4265 WebRtcSessionTest,
4266 testing::Values(ALREADY_GENERATED,
4267 DTLS_IDENTITY_STORE));