blob: 25cb35a6a9c1a738651db8f618cdee9e2826c823 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
10
jbauch555604a2016-04-26 03:13:22 -070011#include <memory>
kwiberg0eb15ed2015-12-17 03:04:15 -080012#include <utility>
deadbeefcbecd352015-09-23 11:50:27 -070013#include <vector>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "api/fakemetricsobserver.h"
16#include "api/jsepicecandidate.h"
17#include "api/jsepsessiondescription.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "media/base/fakemediaengine.h"
19#include "media/base/fakevideorenderer.h"
20#include "media/base/mediachannel.h"
21#include "media/engine/fakewebrtccall.h"
22#include "media/sctp/sctptransportinternal.h"
23#include "p2p/base/packettransportinternal.h"
24#include "p2p/base/stunserver.h"
25#include "p2p/base/teststunserver.h"
26#include "p2p/base/testturnserver.h"
27#include "p2p/client/basicportallocator.h"
28#include "pc/audiotrack.h"
29#include "pc/channelmanager.h"
30#include "pc/mediasession.h"
31#include "pc/peerconnection.h"
32#include "pc/sctputils.h"
33#include "pc/test/fakertccertificategenerator.h"
34#include "pc/videotrack.h"
35#include "pc/webrtcsession.h"
36#include "pc/webrtcsessiondescriptionfactory.h"
37#include "rtc_base/checks.h"
38#include "rtc_base/fakenetwork.h"
39#include "rtc_base/firewallsocketserver.h"
40#include "rtc_base/gunit.h"
41#include "rtc_base/logging.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020042#include "rtc_base/stringutils.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020043#include "rtc_base/virtualsocketserver.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000044
henrike@webrtc.org28e20752013-07-10 00:45:36 +000045using cricket::FakeVoiceMediaChannel;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000046using cricket::TransportInfo;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000047using rtc::SocketAddress;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000048using rtc::Thread;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000049using webrtc::CreateSessionDescription;
wu@webrtc.org91053e72013-08-10 07:18:04 +000050using webrtc::CreateSessionDescriptionObserver;
51using webrtc::CreateSessionDescriptionRequest;
deadbeefab9b2d12015-10-14 11:33:11 -070052using webrtc::DataChannel;
jbauchac8869e2015-07-03 01:36:14 -070053using webrtc::FakeMetricsObserver;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000054using webrtc::IceCandidateCollection;
deadbeefab9b2d12015-10-14 11:33:11 -070055using webrtc::InternalDataChannelInit;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056using webrtc::JsepIceCandidate;
57using webrtc::JsepSessionDescription;
wu@webrtc.org97077a32013-10-25 21:18:33 +000058using webrtc::PeerConnectionFactoryInterface;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000059using webrtc::PeerConnectionInterface;
60using webrtc::SessionDescriptionInterface;
deadbeefd59daf82015-10-14 15:02:44 -070061using webrtc::SessionStats;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062using webrtc::StreamCollection;
wu@webrtc.org91053e72013-08-10 07:18:04 +000063using webrtc::WebRtcSession;
wu@webrtc.org364f2042013-11-20 21:49:41 +000064using webrtc::kBundleWithoutRtcpMux;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000065using webrtc::kCreateChannelFailed;
66using webrtc::kInvalidSdp;
Zhi Huang2a5e4262017-09-14 01:15:03 -070067using webrtc::kMlineMismatchInAnswer;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000068using webrtc::kPushDownTDFailed;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000069using webrtc::kSdpWithoutIceUfragPwd;
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +000070using webrtc::kSdpWithoutDtlsFingerprint;
71using webrtc::kSdpWithoutSdesCrypto;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000072using webrtc::kSessionError;
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +000073using webrtc::kSessionErrorDesc;
buildbot@webrtc.org53df88c2014-08-07 22:46:01 +000074using webrtc::kMaxUnsignalledRecvStreams;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +000076typedef PeerConnectionInterface::RTCOfferAnswerOptions RTCOfferAnswerOptions;
77
wu@webrtc.org364f2042013-11-20 21:49:41 +000078static const int kClientAddrPort = 0;
79static const char kClientAddrHost1[] = "11.11.11.11";
wu@webrtc.org364f2042013-11-20 21:49:41 +000080static const char kStunAddrHost[] = "99.99.99.1";
henrike@webrtc.org28e20752013-07-10 00:45:36 +000081
82static const char kSessionVersion[] = "1";
83
henrike@webrtc.org28e20752013-07-10 00:45:36 +000084// Media index of candidates belonging to the first media content.
85static const int kMediaContentIndex0 = 0;
86static const char kMediaContentName0[] = "audio";
87
88// Media index of candidates belonging to the second media content.
89static const int kMediaContentIndex1 = 1;
90static const char kMediaContentName1[] = "video";
91
deadbeef953c2ce2017-01-09 14:53:41 -080092static const int kDefaultTimeout = 10000; // 10 seconds.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000093static const int kIceCandidatesTimeout = 10000;
94
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +000095static const char kSdpWithRtx[] =
96 "v=0\r\n"
97 "o=- 4104004319237231850 2 IN IP4 127.0.0.1\r\n"
98 "s=-\r\n"
99 "t=0 0\r\n"
100 "a=msid-semantic: WMS stream1\r\n"
101 "m=video 9 RTP/SAVPF 0 96\r\n"
102 "c=IN IP4 0.0.0.0\r\n"
103 "a=rtcp:9 IN IP4 0.0.0.0\r\n"
104 "a=ice-ufrag:CerjGp19G7wpXwl7\r\n"
105 "a=ice-pwd:cMvOlFvQ6ochez1ZOoC2uBEC\r\n"
106 "a=mid:video\r\n"
107 "a=sendrecv\r\n"
108 "a=rtcp-mux\r\n"
109 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
110 "inline:5/4N5CDvMiyDArHtBByUM71VIkguH17ZNoX60GrA\r\n"
111 "a=rtpmap:0 fake_video_codec/90000\r\n"
112 "a=rtpmap:96 rtx/90000\r\n"
113 "a=fmtp:96 apt=0\r\n";
114
deadbeefab9b2d12015-10-14 11:33:11 -0700115static const char kStream1[] = "stream1";
116static const char kVideoTrack1[] = "video1";
117static const char kAudioTrack1[] = "audio1";
118
119static const char kStream2[] = "stream2";
120static const char kVideoTrack2[] = "video2";
121static const char kAudioTrack2[] = "audio2";
122
zhihuang1c378ed2017-08-17 14:10:50 -0700123static constexpr bool kStopped = true;
124static constexpr bool kActive = false;
125
Henrik Boström87713d02015-08-25 09:53:21 +0200126enum RTCCertificateGenerationMethod { ALREADY_GENERATED, DTLS_IDENTITY_STORE };
127
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000128class MockIceObserver : public webrtc::IceObserver {
129 public:
130 MockIceObserver()
131 : oncandidatesready_(false),
132 ice_connection_state_(PeerConnectionInterface::kIceConnectionNew),
133 ice_gathering_state_(PeerConnectionInterface::kIceGatheringNew) {
134 }
135
Henrik Kjellander3fe372d2016-05-12 08:10:52 +0200136 virtual ~MockIceObserver() = default;
137
zstein6dfd53a2017-03-06 13:49:03 -0800138 void OnIceConnectionStateChange(
perkjdfb769d2016-02-09 03:09:43 -0800139 PeerConnectionInterface::IceConnectionState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000140 ice_connection_state_ = new_state;
skvlad6c87a672016-05-17 17:49:52 -0700141 ice_connection_state_history_.push_back(new_state);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000142 }
perkjdfb769d2016-02-09 03:09:43 -0800143 void OnIceGatheringChange(
144 PeerConnectionInterface::IceGatheringState new_state) override {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000145 // We can never transition back to "new".
146 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, new_state);
147 ice_gathering_state_ = new_state;
perkjdfb769d2016-02-09 03:09:43 -0800148 oncandidatesready_ =
149 new_state == PeerConnectionInterface::kIceGatheringComplete;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000150 }
151
152 // Found a new candidate.
jbauch81bf7b02017-03-25 08:31:12 -0700153 void OnIceCandidate(
154 std::unique_ptr<webrtc::IceCandidateInterface> candidate) override {
wu@webrtc.org364f2042013-11-20 21:49:41 +0000155 switch (candidate->sdp_mline_index()) {
156 case kMediaContentIndex0:
157 mline_0_candidates_.push_back(candidate->candidate());
158 break;
159 case kMediaContentIndex1:
160 mline_1_candidates_.push_back(candidate->candidate());
161 break;
162 default:
nissec80e7412017-01-11 05:56:46 -0800163 RTC_NOTREACHED();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000164 }
wu@webrtc.org364f2042013-11-20 21:49:41 +0000165
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000166 // The ICE gathering state should always be Gathering when a candidate is
167 // received (or possibly Completed in the case of the final candidate).
168 EXPECT_NE(PeerConnectionInterface::kIceGatheringNew, ice_gathering_state_);
169 }
170
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700171 // Some local candidates are removed.
172 void OnIceCandidatesRemoved(
nisseef8b61e2016-04-29 06:09:15 -0700173 const std::vector<cricket::Candidate>& candidates) override {
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700174 num_candidates_removed_ += candidates.size();
175 }
176
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000177 bool oncandidatesready_;
178 std::vector<cricket::Candidate> mline_0_candidates_;
179 std::vector<cricket::Candidate> mline_1_candidates_;
180 PeerConnectionInterface::IceConnectionState ice_connection_state_;
181 PeerConnectionInterface::IceGatheringState ice_gathering_state_;
skvlad6c87a672016-05-17 17:49:52 -0700182 std::vector<PeerConnectionInterface::IceConnectionState>
183 ice_connection_state_history_;
Honghai Zhang7fb69db2016-03-14 11:59:18 -0700184 size_t num_candidates_removed_ = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000185};
186
deadbeef953c2ce2017-01-09 14:53:41 -0800187// Used for tests in this file to verify that WebRtcSession responds to signals
188// from the SctpTransport correctly, and calls Start with the correct
189// local/remote ports.
190class FakeSctpTransport : public cricket::SctpTransportInternal {
191 public:
deadbeef5bd5ca32017-02-10 11:31:50 -0800192 void SetTransportChannel(rtc::PacketTransportInternal* channel) override {}
deadbeef953c2ce2017-01-09 14:53:41 -0800193 bool Start(int local_port, int remote_port) override {
194 local_port_ = local_port;
195 remote_port_ = remote_port;
196 return true;
197 }
198 bool OpenStream(int sid) override { return true; }
199 bool ResetStream(int sid) override { return true; }
200 bool SendData(const cricket::SendDataParams& params,
201 const rtc::CopyOnWriteBuffer& payload,
202 cricket::SendDataResult* result = nullptr) override {
203 return true;
204 }
205 bool ReadyToSendData() override { return true; }
206 void set_debug_name_for_testing(const char* debug_name) override {}
207
208 int local_port() const { return local_port_; }
209 int remote_port() const { return remote_port_; }
210
211 private:
212 int local_port_ = -1;
213 int remote_port_ = -1;
214};
215
216class FakeSctpTransportFactory : public cricket::SctpTransportInternalFactory {
217 public:
218 std::unique_ptr<cricket::SctpTransportInternal> CreateSctpTransport(
deadbeef5bd5ca32017-02-10 11:31:50 -0800219 rtc::PacketTransportInternal*) override {
deadbeef953c2ce2017-01-09 14:53:41 -0800220 last_fake_sctp_transport_ = new FakeSctpTransport();
221 return std::unique_ptr<cricket::SctpTransportInternal>(
222 last_fake_sctp_transport_);
223 }
224
225 FakeSctpTransport* last_fake_sctp_transport() {
226 return last_fake_sctp_transport_;
227 }
228
229 private:
230 FakeSctpTransport* last_fake_sctp_transport_ = nullptr;
231};
232
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000233class WebRtcSessionForTest : public webrtc::WebRtcSession {
234 public:
zhihuang29ff8442016-07-27 11:07:25 -0700235 WebRtcSessionForTest(
nisseeaabdf62017-05-05 02:23:02 -0700236 webrtc::Call* fake_call,
237 cricket::ChannelManager* channel_manager,
238 const cricket::MediaConfig& media_config,
239 webrtc::RtcEventLog* event_log,
zhihuang29ff8442016-07-27 11:07:25 -0700240 rtc::Thread* network_thread,
241 rtc::Thread* worker_thread,
242 rtc::Thread* signaling_thread,
243 cricket::PortAllocator* port_allocator,
244 webrtc::IceObserver* ice_observer,
deadbeef953c2ce2017-01-09 14:53:41 -0800245 std::unique_ptr<cricket::TransportController> transport_controller,
246 std::unique_ptr<FakeSctpTransportFactory> sctp_factory)
nisseeaabdf62017-05-05 02:23:02 -0700247 : WebRtcSession(fake_call, channel_manager, media_config, event_log,
danilchape9021a32016-05-17 01:52:02 -0700248 network_thread,
stefanc1aeaf02015-10-15 07:26:07 -0700249 worker_thread,
danilchape9021a32016-05-17 01:52:02 -0700250 signaling_thread,
zhihuang29ff8442016-07-27 11:07:25 -0700251 port_allocator,
deadbeef953c2ce2017-01-09 14:53:41 -0800252 std::move(transport_controller),
253 std::move(sctp_factory)) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000254 RegisterIceObserver(ice_observer);
255 }
256 virtual ~WebRtcSessionForTest() {}
257
deadbeefcbecd352015-09-23 11:50:27 -0700258 // Note that these methods are only safe to use if the signaling thread
259 // is the same as the worker thread
deadbeef5bd5ca32017-02-10 11:31:50 -0800260 rtc::PacketTransportInternal* voice_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700261 return rtp_transport_channel(voice_channel());
262 }
263
deadbeef5bd5ca32017-02-10 11:31:50 -0800264 rtc::PacketTransportInternal* voice_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700265 return rtcp_transport_channel(voice_channel());
266 }
267
deadbeef5bd5ca32017-02-10 11:31:50 -0800268 rtc::PacketTransportInternal* video_rtp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700269 return rtp_transport_channel(video_channel());
270 }
271
deadbeef5bd5ca32017-02-10 11:31:50 -0800272 rtc::PacketTransportInternal* video_rtcp_transport_channel() {
deadbeefcbecd352015-09-23 11:50:27 -0700273 return rtcp_transport_channel(video_channel());
274 }
275
deadbeefcbecd352015-09-23 11:50:27 -0700276 private:
deadbeef5bd5ca32017-02-10 11:31:50 -0800277 rtc::PacketTransportInternal* rtp_transport_channel(
johan669d69b2016-11-08 14:14:08 -0800278 cricket::BaseChannel* ch) {
deadbeefcbecd352015-09-23 11:50:27 -0700279 if (!ch) {
280 return nullptr;
281 }
zhihuangb2cdd932017-01-19 16:54:25 -0800282 return ch->rtp_dtls_transport();
deadbeefcbecd352015-09-23 11:50:27 -0700283 }
284
deadbeef5bd5ca32017-02-10 11:31:50 -0800285 rtc::PacketTransportInternal* rtcp_transport_channel(
johan669d69b2016-11-08 14:14:08 -0800286 cricket::BaseChannel* ch) {
deadbeefcbecd352015-09-23 11:50:27 -0700287 if (!ch) {
288 return nullptr;
289 }
zhihuangb2cdd932017-01-19 16:54:25 -0800290 return ch->rtcp_dtls_transport();
deadbeefcbecd352015-09-23 11:50:27 -0700291 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000292};
293
wu@webrtc.org91053e72013-08-10 07:18:04 +0000294class WebRtcSessionCreateSDPObserverForTest
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000295 : public rtc::RefCountedObject<CreateSessionDescriptionObserver> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000296 public:
wu@webrtc.org91053e72013-08-10 07:18:04 +0000297 enum State {
298 kInit,
299 kFailed,
300 kSucceeded,
301 };
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000302 WebRtcSessionCreateSDPObserverForTest() : state_(kInit) {}
wu@webrtc.org91053e72013-08-10 07:18:04 +0000303
304 // CreateSessionDescriptionObserver implementation.
305 virtual void OnSuccess(SessionDescriptionInterface* desc) {
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000306 description_.reset(desc);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000307 state_ = kSucceeded;
308 }
309 virtual void OnFailure(const std::string& error) {
310 state_ = kFailed;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000311 }
312
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000313 SessionDescriptionInterface* description() { return description_.get(); }
314
315 SessionDescriptionInterface* ReleaseDescription() {
316 return description_.release();
317 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000318
wu@webrtc.org91053e72013-08-10 07:18:04 +0000319 State state() const { return state_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000320
wu@webrtc.org91053e72013-08-10 07:18:04 +0000321 protected:
322 ~WebRtcSessionCreateSDPObserverForTest() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000323
324 private:
kwibergd1fe2812016-04-27 06:47:29 -0700325 std::unique_ptr<SessionDescriptionInterface> description_;
wu@webrtc.org91053e72013-08-10 07:18:04 +0000326 State state_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000327};
328
Henrik Boström87713d02015-08-25 09:53:21 +0200329class WebRtcSessionTest
deadbeefab9b2d12015-10-14 11:33:11 -0700330 : public testing::TestWithParam<RTCCertificateGenerationMethod>,
331 public sigslot::has_slots<> {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000332 protected:
333 // TODO Investigate why ChannelManager crashes, if it's created
334 // after stun_server.
335 WebRtcSessionTest()
deadbeef98e186c2017-05-16 18:00:06 -0700336 : vss_(new rtc::VirtualSocketServer()),
nisse7eaa4ea2017-05-08 05:25:41 -0700337 fss_(new rtc::FirewallSocketServer(vss_.get())),
338 thread_(fss_.get()),
339 media_engine_(new cricket::FakeMediaEngine()),
stefanc1aeaf02015-10-15 07:26:07 -0700340 data_engine_(new cricket::FakeDataEngine()),
deadbeef112b2e92017-02-10 20:13:37 -0800341 channel_manager_(new cricket::ChannelManager(
342 std::unique_ptr<cricket::MediaEngineInterface>(media_engine_),
343 std::unique_ptr<cricket::DataEngineInterface>(data_engine_),
344 rtc::Thread::Current())),
skvlad11a9cbf2016-10-07 11:53:05 -0700345 fake_call_(webrtc::Call::Config(&event_log_)),
stefanc1aeaf02015-10-15 07:26:07 -0700346 tdesc_factory_(new cricket::TransportDescriptionFactory()),
347 desc_factory_(
348 new cricket::MediaSessionDescriptionFactory(channel_manager_.get(),
349 tdesc_factory_.get())),
stefanc1aeaf02015-10-15 07:26:07 -0700350 stun_socket_addr_(
351 rtc::SocketAddress(kStunAddrHost, cricket::STUN_SERVER_PORT)),
352 stun_server_(cricket::TestStunServer::Create(Thread::Current(),
353 stun_socket_addr_)),
stefanc1aeaf02015-10-15 07:26:07 -0700354 metrics_observer_(new rtc::RefCountedObject<FakeMetricsObserver>()) {
buildbot@webrtc.org51c55082014-07-28 22:26:15 +0000355 cricket::ServerAddresses stun_servers;
356 stun_servers.insert(stun_socket_addr_);
357 allocator_.reset(new cricket::BasicPortAllocator(
358 &network_manager_,
359 stun_servers,
360 SocketAddress(), SocketAddress(), SocketAddress()));
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000361 allocator_->set_flags(cricket::PORTALLOCATOR_DISABLE_TCP |
Peter Thatcher7cbd1882015-09-17 18:54:52 -0700362 cricket::PORTALLOCATOR_DISABLE_RELAY);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000363 EXPECT_TRUE(channel_manager_->Init());
buildbot@webrtc.org41451d42014-05-03 05:39:45 +0000364 allocator_->set_step_delay(cricket::kMinimumStepDelay);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000365 }
366
367 void AddInterface(const SocketAddress& addr) {
368 network_manager_.AddInterface(addr);
369 }
370
Henrik Boströmd79599d2016-06-01 13:58:50 +0200371 // If |cert_generator| != null or |rtc_configuration| contains |certificates|
372 // then DTLS will be enabled unless explicitly disabled by |rtc_configuration|
373 // options. When DTLS is enabled a certificate will be used if provided,
374 // otherwise one will be generated using the |cert_generator|.
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000375 void Init(
zhihuang4dfb8ce2016-11-23 10:30:12 -0800376 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
deadbeef7914b8c2017-04-21 03:23:33 -0700377 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy,
378 const rtc::CryptoOptions& crypto_options) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000379 ASSERT_TRUE(session_.get() == NULL);
deadbeef953c2ce2017-01-09 14:53:41 -0800380 fake_sctp_transport_factory_ = new FakeSctpTransportFactory();
nisseeaabdf62017-05-05 02:23:02 -0700381 session_.reset(new WebRtcSessionForTest(&fake_call_,
382 channel_manager_.get(), cricket::MediaConfig(), &event_log_,
383 rtc::Thread::Current(), rtc::Thread::Current(),
zhihuang29ff8442016-07-27 11:07:25 -0700384 rtc::Thread::Current(), allocator_.get(), &observer_,
385 std::unique_ptr<cricket::TransportController>(
deadbeef7914b8c2017-04-21 03:23:33 -0700386 new cricket::TransportController(
387 rtc::Thread::Current(), rtc::Thread::Current(),
388 allocator_.get(),
389 /*redetermine_role_on_ice_restart=*/true, crypto_options)),
deadbeef953c2ce2017-01-09 14:53:41 -0800390 std::unique_ptr<FakeSctpTransportFactory>(
391 fake_sctp_transport_factory_)));
deadbeefab9b2d12015-10-14 11:33:11 -0700392 session_->SignalDataChannelOpenMessage.connect(
393 this, &WebRtcSessionTest::OnDataChannelOpenMessage);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000394
zhihuang4dfb8ce2016-11-23 10:30:12 -0800395 configuration_.rtcp_mux_policy = rtcp_mux_policy;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000396 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
397 observer_.ice_connection_state_);
398 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
399 observer_.ice_gathering_state_);
400
Henrik Boströmd03c23b2016-06-01 11:44:18 +0200401 EXPECT_TRUE(session_->Initialize(options_, std::move(cert_generator),
htaa2a49d92016-03-04 02:51:39 -0800402 configuration_));
jbauchac8869e2015-07-03 01:36:14 -0700403 session_->set_metrics_observer(metrics_observer_);
deadbeef7914b8c2017-04-21 03:23:33 -0700404 crypto_options_ = crypto_options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000405 }
406
deadbeefab9b2d12015-10-14 11:33:11 -0700407 void OnDataChannelOpenMessage(const std::string& label,
408 const InternalDataChannelInit& config) {
409 last_data_channel_label_ = label;
410 last_data_channel_config_ = config;
411 }
412
zhihuang4dfb8ce2016-11-23 10:30:12 -0800413 void Init() {
deadbeef7914b8c2017-04-21 03:23:33 -0700414 Init(nullptr, PeerConnectionInterface::kRtcpMuxPolicyNegotiate,
415 rtc::CryptoOptions());
zhihuang4dfb8ce2016-11-23 10:30:12 -0800416 }
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000417
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000418 void InitWithBundlePolicy(
419 PeerConnectionInterface::BundlePolicy bundle_policy) {
htaa2a49d92016-03-04 02:51:39 -0800420 configuration_.bundle_policy = bundle_policy;
421 Init();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -0700422 }
423
424 void InitWithRtcpMuxPolicy(
425 PeerConnectionInterface::RtcpMuxPolicy rtcp_mux_policy) {
426 PeerConnectionInterface::RTCConfiguration configuration;
deadbeef7914b8c2017-04-21 03:23:33 -0700427 Init(nullptr, rtcp_mux_policy, rtc::CryptoOptions());
428 }
429
Henrik Boström87713d02015-08-25 09:53:21 +0200430 // Successfully init with DTLS; with a certificate generated and supplied or
431 // with a store that generates it for us.
432 void InitWithDtls(RTCCertificateGenerationMethod cert_gen_method) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200433 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator;
Henrik Boström87713d02015-08-25 09:53:21 +0200434 if (cert_gen_method == ALREADY_GENERATED) {
htaa2a49d92016-03-04 02:51:39 -0800435 configuration_.certificates.push_back(
Henrik Boströmd79599d2016-06-01 13:58:50 +0200436 FakeRTCCertificateGenerator::GenerateCertificate());
Henrik Boström87713d02015-08-25 09:53:21 +0200437 } else if (cert_gen_method == DTLS_IDENTITY_STORE) {
Henrik Boströmd79599d2016-06-01 13:58:50 +0200438 cert_generator.reset(new FakeRTCCertificateGenerator());
439 cert_generator->set_should_fail(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200440 } else {
henrikg91d6ede2015-09-17 00:24:34 -0700441 RTC_CHECK(false);
Henrik Boström87713d02015-08-25 09:53:21 +0200442 }
zhihuang4dfb8ce2016-11-23 10:30:12 -0800443 Init(std::move(cert_generator),
deadbeef7914b8c2017-04-21 03:23:33 -0700444 PeerConnectionInterface::kRtcpMuxPolicyNegotiate,
445 rtc::CryptoOptions());
Henrik Boström87713d02015-08-25 09:53:21 +0200446 }
447
zhihuang1c378ed2017-08-17 14:10:50 -0700448 // The following convenience functions can be applied for both local side and
449 // remote side. The flags can be overwritten for different use cases.
deadbeefab9b2d12015-10-14 11:33:11 -0700450 void SendAudioVideoStream1() {
451 send_stream_1_ = true;
452 send_stream_2_ = false;
zhihuang1c378ed2017-08-17 14:10:50 -0700453 local_send_audio_ = true;
454 local_send_video_ = true;
455 remote_send_audio_ = true;
456 remote_send_video_ = true;
deadbeefab9b2d12015-10-14 11:33:11 -0700457 }
458
459 void SendAudioVideoStream2() {
460 send_stream_1_ = false;
461 send_stream_2_ = true;
zhihuang1c378ed2017-08-17 14:10:50 -0700462 local_send_audio_ = true;
463 local_send_video_ = true;
464 remote_send_audio_ = true;
465 remote_send_video_ = true;
deadbeefab9b2d12015-10-14 11:33:11 -0700466 }
467
468 void SendAudioVideoStream1And2() {
469 send_stream_1_ = true;
470 send_stream_2_ = true;
zhihuang1c378ed2017-08-17 14:10:50 -0700471 local_send_audio_ = true;
472 local_send_video_ = true;
473 remote_send_audio_ = true;
474 remote_send_video_ = true;
deadbeefab9b2d12015-10-14 11:33:11 -0700475 }
476
477 void SendNothing() {
478 send_stream_1_ = false;
479 send_stream_2_ = false;
zhihuang1c378ed2017-08-17 14:10:50 -0700480 local_send_audio_ = false;
481 local_send_video_ = false;
482 remote_send_audio_ = false;
483 remote_send_video_ = false;
deadbeefab9b2d12015-10-14 11:33:11 -0700484 }
485
486 void SendAudioOnlyStream2() {
487 send_stream_1_ = false;
488 send_stream_2_ = true;
zhihuang1c378ed2017-08-17 14:10:50 -0700489 local_send_audio_ = true;
490 local_send_video_ = false;
491 remote_send_audio_ = true;
492 remote_send_video_ = false;
deadbeefab9b2d12015-10-14 11:33:11 -0700493 }
494
495 void SendVideoOnlyStream2() {
496 send_stream_1_ = false;
497 send_stream_2_ = true;
zhihuang1c378ed2017-08-17 14:10:50 -0700498 local_send_audio_ = false;
499 local_send_video_ = true;
500 remote_send_audio_ = false;
501 remote_send_video_ = true;
deadbeefab9b2d12015-10-14 11:33:11 -0700502 }
503
zhihuang1c378ed2017-08-17 14:10:50 -0700504 // Helper function used to add a specific media section to the
505 // |session_options|.
506 void AddMediaSection(cricket::MediaType type,
507 const std::string& mid,
508 cricket::MediaContentDirection direction,
509 bool stopped,
510 cricket::MediaSessionOptions* opts) {
511 opts->media_description_options.push_back(cricket::MediaDescriptionOptions(
512 type, mid,
513 cricket::RtpTransceiverDirection::FromMediaContentDirection(direction),
514 stopped));
515 }
516
517 // Add the media sections to the options from |offered_media_sections_| when
518 // creating an answer or a new offer.
519 // This duplicates a lot of logic from PeerConnection but this can be fixed
520 // when PeerConnection and WebRtcSession are merged.
521 void AddExistingMediaSectionsAndSendersToOptions(
522 cricket::MediaSessionOptions* session_options,
523 bool send_audio,
524 bool recv_audio,
525 bool send_video,
526 bool recv_video) {
527 int num_sim_layer = 1;
528 for (auto media_description_options : offered_media_sections_) {
529 if (media_description_options.type == cricket::MEDIA_TYPE_AUDIO) {
530 bool stopped = !send_audio && !recv_audio;
531 auto media_desc_options = cricket::MediaDescriptionOptions(
532 cricket::MEDIA_TYPE_AUDIO, media_description_options.mid,
533 cricket::RtpTransceiverDirection(send_audio, recv_audio), stopped);
534 if (send_stream_1_ && send_audio) {
Steve Anton8ffb9c32017-08-31 15:45:38 -0700535 media_desc_options.AddAudioSender(kAudioTrack1, {kStream1});
zhihuang1c378ed2017-08-17 14:10:50 -0700536 }
537 if (send_stream_2_ && send_audio) {
Steve Anton8ffb9c32017-08-31 15:45:38 -0700538 media_desc_options.AddAudioSender(kAudioTrack2, {kStream2});
zhihuang1c378ed2017-08-17 14:10:50 -0700539 }
540 session_options->media_description_options.push_back(
541 media_desc_options);
542 } else if (media_description_options.type == cricket::MEDIA_TYPE_VIDEO) {
543 bool stopped = !send_video && !recv_video;
544 auto media_desc_options = cricket::MediaDescriptionOptions(
545 cricket::MEDIA_TYPE_VIDEO, media_description_options.mid,
546 cricket::RtpTransceiverDirection(send_video, recv_video), stopped);
547 if (send_stream_1_ && send_video) {
Steve Anton8ffb9c32017-08-31 15:45:38 -0700548 media_desc_options.AddVideoSender(kVideoTrack1, {kStream1},
zhihuang1c378ed2017-08-17 14:10:50 -0700549 num_sim_layer);
550 }
551 if (send_stream_2_ && send_video) {
Steve Anton8ffb9c32017-08-31 15:45:38 -0700552 media_desc_options.AddVideoSender(kVideoTrack2, {kStream2},
zhihuang1c378ed2017-08-17 14:10:50 -0700553 num_sim_layer);
554 }
555 session_options->media_description_options.push_back(
556 media_desc_options);
557 } else if (media_description_options.type == cricket::MEDIA_TYPE_DATA) {
558 session_options->media_description_options.push_back(
559 cricket::MediaDescriptionOptions(
560 cricket::MEDIA_TYPE_DATA, media_description_options.mid,
561 // Direction for data sections is meaningless, but legacy
562 // endpoints might expect sendrecv.
563 cricket::RtpTransceiverDirection(true, true), false));
564 } else {
565 RTC_NOTREACHED();
566 }
deadbeefab9b2d12015-10-14 11:33:11 -0700567 }
zhihuang1c378ed2017-08-17 14:10:50 -0700568 }
569
570 // Add the existing media sections first and then add new media sections if
571 // needed.
572 void AddMediaSectionsAndSendersToOptions(
573 cricket::MediaSessionOptions* session_options,
574 bool send_audio,
575 bool recv_audio,
576 bool send_video,
577 bool recv_video) {
578 AddExistingMediaSectionsAndSendersToOptions(
579 session_options, send_audio, recv_audio, send_video, recv_video);
580
581 if (!session_options->has_audio() && (send_audio || recv_audio)) {
582 cricket::MediaDescriptionOptions media_desc_options =
583 cricket::MediaDescriptionOptions(
584 cricket::MEDIA_TYPE_AUDIO, cricket::CN_AUDIO,
585 cricket::RtpTransceiverDirection(send_audio, recv_audio),
586 kActive);
587 if (send_stream_1_ && send_audio) {
Steve Anton8ffb9c32017-08-31 15:45:38 -0700588 media_desc_options.AddAudioSender(kAudioTrack1, {kStream1});
zhihuang1c378ed2017-08-17 14:10:50 -0700589 }
590 if (send_stream_2_ && send_audio) {
Steve Anton8ffb9c32017-08-31 15:45:38 -0700591 media_desc_options.AddAudioSender(kAudioTrack2, {kStream2});
zhihuang1c378ed2017-08-17 14:10:50 -0700592 }
593 session_options->media_description_options.push_back(media_desc_options);
594 offered_media_sections_.push_back(media_desc_options);
deadbeefab9b2d12015-10-14 11:33:11 -0700595 }
zhihuang1c378ed2017-08-17 14:10:50 -0700596
597 if (!session_options->has_video() && (send_video || recv_video)) {
598 cricket::MediaDescriptionOptions media_desc_options =
599 cricket::MediaDescriptionOptions(
600 cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO,
601 cricket::RtpTransceiverDirection(send_video, recv_video),
602 kActive);
603 int num_sim_layer = 1;
604 if (send_stream_1_ && send_video) {
Steve Anton8ffb9c32017-08-31 15:45:38 -0700605 media_desc_options.AddVideoSender(kVideoTrack1, {kStream1},
zhihuang1c378ed2017-08-17 14:10:50 -0700606 num_sim_layer);
607 }
608 if (send_stream_2_ && send_video) {
Steve Anton8ffb9c32017-08-31 15:45:38 -0700609 media_desc_options.AddVideoSender(kVideoTrack2, {kStream2},
zhihuang1c378ed2017-08-17 14:10:50 -0700610 num_sim_layer);
611 }
612 session_options->media_description_options.push_back(media_desc_options);
613 offered_media_sections_.push_back(media_desc_options);
deadbeefab9b2d12015-10-14 11:33:11 -0700614 }
zhihuang1c378ed2017-08-17 14:10:50 -0700615
616 if (!session_options->has_data() &&
617 (data_channel_ ||
618 session_options->data_channel_type != cricket::DCT_NONE)) {
619 cricket::MediaDescriptionOptions media_desc_options =
620 cricket::MediaDescriptionOptions(
621 cricket::MEDIA_TYPE_DATA, cricket::CN_DATA,
622 cricket::RtpTransceiverDirection(true, true), kActive);
623 if (session_options->data_channel_type == cricket::DCT_RTP) {
624 media_desc_options.AddRtpDataChannel(data_channel_->label(),
625 data_channel_->label());
626 }
627 session_options->media_description_options.push_back(media_desc_options);
628 offered_media_sections_.push_back(media_desc_options);
deadbeefab9b2d12015-10-14 11:33:11 -0700629 }
630 }
631
632 void GetOptionsForOffer(
633 const PeerConnectionInterface::RTCOfferAnswerOptions& rtc_options,
634 cricket::MediaSessionOptions* session_options) {
zhihuang1c378ed2017-08-17 14:10:50 -0700635 ExtractSharedMediaSessionOptions(rtc_options, session_options);
deadbeefab9b2d12015-10-14 11:33:11 -0700636
zhihuang1c378ed2017-08-17 14:10:50 -0700637 // |recv_X| is true by default if |offer_to_receive_X| is undefined.
638 bool recv_audio = rtc_options.offer_to_receive_audio != 0;
639 bool recv_video = rtc_options.offer_to_receive_video != 0;
640
641 AddMediaSectionsAndSendersToOptions(session_options, local_send_audio_,
642 recv_audio, local_send_video_,
643 recv_video);
deadbeefc80741f2015-10-22 13:14:45 -0700644 session_options->bundle_enabled =
645 session_options->bundle_enabled &&
646 (session_options->has_audio() || session_options->has_video() ||
647 session_options->has_data());
648
zhihuang1c378ed2017-08-17 14:10:50 -0700649 session_options->crypto_options = crypto_options_;
650 }
651
652 void GetOptionsForAnswer(cricket::MediaSessionOptions* session_options) {
653 AddExistingMediaSectionsAndSendersToOptions(
654 session_options, local_send_audio_, local_recv_audio_,
655 local_send_video_, local_recv_video_);
656
657 session_options->bundle_enabled =
658 session_options->bundle_enabled &&
659 (session_options->has_audio() || session_options->has_video() ||
660 session_options->has_data());
661
662 if (session_->data_channel_type() != cricket::DCT_RTP) {
663 session_options->data_channel_type = session_->data_channel_type();
olka3c747662017-08-17 06:50:32 -0700664 }
665
zhihuanga77e6bb2017-08-14 18:17:48 -0700666 session_options->crypto_options = crypto_options_;
667 }
668
zhihuang1c378ed2017-08-17 14:10:50 -0700669 void GetOptionsForRemoteAnswer(
670 cricket::MediaSessionOptions* session_options) {
671 bool recv_audio = local_send_audio_ || remote_recv_audio_;
672 bool recv_video = local_send_video_ || remote_recv_video_;
673 bool send_audio = false;
674 bool send_video = false;
zhihuanga77e6bb2017-08-14 18:17:48 -0700675
zhihuang1c378ed2017-08-17 14:10:50 -0700676 AddExistingMediaSectionsAndSendersToOptions(
677 session_options, send_audio, recv_audio, send_video, recv_video);
678
zhihuanga77e6bb2017-08-14 18:17:48 -0700679 session_options->bundle_enabled =
680 session_options->bundle_enabled &&
681 (session_options->has_audio() || session_options->has_video() ||
682 session_options->has_data());
683
684 if (session_->data_channel_type() != cricket::DCT_RTP) {
685 session_options->data_channel_type = session_->data_channel_type();
deadbeefab9b2d12015-10-14 11:33:11 -0700686 }
jbauchcb560652016-08-04 05:20:32 -0700687
deadbeef7914b8c2017-04-21 03:23:33 -0700688 session_options->crypto_options = crypto_options_;
deadbeefab9b2d12015-10-14 11:33:11 -0700689 }
690
zhihuang1c378ed2017-08-17 14:10:50 -0700691 void GetOptionsForAudioOnlyRemoteOffer(
692 cricket::MediaSessionOptions* session_options) {
693 remote_recv_audio_ = true;
694 remote_recv_video_ = false;
695 GetOptionsForRemoteOffer(session_options);
696 }
697
698 void GetOptionsForRemoteOffer(cricket::MediaSessionOptions* session_options) {
699 AddMediaSectionsAndSendersToOptions(session_options, remote_send_audio_,
700 remote_recv_audio_, remote_send_video_,
701 remote_recv_video_);
702 session_options->bundle_enabled =
703 (session_options->has_audio() || session_options->has_video() ||
704 session_options->has_data());
705
706 if (session_->data_channel_type() != cricket::DCT_RTP) {
707 session_options->data_channel_type = session_->data_channel_type();
708 }
709
710 session_options->crypto_options = crypto_options_;
711 }
712
deadbeefab9b2d12015-10-14 11:33:11 -0700713 // Creates a local offer and applies it. Starts ICE.
714 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000715 // to decide which streams to create.
716 void InitiateCall() {
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000717 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000718 SetLocalDescriptionWithoutError(offer);
719 EXPECT_TRUE_WAIT(PeerConnectionInterface::kIceGatheringNew !=
720 observer_.ice_gathering_state_,
721 kIceCandidatesTimeout);
722 }
723
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000724 SessionDescriptionInterface* CreateOffer() {
725 PeerConnectionInterface::RTCOfferAnswerOptions options;
726 options.offer_to_receive_audio =
727 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000728 return CreateOffer(options);
729 }
730
wu@webrtc.org91053e72013-08-10 07:18:04 +0000731 SessionDescriptionInterface* CreateOffer(
htaa2a49d92016-03-04 02:51:39 -0800732 const PeerConnectionInterface::RTCOfferAnswerOptions options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000733 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest>
wu@webrtc.org91053e72013-08-10 07:18:04 +0000734 observer = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -0700735 cricket::MediaSessionOptions session_options;
736 GetOptionsForOffer(options, &session_options);
737 session_->CreateOffer(observer, options, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000738 EXPECT_TRUE_WAIT(
739 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000740 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000741 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000742 }
743
744 SessionDescriptionInterface* CreateAnswer(
htaa2a49d92016-03-04 02:51:39 -0800745 const cricket::MediaSessionOptions& options) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000746 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observer
wu@webrtc.org91053e72013-08-10 07:18:04 +0000747 = new WebRtcSessionCreateSDPObserverForTest();
htaa2a49d92016-03-04 02:51:39 -0800748 cricket::MediaSessionOptions session_options = options;
749 GetOptionsForAnswer(&session_options);
htaa2a49d92016-03-04 02:51:39 -0800750 session_->CreateAnswer(observer, session_options);
wu@webrtc.org91053e72013-08-10 07:18:04 +0000751 EXPECT_TRUE_WAIT(
752 observer->state() != WebRtcSessionCreateSDPObserverForTest::kInit,
wu@webrtc.org822fbd82013-08-15 23:38:54 +0000753 2000);
mallinath@webrtc.orga5506692013-08-12 21:18:15 +0000754 return observer->ReleaseDescription();
wu@webrtc.org91053e72013-08-10 07:18:04 +0000755 }
756
htaa2a49d92016-03-04 02:51:39 -0800757 SessionDescriptionInterface* CreateAnswer() {
758 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -0700759 options.bundle_enabled = true;
htaa2a49d92016-03-04 02:51:39 -0800760 return CreateAnswer(options);
761 }
762
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000763 // Set the internal fake description factories to do DTLS-SRTP.
764 void SetFactoryDtlsSrtp() {
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000765 desc_factory_->set_secure(cricket::SEC_DISABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000766 std::string identity_name = "WebRTC" +
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000767 rtc::ToString(rtc::CreateRandomId());
Torbjorn Granlundb6d4ec42015-08-17 14:08:59 +0200768 // Confirmed to work with KT_RSA and KT_ECDSA.
kwiberg0eb15ed2015-12-17 03:04:15 -0800769 tdesc_factory_->set_certificate(
jbauch555604a2016-04-26 03:13:22 -0700770 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
kwiberg0eb15ed2015-12-17 03:04:15 -0800771 rtc::SSLIdentity::Generate(identity_name, rtc::KT_DEFAULT))));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000772 tdesc_factory_->set_secure(cricket::SEC_REQUIRED);
773 }
774
deadbeef0ed85b22016-02-23 17:24:52 -0800775 // Compares ufrag/password only for the specified |media_type|.
776 bool IceUfragPwdEqual(const cricket::SessionDescription* desc1,
777 const cricket::SessionDescription* desc2,
778 cricket::MediaType media_type) {
779 if (desc1->contents().size() != desc2->contents().size()) {
780 return false;
781 }
782
783 const cricket::ContentInfo* cinfo =
784 cricket::GetFirstMediaContent(desc1->contents(), media_type);
785 const cricket::TransportDescription* transport_desc1 =
786 desc1->GetTransportDescriptionByName(cinfo->name);
787 const cricket::TransportDescription* transport_desc2 =
788 desc2->GetTransportDescriptionByName(cinfo->name);
789 if (!transport_desc1 || !transport_desc2) {
790 return false;
791 }
792 if (transport_desc1->ice_pwd != transport_desc2->ice_pwd ||
793 transport_desc1->ice_ufrag != transport_desc2->ice_ufrag) {
794 return false;
795 }
796 return true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000797 }
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000798
deadbeef0ed85b22016-02-23 17:24:52 -0800799 // Sets ufrag/pwd for specified |media_type|.
800 void SetIceUfragPwd(SessionDescriptionInterface* current_desc,
801 cricket::MediaType media_type,
802 const std::string& ufrag,
803 const std::string& pwd) {
804 cricket::SessionDescription* desc = current_desc->description();
805 const cricket::ContentInfo* cinfo =
806 cricket::GetFirstMediaContent(desc->contents(), media_type);
807 TransportInfo* transport_info = desc->GetTransportInfoByName(cinfo->name);
808 cricket::TransportDescription* transport_desc =
809 &transport_info->description;
810 transport_desc->ice_ufrag = ufrag;
811 transport_desc->ice_pwd = pwd;
812 }
813
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000814 // Creates a remote offer and and applies it as a remote description,
815 // creates a local answer and applies is as a local description.
deadbeefab9b2d12015-10-14 11:33:11 -0700816 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000817 // to decide which local and remote streams to create.
818 void CreateAndSetRemoteOfferAndLocalAnswer() {
819 SessionDescriptionInterface* offer = CreateRemoteOffer();
820 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -0800821 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000822 SetLocalDescriptionWithoutError(answer);
823 }
824 void SetLocalDescriptionWithoutError(SessionDescriptionInterface* desc) {
zhihuang1c378ed2017-08-17 14:10:50 -0700825 ASSERT_TRUE(session_->SetLocalDescription(desc, nullptr));
deadbeefcbecd352015-09-23 11:50:27 -0700826 session_->MaybeStartGathering();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000827 }
828 void SetLocalDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700829 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000830 SetLocalDescriptionWithoutError(desc);
831 EXPECT_EQ(expected_state, session_->state());
832 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000833 void SetLocalDescriptionExpectError(const std::string& action,
834 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000835 SessionDescriptionInterface* desc) {
836 std::string error;
837 EXPECT_FALSE(session_->SetLocalDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000838 std::string sdp_type = "local ";
839 sdp_type.append(action);
840 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000841 EXPECT_NE(std::string::npos, error.find(expected_error));
842 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000843 void SetLocalDescriptionOfferExpectError(const std::string& expected_error,
844 SessionDescriptionInterface* desc) {
845 SetLocalDescriptionExpectError(SessionDescriptionInterface::kOffer,
846 expected_error, desc);
847 }
848 void SetLocalDescriptionAnswerExpectError(const std::string& expected_error,
849 SessionDescriptionInterface* desc) {
850 SetLocalDescriptionExpectError(SessionDescriptionInterface::kAnswer,
851 expected_error, desc);
852 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000853 void SetRemoteDescriptionWithoutError(SessionDescriptionInterface* desc) {
zhihuang1c378ed2017-08-17 14:10:50 -0700854 ASSERT_TRUE(session_->SetRemoteDescription(desc, nullptr));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000855 }
856 void SetRemoteDescriptionExpectState(SessionDescriptionInterface* desc,
deadbeefd59daf82015-10-14 15:02:44 -0700857 WebRtcSession::State expected_state) {
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000858 SetRemoteDescriptionWithoutError(desc);
859 EXPECT_EQ(expected_state, session_->state());
860 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000861 void SetRemoteDescriptionExpectError(const std::string& action,
862 const std::string& expected_error,
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000863 SessionDescriptionInterface* desc) {
864 std::string error;
865 EXPECT_FALSE(session_->SetRemoteDescription(desc, &error));
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000866 std::string sdp_type = "remote ";
867 sdp_type.append(action);
868 EXPECT_NE(std::string::npos, error.find(sdp_type));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000869 EXPECT_NE(std::string::npos, error.find(expected_error));
870 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000871 void SetRemoteDescriptionOfferExpectError(
872 const std::string& expected_error, SessionDescriptionInterface* desc) {
873 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kOffer,
874 expected_error, desc);
875 }
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +0000876 void SetRemoteDescriptionAnswerExpectError(
877 const std::string& expected_error, SessionDescriptionInterface* desc) {
878 SetRemoteDescriptionExpectError(SessionDescriptionInterface::kAnswer,
879 expected_error, desc);
880 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000881
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000882 JsepSessionDescription* CreateRemoteOfferWithVersion(
883 cricket::MediaSessionOptions options,
884 cricket::SecurePolicy secure_policy,
885 const std::string& session_version,
886 const SessionDescriptionInterface* current_desc) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000887 std::string session_id = rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000888 const cricket::SessionDescription* cricket_desc = NULL;
889 if (current_desc) {
890 cricket_desc = current_desc->description();
891 session_id = current_desc->session_id();
892 }
893
894 desc_factory_->set_secure(secure_policy);
895 JsepSessionDescription* offer(
896 new JsepSessionDescription(JsepSessionDescription::kOffer));
897 if (!offer->Initialize(desc_factory_->CreateOffer(options, cricket_desc),
898 session_id, session_version)) {
899 delete offer;
900 offer = NULL;
901 }
902 return offer;
903 }
904 JsepSessionDescription* CreateRemoteOffer(
905 cricket::MediaSessionOptions options) {
906 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
907 kSessionVersion, NULL);
908 }
909 JsepSessionDescription* CreateRemoteOffer(
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +0000910 cricket::MediaSessionOptions options, cricket::SecurePolicy sdes_policy) {
911 return CreateRemoteOfferWithVersion(
912 options, sdes_policy, kSessionVersion, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000913 }
914 JsepSessionDescription* CreateRemoteOffer(
915 cricket::MediaSessionOptions options,
916 const SessionDescriptionInterface* current_desc) {
917 return CreateRemoteOfferWithVersion(options, cricket::SEC_ENABLED,
918 kSessionVersion, current_desc);
919 }
920
Steve Anton6d64e9a2017-09-12 09:44:05 -0700921 SessionDescriptionInterface* CreateRemoteOfferWithSctpPort(
922 const char* sctp_stream_name,
923 int new_port,
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000924 cricket::MediaSessionOptions options) {
925 options.data_channel_type = cricket::DCT_SCTP;
zhihuang1c378ed2017-08-17 14:10:50 -0700926 GetOptionsForRemoteOffer(&options);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000927 return ChangeSDPSctpPort(new_port, CreateRemoteOffer(options));
928 }
929
930 // Takes ownership of offer_basis (and deletes it).
Steve Anton6d64e9a2017-09-12 09:44:05 -0700931 SessionDescriptionInterface* ChangeSDPSctpPort(
932 int new_port,
933 webrtc::SessionDescriptionInterface* offer_basis) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000934 // Stringify the input SDP, swap the 5000 for 'new_port' and create a new
935 // SessionDescription from the mutated string.
936 const char* default_port_str = "5000";
937 char new_port_str[16];
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000938 rtc::sprintfn(new_port_str, sizeof(new_port_str), "%d", new_port);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000939 std::string offer_str;
940 offer_basis->ToString(&offer_str);
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000941 rtc::replace_substrs(default_port_str, strlen(default_port_str),
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000942 new_port_str, strlen(new_port_str),
943 &offer_str);
Steve Anton6d64e9a2017-09-12 09:44:05 -0700944 SessionDescriptionInterface* offer =
945 CreateSessionDescription(offer_basis->type(), offer_str, nullptr);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000946 delete offer_basis;
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000947 return offer;
948 }
949
deadbeefab9b2d12015-10-14 11:33:11 -0700950 // Create a remote offer. Call SendAudioVideoStreamX()
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000951 // before this function to decide which streams to create.
952 JsepSessionDescription* CreateRemoteOffer() {
953 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -0700954 GetOptionsForRemoteOffer(&options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000955 return CreateRemoteOffer(options, session_->remote_description());
956 }
957
958 JsepSessionDescription* CreateRemoteAnswer(
959 const SessionDescriptionInterface* offer,
960 cricket::MediaSessionOptions options,
961 cricket::SecurePolicy policy) {
962 desc_factory_->set_secure(policy);
963 const std::string session_id =
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000964 rtc::ToString(rtc::CreateRandomId64());
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000965 JsepSessionDescription* answer(
966 new JsepSessionDescription(JsepSessionDescription::kAnswer));
967 if (!answer->Initialize(desc_factory_->CreateAnswer(offer->description(),
968 options, NULL),
969 session_id, kSessionVersion)) {
970 delete answer;
971 answer = NULL;
972 }
973 return answer;
974 }
975
976 JsepSessionDescription* CreateRemoteAnswer(
977 const SessionDescriptionInterface* offer,
978 cricket::MediaSessionOptions options) {
979 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
980 }
981
deadbeefab9b2d12015-10-14 11:33:11 -0700982 // Creates an answer session description.
983 // Call SendAudioVideoStreamX() before this function
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000984 // to decide which streams to create.
985 JsepSessionDescription* CreateRemoteAnswer(
986 const SessionDescriptionInterface* offer) {
987 cricket::MediaSessionOptions options;
htaa2a49d92016-03-04 02:51:39 -0800988 GetOptionsForAnswer(&options);
zhihuang1c378ed2017-08-17 14:10:50 -0700989 options.bundle_enabled = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000990 return CreateRemoteAnswer(offer, options, cricket::SEC_REQUIRED);
991 }
992
993 void TestSessionCandidatesWithBundleRtcpMux(bool bundle, bool rtcp_mux) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000994 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +0000995 Init();
deadbeefab9b2d12015-10-14 11:33:11 -0700996 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +0000997
998 PeerConnectionInterface::RTCOfferAnswerOptions options;
999 options.use_rtp_mux = bundle;
1000
1001 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001002 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1003 // and answer.
1004 SetLocalDescriptionWithoutError(offer);
1005
kwibergd1fe2812016-04-27 06:47:29 -07001006 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001007 CreateRemoteAnswer(session_->local_description()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001008 std::string sdp;
1009 EXPECT_TRUE(answer->ToString(&sdp));
1010
1011 size_t expected_candidate_num = 2;
1012 if (!rtcp_mux) {
1013 // If rtcp_mux is enabled we should expect 4 candidates - host and srflex
1014 // for rtp and rtcp.
1015 expected_candidate_num = 4;
1016 // Disable rtcp-mux from the answer
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001017 const std::string kRtcpMux = "a=rtcp-mux";
1018 const std::string kXRtcpMux = "a=xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001019 rtc::replace_substrs(kRtcpMux.c_str(), kRtcpMux.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001020 kXRtcpMux.c_str(), kXRtcpMux.length(),
1021 &sdp);
1022 }
1023
1024 SessionDescriptionInterface* new_answer = CreateSessionDescription(
1025 JsepSessionDescription::kAnswer, sdp, NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001026
1027 // SetRemoteDescription to enable rtcp mux.
henrike@webrtc.org723d6832013-07-12 16:04:50 +00001028 SetRemoteDescriptionWithoutError(new_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001029 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1030 EXPECT_EQ(expected_candidate_num, observer_.mline_0_candidates_.size());
deadbeefcbecd352015-09-23 11:50:27 -07001031 if (bundle) {
1032 EXPECT_EQ(0, observer_.mline_1_candidates_.size());
1033 } else {
1034 EXPECT_EQ(expected_candidate_num, observer_.mline_1_candidates_.size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001035 }
1036 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001037
zhihuang3a334652016-05-05 18:37:49 -07001038 bool ContainsVideoCodecWithName(const SessionDescriptionInterface* desc,
1039 const std::string& codec_name) {
1040 for (const auto& content : desc->description()->contents()) {
1041 if (static_cast<cricket::MediaContentDescription*>(content.description)
1042 ->type() == cricket::MEDIA_TYPE_VIDEO) {
1043 const auto* mdesc =
1044 static_cast<cricket::VideoContentDescription*>(content.description);
1045 for (const auto& codec : mdesc->codecs()) {
1046 if (codec.name == codec_name) {
1047 return true;
1048 }
1049 }
1050 }
1051 }
1052 return false;
1053 }
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001054
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001055 // The method sets up a call from the session to itself, in a loopback
1056 // arrangement. It also uses a firewall rule to create a temporary
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001057 // disconnection, and then a permanent disconnection.
1058 // This code is placed in a method so that it can be invoked
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001059 // by multiple tests with different allocators (e.g. with and without BUNDLE).
1060 // While running the call, this method also checks if the session goes through
1061 // the correct sequence of ICE states when a connection is established,
1062 // broken, and re-established.
1063 // The Connection state should go:
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001064 // New -> Checking -> (Connected) -> Completed -> Disconnected -> Completed
1065 // -> Failed.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001066 // The Gathering state should go: New -> Gathering -> Completed.
guoweis@webrtc.org7169afd2014-12-04 17:59:29 +00001067
stefanc1aeaf02015-10-15 07:26:07 -07001068 void SetupLoopbackCall() {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001069 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001070 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001071 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001072
1073 EXPECT_EQ(PeerConnectionInterface::kIceGatheringNew,
1074 observer_.ice_gathering_state_);
1075 SetLocalDescriptionWithoutError(offer);
1076 EXPECT_EQ(PeerConnectionInterface::kIceConnectionNew,
1077 observer_.ice_connection_state_);
1078 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringGathering,
stefanc1aeaf02015-10-15 07:26:07 -07001079 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001080 EXPECT_TRUE_WAIT(observer_.oncandidatesready_, kIceCandidatesTimeout);
1081 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
stefanc1aeaf02015-10-15 07:26:07 -07001082 observer_.ice_gathering_state_, kIceCandidatesTimeout);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001083
1084 std::string sdp;
1085 offer->ToString(&sdp);
stefanc1aeaf02015-10-15 07:26:07 -07001086 SessionDescriptionInterface* desc = webrtc::CreateSessionDescription(
1087 JsepSessionDescription::kAnswer, sdp, nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001088 ASSERT_TRUE(desc != NULL);
1089 SetRemoteDescriptionWithoutError(desc);
1090
1091 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionChecking,
stefanc1aeaf02015-10-15 07:26:07 -07001092 observer_.ice_connection_state_, kIceCandidatesTimeout);
mallinath@webrtc.orgd3dc4242014-03-01 00:05:52 +00001093
mallinath@webrtc.org385857d2014-02-14 00:56:12 +00001094 // The ice connection state is "Connected" too briefly to catch in a test.
1095 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
stefanc1aeaf02015-10-15 07:26:07 -07001096 observer_.ice_connection_state_, kIceCandidatesTimeout);
1097 }
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001098
stefanc1aeaf02015-10-15 07:26:07 -07001099 void TestPacketOptions() {
Steve Antonede9ca52017-10-16 13:04:27 -07001100 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
stefanc1aeaf02015-10-15 07:26:07 -07001101
1102 SetupLoopbackCall();
1103
Danil Chapovalov33b01f22016-05-11 19:55:27 +02001104 // Wait for channel to be ready for sending.
1105 EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
stefanc1aeaf02015-10-15 07:26:07 -07001106 uint8_t test_packet[15] = {0};
1107 rtc::PacketOptions options;
1108 options.packet_id = 10;
1109 media_engine_->GetVideoChannel(0)
1110 ->SendRtp(test_packet, sizeof(test_packet), options);
1111
1112 const int kPacketTimeout = 2000;
deadbeef14461d42016-06-15 11:06:57 -07001113 EXPECT_EQ_WAIT(10, fake_call_.last_sent_nonnegative_packet_id(),
1114 kPacketTimeout);
stefanc1aeaf02015-10-15 07:26:07 -07001115 EXPECT_GT(fake_call_.last_sent_packet().send_time_ms, -1);
1116 }
1117
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001118 // Adds CN codecs to FakeMediaEngine and MediaDescriptionFactory.
1119 void AddCNCodecs() {
deadbeef67cf2c12016-04-13 10:07:16 -07001120 const cricket::AudioCodec kCNCodec1(102, "CN", 8000, 0, 1);
1121 const cricket::AudioCodec kCNCodec2(103, "CN", 16000, 0, 1);
wu@webrtc.org364f2042013-11-20 21:49:41 +00001122
1123 // Add kCNCodec for dtmf test.
ossudedfd282016-06-14 07:12:39 -07001124 std::vector<cricket::AudioCodec> codecs =
1125 media_engine_->audio_send_codecs();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001126 codecs.push_back(kCNCodec1);
1127 codecs.push_back(kCNCodec2);
1128 media_engine_->SetAudioCodecs(codecs);
ossu075af922016-06-14 03:29:38 -07001129 desc_factory_->set_audio_codecs(codecs, codecs);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001130 }
1131
1132 bool VerifyNoCNCodecs(const cricket::ContentInfo* content) {
1133 const cricket::ContentDescription* description = content->description;
nissec8ee8822017-01-18 07:20:55 -08001134 RTC_CHECK(description != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001135 const cricket::AudioContentDescription* audio_content_desc =
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00001136 static_cast<const cricket::AudioContentDescription*>(description);
nissec8ee8822017-01-18 07:20:55 -08001137 RTC_CHECK(audio_content_desc != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001138 for (size_t i = 0; i < audio_content_desc->codecs().size(); ++i) {
1139 if (audio_content_desc->codecs()[i].name == "CN")
1140 return false;
1141 }
1142 return true;
1143 }
1144
deadbeefab9b2d12015-10-14 11:33:11 -07001145 void CreateDataChannel() {
deadbeeffc648b62015-10-13 16:42:33 -07001146 webrtc::InternalDataChannelInit dci;
nissec8ee8822017-01-18 07:20:55 -08001147 RTC_CHECK(session_.get());
deadbeefab9b2d12015-10-14 11:33:11 -07001148 dci.reliable = session_->data_channel_type() == cricket::DCT_SCTP;
1149 data_channel_ = DataChannel::Create(
1150 session_.get(), session_->data_channel_type(), "datachannel", dci);
1151 }
1152
1153 void SetLocalDescriptionWithDataChannel() {
1154 CreateDataChannel();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001155 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001156 SetLocalDescriptionWithoutError(offer);
1157 }
1158
skvlad11a9cbf2016-10-07 11:53:05 -07001159 webrtc::RtcEventLogNullImpl event_log_;
nisse7eaa4ea2017-05-08 05:25:41 -07001160 std::unique_ptr<rtc::VirtualSocketServer> vss_;
1161 std::unique_ptr<rtc::FirewallSocketServer> fss_;
1162 rtc::AutoSocketServerThread thread_;
deadbeef112b2e92017-02-10 20:13:37 -08001163 // |media_engine_| and |data_engine_| are actually owned by
1164 // |channel_manager_|.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001165 cricket::FakeMediaEngine* media_engine_;
1166 cricket::FakeDataEngine* data_engine_;
deadbeef953c2ce2017-01-09 14:53:41 -08001167 // Actually owned by session_.
1168 FakeSctpTransportFactory* fake_sctp_transport_factory_ = nullptr;
kwibergd1fe2812016-04-27 06:47:29 -07001169 std::unique_ptr<cricket::ChannelManager> channel_manager_;
stefanc1aeaf02015-10-15 07:26:07 -07001170 cricket::FakeCall fake_call_;
kwibergd1fe2812016-04-27 06:47:29 -07001171 std::unique_ptr<cricket::TransportDescriptionFactory> tdesc_factory_;
1172 std::unique_ptr<cricket::MediaSessionDescriptionFactory> desc_factory_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001173 rtc::SocketAddress stun_socket_addr_;
kwibergd1fe2812016-04-27 06:47:29 -07001174 std::unique_ptr<cricket::TestStunServer> stun_server_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00001175 rtc::FakeNetworkManager network_manager_;
kwibergd1fe2812016-04-27 06:47:29 -07001176 std::unique_ptr<cricket::BasicPortAllocator> allocator_;
wu@webrtc.org97077a32013-10-25 21:18:33 +00001177 PeerConnectionFactoryInterface::Options options_;
htaa2a49d92016-03-04 02:51:39 -08001178 PeerConnectionInterface::RTCConfiguration configuration_;
kwibergd1fe2812016-04-27 06:47:29 -07001179 std::unique_ptr<WebRtcSessionForTest> session_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001180 MockIceObserver observer_;
1181 cricket::FakeVideoMediaChannel* video_channel_;
1182 cricket::FakeVoiceMediaChannel* voice_channel_;
jbauchac8869e2015-07-03 01:36:14 -07001183 rtc::scoped_refptr<FakeMetricsObserver> metrics_observer_;
deadbeefab9b2d12015-10-14 11:33:11 -07001184 // The following flags affect options created for CreateOffer/CreateAnswer.
1185 bool send_stream_1_ = false;
1186 bool send_stream_2_ = false;
zhihuang1c378ed2017-08-17 14:10:50 -07001187 bool local_send_audio_ = false;
1188 bool local_send_video_ = false;
1189 bool local_recv_audio_ = true;
1190 bool local_recv_video_ = true;
1191 bool remote_send_audio_ = false;
1192 bool remote_send_video_ = false;
1193 bool remote_recv_audio_ = true;
1194 bool remote_recv_video_ = true;
1195 std::vector<cricket::MediaDescriptionOptions> offered_media_sections_;
deadbeefab9b2d12015-10-14 11:33:11 -07001196 rtc::scoped_refptr<DataChannel> data_channel_;
1197 // Last values received from data channel creation signal.
1198 std::string last_data_channel_label_;
1199 InternalDataChannelInit last_data_channel_config_;
deadbeef7914b8c2017-04-21 03:23:33 -07001200 rtc::CryptoOptions crypto_options_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001201};
1202
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001203TEST_F(WebRtcSessionTest, TestSessionCandidates) {
1204 TestSessionCandidatesWithBundleRtcpMux(false, false);
1205}
1206
1207// Below test cases (TestSessionCandidatesWith*) verify the candidates gathered
1208// with rtcp-mux and/or bundle.
1209TEST_F(WebRtcSessionTest, TestSessionCandidatesWithRtcpMux) {
1210 TestSessionCandidatesWithBundleRtcpMux(false, true);
1211}
1212
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001213TEST_F(WebRtcSessionTest, TestSessionCandidatesWithBundleRtcpMux) {
1214 TestSessionCandidatesWithBundleRtcpMux(true, true);
1215}
1216
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001217TEST_F(WebRtcSessionTest, SetSdpFailedOnInvalidSdp) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001218 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001219 SessionDescriptionInterface* offer = NULL;
1220 // Since |offer| is NULL, there's no way to tell if it's an offer or answer.
1221 std::string unknown_action;
1222 SetLocalDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1223 SetRemoteDescriptionExpectError(unknown_action, kInvalidSdp, offer);
1224}
1225
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001226// Test creating offers and receive answers and make sure the
1227// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001228TEST_F(WebRtcSessionTest, TestCreateSdesOfferReceiveSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001229 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001230 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001231 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001232 const std::string session_id_orig = offer->session_id();
1233 const std::string session_version_orig = offer->session_version();
1234 SetLocalDescriptionWithoutError(offer);
1235
deadbeefab9b2d12015-10-14 11:33:11 -07001236 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001237 SessionDescriptionInterface* answer =
1238 CreateRemoteAnswer(session_->local_description());
1239 SetRemoteDescriptionWithoutError(answer);
1240
1241 video_channel_ = media_engine_->GetVideoChannel(0);
1242 voice_channel_ = media_engine_->GetVoiceChannel(0);
1243
1244 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1245 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1246
1247 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1248 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1249
1250 ASSERT_EQ(1u, video_channel_->send_streams().size());
1251 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1252 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1253 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1254
1255 // Create new offer without send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001256 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001257 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001258
1259 // Verify the session id is the same and the session version is
1260 // increased.
1261 EXPECT_EQ(session_id_orig, offer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001262 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1263 rtc::FromString<uint64_t>(offer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001264
1265 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001266 EXPECT_EQ(0u, video_channel_->send_streams().size());
1267 EXPECT_EQ(0u, voice_channel_->send_streams().size());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001268
deadbeefab9b2d12015-10-14 11:33:11 -07001269 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001270 answer = CreateRemoteAnswer(session_->local_description());
1271 SetRemoteDescriptionWithoutError(answer);
1272
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001273 // Make sure the receive streams have not changed.
1274 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1275 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1276 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1277 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1278}
1279
1280// Test receiving offers and creating answers and make sure the
1281// media engine creates the expected send and receive streams.
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00001282TEST_F(WebRtcSessionTest, TestReceiveSdesOfferCreateSdesAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001283 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001284 SendAudioVideoStream2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001285 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001286 SetRemoteDescriptionWithoutError(offer);
1287
deadbeefab9b2d12015-10-14 11:33:11 -07001288 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001289 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001290 SetLocalDescriptionWithoutError(answer);
1291
1292 const std::string session_id_orig = answer->session_id();
1293 const std::string session_version_orig = answer->session_version();
1294
1295 video_channel_ = media_engine_->GetVideoChannel(0);
1296 voice_channel_ = media_engine_->GetVoiceChannel(0);
1297
htaa2a49d92016-03-04 02:51:39 -08001298 ASSERT_TRUE(video_channel_);
1299 ASSERT_TRUE(voice_channel_);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001300 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1301 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[0].id);
1302
1303 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1304 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[0].id);
1305
1306 ASSERT_EQ(1u, video_channel_->send_streams().size());
1307 EXPECT_TRUE(kVideoTrack1 == video_channel_->send_streams()[0].id);
1308 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1309 EXPECT_TRUE(kAudioTrack1 == voice_channel_->send_streams()[0].id);
1310
deadbeefab9b2d12015-10-14 11:33:11 -07001311 SendAudioVideoStream1And2();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001312 offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001313 SetRemoteDescriptionWithoutError(offer);
1314
1315 // Answer by turning off all send streams.
deadbeefab9b2d12015-10-14 11:33:11 -07001316 SendNothing();
htaa2a49d92016-03-04 02:51:39 -08001317 answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001318
1319 // Verify the session id is the same and the session version is
1320 // increased.
1321 EXPECT_EQ(session_id_orig, answer->session_id());
Peter Boström0c4e06b2015-10-07 12:23:21 +02001322 EXPECT_LT(rtc::FromString<uint64_t>(session_version_orig),
1323 rtc::FromString<uint64_t>(answer->session_version()));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001324 SetLocalDescriptionWithoutError(answer);
1325
1326 ASSERT_EQ(2u, video_channel_->recv_streams().size());
1327 EXPECT_TRUE(kVideoTrack1 == video_channel_->recv_streams()[0].id);
1328 EXPECT_TRUE(kVideoTrack2 == video_channel_->recv_streams()[1].id);
1329 ASSERT_EQ(2u, voice_channel_->recv_streams().size());
1330 EXPECT_TRUE(kAudioTrack1 == voice_channel_->recv_streams()[0].id);
1331 EXPECT_TRUE(kAudioTrack2 == voice_channel_->recv_streams()[1].id);
1332
1333 // Make sure we have no send streams.
1334 EXPECT_EQ(0u, video_channel_->send_streams().size());
1335 EXPECT_EQ(0u, voice_channel_->send_streams().size());
1336}
1337
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001338TEST_F(WebRtcSessionTest, SetLocalSdpFailedOnCreateChannel) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001339 Init();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001340 media_engine_->set_fail_create_channel(true);
1341
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001342 SessionDescriptionInterface* offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001343 ASSERT_TRUE(offer != NULL);
1344 // SetRemoteDescription and SetLocalDescription will take the ownership of
1345 // the offer.
1346 SetRemoteDescriptionOfferExpectError(kCreateChannelFailed, offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001347 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001348 ASSERT_TRUE(offer != NULL);
1349 SetLocalDescriptionOfferExpectError(kCreateChannelFailed, offer);
1350}
1351
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001352// Test that we can create and set an answer correctly when different
1353// SSL roles have been negotiated for different transports.
1354// See: https://bugs.chromium.org/p/webrtc/issues/detail?id=4525
1355TEST_P(WebRtcSessionTest, TestCreateAnswerWithDifferentSslRoles) {
1356 SendAudioVideoStream1();
1357 InitWithDtls(GetParam());
1358 SetFactoryDtlsSrtp();
1359
1360 SessionDescriptionInterface* offer = CreateOffer();
1361 SetLocalDescriptionWithoutError(offer);
1362
1363 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07001364 GetOptionsForAnswer(&options);
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001365
1366 // First, negotiate different SSL roles.
1367 SessionDescriptionInterface* answer =
1368 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
1369 TransportInfo* audio_transport_info =
1370 answer->description()->GetTransportInfoByName("audio");
1371 audio_transport_info->description.connection_role =
1372 cricket::CONNECTIONROLE_ACTIVE;
1373 TransportInfo* video_transport_info =
1374 answer->description()->GetTransportInfoByName("video");
1375 video_transport_info->description.connection_role =
1376 cricket::CONNECTIONROLE_PASSIVE;
1377 SetRemoteDescriptionWithoutError(answer);
1378
1379 // Now create an offer in the reverse direction, and ensure the initial
1380 // offerer responds with an answer with correct SSL roles.
1381 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1382 kSessionVersion,
1383 session_->remote_description());
1384 SetRemoteDescriptionWithoutError(offer);
1385
zhihuang1c378ed2017-08-17 14:10:50 -07001386 cricket::MediaSessionOptions answer_options;
1387 answer_options.bundle_enabled = true;
1388 answer = CreateAnswer(answer_options);
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001389 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1390 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1391 audio_transport_info->description.connection_role);
1392 video_transport_info = answer->description()->GetTransportInfoByName("video");
1393 EXPECT_EQ(cricket::CONNECTIONROLE_ACTIVE,
1394 video_transport_info->description.connection_role);
1395 SetLocalDescriptionWithoutError(answer);
1396
1397 // Lastly, start BUNDLE-ing on "audio", expecting that the "passive" role of
1398 // audio is transferred over to video in the answer that completes the BUNDLE
1399 // negotiation.
1400 options.bundle_enabled = true;
1401 offer = CreateRemoteOfferWithVersion(options, cricket::SEC_DISABLED,
1402 kSessionVersion,
1403 session_->remote_description());
1404 SetRemoteDescriptionWithoutError(offer);
zhihuang1c378ed2017-08-17 14:10:50 -07001405 answer = CreateAnswer(answer_options);
Taylor Brandstetterf475d362016-01-08 15:35:57 -08001406 audio_transport_info = answer->description()->GetTransportInfoByName("audio");
1407 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1408 audio_transport_info->description.connection_role);
1409 video_transport_info = answer->description()->GetTransportInfoByName("video");
1410 EXPECT_EQ(cricket::CONNECTIONROLE_PASSIVE,
1411 video_transport_info->description.connection_role);
1412 SetLocalDescriptionWithoutError(answer);
1413}
1414
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001415TEST_F(WebRtcSessionTest, TestSetLocalOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001416 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001417 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001418 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001419 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001420 SetLocalDescriptionWithoutError(offer);
1421
1422 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001423 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001424 SetLocalDescriptionWithoutError(offer2);
1425}
1426
1427TEST_F(WebRtcSessionTest, TestSetRemoteOfferTwice) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001428 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001429 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001430 // SetLocalDescription take ownership of offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001431 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001432 SetRemoteDescriptionWithoutError(offer);
1433
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001434 SessionDescriptionInterface* offer2 = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001435 SetRemoteDescriptionWithoutError(offer2);
1436}
1437
1438TEST_F(WebRtcSessionTest, TestSetLocalAndRemoteOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001439 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001440 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001441 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001442 SetLocalDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001443 offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07001444 SetRemoteDescriptionOfferExpectError("Called in wrong state: STATE_SENTOFFER",
1445 offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001446}
1447
1448TEST_F(WebRtcSessionTest, TestSetRemoteAndLocalOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001449 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001450 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001451 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001452 SetRemoteDescriptionWithoutError(offer);
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001453 offer = CreateOffer();
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001454 SetLocalDescriptionOfferExpectError(
deadbeefd59daf82015-10-14 15:02:44 -07001455 "Called in wrong state: STATE_RECEIVEDOFFER", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001456}
1457
1458TEST_F(WebRtcSessionTest, TestSetLocalPrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001459 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001460 SendNothing();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001461 SessionDescriptionInterface* offer = CreateRemoteOffer();
deadbeefd59daf82015-10-14 15:02:44 -07001462 SetRemoteDescriptionExpectState(offer, WebRtcSession::STATE_RECEIVEDOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001463
htaa2a49d92016-03-04 02:51:39 -08001464 JsepSessionDescription* pranswer =
1465 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001466 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
deadbeefd59daf82015-10-14 15:02:44 -07001467 SetLocalDescriptionExpectState(pranswer, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001468
deadbeefab9b2d12015-10-14 11:33:11 -07001469 SendAudioVideoStream1();
htaa2a49d92016-03-04 02:51:39 -08001470 JsepSessionDescription* pranswer2 =
1471 static_cast<JsepSessionDescription*>(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001472 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1473
deadbeefd59daf82015-10-14 15:02:44 -07001474 SetLocalDescriptionExpectState(pranswer2, WebRtcSession::STATE_SENTPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001475
deadbeefab9b2d12015-10-14 11:33:11 -07001476 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08001477 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefd59daf82015-10-14 15:02:44 -07001478 SetLocalDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001479}
1480
1481TEST_F(WebRtcSessionTest, TestSetRemotePrAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001482 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001483 SendNothing();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001484 SessionDescriptionInterface* offer = CreateOffer();
deadbeefd59daf82015-10-14 15:02:44 -07001485 SetLocalDescriptionExpectState(offer, WebRtcSession::STATE_SENTOFFER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001486
1487 JsepSessionDescription* pranswer =
1488 CreateRemoteAnswer(session_->local_description());
1489 pranswer->set_type(SessionDescriptionInterface::kPrAnswer);
1490
1491 SetRemoteDescriptionExpectState(pranswer,
deadbeefd59daf82015-10-14 15:02:44 -07001492 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001493
deadbeefab9b2d12015-10-14 11:33:11 -07001494 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001495 JsepSessionDescription* pranswer2 =
1496 CreateRemoteAnswer(session_->local_description());
1497 pranswer2->set_type(SessionDescriptionInterface::kPrAnswer);
1498
1499 SetRemoteDescriptionExpectState(pranswer2,
deadbeefd59daf82015-10-14 15:02:44 -07001500 WebRtcSession::STATE_RECEIVEDPRANSWER);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001501
deadbeefab9b2d12015-10-14 11:33:11 -07001502 SendAudioVideoStream2();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001503 SessionDescriptionInterface* answer =
1504 CreateRemoteAnswer(session_->local_description());
deadbeefd59daf82015-10-14 15:02:44 -07001505 SetRemoteDescriptionExpectState(answer, WebRtcSession::STATE_INPROGRESS);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001506}
1507
1508TEST_F(WebRtcSessionTest, TestSetLocalAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001509 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001510 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07001511 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001512
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001513 SessionDescriptionInterface* answer =
1514 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001515 SetLocalDescriptionAnswerExpectError("Called in wrong state: STATE_INIT",
1516 answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001517}
1518
1519TEST_F(WebRtcSessionTest, TestSetRemoteAnswerWithoutOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001520 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001521 SendNothing();
kwibergd1fe2812016-04-27 06:47:29 -07001522 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001523
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001524 SessionDescriptionInterface* answer =
1525 CreateRemoteAnswer(offer.get());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00001526 SetRemoteDescriptionAnswerExpectError(
1527 "Called in wrong state: STATE_INIT", answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001528}
1529
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001530// Verifies TransportProxy and media channels are created with content names
1531// present in the SessionDescription.
1532TEST_F(WebRtcSessionTest, TestChannelCreationsWithContentNames) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001533 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07001534 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07001535 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001536
1537 // CreateOffer creates session description with the content names "audio" and
deadbeefd59daf82015-10-14 15:02:44 -07001538 // "video". Goal is to modify these content names and verify transport
1539 // channels
1540 // in the WebRtcSession, as channels are created with the content names
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001541 // present in SDP.
1542 std::string sdp;
1543 EXPECT_TRUE(offer->ToString(&sdp));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001544
1545 SessionDescriptionInterface* modified_offer =
1546 CreateSessionDescription(JsepSessionDescription::kOffer, sdp, NULL);
1547
1548 SetRemoteDescriptionWithoutError(modified_offer);
1549
zhihuang1c378ed2017-08-17 14:10:50 -07001550 cricket::MediaSessionOptions answer_options;
1551 answer_options.bundle_enabled = false;
1552 SessionDescriptionInterface* answer = CreateAnswer(answer_options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001553 SetLocalDescriptionWithoutError(answer);
1554
deadbeef5bd5ca32017-02-10 11:31:50 -08001555 rtc::PacketTransportInternal* voice_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07001556 session_->voice_rtp_transport_channel();
1557 EXPECT_TRUE(voice_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08001558 EXPECT_EQ(voice_transport_channel->debug_name(),
zhihuang1c378ed2017-08-17 14:10:50 -07001559 "audio " + std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
deadbeef5bd5ca32017-02-10 11:31:50 -08001560 rtc::PacketTransportInternal* video_transport_channel =
deadbeefcbecd352015-09-23 11:50:27 -07001561 session_->video_rtp_transport_channel();
htaa2a49d92016-03-04 02:51:39 -08001562 ASSERT_TRUE(video_transport_channel != NULL);
johan669d69b2016-11-08 14:14:08 -08001563 EXPECT_EQ(video_transport_channel->debug_name(),
zhihuang1c378ed2017-08-17 14:10:50 -07001564 "video " + std::to_string(cricket::ICE_CANDIDATE_COMPONENT_RTP));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001565 EXPECT_TRUE((video_channel_ = media_engine_->GetVideoChannel(0)) != NULL);
1566 EXPECT_TRUE((voice_channel_ = media_engine_->GetVoiceChannel(0)) != NULL);
1567}
1568
1569// Test that an offer contains the correct media content descriptions based on
1570// the send streams when no constraints have been set.
1571TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001572 Init();
kwibergd1fe2812016-04-27 06:47:29 -07001573 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001574
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001575 ASSERT_TRUE(offer != NULL);
1576 const cricket::ContentInfo* content =
1577 cricket::GetFirstAudioContent(offer->description());
zhihuang1c378ed2017-08-17 14:10:50 -07001578 ASSERT_TRUE(content != NULL);
1579 EXPECT_EQ(
1580 cricket::MD_RECVONLY,
1581 static_cast<const cricket::AudioContentDescription*>(content->description)
1582 ->direction());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001583 content = cricket::GetFirstVideoContent(offer->description());
zhihuang1c378ed2017-08-17 14:10:50 -07001584 ASSERT_TRUE(content != NULL);
1585 EXPECT_EQ(
1586 cricket::MD_RECVONLY,
1587 static_cast<const cricket::VideoContentDescription*>(content->description)
1588 ->direction());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001589}
1590
1591// Test that an offer contains the correct media content descriptions based on
1592// the send streams when no constraints have been set.
1593TEST_F(WebRtcSessionTest, CreateOfferWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001594 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001595 // Test Audio only offer.
deadbeefab9b2d12015-10-14 11:33:11 -07001596 SendAudioOnlyStream2();
kwibergd1fe2812016-04-27 06:47:29 -07001597 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001598
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001599 const cricket::ContentInfo* content =
1600 cricket::GetFirstAudioContent(offer->description());
zhihuang1c378ed2017-08-17 14:10:50 -07001601 ASSERT_TRUE(content != NULL);
1602 EXPECT_EQ(
1603 cricket::MD_SENDRECV,
1604 static_cast<const cricket::AudioContentDescription*>(content->description)
1605 ->direction());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001606 content = cricket::GetFirstVideoContent(offer->description());
zhihuang1c378ed2017-08-17 14:10:50 -07001607 ASSERT_TRUE(content != NULL);
1608 EXPECT_EQ(
1609 cricket::MD_RECVONLY,
1610 static_cast<const cricket::VideoContentDescription*>(content->description)
1611 ->direction());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001612
1613 // Test Audio / Video offer.
deadbeefab9b2d12015-10-14 11:33:11 -07001614 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001615 offer.reset(CreateOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001616 content = cricket::GetFirstAudioContent(offer->description());
zhihuang1c378ed2017-08-17 14:10:50 -07001617 ASSERT_TRUE(content != NULL);
1618 EXPECT_EQ(
1619 cricket::MD_SENDRECV,
1620 static_cast<const cricket::AudioContentDescription*>(content->description)
1621 ->direction());
1622
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001623 content = cricket::GetFirstVideoContent(offer->description());
zhihuang1c378ed2017-08-17 14:10:50 -07001624 ASSERT_TRUE(content != NULL);
1625 EXPECT_EQ(
1626 cricket::MD_SENDRECV,
1627 static_cast<const cricket::VideoContentDescription*>(content->description)
1628 ->direction());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001629}
1630
1631// Test that an offer contains no media content descriptions if
1632// kOfferToReceiveVideo and kOfferToReceiveAudio constraints are set to false.
1633TEST_F(WebRtcSessionTest, CreateOfferWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001634 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001635 PeerConnectionInterface::RTCOfferAnswerOptions options;
1636 options.offer_to_receive_audio = 0;
1637 options.offer_to_receive_video = 0;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001638
kwibergd1fe2812016-04-27 06:47:29 -07001639 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001640
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001641 ASSERT_TRUE(offer != NULL);
1642 const cricket::ContentInfo* content =
1643 cricket::GetFirstAudioContent(offer->description());
1644 EXPECT_TRUE(content == NULL);
1645 content = cricket::GetFirstVideoContent(offer->description());
1646 EXPECT_TRUE(content == NULL);
1647}
1648
1649// Test that an offer contains only audio media content descriptions if
1650// kOfferToReceiveAudio constraints are set to true.
1651TEST_F(WebRtcSessionTest, CreateAudioOnlyOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001652 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001653 PeerConnectionInterface::RTCOfferAnswerOptions options;
1654 options.offer_to_receive_audio =
1655 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
zhihuang1c378ed2017-08-17 14:10:50 -07001656 options.offer_to_receive_video = 0;
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001657
kwibergd1fe2812016-04-27 06:47:29 -07001658 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001659
1660 const cricket::ContentInfo* content =
1661 cricket::GetFirstAudioContent(offer->description());
1662 EXPECT_TRUE(content != NULL);
1663 content = cricket::GetFirstVideoContent(offer->description());
1664 EXPECT_TRUE(content == NULL);
1665}
1666
1667// Test that an offer contains audio and video media content descriptions if
1668// kOfferToReceiveAudio and kOfferToReceiveVideo constraints are set to true.
1669TEST_F(WebRtcSessionTest, CreateOfferWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001670 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001671 // Test Audio / Video offer.
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001672 PeerConnectionInterface::RTCOfferAnswerOptions options;
1673 options.offer_to_receive_audio =
1674 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
1675 options.offer_to_receive_video =
1676 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
1677
kwibergd1fe2812016-04-27 06:47:29 -07001678 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001679
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001680 const cricket::ContentInfo* content =
1681 cricket::GetFirstAudioContent(offer->description());
jiayl@webrtc.orgc1723202014-09-08 20:44:36 +00001682 EXPECT_TRUE(content != NULL);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001683
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001684 content = cricket::GetFirstVideoContent(offer->description());
1685 EXPECT_TRUE(content != NULL);
1686
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001687 // Sets constraints to false and verifies that audio/video contents are
1688 // removed.
1689 options.offer_to_receive_audio = 0;
1690 options.offer_to_receive_video = 0;
zhihuang1c378ed2017-08-17 14:10:50 -07001691 // Remove the media sections added in previous offer.
1692 offered_media_sections_.clear();
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001693 offer.reset(CreateOffer(options));
1694
1695 content = cricket::GetFirstAudioContent(offer->description());
1696 EXPECT_TRUE(content == NULL);
1697 content = cricket::GetFirstVideoContent(offer->description());
1698 EXPECT_TRUE(content == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001699}
1700
1701// Test that an answer can not be created if the last remote description is not
1702// an offer.
1703TEST_F(WebRtcSessionTest, CreateAnswerWithoutAnOffer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001704 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001705 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001706 SetLocalDescriptionWithoutError(offer);
1707 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
1708 SetRemoteDescriptionWithoutError(answer);
htaa2a49d92016-03-04 02:51:39 -08001709 EXPECT_TRUE(CreateAnswer() == NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001710}
1711
1712// Test that an answer contains the correct media content descriptions when no
1713// constraints have been set.
1714TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001715 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001716 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07001717 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001718 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07001719 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001720 const cricket::ContentInfo* content =
1721 cricket::GetFirstAudioContent(answer->description());
1722 ASSERT_TRUE(content != NULL);
1723 EXPECT_FALSE(content->rejected);
1724
1725 content = cricket::GetFirstVideoContent(answer->description());
1726 ASSERT_TRUE(content != NULL);
1727 EXPECT_FALSE(content->rejected);
1728}
1729
1730// Test that an answer contains the correct media content descriptions when no
1731// constraints have been set and the offer only contain audio.
1732TEST_F(WebRtcSessionTest, CreateAudioAnswerWithoutConstraintsOrStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001733 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001734 // Create a remote offer with audio only.
1735 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07001736 GetOptionsForAudioOnlyRemoteOffer(&options);
jiayl@webrtc.org7d4891d2014-09-09 21:43:15 +00001737
kwibergd1fe2812016-04-27 06:47:29 -07001738 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001739 ASSERT_TRUE(cricket::GetFirstVideoContent(offer->description()) == NULL);
1740 ASSERT_TRUE(cricket::GetFirstAudioContent(offer->description()) != NULL);
1741
1742 SetRemoteDescriptionWithoutError(offer.release());
kwibergd1fe2812016-04-27 06:47:29 -07001743 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001744 const cricket::ContentInfo* content =
1745 cricket::GetFirstAudioContent(answer->description());
1746 ASSERT_TRUE(content != NULL);
1747 EXPECT_FALSE(content->rejected);
1748
1749 EXPECT_TRUE(cricket::GetFirstVideoContent(answer->description()) == NULL);
1750}
1751
1752// Test that an answer contains the correct media content descriptions when no
1753// constraints have been set.
1754TEST_F(WebRtcSessionTest, CreateAnswerWithoutConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001755 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001756 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07001757 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001758 SetRemoteDescriptionWithoutError(offer.release());
1759 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07001760 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07001761 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001762 const cricket::ContentInfo* content =
1763 cricket::GetFirstAudioContent(answer->description());
1764 ASSERT_TRUE(content != NULL);
1765 EXPECT_FALSE(content->rejected);
1766
1767 content = cricket::GetFirstVideoContent(answer->description());
1768 ASSERT_TRUE(content != NULL);
1769 EXPECT_FALSE(content->rejected);
1770}
1771
1772// Test that an answer contains the correct media content descriptions when
1773// constraints have been set but no stream is sent.
1774TEST_F(WebRtcSessionTest, CreateAnswerWithConstraintsWithoutStreams) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001775 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001776 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07001777 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001778 SetRemoteDescriptionWithoutError(offer.release());
1779
htaa2a49d92016-03-04 02:51:39 -08001780 cricket::MediaSessionOptions session_options;
zhihuang1c378ed2017-08-17 14:10:50 -07001781 remote_send_audio_ = false;
1782 remote_send_video_ = false;
1783 local_recv_audio_ = false;
1784 local_recv_video_ = false;
kwibergd1fe2812016-04-27 06:47:29 -07001785 std::unique_ptr<SessionDescriptionInterface> answer(
htaa2a49d92016-03-04 02:51:39 -08001786 CreateAnswer(session_options));
1787
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001788 const cricket::ContentInfo* content =
1789 cricket::GetFirstAudioContent(answer->description());
1790 ASSERT_TRUE(content != NULL);
1791 EXPECT_TRUE(content->rejected);
1792
1793 content = cricket::GetFirstVideoContent(answer->description());
1794 ASSERT_TRUE(content != NULL);
1795 EXPECT_TRUE(content->rejected);
1796}
1797
1798// Test that an answer contains the correct media content descriptions when
1799// constraints have been set and streams are sent.
1800TEST_F(WebRtcSessionTest, CreateAnswerWithConstraints) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001801 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001802 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07001803 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001804 SetRemoteDescriptionWithoutError(offer.release());
1805
htaa2a49d92016-03-04 02:51:39 -08001806 cricket::MediaSessionOptions options;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001807 // Test with a stream with tracks.
deadbeefab9b2d12015-10-14 11:33:11 -07001808 SendAudioVideoStream1();
kwibergd1fe2812016-04-27 06:47:29 -07001809 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001810
1811 // TODO(perkj): Should the direction be set to SEND_ONLY?
1812 const cricket::ContentInfo* content =
1813 cricket::GetFirstAudioContent(answer->description());
1814 ASSERT_TRUE(content != NULL);
1815 EXPECT_FALSE(content->rejected);
1816
1817 // TODO(perkj): Should the direction be set to SEND_ONLY?
1818 content = cricket::GetFirstVideoContent(answer->description());
1819 ASSERT_TRUE(content != NULL);
1820 EXPECT_FALSE(content->rejected);
1821}
1822
1823TEST_F(WebRtcSessionTest, CreateOfferWithoutCNCodecs) {
1824 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001825 Init();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001826 PeerConnectionInterface::RTCOfferAnswerOptions options;
1827 options.offer_to_receive_audio =
1828 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
1829 options.voice_activity_detection = false;
1830
kwibergd1fe2812016-04-27 06:47:29 -07001831 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer(options));
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001832
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001833 const cricket::ContentInfo* content =
1834 cricket::GetFirstAudioContent(offer->description());
1835 EXPECT_TRUE(content != NULL);
1836 EXPECT_TRUE(VerifyNoCNCodecs(content));
1837}
1838
1839TEST_F(WebRtcSessionTest, CreateAnswerWithoutCNCodecs) {
1840 AddCNCodecs();
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001841 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001842 // Create a remote offer with audio and video content.
kwibergd1fe2812016-04-27 06:47:29 -07001843 std::unique_ptr<JsepSessionDescription> offer(CreateRemoteOffer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001844 SetRemoteDescriptionWithoutError(offer.release());
1845
htaa2a49d92016-03-04 02:51:39 -08001846 cricket::MediaSessionOptions options;
1847 options.vad_enabled = false;
kwibergd1fe2812016-04-27 06:47:29 -07001848 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer(options));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001849 const cricket::ContentInfo* content =
1850 cricket::GetFirstAudioContent(answer->description());
1851 ASSERT_TRUE(content != NULL);
1852 EXPECT_TRUE(VerifyNoCNCodecs(content));
1853}
1854
1855// This test verifies the call setup when remote answer with audio only and
1856// later updates with video.
1857TEST_F(WebRtcSessionTest, TestAVOfferWithAudioOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001858 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001859 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
1860 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
1861
deadbeefab9b2d12015-10-14 11:33:11 -07001862 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001863 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001864
1865 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07001866 AddMediaSection(cricket::MEDIA_TYPE_AUDIO, cricket::CN_AUDIO,
1867 cricket::MD_RECVONLY, kActive, &options);
1868 AddMediaSection(cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO,
1869 cricket::MD_INACTIVE, kStopped, &options);
1870 local_recv_video_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001871 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer, options);
1872
1873 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1874 // and answer;
1875 SetLocalDescriptionWithoutError(offer);
1876 SetRemoteDescriptionWithoutError(answer);
1877
1878 video_channel_ = media_engine_->GetVideoChannel(0);
1879 voice_channel_ = media_engine_->GetVoiceChannel(0);
1880
zhihuang1c378ed2017-08-17 14:10:50 -07001881 ASSERT_TRUE(video_channel_ == nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001882
1883 ASSERT_EQ(0u, voice_channel_->recv_streams().size());
1884 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1885 EXPECT_EQ(kAudioTrack1, voice_channel_->send_streams()[0].id);
1886
1887 // Let the remote end update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07001888 SendAudioVideoStream2();
zhihuang1c378ed2017-08-17 14:10:50 -07001889 local_recv_video_ = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001890 CreateAndSetRemoteOfferAndLocalAnswer();
1891
1892 video_channel_ = media_engine_->GetVideoChannel(0);
1893 voice_channel_ = media_engine_->GetVoiceChannel(0);
1894
zhihuang1c378ed2017-08-17 14:10:50 -07001895 ASSERT_TRUE(video_channel_ != nullptr);
1896 ASSERT_TRUE(voice_channel_ != nullptr);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001897
1898 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1899 ASSERT_EQ(1u, video_channel_->send_streams().size());
1900 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
1901 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
1902 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1903 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1904 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
1905 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
1906
1907 // Change session back to audio only.
zhihuang1c378ed2017-08-17 14:10:50 -07001908 // The remote side doesn't send and recv video.
deadbeefab9b2d12015-10-14 11:33:11 -07001909 SendAudioOnlyStream2();
zhihuang1c378ed2017-08-17 14:10:50 -07001910 remote_recv_video_ = false;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001911 CreateAndSetRemoteOfferAndLocalAnswer();
1912
zhihuang1c378ed2017-08-17 14:10:50 -07001913 video_channel_ = media_engine_->GetVideoChannel(0);
1914 voice_channel_ = media_engine_->GetVoiceChannel(0);
1915
1916 // The audio is expected to be rejected.
1917 EXPECT_TRUE(video_channel_ == nullptr);
1918
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001919 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1920 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
1921 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1922 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
1923}
1924
1925// This test verifies the call setup when remote answer with video only and
1926// later updates with audio.
1927TEST_F(WebRtcSessionTest, TestAVOfferWithVideoOnlyAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00001928 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001929 EXPECT_TRUE(media_engine_->GetVideoChannel(0) == NULL);
1930 EXPECT_TRUE(media_engine_->GetVoiceChannel(0) == NULL);
deadbeefab9b2d12015-10-14 11:33:11 -07001931 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00001932 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001933
1934 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07001935 AddMediaSection(cricket::MEDIA_TYPE_AUDIO, cricket::CN_AUDIO,
1936 cricket::MD_INACTIVE, kStopped, &options);
1937 AddMediaSection(cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO,
1938 cricket::MD_RECVONLY, kActive, &options);
1939 local_recv_audio_ = false;
1940 SessionDescriptionInterface* answer =
1941 CreateRemoteAnswer(offer, options, cricket::SEC_ENABLED);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001942
1943 // SetLocalDescription and SetRemoteDescriptions takes ownership of offer
1944 // and answer.
1945 SetLocalDescriptionWithoutError(offer);
1946 SetRemoteDescriptionWithoutError(answer);
1947
1948 video_channel_ = media_engine_->GetVideoChannel(0);
1949 voice_channel_ = media_engine_->GetVoiceChannel(0);
1950
1951 ASSERT_TRUE(voice_channel_ == NULL);
1952 ASSERT_TRUE(video_channel_ != NULL);
1953
1954 EXPECT_EQ(0u, video_channel_->recv_streams().size());
1955 ASSERT_EQ(1u, video_channel_->send_streams().size());
1956 EXPECT_EQ(kVideoTrack1, video_channel_->send_streams()[0].id);
1957
1958 // Update the session descriptions, with Audio and Video.
deadbeefab9b2d12015-10-14 11:33:11 -07001959 SendAudioVideoStream2();
zhihuang1c378ed2017-08-17 14:10:50 -07001960 local_recv_audio_ = true;
1961 SessionDescriptionInterface* offer2 = CreateRemoteOffer();
1962 SetRemoteDescriptionWithoutError(offer2);
1963 cricket::MediaSessionOptions answer_options;
1964 // Disable the bundling here. If the media is bundled on audio
1965 // transport, then we can't reject the audio because switching the bundled
1966 // transport is not currently supported.
1967 // (https://bugs.chromium.org/p/webrtc/issues/detail?id=6704)
1968 answer_options.bundle_enabled = false;
1969 SessionDescriptionInterface* answer2 = CreateAnswer(answer_options);
1970 SetLocalDescriptionWithoutError(answer2);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001971
1972 voice_channel_ = media_engine_->GetVoiceChannel(0);
olka3c747662017-08-17 06:50:32 -07001973
zhihuang1c378ed2017-08-17 14:10:50 -07001974 ASSERT_TRUE(voice_channel_ != NULL);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001975 ASSERT_EQ(1u, voice_channel_->recv_streams().size());
1976 ASSERT_EQ(1u, voice_channel_->send_streams().size());
1977 EXPECT_EQ(kAudioTrack2, voice_channel_->recv_streams()[0].id);
1978 EXPECT_EQ(kAudioTrack2, voice_channel_->send_streams()[0].id);
1979
1980 // Change session back to video only.
zhihuang1c378ed2017-08-17 14:10:50 -07001981 // The remote side doesn't send and recv audio.
deadbeefab9b2d12015-10-14 11:33:11 -07001982 SendVideoOnlyStream2();
zhihuang1c378ed2017-08-17 14:10:50 -07001983 remote_recv_audio_ = false;
1984 SessionDescriptionInterface* offer3 = CreateRemoteOffer();
1985 SetRemoteDescriptionWithoutError(offer3);
1986 SessionDescriptionInterface* answer3 = CreateAnswer(answer_options);
1987 SetLocalDescriptionWithoutError(answer3);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001988
1989 video_channel_ = media_engine_->GetVideoChannel(0);
1990 voice_channel_ = media_engine_->GetVoiceChannel(0);
1991
zhihuang1c378ed2017-08-17 14:10:50 -07001992 // The video is expected to be rejected.
1993 EXPECT_TRUE(voice_channel_ == nullptr);
1994
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001995 ASSERT_EQ(1u, video_channel_->recv_streams().size());
1996 EXPECT_EQ(kVideoTrack2, video_channel_->recv_streams()[0].id);
1997 ASSERT_EQ(1u, video_channel_->send_streams().size());
1998 EXPECT_EQ(kVideoTrack2, video_channel_->send_streams()[0].id);
1999}
2000
Donald Curtisd4f769d2015-05-28 09:48:21 -07002001// Test that candidates sent to the "video" transport do not get pushed down to
deadbeefd59daf82015-10-14 15:02:44 -07002002// the "audio" transport channel when bundling.
Donald Curtisd4f769d2015-05-28 09:48:21 -07002003TEST_F(WebRtcSessionTest, TestIgnoreCandidatesForUnusedTransportWhenBundling) {
2004 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
2005
2006 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002007 SendAudioVideoStream1();
Donald Curtisd4f769d2015-05-28 09:48:21 -07002008
zhihuang1c378ed2017-08-17 14:10:50 -07002009 cricket::MediaSessionOptions offer_options;
2010 GetOptionsForRemoteOffer(&offer_options);
2011 offer_options.bundle_enabled = true;
Donald Curtisd4f769d2015-05-28 09:48:21 -07002012
zhihuang1c378ed2017-08-17 14:10:50 -07002013 SessionDescriptionInterface* offer = CreateRemoteOffer(offer_options);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002014 SetRemoteDescriptionWithoutError(offer);
2015
zhihuang1c378ed2017-08-17 14:10:50 -07002016 cricket::MediaSessionOptions answer_options;
2017 answer_options.bundle_enabled = true;
2018 SessionDescriptionInterface* answer = CreateAnswer(answer_options);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002019 SetLocalDescriptionWithoutError(answer);
2020
deadbeefcbecd352015-09-23 11:50:27 -07002021 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2022 session_->video_rtp_transport_channel());
Donald Curtisd4f769d2015-05-28 09:48:21 -07002023
deadbeefcbecd352015-09-23 11:50:27 -07002024 cricket::BaseChannel* voice_channel = session_->voice_channel();
nissec8ee8822017-01-18 07:20:55 -08002025 ASSERT_TRUE(voice_channel != NULL);
Donald Curtisd4f769d2015-05-28 09:48:21 -07002026
2027 // Checks if one of the transport channels contains a connection using a given
2028 // port.
eladalon1cc5fc32017-08-23 04:15:18 -07002029 auto connection_with_remote_port = [this](int port) {
hbosdf6075a2016-12-19 04:58:02 -08002030 std::unique_ptr<webrtc::SessionStats> stats = session_->GetStats_s();
2031 for (auto& kv : stats->transport_stats) {
deadbeefcbecd352015-09-23 11:50:27 -07002032 for (auto& chan_stat : kv.second.channel_stats) {
2033 for (auto& conn_info : chan_stat.connection_infos) {
2034 if (conn_info.remote_candidate.address().port() == port) {
2035 return true;
2036 }
Donald Curtisd4f769d2015-05-28 09:48:21 -07002037 }
2038 }
2039 }
2040 return false;
2041 };
2042
2043 EXPECT_FALSE(connection_with_remote_port(5000));
2044 EXPECT_FALSE(connection_with_remote_port(5001));
2045 EXPECT_FALSE(connection_with_remote_port(6000));
2046
2047 // The way the *_WAIT checks work is they only wait if the condition fails,
2048 // which does not help in the case where state is not changing. This is
2049 // problematic in this test since we want to verify that adding a video
2050 // candidate does _not_ change state. So we interleave candidates and assume
2051 // that messages are executed in the order they were posted.
2052
2053 // First audio candidate.
2054 cricket::Candidate candidate0;
2055 candidate0.set_address(rtc::SocketAddress("1.1.1.1", 5000));
2056 candidate0.set_component(1);
2057 candidate0.set_protocol("udp");
zhihuang38989e52017-03-21 11:04:53 -07002058 candidate0.set_type("local");
Donald Curtisd4f769d2015-05-28 09:48:21 -07002059 JsepIceCandidate ice_candidate0(kMediaContentName0, kMediaContentIndex0,
2060 candidate0);
2061 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate0));
2062
2063 // Video candidate.
2064 cricket::Candidate candidate1;
2065 candidate1.set_address(rtc::SocketAddress("1.1.1.1", 6000));
2066 candidate1.set_component(1);
2067 candidate1.set_protocol("udp");
zhihuang38989e52017-03-21 11:04:53 -07002068 candidate1.set_type("local");
Donald Curtisd4f769d2015-05-28 09:48:21 -07002069 JsepIceCandidate ice_candidate1(kMediaContentName1, kMediaContentIndex1,
2070 candidate1);
2071 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate1));
2072
2073 // Second audio candidate.
2074 cricket::Candidate candidate2;
2075 candidate2.set_address(rtc::SocketAddress("1.1.1.1", 5001));
2076 candidate2.set_component(1);
2077 candidate2.set_protocol("udp");
zhihuang38989e52017-03-21 11:04:53 -07002078 candidate2.set_type("local");
Donald Curtisd4f769d2015-05-28 09:48:21 -07002079 JsepIceCandidate ice_candidate2(kMediaContentName0, kMediaContentIndex0,
2080 candidate2);
2081 EXPECT_TRUE(session_->ProcessIceMessage(&ice_candidate2));
2082
2083 EXPECT_TRUE_WAIT(connection_with_remote_port(5000), 1000);
2084 EXPECT_TRUE_WAIT(connection_with_remote_port(5001), 1000);
2085
2086 // No need here for a _WAIT check since we are checking that state hasn't
2087 // changed: if this is false we would be doing waits for nothing and if this
2088 // is true then there will be no messages processed anyways.
2089 EXPECT_FALSE(connection_with_remote_port(6000));
2090}
2091
deadbeefcbecd352015-09-23 11:50:27 -07002092// kBundlePolicyBalanced BUNDLE policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002093TEST_F(WebRtcSessionTest, TestBalancedBundleInAnswer) {
2094 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002095 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002096
2097 PeerConnectionInterface::RTCOfferAnswerOptions options;
2098 options.use_rtp_mux = true;
2099
2100 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002101 SetLocalDescriptionWithoutError(offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07002102
deadbeefcbecd352015-09-23 11:50:27 -07002103 EXPECT_NE(session_->voice_rtp_transport_channel(),
2104 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002105
deadbeefab9b2d12015-10-14 11:33:11 -07002106 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002107 SessionDescriptionInterface* answer =
2108 CreateRemoteAnswer(session_->local_description());
2109 SetRemoteDescriptionWithoutError(answer);
2110
deadbeefcbecd352015-09-23 11:50:27 -07002111 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2112 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002113}
2114
deadbeefcbecd352015-09-23 11:50:27 -07002115// kBundlePolicyBalanced BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07002116TEST_F(WebRtcSessionTest, TestBalancedNoBundleInAnswer) {
2117 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002118 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002119
Donald Curtis0e209b02015-03-24 09:29:54 -07002120 PeerConnectionInterface::RTCOfferAnswerOptions options;
2121 options.use_rtp_mux = true;
2122
2123 SessionDescriptionInterface* offer = CreateOffer(options);
2124 SetLocalDescriptionWithoutError(offer);
2125
deadbeefcbecd352015-09-23 11:50:27 -07002126 EXPECT_NE(session_->voice_rtp_transport_channel(),
2127 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002128
deadbeefab9b2d12015-10-14 11:33:11 -07002129 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002130
2131 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07002132 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07002133 CreateRemoteAnswer(session_->local_description()));
2134 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2135 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2136 JsepSessionDescription* modified_answer =
2137 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2138 modified_answer->Initialize(answer_copy, "1", "1");
2139 SetRemoteDescriptionWithoutError(modified_answer); //
2140
deadbeefcbecd352015-09-23 11:50:27 -07002141 EXPECT_NE(session_->voice_rtp_transport_channel(),
2142 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002143}
2144
2145// kBundlePolicyMaxBundle policy with BUNDLE in the answer.
2146TEST_F(WebRtcSessionTest, TestMaxBundleBundleInAnswer) {
2147 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07002148 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07002149
2150 PeerConnectionInterface::RTCOfferAnswerOptions options;
2151 options.use_rtp_mux = true;
2152
2153 SessionDescriptionInterface* offer = CreateOffer(options);
2154 SetLocalDescriptionWithoutError(offer);
2155
deadbeefcbecd352015-09-23 11:50:27 -07002156 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2157 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002158
deadbeefab9b2d12015-10-14 11:33:11 -07002159 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002160 SessionDescriptionInterface* answer =
2161 CreateRemoteAnswer(session_->local_description());
2162 SetRemoteDescriptionWithoutError(answer);
2163
deadbeefcbecd352015-09-23 11:50:27 -07002164 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2165 session_->video_rtp_transport_channel());
2166}
2167
2168// kBundlePolicyMaxBundle policy with BUNDLE in the answer, but no
2169// audio content in the answer.
2170TEST_F(WebRtcSessionTest, TestMaxBundleRejectAudio) {
2171 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07002172 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07002173
2174 PeerConnectionInterface::RTCOfferAnswerOptions options;
2175 options.use_rtp_mux = true;
2176
2177 SessionDescriptionInterface* offer = CreateOffer(options);
2178 SetLocalDescriptionWithoutError(offer);
2179
2180 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2181 session_->video_rtp_transport_channel());
2182
zhihuang1c378ed2017-08-17 14:10:50 -07002183 SendVideoOnlyStream2();
2184 local_send_audio_ = false;
2185 remote_recv_audio_ = false;
deadbeefcbecd352015-09-23 11:50:27 -07002186 cricket::MediaSessionOptions recv_options;
zhihuang1c378ed2017-08-17 14:10:50 -07002187 GetOptionsForRemoteAnswer(&recv_options);
deadbeefcbecd352015-09-23 11:50:27 -07002188 SessionDescriptionInterface* answer =
2189 CreateRemoteAnswer(session_->local_description(), recv_options);
2190 SetRemoteDescriptionWithoutError(answer);
2191
deadbeefd59daf82015-10-14 15:02:44 -07002192 EXPECT_TRUE(nullptr == session_->voice_channel());
2193 EXPECT_TRUE(nullptr != session_->video_rtp_transport_channel());
deadbeefcbecd352015-09-23 11:50:27 -07002194
deadbeefd59daf82015-10-14 15:02:44 -07002195 session_->Close();
2196 EXPECT_TRUE(nullptr == session_->voice_rtp_transport_channel());
2197 EXPECT_TRUE(nullptr == session_->voice_rtcp_transport_channel());
2198 EXPECT_TRUE(nullptr == session_->video_rtp_transport_channel());
2199 EXPECT_TRUE(nullptr == session_->video_rtcp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002200}
2201
2202// kBundlePolicyMaxBundle policy but no BUNDLE in the answer.
2203TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInAnswer) {
2204 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07002205 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002206
Donald Curtis0e209b02015-03-24 09:29:54 -07002207 PeerConnectionInterface::RTCOfferAnswerOptions options;
2208 options.use_rtp_mux = true;
2209
2210 SessionDescriptionInterface* offer = CreateOffer(options);
2211 SetLocalDescriptionWithoutError(offer);
2212
deadbeefcbecd352015-09-23 11:50:27 -07002213 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2214 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002215
deadbeefab9b2d12015-10-14 11:33:11 -07002216 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002217
2218 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07002219 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002220 CreateRemoteAnswer(session_->local_description()));
2221 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2222 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2223 JsepSessionDescription* modified_answer =
2224 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2225 modified_answer->Initialize(answer_copy, "1", "1");
2226 SetRemoteDescriptionWithoutError(modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002227
deadbeefcbecd352015-09-23 11:50:27 -07002228 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2229 session_->video_rtp_transport_channel());
2230}
2231
2232// kBundlePolicyMaxBundle policy with BUNDLE in the remote offer.
2233TEST_F(WebRtcSessionTest, TestMaxBundleBundleInRemoteOffer) {
2234 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07002235 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07002236
2237 SessionDescriptionInterface* offer = CreateRemoteOffer();
2238 SetRemoteDescriptionWithoutError(offer);
2239
2240 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2241 session_->video_rtp_transport_channel());
2242
deadbeefab9b2d12015-10-14 11:33:11 -07002243 SendAudioVideoStream2();
htaa2a49d92016-03-04 02:51:39 -08002244 SessionDescriptionInterface* answer = CreateAnswer();
deadbeefcbecd352015-09-23 11:50:27 -07002245 SetLocalDescriptionWithoutError(answer);
2246
2247 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2248 session_->video_rtp_transport_channel());
2249}
2250
2251// kBundlePolicyMaxBundle policy but no BUNDLE in the remote offer.
2252TEST_F(WebRtcSessionTest, TestMaxBundleNoBundleInRemoteOffer) {
2253 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07002254 SendAudioVideoStream1();
deadbeefcbecd352015-09-23 11:50:27 -07002255
2256 // Remove BUNDLE from the offer.
kwibergd1fe2812016-04-27 06:47:29 -07002257 std::unique_ptr<SessionDescriptionInterface> offer(CreateRemoteOffer());
deadbeefcbecd352015-09-23 11:50:27 -07002258 cricket::SessionDescription* offer_copy = offer->description()->Copy();
2259 offer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2260 JsepSessionDescription* modified_offer =
2261 new JsepSessionDescription(JsepSessionDescription::kOffer);
2262 modified_offer->Initialize(offer_copy, "1", "1");
2263
2264 // Expect an error when applying the remote description
2265 SetRemoteDescriptionExpectError(JsepSessionDescription::kOffer,
2266 kCreateChannelFailed, modified_offer);
Donald Curtis0e209b02015-03-24 09:29:54 -07002267}
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002268
Peter Thatcher4eddf182015-04-30 10:55:59 -07002269// kBundlePolicyMaxCompat bundle policy and answer contains BUNDLE.
Donald Curtis0e209b02015-03-24 09:29:54 -07002270TEST_F(WebRtcSessionTest, TestMaxCompatBundleInAnswer) {
2271 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07002272 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002273
zhihuang1c378ed2017-08-17 14:10:50 -07002274 PeerConnectionInterface::RTCOfferAnswerOptions rtc_options;
2275 rtc_options.use_rtp_mux = true;
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002276
zhihuang1c378ed2017-08-17 14:10:50 -07002277 SessionDescriptionInterface* offer = CreateOffer(rtc_options);
Donald Curtis0e209b02015-03-24 09:29:54 -07002278 SetLocalDescriptionWithoutError(offer);
2279
deadbeefcbecd352015-09-23 11:50:27 -07002280 EXPECT_NE(session_->voice_rtp_transport_channel(),
2281 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002282
deadbeefab9b2d12015-10-14 11:33:11 -07002283 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002284 SessionDescriptionInterface* answer =
2285 CreateRemoteAnswer(session_->local_description());
2286 SetRemoteDescriptionWithoutError(answer);
2287
2288 // This should lead to an audio-only call but isn't implemented
2289 // correctly yet.
deadbeefcbecd352015-09-23 11:50:27 -07002290 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2291 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002292}
2293
deadbeefcbecd352015-09-23 11:50:27 -07002294// kBundlePolicyMaxCompat BUNDLE policy but no BUNDLE in the answer.
Donald Curtis0e209b02015-03-24 09:29:54 -07002295TEST_F(WebRtcSessionTest, TestMaxCompatNoBundleInAnswer) {
2296 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxCompat);
deadbeefab9b2d12015-10-14 11:33:11 -07002297 SendAudioVideoStream1();
Donald Curtis0e209b02015-03-24 09:29:54 -07002298 PeerConnectionInterface::RTCOfferAnswerOptions options;
2299 options.use_rtp_mux = true;
2300
2301 SessionDescriptionInterface* offer = CreateOffer(options);
2302 SetLocalDescriptionWithoutError(offer);
2303
deadbeefcbecd352015-09-23 11:50:27 -07002304 EXPECT_NE(session_->voice_rtp_transport_channel(),
2305 session_->video_rtp_transport_channel());
Donald Curtis0e209b02015-03-24 09:29:54 -07002306
deadbeefab9b2d12015-10-14 11:33:11 -07002307 SendAudioVideoStream2();
Donald Curtis0e209b02015-03-24 09:29:54 -07002308
2309 // Remove BUNDLE from the answer.
kwibergd1fe2812016-04-27 06:47:29 -07002310 std::unique_ptr<SessionDescriptionInterface> answer(
Donald Curtis0e209b02015-03-24 09:29:54 -07002311 CreateRemoteAnswer(session_->local_description()));
2312 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2313 answer_copy->RemoveGroupByName(cricket::GROUP_TYPE_BUNDLE);
2314 JsepSessionDescription* modified_answer =
2315 new JsepSessionDescription(JsepSessionDescription::kAnswer);
2316 modified_answer->Initialize(answer_copy, "1", "1");
2317 SetRemoteDescriptionWithoutError(modified_answer); //
2318
deadbeefcbecd352015-09-23 11:50:27 -07002319 EXPECT_NE(session_->voice_rtp_transport_channel(),
2320 session_->video_rtp_transport_channel());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002321}
2322
Peter Thatcher4eddf182015-04-30 10:55:59 -07002323// kBundlePolicyMaxbundle and then we call SetRemoteDescription first.
2324TEST_F(WebRtcSessionTest, TestMaxBundleWithSetRemoteDescriptionFirst) {
2325 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyMaxBundle);
deadbeefab9b2d12015-10-14 11:33:11 -07002326 SendAudioVideoStream1();
Peter Thatcher4eddf182015-04-30 10:55:59 -07002327
2328 PeerConnectionInterface::RTCOfferAnswerOptions options;
2329 options.use_rtp_mux = true;
2330
2331 SessionDescriptionInterface* offer = CreateOffer(options);
2332 SetRemoteDescriptionWithoutError(offer);
2333
deadbeefcbecd352015-09-23 11:50:27 -07002334 EXPECT_EQ(session_->voice_rtp_transport_channel(),
2335 session_->video_rtp_transport_channel());
Peter Thatcher4eddf182015-04-30 10:55:59 -07002336}
2337
skvlad6c87a672016-05-17 17:49:52 -07002338// Adding a new channel to a BUNDLE which is already connected should directly
2339// assign the bundle transport to the channel, without first setting a
2340// disconnected non-bundle transport and then replacing it. The application
2341// should not receive any changes in the ICE state.
2342TEST_F(WebRtcSessionTest, TestAddChannelToConnectedBundle) {
Steve Antonede9ca52017-10-16 13:04:27 -07002343 AddInterface(rtc::SocketAddress(kClientAddrHost1, kClientAddrPort));
skvlad6c87a672016-05-17 17:49:52 -07002344 // Both BUNDLE and RTCP-mux need to be enabled for the ICE state to remain
2345 // connected. Disabling either of these two means that we need to wait for the
2346 // answer to find out if more transports are needed.
2347 configuration_.bundle_policy =
2348 PeerConnectionInterface::kBundlePolicyMaxBundle;
skvlad6c87a672016-05-17 17:49:52 -07002349 options_.disable_encryption = true;
deadbeef7914b8c2017-04-21 03:23:33 -07002350 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
skvlad6c87a672016-05-17 17:49:52 -07002351
2352 // Negotiate an audio channel with MAX_BUNDLE enabled.
2353 SendAudioOnlyStream2();
2354 SessionDescriptionInterface* offer = CreateOffer();
2355 SetLocalDescriptionWithoutError(offer);
2356 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
2357 observer_.ice_gathering_state_, kIceCandidatesTimeout);
2358 std::string sdp;
2359 offer->ToString(&sdp);
2360 SessionDescriptionInterface* answer = webrtc::CreateSessionDescription(
2361 JsepSessionDescription::kAnswer, sdp, nullptr);
2362 ASSERT_TRUE(answer != NULL);
2363 SetRemoteDescriptionWithoutError(answer);
2364
2365 // Wait for the ICE state to stabilize.
2366 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
2367 observer_.ice_connection_state_, kIceCandidatesTimeout);
2368 observer_.ice_connection_state_history_.clear();
2369
2370 // Now add a video channel which should be using the same bundle transport.
2371 SendAudioVideoStream2();
2372 offer = CreateOffer();
2373 offer->ToString(&sdp);
2374 SetLocalDescriptionWithoutError(offer);
2375 answer = webrtc::CreateSessionDescription(JsepSessionDescription::kAnswer,
2376 sdp, nullptr);
2377 ASSERT_TRUE(answer != NULL);
2378 SetRemoteDescriptionWithoutError(answer);
2379
2380 // Wait for ICE state to stabilize
2381 rtc::Thread::Current()->ProcessMessages(0);
2382 EXPECT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
2383 observer_.ice_connection_state_, kIceCandidatesTimeout);
2384
2385 // No ICE state changes are expected to happen.
2386 EXPECT_EQ(0, observer_.ice_connection_state_history_.size());
2387}
2388
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002389TEST_F(WebRtcSessionTest, TestRequireRtcpMux) {
2390 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyRequire);
deadbeefab9b2d12015-10-14 11:33:11 -07002391 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002392
2393 PeerConnectionInterface::RTCOfferAnswerOptions options;
2394 SessionDescriptionInterface* offer = CreateOffer(options);
2395 SetLocalDescriptionWithoutError(offer);
2396
deadbeefcbecd352015-09-23 11:50:27 -07002397 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
2398 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002399
deadbeefab9b2d12015-10-14 11:33:11 -07002400 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002401 SessionDescriptionInterface* answer =
2402 CreateRemoteAnswer(session_->local_description());
2403 SetRemoteDescriptionWithoutError(answer);
2404
deadbeefcbecd352015-09-23 11:50:27 -07002405 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
2406 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002407}
2408
2409TEST_F(WebRtcSessionTest, TestNegotiateRtcpMux) {
2410 InitWithRtcpMuxPolicy(PeerConnectionInterface::kRtcpMuxPolicyNegotiate);
deadbeefab9b2d12015-10-14 11:33:11 -07002411 SendAudioVideoStream1();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002412
2413 PeerConnectionInterface::RTCOfferAnswerOptions options;
2414 SessionDescriptionInterface* offer = CreateOffer(options);
2415 SetLocalDescriptionWithoutError(offer);
2416
deadbeefcbecd352015-09-23 11:50:27 -07002417 EXPECT_TRUE(session_->voice_rtcp_transport_channel() != NULL);
2418 EXPECT_TRUE(session_->video_rtcp_transport_channel() != NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002419
deadbeefab9b2d12015-10-14 11:33:11 -07002420 SendAudioVideoStream2();
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002421 SessionDescriptionInterface* answer =
2422 CreateRemoteAnswer(session_->local_description());
2423 SetRemoteDescriptionWithoutError(answer);
2424
deadbeefcbecd352015-09-23 11:50:27 -07002425 EXPECT_TRUE(session_->voice_rtcp_transport_channel() == NULL);
2426 EXPECT_TRUE(session_->video_rtcp_transport_channel() == NULL);
Peter Thatcheraf55ccc2015-05-21 07:48:41 -07002427}
2428
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002429// This test verifies that SetLocalDescription and SetRemoteDescription fails
2430// if BUNDLE is enabled but rtcp-mux is disabled in m-lines.
2431TEST_F(WebRtcSessionTest, TestDisabledRtcpMuxWithBundleEnabled) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002432 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002433 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002434
2435 PeerConnectionInterface::RTCOfferAnswerOptions options;
2436 options.use_rtp_mux = true;
2437
2438 SessionDescriptionInterface* offer = CreateOffer(options);
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002439 std::string offer_str;
2440 offer->ToString(&offer_str);
2441 // Disable rtcp-mux
2442 const std::string rtcp_mux = "rtcp-mux";
2443 const std::string xrtcp_mux = "xrtcp-mux";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002444 rtc::replace_substrs(rtcp_mux.c_str(), rtcp_mux.length(),
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002445 xrtcp_mux.c_str(), xrtcp_mux.length(),
2446 &offer_str);
Steve Anton6d64e9a2017-09-12 09:44:05 -07002447 SessionDescriptionInterface* local_offer = CreateSessionDescription(
2448 SessionDescriptionInterface::kOffer, offer_str, nullptr);
2449 ASSERT_TRUE(local_offer);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002450 SetLocalDescriptionOfferExpectError(kBundleWithoutRtcpMux, local_offer);
Steve Anton6d64e9a2017-09-12 09:44:05 -07002451
2452 SessionDescriptionInterface* remote_offer = CreateSessionDescription(
2453 SessionDescriptionInterface::kOffer, offer_str, nullptr);
2454 ASSERT_TRUE(remote_offer);
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002455 SetRemoteDescriptionOfferExpectError(kBundleWithoutRtcpMux, remote_offer);
Steve Anton6d64e9a2017-09-12 09:44:05 -07002456
henrike@webrtc.org1e09a712013-07-26 19:17:59 +00002457 // Trying unmodified SDP.
2458 SetLocalDescriptionWithoutError(offer);
2459}
2460
deadbeefd59daf82015-10-14 15:02:44 -07002461// This test verifies the |initial_offerer| flag when session initiates the
2462// call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002463TEST_F(WebRtcSessionTest, TestInitiatorFlagAsOriginator) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002464 Init();
deadbeefd59daf82015-10-14 15:02:44 -07002465 EXPECT_FALSE(session_->initial_offerer());
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002466 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002467 SessionDescriptionInterface* answer = CreateRemoteAnswer(offer);
2468 SetLocalDescriptionWithoutError(offer);
deadbeefd59daf82015-10-14 15:02:44 -07002469 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002470 SetRemoteDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07002471 EXPECT_TRUE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002472}
2473
deadbeefd59daf82015-10-14 15:02:44 -07002474// This test verifies the |initial_offerer| flag when session receives the call.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002475TEST_F(WebRtcSessionTest, TestInitiatorFlagAsReceiver) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002476 Init();
deadbeefd59daf82015-10-14 15:02:44 -07002477 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002478 SessionDescriptionInterface* offer = CreateRemoteOffer();
2479 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08002480 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002481
deadbeefd59daf82015-10-14 15:02:44 -07002482 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002483 SetLocalDescriptionWithoutError(answer);
deadbeefd59daf82015-10-14 15:02:44 -07002484 EXPECT_FALSE(session_->initial_offerer());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002485}
2486
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002487// Verifing local offer and remote answer have matching m-lines as per RFC 3264.
2488TEST_F(WebRtcSessionTest, TestIncorrectMLinesInRemoteAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002489 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002490 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002491 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002492 SetLocalDescriptionWithoutError(offer);
kwibergd1fe2812016-04-27 06:47:29 -07002493 std::unique_ptr<SessionDescriptionInterface> answer(
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002494 CreateRemoteAnswer(session_->local_description()));
2495
2496 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2497 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002498 JsepSessionDescription* modified_answer =
2499 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002500
2501 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2502 answer->session_id(),
2503 answer->session_version()));
Zhi Huang2a5e4262017-09-14 01:15:03 -07002504 SetRemoteDescriptionAnswerExpectError(kMlineMismatchInAnswer,
2505 modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002506
wu@webrtc.org4e393072014-04-07 17:04:35 +00002507 // Different content names.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002508 std::string sdp;
2509 EXPECT_TRUE(answer->ToString(&sdp));
2510 const std::string kAudioMid = "a=mid:audio";
2511 const std::string kAudioMidReplaceStr = "a=mid:audio_content_name";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002512 rtc::replace_substrs(kAudioMid.c_str(), kAudioMid.length(),
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002513 kAudioMidReplaceStr.c_str(),
2514 kAudioMidReplaceStr.length(),
2515 &sdp);
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002516 SessionDescriptionInterface* modified_answer1 =
2517 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
Zhi Huang2a5e4262017-09-14 01:15:03 -07002518 SetRemoteDescriptionAnswerExpectError(kMlineMismatchInAnswer,
2519 modified_answer1);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002520
wu@webrtc.org4e393072014-04-07 17:04:35 +00002521 // Different media types.
2522 EXPECT_TRUE(answer->ToString(&sdp));
2523 const std::string kAudioMline = "m=audio";
2524 const std::string kAudioMlineReplaceStr = "m=video";
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +00002525 rtc::replace_substrs(kAudioMline.c_str(), kAudioMline.length(),
wu@webrtc.org4e393072014-04-07 17:04:35 +00002526 kAudioMlineReplaceStr.c_str(),
2527 kAudioMlineReplaceStr.length(),
2528 &sdp);
2529 SessionDescriptionInterface* modified_answer2 =
2530 CreateSessionDescription(JsepSessionDescription::kAnswer, sdp, NULL);
Zhi Huang2a5e4262017-09-14 01:15:03 -07002531 SetRemoteDescriptionAnswerExpectError(kMlineMismatchInAnswer,
2532 modified_answer2);
wu@webrtc.org4e393072014-04-07 17:04:35 +00002533
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002534 SetRemoteDescriptionWithoutError(answer.release());
2535}
2536
2537// Verifying remote offer and local answer have matching m-lines as per
2538// RFC 3264.
2539TEST_F(WebRtcSessionTest, TestIncorrectMLinesInLocalAnswer) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002540 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002541 SendAudioVideoStream1();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002542 SessionDescriptionInterface* offer = CreateRemoteOffer();
2543 SetRemoteDescriptionWithoutError(offer);
htaa2a49d92016-03-04 02:51:39 -08002544 SessionDescriptionInterface* answer = CreateAnswer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002545
2546 cricket::SessionDescription* answer_copy = answer->description()->Copy();
2547 answer_copy->RemoveContentByName("video");
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002548 JsepSessionDescription* modified_answer =
2549 new JsepSessionDescription(JsepSessionDescription::kAnswer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002550
2551 EXPECT_TRUE(modified_answer->Initialize(answer_copy,
2552 answer->session_id(),
2553 answer->session_version()));
Zhi Huang2a5e4262017-09-14 01:15:03 -07002554 SetLocalDescriptionAnswerExpectError(kMlineMismatchInAnswer, modified_answer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002555 SetLocalDescriptionWithoutError(answer);
2556}
2557
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002558TEST_F(WebRtcSessionTest, TestSessionContentError) {
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002559 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002560 SendAudioVideoStream1();
jiayl@webrtc.orgb18bf5e2014-08-04 18:34:16 +00002561 SessionDescriptionInterface* offer = CreateOffer();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002562 const std::string session_id_orig = offer->session_id();
2563 const std::string session_version_orig = offer->session_version();
2564 SetLocalDescriptionWithoutError(offer);
2565
2566 video_channel_ = media_engine_->GetVideoChannel(0);
2567 video_channel_->set_fail_set_send_codecs(true);
2568
henrike@webrtc.org28654cb2013-07-22 21:07:49 +00002569 SessionDescriptionInterface* answer =
2570 CreateRemoteAnswer(session_->local_description());
sergeyu@chromium.org4b26e2e2014-01-15 23:15:54 +00002571 SetRemoteDescriptionAnswerExpectError("ERROR_CONTENT", answer);
deadbeefd59daf82015-10-14 15:02:44 -07002572
2573 // Test that after a content error, setting any description will
2574 // result in an error.
2575 video_channel_->set_fail_set_send_codecs(false);
2576 answer = CreateRemoteAnswer(session_->local_description());
2577 SetRemoteDescriptionExpectError("", "ERROR_CONTENT", answer);
2578 offer = CreateRemoteOffer();
2579 SetLocalDescriptionExpectError("", "ERROR_CONTENT", offer);
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002580}
2581
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002582TEST_F(WebRtcSessionTest, TestRtpDataChannel) {
htaa2a49d92016-03-04 02:51:39 -08002583 configuration_.enable_rtp_data_channel = true;
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002584 Init();
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002585 SetLocalDescriptionWithDataChannel();
htaa2a49d92016-03-04 02:51:39 -08002586 ASSERT_TRUE(data_engine_);
deadbeef953c2ce2017-01-09 14:53:41 -08002587 EXPECT_NE(nullptr, data_engine_->GetChannel(0));
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002588}
2589
Henrik Boström87713d02015-08-25 09:53:21 +02002590TEST_P(WebRtcSessionTest, TestRtpDataChannelConstraintTakesPrecedence) {
htaa2a49d92016-03-04 02:51:39 -08002591 configuration_.enable_rtp_data_channel = true;
wu@webrtc.org97077a32013-10-25 21:18:33 +00002592 options_.disable_sctp_data_channels = false;
2593
Henrik Boström87713d02015-08-25 09:53:21 +02002594 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002595
2596 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08002597 EXPECT_NE(nullptr, data_engine_->GetChannel(0));
2598}
2599
2600// Test that sctp_content_name/sctp_transport_name (used for stats) are correct
2601// before and after BUNDLE is negotiated.
2602TEST_P(WebRtcSessionTest, SctpContentAndTransportName) {
deadbeef953c2ce2017-01-09 14:53:41 -08002603 SetFactoryDtlsSrtp();
2604 InitWithDtls(GetParam());
2605
2606 // Initially these fields should be empty.
2607 EXPECT_FALSE(session_->sctp_content_name());
2608 EXPECT_FALSE(session_->sctp_transport_name());
2609
2610 // Create offer with audio/video/data.
2611 // Default bundle policy is "balanced", so data should be using its own
2612 // transport.
2613 SendAudioVideoStream1();
2614 CreateDataChannel();
2615 InitiateCall();
2616 ASSERT_TRUE(session_->sctp_content_name());
2617 ASSERT_TRUE(session_->sctp_transport_name());
2618 EXPECT_EQ("data", *session_->sctp_content_name());
2619 EXPECT_EQ("data", *session_->sctp_transport_name());
2620
2621 // Create answer that finishes BUNDLE negotiation, which means everything
2622 // should be bundled on the first transport (audio).
2623 cricket::MediaSessionOptions answer_options;
deadbeef953c2ce2017-01-09 14:53:41 -08002624 answer_options.bundle_enabled = true;
2625 answer_options.data_channel_type = cricket::DCT_SCTP;
zhihuang1c378ed2017-08-17 14:10:50 -07002626 GetOptionsForAnswer(&answer_options);
deadbeef953c2ce2017-01-09 14:53:41 -08002627 SetRemoteDescriptionWithoutError(CreateRemoteAnswer(
2628 session_->local_description(), answer_options, cricket::SEC_DISABLED));
2629 ASSERT_TRUE(session_->sctp_content_name());
2630 ASSERT_TRUE(session_->sctp_transport_name());
2631 EXPECT_EQ("data", *session_->sctp_content_name());
2632 EXPECT_EQ("audio", *session_->sctp_transport_name());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002633}
2634
Henrik Boström87713d02015-08-25 09:53:21 +02002635TEST_P(WebRtcSessionTest, TestCreateOfferWithSctpEnabledWithoutStreams) {
Henrik Boström87713d02015-08-25 09:53:21 +02002636 InitWithDtls(GetParam());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002637
kwibergd1fe2812016-04-27 06:47:29 -07002638 std::unique_ptr<SessionDescriptionInterface> offer(CreateOffer());
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002639 EXPECT_TRUE(offer->description()->GetContentByName("data") == NULL);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00002640 EXPECT_TRUE(offer->description()->GetTransportInfoByName("data") == NULL);
2641}
2642
Henrik Boström87713d02015-08-25 09:53:21 +02002643TEST_P(WebRtcSessionTest, TestCreateAnswerWithSctpInOfferAndNoStreams) {
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00002644 SetFactoryDtlsSrtp();
Henrik Boström87713d02015-08-25 09:53:21 +02002645 InitWithDtls(GetParam());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00002646
2647 // Create remote offer with SCTP.
2648 cricket::MediaSessionOptions options;
2649 options.data_channel_type = cricket::DCT_SCTP;
zhihuang1c378ed2017-08-17 14:10:50 -07002650 GetOptionsForRemoteOffer(&options);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00002651 JsepSessionDescription* offer =
henrike@webrtc.orgb90991d2014-03-04 19:54:57 +00002652 CreateRemoteOffer(options, cricket::SEC_DISABLED);
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00002653 SetRemoteDescriptionWithoutError(offer);
2654
2655 // Verifies the answer contains SCTP.
kwibergd1fe2812016-04-27 06:47:29 -07002656 std::unique_ptr<SessionDescriptionInterface> answer(CreateAnswer());
mallinath@webrtc.org1112c302013-09-23 20:34:45 +00002657 EXPECT_TRUE(answer != NULL);
2658 EXPECT_TRUE(answer->description()->GetContentByName("data") != NULL);
2659 EXPECT_TRUE(answer->description()->GetTransportInfoByName("data") != NULL);
sergeyu@chromium.orga59696b2013-09-13 23:48:58 +00002660}
2661
deadbeef953c2ce2017-01-09 14:53:41 -08002662// Test that if DTLS is disabled, we don't end up with an SctpTransport
2663// created (or an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02002664TEST_P(WebRtcSessionTest, TestSctpDataChannelWithoutDtls) {
htaa2a49d92016-03-04 02:51:39 -08002665 configuration_.enable_dtls_srtp = rtc::Optional<bool>(false);
Henrik Boström87713d02015-08-25 09:53:21 +02002666 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002667
2668 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08002669 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
2670 EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002671}
2672
deadbeef953c2ce2017-01-09 14:53:41 -08002673// Test that if DTLS is enabled, we end up with an SctpTransport created
2674// (and not an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02002675TEST_P(WebRtcSessionTest, TestSctpDataChannelWithDtls) {
Henrik Boström87713d02015-08-25 09:53:21 +02002676 InitWithDtls(GetParam());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002677
2678 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08002679 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
2680 EXPECT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002681}
wu@webrtc.org91053e72013-08-10 07:18:04 +00002682
deadbeef953c2ce2017-01-09 14:53:41 -08002683// Test that if SCTP is disabled, we don't end up with an SctpTransport
2684// created (or an RtpDataChannel).
Henrik Boström87713d02015-08-25 09:53:21 +02002685TEST_P(WebRtcSessionTest, TestDisableSctpDataChannels) {
wu@webrtc.org97077a32013-10-25 21:18:33 +00002686 options_.disable_sctp_data_channels = true;
Henrik Boström87713d02015-08-25 09:53:21 +02002687 InitWithDtls(GetParam());
wu@webrtc.org97077a32013-10-25 21:18:33 +00002688
2689 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08002690 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
2691 EXPECT_EQ(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
wu@webrtc.org97077a32013-10-25 21:18:33 +00002692}
2693
Henrik Boström87713d02015-08-25 09:53:21 +02002694TEST_P(WebRtcSessionTest, TestSctpDataChannelSendPortParsing) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002695 const int new_send_port = 9998;
2696 const int new_recv_port = 7775;
2697
Henrik Boström87713d02015-08-25 09:53:21 +02002698 InitWithDtls(GetParam());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002699 SetFactoryDtlsSrtp();
2700
2701 // By default, don't actually add the codecs to desc_factory_; they don't
2702 // actually get serialized for SCTP in BuildMediaDescription(). Instead,
2703 // let the session description get parsed. That'll get the proper codecs
2704 // into the stream.
2705 cricket::MediaSessionOptions options;
Steve Anton6d64e9a2017-09-12 09:44:05 -07002706 SessionDescriptionInterface* offer =
2707 CreateRemoteOfferWithSctpPort("stream1", new_send_port, options);
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002708
2709 // SetRemoteDescription will take the ownership of the offer.
2710 SetRemoteDescriptionWithoutError(offer);
2711
htaa2a49d92016-03-04 02:51:39 -08002712 SessionDescriptionInterface* answer =
2713 ChangeSDPSctpPort(new_recv_port, CreateAnswer());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002714 ASSERT_TRUE(answer != NULL);
2715
2716 // Now set the local description, which'll take ownership of the answer.
2717 SetLocalDescriptionWithoutError(answer);
2718
2719 // TEST PLAN: Set the port number to something new, set it in the SDP,
2720 // and pass it all the way down.
deadbeef953c2ce2017-01-09 14:53:41 -08002721 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
deadbeefab9b2d12015-10-14 11:33:11 -07002722 CreateDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08002723 ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
2724 EXPECT_EQ(
2725 new_recv_port,
2726 fake_sctp_transport_factory_->last_fake_sctp_transport()->local_port());
2727 EXPECT_EQ(
2728 new_send_port,
2729 fake_sctp_transport_factory_->last_fake_sctp_transport()->remote_port());
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +00002730}
2731
deadbeef953c2ce2017-01-09 14:53:41 -08002732// Verifies that when a session's SctpTransport receives an OPEN message,
2733// WebRtcSession signals the SctpTransport creation request with the expected
deadbeefab9b2d12015-10-14 11:33:11 -07002734// config.
2735TEST_P(WebRtcSessionTest, TestSctpDataChannelOpenMessage) {
deadbeefab9b2d12015-10-14 11:33:11 -07002736 InitWithDtls(GetParam());
2737
2738 SetLocalDescriptionWithDataChannel();
deadbeef953c2ce2017-01-09 14:53:41 -08002739 EXPECT_EQ(nullptr, data_engine_->GetChannel(0));
2740 ASSERT_NE(nullptr, fake_sctp_transport_factory_->last_fake_sctp_transport());
deadbeefab9b2d12015-10-14 11:33:11 -07002741
deadbeef953c2ce2017-01-09 14:53:41 -08002742 // Make the fake SCTP transport pretend it received an OPEN message.
deadbeefab9b2d12015-10-14 11:33:11 -07002743 webrtc::DataChannelInit config;
2744 config.id = 1;
jbaucheec21bd2016-03-20 06:15:43 -07002745 rtc::CopyOnWriteBuffer payload;
deadbeefab9b2d12015-10-14 11:33:11 -07002746 webrtc::WriteDataChannelOpenMessage("a", config, &payload);
2747 cricket::ReceiveDataParams params;
2748 params.ssrc = config.id;
2749 params.type = cricket::DMT_CONTROL;
deadbeef953c2ce2017-01-09 14:53:41 -08002750 fake_sctp_transport_factory_->last_fake_sctp_transport()->SignalDataReceived(
2751 params, payload);
deadbeefab9b2d12015-10-14 11:33:11 -07002752
deadbeef953c2ce2017-01-09 14:53:41 -08002753 EXPECT_EQ_WAIT("a", last_data_channel_label_, kDefaultTimeout);
deadbeefab9b2d12015-10-14 11:33:11 -07002754 EXPECT_EQ(config.id, last_data_channel_config_.id);
2755 EXPECT_FALSE(last_data_channel_config_.negotiated);
2756 EXPECT_EQ(webrtc::InternalDataChannelInit::kAcker,
2757 last_data_channel_config_.open_handshake_role);
2758}
2759
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00002760TEST_F(WebRtcSessionTest, TestCombinedAudioVideoBweConstraint) {
htaa2a49d92016-03-04 02:51:39 -08002761 configuration_.combined_audio_video_bwe = rtc::Optional<bool>(true);
pthatcher@webrtc.org877ac762015-02-04 22:03:09 +00002762 Init();
deadbeefab9b2d12015-10-14 11:33:11 -07002763 SendAudioVideoStream1();
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00002764 SessionDescriptionInterface* offer = CreateOffer();
2765
2766 SetLocalDescriptionWithoutError(offer);
2767
2768 voice_channel_ = media_engine_->GetVoiceChannel(0);
2769
2770 ASSERT_TRUE(voice_channel_ != NULL);
solenberg66f43392015-09-09 01:36:22 -07002771 const cricket::AudioOptions& audio_options = voice_channel_->options();
Karl Wibergbe579832015-11-10 22:34:18 +01002772 EXPECT_EQ(rtc::Optional<bool>(true), audio_options.combined_audio_video_bwe);
buildbot@webrtc.orgb4c7b092014-08-25 12:11:58 +00002773}
2774
zhihuang9763d562016-08-05 11:14:50 -07002775#ifdef HAVE_QUIC
2776TEST_P(WebRtcSessionTest, TestNegotiateQuic) {
2777 configuration_.enable_quic = true;
2778 InitWithDtls(GetParam());
2779 EXPECT_TRUE(session_->data_channel_type() == cricket::DCT_QUIC);
2780 SessionDescriptionInterface* offer = CreateOffer();
2781 ASSERT_TRUE(offer);
2782 ASSERT_TRUE(offer->description());
2783 SetLocalDescriptionWithoutError(offer);
2784 cricket::MediaSessionOptions options;
zhihuang1c378ed2017-08-17 14:10:50 -07002785 GetOptionsForAnswer(&options);
zhihuang9763d562016-08-05 11:14:50 -07002786 SessionDescriptionInterface* answer =
2787 CreateRemoteAnswer(offer, options, cricket::SEC_DISABLED);
2788 ASSERT_TRUE(answer);
2789 ASSERT_TRUE(answer->description());
2790 SetRemoteDescriptionWithoutError(answer);
2791}
2792#endif // HAVE_QUIC
2793
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00002794// Tests that RTX codec is removed from the answer when it isn't supported
2795// by local side.
zhihuang3a334652016-05-05 18:37:49 -07002796TEST_F(WebRtcSessionTest, TestRtxRemovedByCreateAnswer) {
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00002797 Init();
zhihuang1c378ed2017-08-17 14:10:50 -07002798 // Send video only to match the |kSdpWithRtx|.
2799 SendVideoOnlyStream2();
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00002800 std::string offer_sdp(kSdpWithRtx);
2801
2802 SessionDescriptionInterface* offer =
2803 CreateSessionDescription(JsepSessionDescription::kOffer, offer_sdp, NULL);
2804 EXPECT_TRUE(offer->ToString(&offer_sdp));
2805
2806 // Offer SDP contains the RTX codec.
zhihuang3a334652016-05-05 18:37:49 -07002807 EXPECT_TRUE(ContainsVideoCodecWithName(offer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00002808 SetRemoteDescriptionWithoutError(offer);
2809
zhihuang1c378ed2017-08-17 14:10:50 -07002810 // |offered_media_sections_| is used when creating answer.
2811 offered_media_sections_.push_back(cricket::MediaDescriptionOptions(
2812 cricket::MEDIA_TYPE_VIDEO, cricket::CN_VIDEO,
2813 cricket::RtpTransceiverDirection(true, true), false));
2814 // Don't create media section for audio in the answer.
htaa2a49d92016-03-04 02:51:39 -08002815 SessionDescriptionInterface* answer = CreateAnswer();
zhihuang3a334652016-05-05 18:37:49 -07002816 // Answer SDP does not contain the RTX codec.
2817 EXPECT_FALSE(ContainsVideoCodecWithName(answer, "rtx"));
changbin.shao@webrtc.org2d25b442015-03-16 04:14:34 +00002818 SetLocalDescriptionWithoutError(answer);
2819}
jiayl@webrtc.orge10d28c2014-07-17 17:07:49 +00002820
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00002821// This verifies that the voice channel after bundle has both options from video
2822// and voice channels.
2823TEST_F(WebRtcSessionTest, TestSetSocketOptionBeforeBundle) {
2824 InitWithBundlePolicy(PeerConnectionInterface::kBundlePolicyBalanced);
deadbeefab9b2d12015-10-14 11:33:11 -07002825 SendAudioVideoStream1();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00002826
2827 PeerConnectionInterface::RTCOfferAnswerOptions options;
2828 options.use_rtp_mux = true;
2829
2830 SessionDescriptionInterface* offer = CreateOffer(options);
2831 SetLocalDescriptionWithoutError(offer);
2832
2833 session_->video_channel()->SetOption(cricket::BaseChannel::ST_RTP,
2834 rtc::Socket::Option::OPT_SNDBUF, 4000);
2835
2836 session_->voice_channel()->SetOption(cricket::BaseChannel::ST_RTP,
2837 rtc::Socket::Option::OPT_RCVBUF, 8000);
2838
2839 int option_val;
deadbeefcbecd352015-09-23 11:50:27 -07002840 EXPECT_TRUE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00002841 rtc::Socket::Option::OPT_SNDBUF, &option_val));
2842 EXPECT_EQ(4000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07002843 EXPECT_FALSE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00002844 rtc::Socket::Option::OPT_SNDBUF, &option_val));
2845
deadbeefcbecd352015-09-23 11:50:27 -07002846 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00002847 rtc::Socket::Option::OPT_RCVBUF, &option_val));
2848 EXPECT_EQ(8000, option_val);
deadbeefcbecd352015-09-23 11:50:27 -07002849 EXPECT_FALSE(session_->video_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00002850 rtc::Socket::Option::OPT_RCVBUF, &option_val));
2851
deadbeefcbecd352015-09-23 11:50:27 -07002852 EXPECT_NE(session_->voice_rtp_transport_channel(),
2853 session_->video_rtp_transport_channel());
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00002854
deadbeefab9b2d12015-10-14 11:33:11 -07002855 SendAudioVideoStream2();
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00002856 SessionDescriptionInterface* answer =
2857 CreateRemoteAnswer(session_->local_description());
2858 SetRemoteDescriptionWithoutError(answer);
2859
deadbeefcbecd352015-09-23 11:50:27 -07002860 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00002861 rtc::Socket::Option::OPT_SNDBUF, &option_val));
2862 EXPECT_EQ(4000, option_val);
2863
deadbeefcbecd352015-09-23 11:50:27 -07002864 EXPECT_TRUE(session_->voice_rtp_transport_channel()->GetOption(
guoweis@webrtc.org4f852882015-03-12 20:09:44 +00002865 rtc::Socket::Option::OPT_RCVBUF, &option_val));
2866 EXPECT_EQ(8000, option_val);
2867}
2868
tommi0f620f42015-07-09 03:25:02 -07002869// Test creating a session, request multiple offers, destroy the session
2870// and make sure we got success/failure callbacks for all of the requests.
2871// Background: crbug.com/507307
2872TEST_F(WebRtcSessionTest, CreateOffersAndShutdown) {
2873 Init();
2874
2875 rtc::scoped_refptr<WebRtcSessionCreateSDPObserverForTest> observers[100];
2876 PeerConnectionInterface::RTCOfferAnswerOptions options;
2877 options.offer_to_receive_audio =
2878 RTCOfferAnswerOptions::kOfferToReceiveMediaTrue;
deadbeefab9b2d12015-10-14 11:33:11 -07002879 cricket::MediaSessionOptions session_options;
zhihuang1c378ed2017-08-17 14:10:50 -07002880 GetOptionsForOffer(options, &session_options);
tommi0f620f42015-07-09 03:25:02 -07002881 for (auto& o : observers) {
2882 o = new WebRtcSessionCreateSDPObserverForTest();
deadbeefab9b2d12015-10-14 11:33:11 -07002883 session_->CreateOffer(o, options, session_options);
tommi0f620f42015-07-09 03:25:02 -07002884 }
2885
2886 session_.reset();
2887
tommi0f620f42015-07-09 03:25:02 -07002888 for (auto& o : observers) {
2889 // We expect to have received a notification now even if the session was
2890 // terminated. The offer creation may or may not have succeeded, but we
2891 // must have received a notification which, so the only invalid state
2892 // is kInit.
2893 EXPECT_NE(WebRtcSessionCreateSDPObserverForTest::kInit, o->state());
2894 }
2895}
2896
stefanc1aeaf02015-10-15 07:26:07 -07002897TEST_F(WebRtcSessionTest, TestPacketOptionsAndOnPacketSent) {
2898 TestPacketOptions();
2899}
2900
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002901// TODO(bemasc): Add a TestIceStatesBundle with BUNDLE enabled. That test
2902// currently fails because upon disconnection and reconnection OnIceComplete is
2903// called more than once without returning to IceGatheringGathering.
Henrik Boström87713d02015-08-25 09:53:21 +02002904
deadbeefcbecd352015-09-23 11:50:27 -07002905INSTANTIATE_TEST_CASE_P(WebRtcSessionTests,
2906 WebRtcSessionTest,
2907 testing::Values(ALREADY_GENERATED,
2908 DTLS_IDENTITY_STORE));