blob: 0bd9066fea7a2f1776cbdb9c10167dcebda5c154 [file] [log] [blame]
deadbeef1dcb1642017-03-29 21:08:16 -07001/*
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
3 *
4 * 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.
9 */
10
11// Disable for TSan v2, see
12// https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
13#if !defined(THREAD_SANITIZER)
14
15#include <stdio.h>
16
17#include <algorithm>
18#include <functional>
19#include <list>
20#include <map>
21#include <memory>
22#include <utility>
23#include <vector>
24
Karl Wiberg1b0eae32017-10-17 14:48:54 +020025#include "api/audio_codecs/builtin_audio_decoder_factory.h"
26#include "api/audio_codecs/builtin_audio_encoder_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020027#include "api/fakemetricsobserver.h"
28#include "api/mediastreaminterface.h"
29#include "api/peerconnectioninterface.h"
Steve Anton8c0f7a72017-10-03 10:03:10 -070030#include "api/peerconnectionproxy.h"
Mirko Bonadeic61ce0d2017-11-21 17:04:20 +010031#include "api/rtpreceiverinterface.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020032#include "api/test/fakeconstraints.h"
Anders Carlsson67537952018-05-03 11:28:29 +020033#include "api/video_codecs/builtin_video_decoder_factory.h"
34#include "api/video_codecs/builtin_video_encoder_factory.h"
35#include "api/video_codecs/sdp_video_format.h"
Qingsi Wang7685e862018-06-11 20:15:46 -070036#include "call/call.h"
37#include "logging/rtc_event_log/fake_rtc_event_log_factory.h"
38#include "logging/rtc_event_log/rtc_event_log_factory_interface.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020039#include "media/engine/fakewebrtcvideoengine.h"
Qingsi Wang7685e862018-06-11 20:15:46 -070040#include "media/engine/webrtcmediaengine.h"
41#include "modules/audio_processing/include/audio_processing.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020042#include "p2p/base/p2pconstants.h"
43#include "p2p/base/portinterface.h"
Steve Antonede9ca52017-10-16 13:04:27 -070044#include "p2p/base/teststunserver.h"
Jonas Orelandbdcee282017-10-10 14:01:40 +020045#include "p2p/base/testturncustomizer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020046#include "p2p/base/testturnserver.h"
47#include "p2p/client/basicportallocator.h"
48#include "pc/dtmfsender.h"
49#include "pc/localaudiosource.h"
50#include "pc/mediasession.h"
51#include "pc/peerconnection.h"
52#include "pc/peerconnectionfactory.h"
Seth Hampson2f0d7022018-02-20 11:54:42 -080053#include "pc/rtpmediautils.h"
Steve Anton4ab68ee2017-12-19 14:26:11 -080054#include "pc/sessiondescription.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020055#include "pc/test/fakeaudiocapturemodule.h"
Niels Möller0f405822018-05-17 09:16:41 +020056#include "pc/test/fakeperiodicvideotracksource.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020057#include "pc/test/fakertccertificategenerator.h"
58#include "pc/test/fakevideotrackrenderer.h"
59#include "pc/test/mockpeerconnectionobservers.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020060#include "rtc_base/fakenetwork.h"
Steve Antonede9ca52017-10-16 13:04:27 -070061#include "rtc_base/firewallsocketserver.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020062#include "rtc_base/gunit.h"
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +020063#include "rtc_base/numerics/safe_conversions.h"
Benjamin Wrightd6f86e82018-05-08 13:12:25 -070064#include "rtc_base/testcertificateverifier.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020065#include "rtc_base/virtualsocketserver.h"
Elad Alon99c3fe52017-10-13 16:29:40 +020066#include "test/gmock.h"
deadbeef1dcb1642017-03-29 21:08:16 -070067
68using cricket::ContentInfo;
69using cricket::FakeWebRtcVideoDecoder;
70using cricket::FakeWebRtcVideoDecoderFactory;
71using cricket::FakeWebRtcVideoEncoder;
72using cricket::FakeWebRtcVideoEncoderFactory;
73using cricket::MediaContentDescription;
Steve Antondf527fd2018-04-27 15:52:03 -070074using cricket::StreamParams;
Steve Antonede9ca52017-10-16 13:04:27 -070075using rtc::SocketAddress;
Seth Hampson2f0d7022018-02-20 11:54:42 -080076using ::testing::Combine;
Steve Antonede9ca52017-10-16 13:04:27 -070077using ::testing::ElementsAre;
78using ::testing::Values;
deadbeef1dcb1642017-03-29 21:08:16 -070079using webrtc::DataBuffer;
80using webrtc::DataChannelInterface;
81using webrtc::DtmfSender;
82using webrtc::DtmfSenderInterface;
83using webrtc::DtmfSenderObserverInterface;
84using webrtc::FakeConstraints;
Steve Anton15324772018-01-16 10:26:49 -080085using webrtc::FakeVideoTrackRenderer;
deadbeef1dcb1642017-03-29 21:08:16 -070086using webrtc::MediaConstraintsInterface;
87using webrtc::MediaStreamInterface;
88using webrtc::MediaStreamTrackInterface;
89using webrtc::MockCreateSessionDescriptionObserver;
90using webrtc::MockDataChannelObserver;
91using webrtc::MockSetSessionDescriptionObserver;
92using webrtc::MockStatsObserver;
93using webrtc::ObserverInterface;
Steve Anton8c0f7a72017-10-03 10:03:10 -070094using webrtc::PeerConnection;
deadbeef1dcb1642017-03-29 21:08:16 -070095using webrtc::PeerConnectionInterface;
Steve Anton74255ff2018-01-24 18:32:57 -080096using RTCConfiguration = PeerConnectionInterface::RTCConfiguration;
deadbeef1dcb1642017-03-29 21:08:16 -070097using webrtc::PeerConnectionFactory;
Steve Anton8c0f7a72017-10-03 10:03:10 -070098using webrtc::PeerConnectionProxy;
Steve Anton15324772018-01-16 10:26:49 -080099using webrtc::RTCErrorType;
Steve Anton7eca0932018-03-30 15:18:41 -0700100using webrtc::RTCTransportStats;
Steve Anton74255ff2018-01-24 18:32:57 -0800101using webrtc::RtpSenderInterface;
Mirko Bonadeic61ce0d2017-11-21 17:04:20 +0100102using webrtc::RtpReceiverInterface;
Seth Hampson2f0d7022018-02-20 11:54:42 -0800103using webrtc::RtpSenderInterface;
104using webrtc::RtpTransceiverDirection;
105using webrtc::RtpTransceiverInit;
106using webrtc::RtpTransceiverInterface;
Steve Antond3679212018-01-17 17:41:02 -0800107using webrtc::SdpSemantics;
Steve Antona3a92c22017-12-07 10:27:41 -0800108using webrtc::SdpType;
deadbeef1dcb1642017-03-29 21:08:16 -0700109using webrtc::SessionDescriptionInterface;
110using webrtc::StreamCollectionInterface;
Steve Anton15324772018-01-16 10:26:49 -0800111using webrtc::VideoTrackInterface;
deadbeef1dcb1642017-03-29 21:08:16 -0700112
113namespace {
114
115static const int kDefaultTimeout = 10000;
116static const int kMaxWaitForStatsMs = 3000;
117static const int kMaxWaitForActivationMs = 5000;
118static const int kMaxWaitForFramesMs = 10000;
119// Default number of audio/video frames to wait for before considering a test
120// successful.
121static const int kDefaultExpectedAudioFrameCount = 3;
122static const int kDefaultExpectedVideoFrameCount = 3;
123
deadbeef1dcb1642017-03-29 21:08:16 -0700124static const char kDataChannelLabel[] = "data_channel";
125
126// SRTP cipher name negotiated by the tests. This must be updated if the
127// default changes.
Taylor Brandstetterfd350d72018-04-03 16:29:26 -0700128static const int kDefaultSrtpCryptoSuite = rtc::SRTP_AES128_CM_SHA1_80;
deadbeef1dcb1642017-03-29 21:08:16 -0700129static const int kDefaultSrtpCryptoSuiteGcm = rtc::SRTP_AEAD_AES_256_GCM;
130
Steve Antonede9ca52017-10-16 13:04:27 -0700131static const SocketAddress kDefaultLocalAddress("192.168.1.1", 0);
132
deadbeef1dcb1642017-03-29 21:08:16 -0700133// Helper function for constructing offer/answer options to initiate an ICE
134// restart.
135PeerConnectionInterface::RTCOfferAnswerOptions IceRestartOfferAnswerOptions() {
136 PeerConnectionInterface::RTCOfferAnswerOptions options;
137 options.ice_restart = true;
138 return options;
139}
140
deadbeefd8ad7882017-04-18 16:01:17 -0700141// Remove all stream information (SSRCs, track IDs, etc.) and "msid-semantic"
142// attribute from received SDP, simulating a legacy endpoint.
143void RemoveSsrcsAndMsids(cricket::SessionDescription* desc) {
144 for (ContentInfo& content : desc->contents()) {
Steve Antonb1c1de12017-12-21 15:14:30 -0800145 content.media_description()->mutable_streams().clear();
deadbeefd8ad7882017-04-18 16:01:17 -0700146 }
147 desc->set_msid_supported(false);
148}
149
Seth Hampson5897a6e2018-04-03 11:16:33 -0700150// Removes all stream information besides the stream ids, simulating an
151// endpoint that only signals a=msid lines to convey stream_ids.
152void RemoveSsrcsAndKeepMsids(cricket::SessionDescription* desc) {
153 for (ContentInfo& content : desc->contents()) {
Steve Antondf527fd2018-04-27 15:52:03 -0700154 std::string track_id;
Seth Hampson5897a6e2018-04-03 11:16:33 -0700155 std::vector<std::string> stream_ids;
156 if (!content.media_description()->streams().empty()) {
Steve Antondf527fd2018-04-27 15:52:03 -0700157 const StreamParams& first_stream =
158 content.media_description()->streams()[0];
159 track_id = first_stream.id;
160 stream_ids = first_stream.stream_ids();
Seth Hampson5897a6e2018-04-03 11:16:33 -0700161 }
162 content.media_description()->mutable_streams().clear();
Steve Antondf527fd2018-04-27 15:52:03 -0700163 StreamParams new_stream;
164 new_stream.id = track_id;
Seth Hampson5897a6e2018-04-03 11:16:33 -0700165 new_stream.set_stream_ids(stream_ids);
166 content.media_description()->AddStream(new_stream);
167 }
168}
169
zhihuangf8164932017-05-19 13:09:47 -0700170int FindFirstMediaStatsIndexByKind(
171 const std::string& kind,
172 const std::vector<const webrtc::RTCMediaStreamTrackStats*>&
173 media_stats_vec) {
174 for (size_t i = 0; i < media_stats_vec.size(); i++) {
175 if (media_stats_vec[i]->kind.ValueToString() == kind) {
176 return i;
177 }
178 }
179 return -1;
180}
181
deadbeef1dcb1642017-03-29 21:08:16 -0700182class SignalingMessageReceiver {
183 public:
Steve Antona3a92c22017-12-07 10:27:41 -0800184 virtual void ReceiveSdpMessage(SdpType type, const std::string& msg) = 0;
deadbeef1dcb1642017-03-29 21:08:16 -0700185 virtual void ReceiveIceMessage(const std::string& sdp_mid,
186 int sdp_mline_index,
187 const std::string& msg) = 0;
188
189 protected:
190 SignalingMessageReceiver() {}
191 virtual ~SignalingMessageReceiver() {}
192};
193
194class MockRtpReceiverObserver : public webrtc::RtpReceiverObserverInterface {
195 public:
196 explicit MockRtpReceiverObserver(cricket::MediaType media_type)
197 : expected_media_type_(media_type) {}
198
199 void OnFirstPacketReceived(cricket::MediaType media_type) override {
200 ASSERT_EQ(expected_media_type_, media_type);
201 first_packet_received_ = true;
202 }
203
204 bool first_packet_received() const { return first_packet_received_; }
205
206 virtual ~MockRtpReceiverObserver() {}
207
208 private:
209 bool first_packet_received_ = false;
210 cricket::MediaType expected_media_type_;
211};
212
213// Helper class that wraps a peer connection, observes it, and can accept
214// signaling messages from another wrapper.
215//
216// Uses a fake network, fake A/V capture, and optionally fake
217// encoders/decoders, though they aren't used by default since they don't
218// advertise support of any codecs.
Steve Anton94286cb2017-09-26 16:20:19 -0700219// TODO(steveanton): See how this could become a subclass of
Seth Hampson2f0d7022018-02-20 11:54:42 -0800220// PeerConnectionWrapper defined in peerconnectionwrapper.h.
deadbeef1dcb1642017-03-29 21:08:16 -0700221class PeerConnectionWrapper : public webrtc::PeerConnectionObserver,
Steve Anton15324772018-01-16 10:26:49 -0800222 public SignalingMessageReceiver {
deadbeef1dcb1642017-03-29 21:08:16 -0700223 public:
224 // Different factory methods for convenience.
225 // TODO(deadbeef): Could use the pattern of:
226 //
227 // PeerConnectionWrapper =
228 // WrapperBuilder.WithConfig(...).WithOptions(...).build();
229 //
230 // To reduce some code duplication.
231 static PeerConnectionWrapper* CreateWithDtlsIdentityStore(
232 const std::string& debug_name,
233 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
234 rtc::Thread* network_thread,
235 rtc::Thread* worker_thread) {
236 PeerConnectionWrapper* client(new PeerConnectionWrapper(debug_name));
Benjamin Wrightd6f86e82018-05-08 13:12:25 -0700237 webrtc::PeerConnectionDependencies dependencies(nullptr);
238 dependencies.cert_generator = std::move(cert_generator);
239 if (!client->Init(nullptr, nullptr, nullptr, std::move(dependencies),
Qingsi Wang7685e862018-06-11 20:15:46 -0700240 network_thread, worker_thread, nullptr)) {
deadbeef1dcb1642017-03-29 21:08:16 -0700241 delete client;
242 return nullptr;
243 }
244 return client;
245 }
246
deadbeef2f425aa2017-04-14 10:41:32 -0700247 webrtc::PeerConnectionFactoryInterface* pc_factory() const {
248 return peer_connection_factory_.get();
249 }
250
deadbeef1dcb1642017-03-29 21:08:16 -0700251 webrtc::PeerConnectionInterface* pc() const { return peer_connection_.get(); }
252
253 // If a signaling message receiver is set (via ConnectFakeSignaling), this
254 // will set the whole offer/answer exchange in motion. Just need to wait for
255 // the signaling state to reach "stable".
256 void CreateAndSetAndSignalOffer() {
257 auto offer = CreateOffer();
258 ASSERT_NE(nullptr, offer);
259 EXPECT_TRUE(SetLocalDescriptionAndSendSdpMessage(std::move(offer)));
260 }
261
262 // Sets the options to be used when CreateAndSetAndSignalOffer is called, or
263 // when a remote offer is received (via fake signaling) and an answer is
264 // generated. By default, uses default options.
265 void SetOfferAnswerOptions(
266 const PeerConnectionInterface::RTCOfferAnswerOptions& options) {
267 offer_answer_options_ = options;
268 }
269
270 // Set a callback to be invoked when SDP is received via the fake signaling
271 // channel, which provides an opportunity to munge (modify) the SDP. This is
272 // used to test SDP being applied that a PeerConnection would normally not
273 // generate, but a non-JSEP endpoint might.
274 void SetReceivedSdpMunger(
275 std::function<void(cricket::SessionDescription*)> munger) {
Mirko Bonadeic61ce0d2017-11-21 17:04:20 +0100276 received_sdp_munger_ = std::move(munger);
deadbeef1dcb1642017-03-29 21:08:16 -0700277 }
278
deadbeefc964d0b2017-04-03 10:03:35 -0700279 // Similar to the above, but this is run on SDP immediately after it's
deadbeef1dcb1642017-03-29 21:08:16 -0700280 // generated.
281 void SetGeneratedSdpMunger(
282 std::function<void(cricket::SessionDescription*)> munger) {
Mirko Bonadeic61ce0d2017-11-21 17:04:20 +0100283 generated_sdp_munger_ = std::move(munger);
deadbeef1dcb1642017-03-29 21:08:16 -0700284 }
285
Seth Hampson2f0d7022018-02-20 11:54:42 -0800286 // Set a callback to be invoked when a remote offer is received via the fake
287 // signaling channel. This provides an opportunity to change the
288 // PeerConnection state before an answer is created and sent to the caller.
289 void SetRemoteOfferHandler(std::function<void()> handler) {
290 remote_offer_handler_ = std::move(handler);
291 }
292
Steve Antonede9ca52017-10-16 13:04:27 -0700293 // Every ICE connection state in order that has been seen by the observer.
294 std::vector<PeerConnectionInterface::IceConnectionState>
295 ice_connection_state_history() const {
296 return ice_connection_state_history_;
297 }
Steve Anton6f25b092017-10-23 09:39:20 -0700298 void clear_ice_connection_state_history() {
299 ice_connection_state_history_.clear();
300 }
Steve Antonede9ca52017-10-16 13:04:27 -0700301
302 // Every ICE gathering state in order that has been seen by the observer.
303 std::vector<PeerConnectionInterface::IceGatheringState>
304 ice_gathering_state_history() const {
305 return ice_gathering_state_history_;
deadbeef1dcb1642017-03-29 21:08:16 -0700306 }
307
Steve Anton15324772018-01-16 10:26:49 -0800308 void AddAudioVideoTracks() {
309 AddAudioTrack();
310 AddVideoTrack();
deadbeef1dcb1642017-03-29 21:08:16 -0700311 }
312
Steve Anton74255ff2018-01-24 18:32:57 -0800313 rtc::scoped_refptr<RtpSenderInterface> AddAudioTrack() {
314 return AddTrack(CreateLocalAudioTrack());
315 }
deadbeef1dcb1642017-03-29 21:08:16 -0700316
Steve Anton74255ff2018-01-24 18:32:57 -0800317 rtc::scoped_refptr<RtpSenderInterface> AddVideoTrack() {
318 return AddTrack(CreateLocalVideoTrack());
319 }
deadbeef1dcb1642017-03-29 21:08:16 -0700320
321 rtc::scoped_refptr<webrtc::AudioTrackInterface> CreateLocalAudioTrack() {
Niels Möller2d02e082018-05-21 11:23:35 +0200322 cricket::AudioOptions options;
deadbeef1dcb1642017-03-29 21:08:16 -0700323 // Disable highpass filter so that we can get all the test audio frames.
Niels Möller2d02e082018-05-21 11:23:35 +0200324 options.highpass_filter = false;
deadbeef1dcb1642017-03-29 21:08:16 -0700325 rtc::scoped_refptr<webrtc::AudioSourceInterface> source =
Niels Möller2d02e082018-05-21 11:23:35 +0200326 peer_connection_factory_->CreateAudioSource(options);
deadbeef1dcb1642017-03-29 21:08:16 -0700327 // TODO(perkj): Test audio source when it is implemented. Currently audio
328 // always use the default input.
deadbeefb1a15d72017-09-07 14:12:05 -0700329 return peer_connection_factory_->CreateAudioTrack(rtc::CreateRandomUuid(),
deadbeef1dcb1642017-03-29 21:08:16 -0700330 source);
331 }
332
333 rtc::scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrack() {
Niels Möller5c7efe72018-05-11 10:34:46 +0200334 return CreateLocalVideoTrackInternal(
335 webrtc::FakePeriodicVideoSource::Config());
deadbeef1dcb1642017-03-29 21:08:16 -0700336 }
337
338 rtc::scoped_refptr<webrtc::VideoTrackInterface>
Niels Möller5c7efe72018-05-11 10:34:46 +0200339 CreateLocalVideoTrackWithConfig(
340 webrtc::FakePeriodicVideoSource::Config config) {
341 return CreateLocalVideoTrackInternal(config);
deadbeef1dcb1642017-03-29 21:08:16 -0700342 }
343
344 rtc::scoped_refptr<webrtc::VideoTrackInterface>
345 CreateLocalVideoTrackWithRotation(webrtc::VideoRotation rotation) {
Niels Möller5c7efe72018-05-11 10:34:46 +0200346 webrtc::FakePeriodicVideoSource::Config config;
347 config.rotation = rotation;
348 return CreateLocalVideoTrackInternal(config);
deadbeef1dcb1642017-03-29 21:08:16 -0700349 }
350
Steve Anton74255ff2018-01-24 18:32:57 -0800351 rtc::scoped_refptr<RtpSenderInterface> AddTrack(
352 rtc::scoped_refptr<MediaStreamTrackInterface> track,
Seth Hampson845e8782018-03-02 11:34:10 -0800353 const std::vector<std::string>& stream_ids = {}) {
354 auto result = pc()->AddTrack(track, stream_ids);
Steve Anton15324772018-01-16 10:26:49 -0800355 EXPECT_EQ(RTCErrorType::NONE, result.error().type());
Steve Anton74255ff2018-01-24 18:32:57 -0800356 return result.MoveValue();
357 }
358
359 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceiversOfType(
360 cricket::MediaType media_type) {
361 std::vector<rtc::scoped_refptr<RtpReceiverInterface>> receivers;
362 for (auto receiver : pc()->GetReceivers()) {
363 if (receiver->media_type() == media_type) {
364 receivers.push_back(receiver);
365 }
366 }
367 return receivers;
deadbeef1dcb1642017-03-29 21:08:16 -0700368 }
369
Seth Hampson2f0d7022018-02-20 11:54:42 -0800370 rtc::scoped_refptr<RtpTransceiverInterface> GetFirstTransceiverOfType(
371 cricket::MediaType media_type) {
372 for (auto transceiver : pc()->GetTransceivers()) {
373 if (transceiver->receiver()->media_type() == media_type) {
374 return transceiver;
375 }
376 }
377 return nullptr;
378 }
379
deadbeef1dcb1642017-03-29 21:08:16 -0700380 bool SignalingStateStable() {
381 return pc()->signaling_state() == webrtc::PeerConnectionInterface::kStable;
382 }
383
384 void CreateDataChannel() { CreateDataChannel(nullptr); }
385
386 void CreateDataChannel(const webrtc::DataChannelInit* init) {
Steve Antonda6c0952017-10-23 11:41:54 -0700387 CreateDataChannel(kDataChannelLabel, init);
388 }
389
390 void CreateDataChannel(const std::string& label,
391 const webrtc::DataChannelInit* init) {
392 data_channel_ = pc()->CreateDataChannel(label, init);
deadbeef1dcb1642017-03-29 21:08:16 -0700393 ASSERT_TRUE(data_channel_.get() != nullptr);
394 data_observer_.reset(new MockDataChannelObserver(data_channel_));
395 }
396
397 DataChannelInterface* data_channel() { return data_channel_; }
398 const MockDataChannelObserver* data_observer() const {
399 return data_observer_.get();
400 }
401
402 int audio_frames_received() const {
403 return fake_audio_capture_module_->frames_received();
404 }
405
406 // Takes minimum of video frames received for each track.
407 //
408 // Can be used like:
409 // EXPECT_GE(expected_frames, min_video_frames_received_per_track());
410 //
411 // To ensure that all video tracks received at least a certain number of
412 // frames.
413 int min_video_frames_received_per_track() const {
414 int min_frames = INT_MAX;
Anders Carlsson5f2bb622018-05-14 09:48:06 +0200415 if (fake_video_renderers_.empty()) {
416 return 0;
deadbeef1dcb1642017-03-29 21:08:16 -0700417 }
deadbeef1dcb1642017-03-29 21:08:16 -0700418
Anders Carlsson5f2bb622018-05-14 09:48:06 +0200419 for (const auto& pair : fake_video_renderers_) {
420 min_frames = std::min(min_frames, pair.second->num_rendered_frames());
deadbeef1dcb1642017-03-29 21:08:16 -0700421 }
Anders Carlsson5f2bb622018-05-14 09:48:06 +0200422 return min_frames;
deadbeef1dcb1642017-03-29 21:08:16 -0700423 }
424
425 // Returns a MockStatsObserver in a state after stats gathering finished,
426 // which can be used to access the gathered stats.
deadbeefd8ad7882017-04-18 16:01:17 -0700427 rtc::scoped_refptr<MockStatsObserver> OldGetStatsForTrack(
deadbeef1dcb1642017-03-29 21:08:16 -0700428 webrtc::MediaStreamTrackInterface* track) {
429 rtc::scoped_refptr<MockStatsObserver> observer(
430 new rtc::RefCountedObject<MockStatsObserver>());
431 EXPECT_TRUE(peer_connection_->GetStats(
432 observer, nullptr, PeerConnectionInterface::kStatsOutputLevelStandard));
433 EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout);
434 return observer;
435 }
436
437 // Version that doesn't take a track "filter", and gathers all stats.
deadbeefd8ad7882017-04-18 16:01:17 -0700438 rtc::scoped_refptr<MockStatsObserver> OldGetStats() {
439 return OldGetStatsForTrack(nullptr);
440 }
441
442 // Synchronously gets stats and returns them. If it times out, fails the test
443 // and returns null.
444 rtc::scoped_refptr<const webrtc::RTCStatsReport> NewGetStats() {
445 rtc::scoped_refptr<webrtc::MockRTCStatsCollectorCallback> callback(
446 new rtc::RefCountedObject<webrtc::MockRTCStatsCollectorCallback>());
447 peer_connection_->GetStats(callback);
448 EXPECT_TRUE_WAIT(callback->called(), kDefaultTimeout);
449 return callback->report();
deadbeef1dcb1642017-03-29 21:08:16 -0700450 }
451
452 int rendered_width() {
453 EXPECT_FALSE(fake_video_renderers_.empty());
454 return fake_video_renderers_.empty()
455 ? 0
456 : fake_video_renderers_.begin()->second->width();
457 }
458
459 int rendered_height() {
460 EXPECT_FALSE(fake_video_renderers_.empty());
461 return fake_video_renderers_.empty()
462 ? 0
463 : fake_video_renderers_.begin()->second->height();
464 }
465
466 double rendered_aspect_ratio() {
467 if (rendered_height() == 0) {
468 return 0.0;
469 }
470 return static_cast<double>(rendered_width()) / rendered_height();
471 }
472
473 webrtc::VideoRotation rendered_rotation() {
474 EXPECT_FALSE(fake_video_renderers_.empty());
475 return fake_video_renderers_.empty()
476 ? webrtc::kVideoRotation_0
477 : fake_video_renderers_.begin()->second->rotation();
478 }
479
480 int local_rendered_width() {
481 return local_video_renderer_ ? local_video_renderer_->width() : 0;
482 }
483
484 int local_rendered_height() {
485 return local_video_renderer_ ? local_video_renderer_->height() : 0;
486 }
487
488 double local_rendered_aspect_ratio() {
489 if (local_rendered_height() == 0) {
490 return 0.0;
491 }
492 return static_cast<double>(local_rendered_width()) /
493 local_rendered_height();
494 }
495
496 size_t number_of_remote_streams() {
497 if (!pc()) {
498 return 0;
499 }
500 return pc()->remote_streams()->count();
501 }
502
503 StreamCollectionInterface* remote_streams() const {
504 if (!pc()) {
505 ADD_FAILURE();
506 return nullptr;
507 }
508 return pc()->remote_streams();
509 }
510
511 StreamCollectionInterface* local_streams() {
512 if (!pc()) {
513 ADD_FAILURE();
514 return nullptr;
515 }
516 return pc()->local_streams();
517 }
518
519 webrtc::PeerConnectionInterface::SignalingState signaling_state() {
520 return pc()->signaling_state();
521 }
522
523 webrtc::PeerConnectionInterface::IceConnectionState ice_connection_state() {
524 return pc()->ice_connection_state();
525 }
526
527 webrtc::PeerConnectionInterface::IceGatheringState ice_gathering_state() {
528 return pc()->ice_gathering_state();
529 }
530
531 // Returns a MockRtpReceiverObserver for each RtpReceiver returned by
532 // GetReceivers. They're updated automatically when a remote offer/answer
533 // from the fake signaling channel is applied, or when
534 // ResetRtpReceiverObservers below is called.
535 const std::vector<std::unique_ptr<MockRtpReceiverObserver>>&
536 rtp_receiver_observers() {
537 return rtp_receiver_observers_;
538 }
539
540 void ResetRtpReceiverObservers() {
541 rtp_receiver_observers_.clear();
Mirko Bonadeic61ce0d2017-11-21 17:04:20 +0100542 for (const rtc::scoped_refptr<RtpReceiverInterface>& receiver :
543 pc()->GetReceivers()) {
deadbeef1dcb1642017-03-29 21:08:16 -0700544 std::unique_ptr<MockRtpReceiverObserver> observer(
545 new MockRtpReceiverObserver(receiver->media_type()));
546 receiver->SetObserver(observer.get());
547 rtp_receiver_observers_.push_back(std::move(observer));
548 }
549 }
550
Steve Antonede9ca52017-10-16 13:04:27 -0700551 rtc::FakeNetworkManager* network() const {
552 return fake_network_manager_.get();
553 }
554 cricket::PortAllocator* port_allocator() const { return port_allocator_; }
555
Qingsi Wang7685e862018-06-11 20:15:46 -0700556 webrtc::FakeRtcEventLogFactory* event_log_factory() const {
557 return event_log_factory_;
558 }
559
deadbeef1dcb1642017-03-29 21:08:16 -0700560 private:
561 explicit PeerConnectionWrapper(const std::string& debug_name)
562 : debug_name_(debug_name) {}
563
Benjamin Wrightd6f86e82018-05-08 13:12:25 -0700564 bool Init(const MediaConstraintsInterface* constraints,
565 const PeerConnectionFactory::Options* options,
566 const PeerConnectionInterface::RTCConfiguration* config,
567 webrtc::PeerConnectionDependencies dependencies,
568 rtc::Thread* network_thread,
Qingsi Wang7685e862018-06-11 20:15:46 -0700569 rtc::Thread* worker_thread,
570 std::unique_ptr<webrtc::FakeRtcEventLogFactory> event_log_factory) {
deadbeef1dcb1642017-03-29 21:08:16 -0700571 // There's an error in this test code if Init ends up being called twice.
572 RTC_DCHECK(!peer_connection_);
573 RTC_DCHECK(!peer_connection_factory_);
574
575 fake_network_manager_.reset(new rtc::FakeNetworkManager());
Steve Antonede9ca52017-10-16 13:04:27 -0700576 fake_network_manager_->AddInterface(kDefaultLocalAddress);
deadbeef1dcb1642017-03-29 21:08:16 -0700577
578 std::unique_ptr<cricket::PortAllocator> port_allocator(
579 new cricket::BasicPortAllocator(fake_network_manager_.get()));
Steve Antonede9ca52017-10-16 13:04:27 -0700580 port_allocator_ = port_allocator.get();
deadbeef1dcb1642017-03-29 21:08:16 -0700581 fake_audio_capture_module_ = FakeAudioCaptureModule::Create();
582 if (!fake_audio_capture_module_) {
583 return false;
584 }
deadbeef1dcb1642017-03-29 21:08:16 -0700585 rtc::Thread* const signaling_thread = rtc::Thread::Current();
Qingsi Wang7685e862018-06-11 20:15:46 -0700586
587 webrtc::PeerConnectionFactoryDependencies pc_factory_dependencies;
588 pc_factory_dependencies.network_thread = network_thread;
589 pc_factory_dependencies.worker_thread = worker_thread;
590 pc_factory_dependencies.signaling_thread = signaling_thread;
591 pc_factory_dependencies.media_engine =
592 cricket::WebRtcMediaEngineFactory::Create(
593 rtc::scoped_refptr<webrtc::AudioDeviceModule>(
594 fake_audio_capture_module_),
595 webrtc::CreateBuiltinAudioEncoderFactory(),
596 webrtc::CreateBuiltinAudioDecoderFactory(),
597 webrtc::CreateBuiltinVideoEncoderFactory(),
598 webrtc::CreateBuiltinVideoDecoderFactory(), nullptr,
599 webrtc::AudioProcessingBuilder().Create());
600 pc_factory_dependencies.call_factory = webrtc::CreateCallFactory();
601 if (event_log_factory) {
602 event_log_factory_ = event_log_factory.get();
603 pc_factory_dependencies.event_log_factory = std::move(event_log_factory);
604 } else {
605 pc_factory_dependencies.event_log_factory =
606 webrtc::CreateRtcEventLogFactory();
607 }
608 peer_connection_factory_ = webrtc::CreateModularPeerConnectionFactory(
609 std::move(pc_factory_dependencies));
610
deadbeef1dcb1642017-03-29 21:08:16 -0700611 if (!peer_connection_factory_) {
612 return false;
613 }
614 if (options) {
615 peer_connection_factory_->SetOptions(*options);
616 }
Seth Hampson2f0d7022018-02-20 11:54:42 -0800617 if (config) {
618 sdp_semantics_ = config->sdp_semantics;
619 }
Benjamin Wrightd6f86e82018-05-08 13:12:25 -0700620
621 dependencies.allocator = std::move(port_allocator);
deadbeef1dcb1642017-03-29 21:08:16 -0700622 peer_connection_ =
Benjamin Wrightd6f86e82018-05-08 13:12:25 -0700623 CreatePeerConnection(constraints, config, std::move(dependencies));
deadbeef1dcb1642017-03-29 21:08:16 -0700624 return peer_connection_.get() != nullptr;
625 }
626
627 rtc::scoped_refptr<webrtc::PeerConnectionInterface> CreatePeerConnection(
deadbeef1dcb1642017-03-29 21:08:16 -0700628 const MediaConstraintsInterface* constraints,
629 const PeerConnectionInterface::RTCConfiguration* config,
Benjamin Wrightd6f86e82018-05-08 13:12:25 -0700630 webrtc::PeerConnectionDependencies dependencies) {
deadbeef1dcb1642017-03-29 21:08:16 -0700631 PeerConnectionInterface::RTCConfiguration modified_config;
632 // If |config| is null, this will result in a default configuration being
633 // used.
634 if (config) {
635 modified_config = *config;
636 }
637 // Disable resolution adaptation; we don't want it interfering with the
638 // test results.
639 // TODO(deadbeef): Do something more robust. Since we're testing for aspect
640 // ratios and not specific resolutions, is this even necessary?
641 modified_config.set_cpu_adaptation(false);
642
Benjamin Wrightd6f86e82018-05-08 13:12:25 -0700643 // Use the legacy interface.
644 if (constraints != nullptr) {
645 return peer_connection_factory_->CreatePeerConnection(
646 modified_config, constraints, std::move(dependencies.allocator),
647 std::move(dependencies.cert_generator), this);
648 }
649 dependencies.observer = this;
deadbeef1dcb1642017-03-29 21:08:16 -0700650 return peer_connection_factory_->CreatePeerConnection(
Benjamin Wrightd6f86e82018-05-08 13:12:25 -0700651 modified_config, std::move(dependencies));
deadbeef1dcb1642017-03-29 21:08:16 -0700652 }
653
654 void set_signaling_message_receiver(
655 SignalingMessageReceiver* signaling_message_receiver) {
656 signaling_message_receiver_ = signaling_message_receiver;
657 }
658
659 void set_signaling_delay_ms(int delay_ms) { signaling_delay_ms_ = delay_ms; }
660
Steve Antonede9ca52017-10-16 13:04:27 -0700661 void set_signal_ice_candidates(bool signal) {
662 signal_ice_candidates_ = signal;
663 }
664
deadbeef1dcb1642017-03-29 21:08:16 -0700665 rtc::scoped_refptr<webrtc::VideoTrackInterface> CreateLocalVideoTrackInternal(
Niels Möller5c7efe72018-05-11 10:34:46 +0200666 webrtc::FakePeriodicVideoSource::Config config) {
deadbeef1dcb1642017-03-29 21:08:16 -0700667 // Set max frame rate to 10fps to reduce the risk of test flakiness.
668 // TODO(deadbeef): Do something more robust.
Niels Möller5c7efe72018-05-11 10:34:46 +0200669 config.frame_interval_ms = 100;
deadbeef1dcb1642017-03-29 21:08:16 -0700670
Niels Möller5c7efe72018-05-11 10:34:46 +0200671 video_track_sources_.emplace_back(
Niels Möller0f405822018-05-17 09:16:41 +0200672 new rtc::RefCountedObject<webrtc::FakePeriodicVideoTrackSource>(
673 config, false /* remote */));
deadbeef1dcb1642017-03-29 21:08:16 -0700674 rtc::scoped_refptr<webrtc::VideoTrackInterface> track(
Niels Möller5c7efe72018-05-11 10:34:46 +0200675 peer_connection_factory_->CreateVideoTrack(
676 rtc::CreateRandomUuid(), video_track_sources_.back()));
deadbeef1dcb1642017-03-29 21:08:16 -0700677 if (!local_video_renderer_) {
678 local_video_renderer_.reset(new webrtc::FakeVideoTrackRenderer(track));
679 }
680 return track;
681 }
682
683 void HandleIncomingOffer(const std::string& msg) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100684 RTC_LOG(LS_INFO) << debug_name_ << ": HandleIncomingOffer";
Steve Antona3a92c22017-12-07 10:27:41 -0800685 std::unique_ptr<SessionDescriptionInterface> desc =
686 webrtc::CreateSessionDescription(SdpType::kOffer, msg);
deadbeef1dcb1642017-03-29 21:08:16 -0700687 if (received_sdp_munger_) {
688 received_sdp_munger_(desc->description());
689 }
690
691 EXPECT_TRUE(SetRemoteDescription(std::move(desc)));
692 // Setting a remote description may have changed the number of receivers,
693 // so reset the receiver observers.
694 ResetRtpReceiverObservers();
Seth Hampson2f0d7022018-02-20 11:54:42 -0800695 if (remote_offer_handler_) {
696 remote_offer_handler_();
697 }
deadbeef1dcb1642017-03-29 21:08:16 -0700698 auto answer = CreateAnswer();
699 ASSERT_NE(nullptr, answer);
700 EXPECT_TRUE(SetLocalDescriptionAndSendSdpMessage(std::move(answer)));
701 }
702
703 void HandleIncomingAnswer(const std::string& msg) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100704 RTC_LOG(LS_INFO) << debug_name_ << ": HandleIncomingAnswer";
Steve Antona3a92c22017-12-07 10:27:41 -0800705 std::unique_ptr<SessionDescriptionInterface> desc =
706 webrtc::CreateSessionDescription(SdpType::kAnswer, msg);
deadbeef1dcb1642017-03-29 21:08:16 -0700707 if (received_sdp_munger_) {
708 received_sdp_munger_(desc->description());
709 }
710
711 EXPECT_TRUE(SetRemoteDescription(std::move(desc)));
712 // Set the RtpReceiverObserver after receivers are created.
713 ResetRtpReceiverObservers();
714 }
715
716 // Returns null on failure.
717 std::unique_ptr<SessionDescriptionInterface> CreateOffer() {
718 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
719 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
720 pc()->CreateOffer(observer, offer_answer_options_);
721 return WaitForDescriptionFromObserver(observer);
722 }
723
724 // Returns null on failure.
725 std::unique_ptr<SessionDescriptionInterface> CreateAnswer() {
726 rtc::scoped_refptr<MockCreateSessionDescriptionObserver> observer(
727 new rtc::RefCountedObject<MockCreateSessionDescriptionObserver>());
728 pc()->CreateAnswer(observer, offer_answer_options_);
729 return WaitForDescriptionFromObserver(observer);
730 }
731
732 std::unique_ptr<SessionDescriptionInterface> WaitForDescriptionFromObserver(
Mirko Bonadeic61ce0d2017-11-21 17:04:20 +0100733 MockCreateSessionDescriptionObserver* observer) {
deadbeef1dcb1642017-03-29 21:08:16 -0700734 EXPECT_EQ_WAIT(true, observer->called(), kDefaultTimeout);
735 if (!observer->result()) {
736 return nullptr;
737 }
738 auto description = observer->MoveDescription();
739 if (generated_sdp_munger_) {
740 generated_sdp_munger_(description->description());
741 }
742 return description;
743 }
744
745 // Setting the local description and sending the SDP message over the fake
746 // signaling channel are combined into the same method because the SDP
747 // message needs to be sent as soon as SetLocalDescription finishes, without
748 // waiting for the observer to be called. This ensures that ICE candidates
749 // don't outrace the description.
750 bool SetLocalDescriptionAndSendSdpMessage(
751 std::unique_ptr<SessionDescriptionInterface> desc) {
752 rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer(
753 new rtc::RefCountedObject<MockSetSessionDescriptionObserver>());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100754 RTC_LOG(LS_INFO) << debug_name_ << ": SetLocalDescriptionAndSendSdpMessage";
Steve Antona3a92c22017-12-07 10:27:41 -0800755 SdpType type = desc->GetType();
deadbeef1dcb1642017-03-29 21:08:16 -0700756 std::string sdp;
757 EXPECT_TRUE(desc->ToString(&sdp));
758 pc()->SetLocalDescription(observer, desc.release());
Seth Hampson2f0d7022018-02-20 11:54:42 -0800759 if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) {
760 RemoveUnusedVideoRenderers();
761 }
deadbeef1dcb1642017-03-29 21:08:16 -0700762 // As mentioned above, we need to send the message immediately after
763 // SetLocalDescription.
764 SendSdpMessage(type, sdp);
765 EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout);
766 return true;
767 }
768
769 bool SetRemoteDescription(std::unique_ptr<SessionDescriptionInterface> desc) {
770 rtc::scoped_refptr<MockSetSessionDescriptionObserver> observer(
771 new rtc::RefCountedObject<MockSetSessionDescriptionObserver>());
Mirko Bonadei675513b2017-11-09 11:09:25 +0100772 RTC_LOG(LS_INFO) << debug_name_ << ": SetRemoteDescription";
deadbeef1dcb1642017-03-29 21:08:16 -0700773 pc()->SetRemoteDescription(observer, desc.release());
Seth Hampson2f0d7022018-02-20 11:54:42 -0800774 if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) {
775 RemoveUnusedVideoRenderers();
776 }
deadbeef1dcb1642017-03-29 21:08:16 -0700777 EXPECT_TRUE_WAIT(observer->called(), kDefaultTimeout);
778 return observer->result();
779 }
780
Seth Hampson2f0d7022018-02-20 11:54:42 -0800781 // This is a work around to remove unused fake_video_renderers from
782 // transceivers that have either stopped or are no longer receiving.
783 void RemoveUnusedVideoRenderers() {
784 auto transceivers = pc()->GetTransceivers();
785 for (auto& transceiver : transceivers) {
786 if (transceiver->receiver()->media_type() != cricket::MEDIA_TYPE_VIDEO) {
787 continue;
788 }
789 // Remove fake video renderers from any stopped transceivers.
790 if (transceiver->stopped()) {
791 auto it =
792 fake_video_renderers_.find(transceiver->receiver()->track()->id());
793 if (it != fake_video_renderers_.end()) {
794 fake_video_renderers_.erase(it);
795 }
796 }
797 // Remove fake video renderers from any transceivers that are no longer
798 // receiving.
799 if ((transceiver->current_direction() &&
800 !webrtc::RtpTransceiverDirectionHasRecv(
801 *transceiver->current_direction()))) {
802 auto it =
803 fake_video_renderers_.find(transceiver->receiver()->track()->id());
804 if (it != fake_video_renderers_.end()) {
805 fake_video_renderers_.erase(it);
806 }
807 }
808 }
809 }
810
deadbeef1dcb1642017-03-29 21:08:16 -0700811 // Simulate sending a blob of SDP with delay |signaling_delay_ms_| (0 by
812 // default).
Steve Antona3a92c22017-12-07 10:27:41 -0800813 void SendSdpMessage(SdpType type, const std::string& msg) {
deadbeef1dcb1642017-03-29 21:08:16 -0700814 if (signaling_delay_ms_ == 0) {
815 RelaySdpMessageIfReceiverExists(type, msg);
816 } else {
817 invoker_.AsyncInvokeDelayed<void>(
818 RTC_FROM_HERE, rtc::Thread::Current(),
819 rtc::Bind(&PeerConnectionWrapper::RelaySdpMessageIfReceiverExists,
820 this, type, msg),
821 signaling_delay_ms_);
822 }
823 }
824
Steve Antona3a92c22017-12-07 10:27:41 -0800825 void RelaySdpMessageIfReceiverExists(SdpType type, const std::string& msg) {
deadbeef1dcb1642017-03-29 21:08:16 -0700826 if (signaling_message_receiver_) {
827 signaling_message_receiver_->ReceiveSdpMessage(type, msg);
828 }
829 }
830
831 // Simulate trickling an ICE candidate with delay |signaling_delay_ms_| (0 by
832 // default).
833 void SendIceMessage(const std::string& sdp_mid,
834 int sdp_mline_index,
835 const std::string& msg) {
836 if (signaling_delay_ms_ == 0) {
837 RelayIceMessageIfReceiverExists(sdp_mid, sdp_mline_index, msg);
838 } else {
839 invoker_.AsyncInvokeDelayed<void>(
840 RTC_FROM_HERE, rtc::Thread::Current(),
841 rtc::Bind(&PeerConnectionWrapper::RelayIceMessageIfReceiverExists,
842 this, sdp_mid, sdp_mline_index, msg),
843 signaling_delay_ms_);
844 }
845 }
846
847 void RelayIceMessageIfReceiverExists(const std::string& sdp_mid,
848 int sdp_mline_index,
849 const std::string& msg) {
850 if (signaling_message_receiver_) {
851 signaling_message_receiver_->ReceiveIceMessage(sdp_mid, sdp_mline_index,
852 msg);
853 }
854 }
855
856 // SignalingMessageReceiver callbacks.
Steve Antona3a92c22017-12-07 10:27:41 -0800857 void ReceiveSdpMessage(SdpType type, const std::string& msg) override {
858 if (type == SdpType::kOffer) {
deadbeef1dcb1642017-03-29 21:08:16 -0700859 HandleIncomingOffer(msg);
860 } else {
861 HandleIncomingAnswer(msg);
862 }
863 }
864
865 void ReceiveIceMessage(const std::string& sdp_mid,
866 int sdp_mline_index,
867 const std::string& msg) override {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100868 RTC_LOG(LS_INFO) << debug_name_ << ": ReceiveIceMessage";
deadbeef1dcb1642017-03-29 21:08:16 -0700869 std::unique_ptr<webrtc::IceCandidateInterface> candidate(
870 webrtc::CreateIceCandidate(sdp_mid, sdp_mline_index, msg, nullptr));
871 EXPECT_TRUE(pc()->AddIceCandidate(candidate.get()));
872 }
873
874 // PeerConnectionObserver callbacks.
875 void OnSignalingChange(
876 webrtc::PeerConnectionInterface::SignalingState new_state) override {
877 EXPECT_EQ(pc()->signaling_state(), new_state);
878 }
Steve Anton15324772018-01-16 10:26:49 -0800879 void OnAddTrack(rtc::scoped_refptr<RtpReceiverInterface> receiver,
880 const std::vector<rtc::scoped_refptr<MediaStreamInterface>>&
881 streams) override {
882 if (receiver->media_type() == cricket::MEDIA_TYPE_VIDEO) {
883 rtc::scoped_refptr<VideoTrackInterface> video_track(
884 static_cast<VideoTrackInterface*>(receiver->track().get()));
885 ASSERT_TRUE(fake_video_renderers_.find(video_track->id()) ==
deadbeef1dcb1642017-03-29 21:08:16 -0700886 fake_video_renderers_.end());
Steve Anton15324772018-01-16 10:26:49 -0800887 fake_video_renderers_[video_track->id()] =
888 rtc::MakeUnique<FakeVideoTrackRenderer>(video_track);
deadbeef1dcb1642017-03-29 21:08:16 -0700889 }
890 }
Steve Anton15324772018-01-16 10:26:49 -0800891 void OnRemoveTrack(
892 rtc::scoped_refptr<RtpReceiverInterface> receiver) override {
893 if (receiver->media_type() == cricket::MEDIA_TYPE_VIDEO) {
894 auto it = fake_video_renderers_.find(receiver->track()->id());
895 RTC_DCHECK(it != fake_video_renderers_.end());
896 fake_video_renderers_.erase(it);
897 }
898 }
deadbeef1dcb1642017-03-29 21:08:16 -0700899 void OnRenegotiationNeeded() override {}
900 void OnIceConnectionChange(
901 webrtc::PeerConnectionInterface::IceConnectionState new_state) override {
902 EXPECT_EQ(pc()->ice_connection_state(), new_state);
Steve Antonede9ca52017-10-16 13:04:27 -0700903 ice_connection_state_history_.push_back(new_state);
deadbeef1dcb1642017-03-29 21:08:16 -0700904 }
905 void OnIceGatheringChange(
906 webrtc::PeerConnectionInterface::IceGatheringState new_state) override {
deadbeef1dcb1642017-03-29 21:08:16 -0700907 EXPECT_EQ(pc()->ice_gathering_state(), new_state);
Steve Antonede9ca52017-10-16 13:04:27 -0700908 ice_gathering_state_history_.push_back(new_state);
deadbeef1dcb1642017-03-29 21:08:16 -0700909 }
910 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100911 RTC_LOG(LS_INFO) << debug_name_ << ": OnIceCandidate";
deadbeef1dcb1642017-03-29 21:08:16 -0700912
913 std::string ice_sdp;
914 EXPECT_TRUE(candidate->ToString(&ice_sdp));
Steve Antonede9ca52017-10-16 13:04:27 -0700915 if (signaling_message_receiver_ == nullptr || !signal_ice_candidates_) {
deadbeef1dcb1642017-03-29 21:08:16 -0700916 // Remote party may be deleted.
917 return;
918 }
919 SendIceMessage(candidate->sdp_mid(), candidate->sdp_mline_index(), ice_sdp);
920 }
921 void OnDataChannel(
922 rtc::scoped_refptr<DataChannelInterface> data_channel) override {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100923 RTC_LOG(LS_INFO) << debug_name_ << ": OnDataChannel";
deadbeef1dcb1642017-03-29 21:08:16 -0700924 data_channel_ = data_channel;
925 data_observer_.reset(new MockDataChannelObserver(data_channel));
926 }
927
deadbeef1dcb1642017-03-29 21:08:16 -0700928 std::string debug_name_;
929
930 std::unique_ptr<rtc::FakeNetworkManager> fake_network_manager_;
931
932 rtc::scoped_refptr<webrtc::PeerConnectionInterface> peer_connection_;
933 rtc::scoped_refptr<webrtc::PeerConnectionFactoryInterface>
934 peer_connection_factory_;
935
Steve Antonede9ca52017-10-16 13:04:27 -0700936 cricket::PortAllocator* port_allocator_;
deadbeef1dcb1642017-03-29 21:08:16 -0700937 // Needed to keep track of number of frames sent.
938 rtc::scoped_refptr<FakeAudioCaptureModule> fake_audio_capture_module_;
939 // Needed to keep track of number of frames received.
940 std::map<std::string, std::unique_ptr<webrtc::FakeVideoTrackRenderer>>
941 fake_video_renderers_;
942 // Needed to ensure frames aren't received for removed tracks.
943 std::vector<std::unique_ptr<webrtc::FakeVideoTrackRenderer>>
944 removed_fake_video_renderers_;
deadbeef1dcb1642017-03-29 21:08:16 -0700945
946 // For remote peer communication.
947 SignalingMessageReceiver* signaling_message_receiver_ = nullptr;
948 int signaling_delay_ms_ = 0;
Steve Antonede9ca52017-10-16 13:04:27 -0700949 bool signal_ice_candidates_ = true;
deadbeef1dcb1642017-03-29 21:08:16 -0700950
Niels Möller5c7efe72018-05-11 10:34:46 +0200951 // Store references to the video sources we've created, so that we can stop
deadbeef1dcb1642017-03-29 21:08:16 -0700952 // them, if required.
Niels Möller5c7efe72018-05-11 10:34:46 +0200953 std::vector<rtc::scoped_refptr<webrtc::VideoTrackSource>>
954 video_track_sources_;
deadbeef1dcb1642017-03-29 21:08:16 -0700955 // |local_video_renderer_| attached to the first created local video track.
956 std::unique_ptr<webrtc::FakeVideoTrackRenderer> local_video_renderer_;
957
Seth Hampson2f0d7022018-02-20 11:54:42 -0800958 SdpSemantics sdp_semantics_;
deadbeef1dcb1642017-03-29 21:08:16 -0700959 PeerConnectionInterface::RTCOfferAnswerOptions offer_answer_options_;
960 std::function<void(cricket::SessionDescription*)> received_sdp_munger_;
961 std::function<void(cricket::SessionDescription*)> generated_sdp_munger_;
Seth Hampson2f0d7022018-02-20 11:54:42 -0800962 std::function<void()> remote_offer_handler_;
deadbeef1dcb1642017-03-29 21:08:16 -0700963
964 rtc::scoped_refptr<DataChannelInterface> data_channel_;
965 std::unique_ptr<MockDataChannelObserver> data_observer_;
966
967 std::vector<std::unique_ptr<MockRtpReceiverObserver>> rtp_receiver_observers_;
968
Steve Antonede9ca52017-10-16 13:04:27 -0700969 std::vector<PeerConnectionInterface::IceConnectionState>
970 ice_connection_state_history_;
971 std::vector<PeerConnectionInterface::IceGatheringState>
972 ice_gathering_state_history_;
deadbeef1dcb1642017-03-29 21:08:16 -0700973
Qingsi Wang7685e862018-06-11 20:15:46 -0700974 webrtc::FakeRtcEventLogFactory* event_log_factory_;
975
deadbeef1dcb1642017-03-29 21:08:16 -0700976 rtc::AsyncInvoker invoker_;
977
Seth Hampson2f0d7022018-02-20 11:54:42 -0800978 friend class PeerConnectionIntegrationBaseTest;
deadbeef1dcb1642017-03-29 21:08:16 -0700979};
980
Elad Alon99c3fe52017-10-13 16:29:40 +0200981class MockRtcEventLogOutput : public webrtc::RtcEventLogOutput {
982 public:
983 virtual ~MockRtcEventLogOutput() = default;
984 MOCK_CONST_METHOD0(IsActive, bool());
985 MOCK_METHOD1(Write, bool(const std::string&));
986};
987
Seth Hampson2f0d7022018-02-20 11:54:42 -0800988// This helper object is used for both specifying how many audio/video frames
989// are expected to be received for a caller/callee. It provides helper functions
990// to specify these expectations. The object initially starts in a state of no
991// expectations.
992class MediaExpectations {
993 public:
994 enum ExpectFrames {
995 kExpectSomeFrames,
996 kExpectNoFrames,
997 kNoExpectation,
998 };
999
1000 void ExpectBidirectionalAudioAndVideo() {
1001 ExpectBidirectionalAudio();
1002 ExpectBidirectionalVideo();
1003 }
1004
1005 void ExpectBidirectionalAudio() {
1006 CallerExpectsSomeAudio();
1007 CalleeExpectsSomeAudio();
1008 }
1009
1010 void ExpectNoAudio() {
1011 CallerExpectsNoAudio();
1012 CalleeExpectsNoAudio();
1013 }
1014
1015 void ExpectBidirectionalVideo() {
1016 CallerExpectsSomeVideo();
1017 CalleeExpectsSomeVideo();
1018 }
1019
1020 void ExpectNoVideo() {
1021 CallerExpectsNoVideo();
1022 CalleeExpectsNoVideo();
1023 }
1024
1025 void CallerExpectsSomeAudioAndVideo() {
1026 CallerExpectsSomeAudio();
1027 CallerExpectsSomeVideo();
1028 }
1029
1030 void CalleeExpectsSomeAudioAndVideo() {
1031 CalleeExpectsSomeAudio();
1032 CalleeExpectsSomeVideo();
1033 }
1034
1035 // Caller's audio functions.
1036 void CallerExpectsSomeAudio(
1037 int expected_audio_frames = kDefaultExpectedAudioFrameCount) {
1038 caller_audio_expectation_ = kExpectSomeFrames;
1039 caller_audio_frames_expected_ = expected_audio_frames;
1040 }
1041
1042 void CallerExpectsNoAudio() {
1043 caller_audio_expectation_ = kExpectNoFrames;
1044 caller_audio_frames_expected_ = 0;
1045 }
1046
1047 // Caller's video functions.
1048 void CallerExpectsSomeVideo(
1049 int expected_video_frames = kDefaultExpectedVideoFrameCount) {
1050 caller_video_expectation_ = kExpectSomeFrames;
1051 caller_video_frames_expected_ = expected_video_frames;
1052 }
1053
1054 void CallerExpectsNoVideo() {
1055 caller_video_expectation_ = kExpectNoFrames;
1056 caller_video_frames_expected_ = 0;
1057 }
1058
1059 // Callee's audio functions.
1060 void CalleeExpectsSomeAudio(
1061 int expected_audio_frames = kDefaultExpectedAudioFrameCount) {
1062 callee_audio_expectation_ = kExpectSomeFrames;
1063 callee_audio_frames_expected_ = expected_audio_frames;
1064 }
1065
1066 void CalleeExpectsNoAudio() {
1067 callee_audio_expectation_ = kExpectNoFrames;
1068 callee_audio_frames_expected_ = 0;
1069 }
1070
1071 // Callee's video functions.
1072 void CalleeExpectsSomeVideo(
1073 int expected_video_frames = kDefaultExpectedVideoFrameCount) {
1074 callee_video_expectation_ = kExpectSomeFrames;
1075 callee_video_frames_expected_ = expected_video_frames;
1076 }
1077
1078 void CalleeExpectsNoVideo() {
1079 callee_video_expectation_ = kExpectNoFrames;
1080 callee_video_frames_expected_ = 0;
1081 }
1082
1083 ExpectFrames caller_audio_expectation_ = kNoExpectation;
1084 ExpectFrames caller_video_expectation_ = kNoExpectation;
1085 ExpectFrames callee_audio_expectation_ = kNoExpectation;
1086 ExpectFrames callee_video_expectation_ = kNoExpectation;
1087 int caller_audio_frames_expected_ = 0;
1088 int caller_video_frames_expected_ = 0;
1089 int callee_audio_frames_expected_ = 0;
1090 int callee_video_frames_expected_ = 0;
1091};
1092
deadbeef1dcb1642017-03-29 21:08:16 -07001093// Tests two PeerConnections connecting to each other end-to-end, using a
1094// virtual network, fake A/V capture and fake encoder/decoders. The
1095// PeerConnections share the threads/socket servers, but use separate versions
1096// of everything else (including "PeerConnectionFactory"s).
Seth Hampson2f0d7022018-02-20 11:54:42 -08001097class PeerConnectionIntegrationBaseTest : public testing::Test {
deadbeef1dcb1642017-03-29 21:08:16 -07001098 public:
Seth Hampson2f0d7022018-02-20 11:54:42 -08001099 explicit PeerConnectionIntegrationBaseTest(SdpSemantics sdp_semantics)
1100 : sdp_semantics_(sdp_semantics),
1101 ss_(new rtc::VirtualSocketServer()),
Steve Antonede9ca52017-10-16 13:04:27 -07001102 fss_(new rtc::FirewallSocketServer(ss_.get())),
1103 network_thread_(new rtc::Thread(fss_.get())),
deadbeef1dcb1642017-03-29 21:08:16 -07001104 worker_thread_(rtc::Thread::Create()) {
Sebastian Jansson8a793a02018-03-13 15:21:48 +01001105 network_thread_->SetName("PCNetworkThread", this);
1106 worker_thread_->SetName("PCWorkerThread", this);
deadbeef1dcb1642017-03-29 21:08:16 -07001107 RTC_CHECK(network_thread_->Start());
1108 RTC_CHECK(worker_thread_->Start());
1109 }
1110
Seth Hampson2f0d7022018-02-20 11:54:42 -08001111 ~PeerConnectionIntegrationBaseTest() {
Seth Hampsonaed71642018-06-11 07:41:32 -07001112 // The PeerConnections should deleted before the TurnCustomizers.
1113 // A TurnPort is created with a raw pointer to a TurnCustomizer. The
1114 // TurnPort has the same lifetime as the PeerConnection, so it's expected
1115 // that the TurnCustomizer outlives the life of the PeerConnection or else
1116 // when Send() is called it will hit a seg fault.
deadbeef1dcb1642017-03-29 21:08:16 -07001117 if (caller_) {
1118 caller_->set_signaling_message_receiver(nullptr);
Seth Hampsonaed71642018-06-11 07:41:32 -07001119 delete SetCallerPcWrapperAndReturnCurrent(nullptr);
deadbeef1dcb1642017-03-29 21:08:16 -07001120 }
1121 if (callee_) {
1122 callee_->set_signaling_message_receiver(nullptr);
Seth Hampsonaed71642018-06-11 07:41:32 -07001123 delete SetCalleePcWrapperAndReturnCurrent(nullptr);
deadbeef1dcb1642017-03-29 21:08:16 -07001124 }
Seth Hampsonaed71642018-06-11 07:41:32 -07001125
1126 // If turn servers were created for the test they need to be destroyed on
1127 // the network thread.
1128 network_thread()->Invoke<void>(RTC_FROM_HERE, [this] {
1129 turn_servers_.clear();
1130 turn_customizers_.clear();
1131 });
deadbeef1dcb1642017-03-29 21:08:16 -07001132 }
1133
1134 bool SignalingStateStable() {
1135 return caller_->SignalingStateStable() && callee_->SignalingStateStable();
1136 }
1137
deadbeef71452802017-05-07 17:21:01 -07001138 bool DtlsConnected() {
1139 // TODO(deadbeef): kIceConnectionConnected currently means both ICE and DTLS
1140 // are connected. This is an important distinction. Once we have separate
1141 // ICE and DTLS state, this check needs to use the DTLS state.
1142 return (callee()->ice_connection_state() ==
1143 webrtc::PeerConnectionInterface::kIceConnectionConnected ||
1144 callee()->ice_connection_state() ==
1145 webrtc::PeerConnectionInterface::kIceConnectionCompleted) &&
1146 (caller()->ice_connection_state() ==
1147 webrtc::PeerConnectionInterface::kIceConnectionConnected ||
1148 caller()->ice_connection_state() ==
1149 webrtc::PeerConnectionInterface::kIceConnectionCompleted);
1150 }
1151
Qingsi Wang7685e862018-06-11 20:15:46 -07001152 // When |event_log_factory| is null, the default implementation of the event
1153 // log factory will be used.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001154 std::unique_ptr<PeerConnectionWrapper> CreatePeerConnectionWrapper(
1155 const std::string& debug_name,
1156 const MediaConstraintsInterface* constraints,
1157 const PeerConnectionFactory::Options* options,
1158 const RTCConfiguration* config,
Qingsi Wang7685e862018-06-11 20:15:46 -07001159 webrtc::PeerConnectionDependencies dependencies,
1160 std::unique_ptr<webrtc::FakeRtcEventLogFactory> event_log_factory) {
Seth Hampson2f0d7022018-02-20 11:54:42 -08001161 RTCConfiguration modified_config;
1162 if (config) {
1163 modified_config = *config;
1164 }
Steve Anton3acffc32018-04-12 17:21:03 -07001165 modified_config.sdp_semantics = sdp_semantics_;
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07001166 if (!dependencies.cert_generator) {
1167 dependencies.cert_generator =
1168 rtc::MakeUnique<FakeRTCCertificateGenerator>();
Seth Hampson2f0d7022018-02-20 11:54:42 -08001169 }
1170 std::unique_ptr<PeerConnectionWrapper> client(
1171 new PeerConnectionWrapper(debug_name));
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07001172
Seth Hampson2f0d7022018-02-20 11:54:42 -08001173 if (!client->Init(constraints, options, &modified_config,
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07001174 std::move(dependencies), network_thread_.get(),
Qingsi Wang7685e862018-06-11 20:15:46 -07001175 worker_thread_.get(), std::move(event_log_factory))) {
Seth Hampson2f0d7022018-02-20 11:54:42 -08001176 return nullptr;
1177 }
1178 return client;
1179 }
1180
Qingsi Wang7685e862018-06-11 20:15:46 -07001181 std::unique_ptr<PeerConnectionWrapper>
1182 CreatePeerConnectionWrapperWithFakeRtcEventLog(
1183 const std::string& debug_name,
1184 const MediaConstraintsInterface* constraints,
1185 const PeerConnectionFactory::Options* options,
1186 const RTCConfiguration* config,
1187 webrtc::PeerConnectionDependencies dependencies) {
1188 std::unique_ptr<webrtc::FakeRtcEventLogFactory> event_log_factory(
1189 new webrtc::FakeRtcEventLogFactory(rtc::Thread::Current()));
1190 return CreatePeerConnectionWrapper(debug_name, constraints, options, config,
1191 std::move(dependencies),
1192 std::move(event_log_factory));
1193 }
1194
deadbeef1dcb1642017-03-29 21:08:16 -07001195 bool CreatePeerConnectionWrappers() {
1196 return CreatePeerConnectionWrappersWithConfig(
1197 PeerConnectionInterface::RTCConfiguration(),
1198 PeerConnectionInterface::RTCConfiguration());
1199 }
1200
Steve Anton3acffc32018-04-12 17:21:03 -07001201 bool CreatePeerConnectionWrappersWithSdpSemantics(
1202 SdpSemantics caller_semantics,
1203 SdpSemantics callee_semantics) {
1204 // Can't specify the sdp_semantics in the passed-in configuration since it
1205 // will be overwritten by CreatePeerConnectionWrapper with whatever is
1206 // stored in sdp_semantics_. So get around this by modifying the instance
1207 // variable before calling CreatePeerConnectionWrapper for the caller and
1208 // callee PeerConnections.
1209 SdpSemantics original_semantics = sdp_semantics_;
1210 sdp_semantics_ = caller_semantics;
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07001211 caller_ = CreatePeerConnectionWrapper(
1212 "Caller", nullptr, nullptr, nullptr,
Qingsi Wang7685e862018-06-11 20:15:46 -07001213 webrtc::PeerConnectionDependencies(nullptr), nullptr);
Steve Anton3acffc32018-04-12 17:21:03 -07001214 sdp_semantics_ = callee_semantics;
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07001215 callee_ = CreatePeerConnectionWrapper(
1216 "Callee", nullptr, nullptr, nullptr,
Qingsi Wang7685e862018-06-11 20:15:46 -07001217 webrtc::PeerConnectionDependencies(nullptr), nullptr);
Steve Anton3acffc32018-04-12 17:21:03 -07001218 sdp_semantics_ = original_semantics;
1219 return caller_ && callee_;
1220 }
1221
deadbeef1dcb1642017-03-29 21:08:16 -07001222 bool CreatePeerConnectionWrappersWithConstraints(
1223 MediaConstraintsInterface* caller_constraints,
1224 MediaConstraintsInterface* callee_constraints) {
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07001225 caller_ = CreatePeerConnectionWrapper(
1226 "Caller", caller_constraints, nullptr, nullptr,
Qingsi Wang7685e862018-06-11 20:15:46 -07001227 webrtc::PeerConnectionDependencies(nullptr), nullptr);
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07001228 callee_ = CreatePeerConnectionWrapper(
1229 "Callee", callee_constraints, nullptr, nullptr,
Qingsi Wang7685e862018-06-11 20:15:46 -07001230 webrtc::PeerConnectionDependencies(nullptr), nullptr);
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07001231
deadbeef1dcb1642017-03-29 21:08:16 -07001232 return caller_ && callee_;
1233 }
1234
1235 bool CreatePeerConnectionWrappersWithConfig(
1236 const PeerConnectionInterface::RTCConfiguration& caller_config,
1237 const PeerConnectionInterface::RTCConfiguration& callee_config) {
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07001238 caller_ = CreatePeerConnectionWrapper(
1239 "Caller", nullptr, nullptr, &caller_config,
Qingsi Wang7685e862018-06-11 20:15:46 -07001240 webrtc::PeerConnectionDependencies(nullptr), nullptr);
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07001241 callee_ = CreatePeerConnectionWrapper(
1242 "Callee", nullptr, nullptr, &callee_config,
Qingsi Wang7685e862018-06-11 20:15:46 -07001243 webrtc::PeerConnectionDependencies(nullptr), nullptr);
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07001244 return caller_ && callee_;
1245 }
1246
1247 bool CreatePeerConnectionWrappersWithConfigAndDeps(
1248 const PeerConnectionInterface::RTCConfiguration& caller_config,
1249 webrtc::PeerConnectionDependencies caller_dependencies,
1250 const PeerConnectionInterface::RTCConfiguration& callee_config,
1251 webrtc::PeerConnectionDependencies callee_dependencies) {
1252 caller_ =
1253 CreatePeerConnectionWrapper("Caller", nullptr, nullptr, &caller_config,
Qingsi Wang7685e862018-06-11 20:15:46 -07001254 std::move(caller_dependencies), nullptr);
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07001255 callee_ =
1256 CreatePeerConnectionWrapper("Callee", nullptr, nullptr, &callee_config,
Qingsi Wang7685e862018-06-11 20:15:46 -07001257 std::move(callee_dependencies), nullptr);
deadbeef1dcb1642017-03-29 21:08:16 -07001258 return caller_ && callee_;
1259 }
1260
1261 bool CreatePeerConnectionWrappersWithOptions(
1262 const PeerConnectionFactory::Options& caller_options,
1263 const PeerConnectionFactory::Options& callee_options) {
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07001264 caller_ = CreatePeerConnectionWrapper(
1265 "Caller", nullptr, &caller_options, nullptr,
Qingsi Wang7685e862018-06-11 20:15:46 -07001266 webrtc::PeerConnectionDependencies(nullptr), nullptr);
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07001267 callee_ = CreatePeerConnectionWrapper(
1268 "Callee", nullptr, &callee_options, nullptr,
Qingsi Wang7685e862018-06-11 20:15:46 -07001269 webrtc::PeerConnectionDependencies(nullptr), nullptr);
1270 return caller_ && callee_;
1271 }
1272
1273 bool CreatePeerConnectionWrappersWithFakeRtcEventLog() {
1274 PeerConnectionInterface::RTCConfiguration default_config;
1275 caller_ = CreatePeerConnectionWrapperWithFakeRtcEventLog(
1276 "Caller", nullptr, nullptr, &default_config,
1277 webrtc::PeerConnectionDependencies(nullptr));
1278 callee_ = CreatePeerConnectionWrapperWithFakeRtcEventLog(
1279 "Callee", nullptr, nullptr, &default_config,
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07001280 webrtc::PeerConnectionDependencies(nullptr));
deadbeef1dcb1642017-03-29 21:08:16 -07001281 return caller_ && callee_;
1282 }
1283
Seth Hampson2f0d7022018-02-20 11:54:42 -08001284 std::unique_ptr<PeerConnectionWrapper>
1285 CreatePeerConnectionWrapperWithAlternateKey() {
deadbeef1dcb1642017-03-29 21:08:16 -07001286 std::unique_ptr<FakeRTCCertificateGenerator> cert_generator(
1287 new FakeRTCCertificateGenerator());
1288 cert_generator->use_alternate_key();
1289
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07001290 webrtc::PeerConnectionDependencies dependencies(nullptr);
1291 dependencies.cert_generator = std::move(cert_generator);
Seth Hampson2f0d7022018-02-20 11:54:42 -08001292 return CreatePeerConnectionWrapper("New Peer", nullptr, nullptr, nullptr,
Qingsi Wang7685e862018-06-11 20:15:46 -07001293 std::move(dependencies), nullptr);
deadbeef1dcb1642017-03-29 21:08:16 -07001294 }
1295
Seth Hampsonaed71642018-06-11 07:41:32 -07001296 cricket::TestTurnServer* CreateTurnServer(
1297 rtc::SocketAddress internal_address,
1298 rtc::SocketAddress external_address,
1299 cricket::ProtocolType type = cricket::ProtocolType::PROTO_UDP,
1300 const std::string& common_name = "test turn server") {
1301 rtc::Thread* thread = network_thread();
1302 std::unique_ptr<cricket::TestTurnServer> turn_server =
1303 network_thread()->Invoke<std::unique_ptr<cricket::TestTurnServer>>(
1304 RTC_FROM_HERE,
1305 [thread, internal_address, external_address, type, common_name] {
1306 return rtc::MakeUnique<cricket::TestTurnServer>(
1307 thread, internal_address, external_address, type,
1308 /*ignore_bad_certs=*/true, common_name);
1309 });
1310 turn_servers_.push_back(std::move(turn_server));
1311 // Interactions with the turn server should be done on the network thread.
1312 return turn_servers_.back().get();
1313 }
1314
1315 cricket::TestTurnCustomizer* CreateTurnCustomizer() {
1316 std::unique_ptr<cricket::TestTurnCustomizer> turn_customizer =
1317 network_thread()->Invoke<std::unique_ptr<cricket::TestTurnCustomizer>>(
1318 RTC_FROM_HERE,
1319 [] { return rtc::MakeUnique<cricket::TestTurnCustomizer>(); });
1320 turn_customizers_.push_back(std::move(turn_customizer));
1321 // Interactions with the turn customizer should be done on the network
1322 // thread.
1323 return turn_customizers_.back().get();
1324 }
1325
1326 // Checks that the function counters for a TestTurnCustomizer are greater than
1327 // 0.
1328 void ExpectTurnCustomizerCountersIncremented(
1329 cricket::TestTurnCustomizer* turn_customizer) {
1330 unsigned int allow_channel_data_counter =
1331 network_thread()->Invoke<unsigned int>(
1332 RTC_FROM_HERE, [turn_customizer] {
1333 return turn_customizer->allow_channel_data_cnt_;
1334 });
1335 EXPECT_GT(allow_channel_data_counter, 0u);
1336 unsigned int modify_counter = network_thread()->Invoke<unsigned int>(
1337 RTC_FROM_HERE,
1338 [turn_customizer] { return turn_customizer->modify_cnt_; });
1339 EXPECT_GT(modify_counter, 0u);
1340 }
1341
deadbeef1dcb1642017-03-29 21:08:16 -07001342 // Once called, SDP blobs and ICE candidates will be automatically signaled
1343 // between PeerConnections.
1344 void ConnectFakeSignaling() {
1345 caller_->set_signaling_message_receiver(callee_.get());
1346 callee_->set_signaling_message_receiver(caller_.get());
1347 }
1348
Steve Antonede9ca52017-10-16 13:04:27 -07001349 // Once called, SDP blobs will be automatically signaled between
1350 // PeerConnections. Note that ICE candidates will not be signaled unless they
1351 // are in the exchanged SDP blobs.
1352 void ConnectFakeSignalingForSdpOnly() {
1353 ConnectFakeSignaling();
1354 SetSignalIceCandidates(false);
1355 }
1356
deadbeef1dcb1642017-03-29 21:08:16 -07001357 void SetSignalingDelayMs(int delay_ms) {
1358 caller_->set_signaling_delay_ms(delay_ms);
1359 callee_->set_signaling_delay_ms(delay_ms);
1360 }
1361
Steve Antonede9ca52017-10-16 13:04:27 -07001362 void SetSignalIceCandidates(bool signal) {
1363 caller_->set_signal_ice_candidates(signal);
1364 callee_->set_signal_ice_candidates(signal);
1365 }
1366
deadbeef1dcb1642017-03-29 21:08:16 -07001367 // Messages may get lost on the unreliable DataChannel, so we send multiple
1368 // times to avoid test flakiness.
1369 void SendRtpDataWithRetries(webrtc::DataChannelInterface* dc,
1370 const std::string& data,
1371 int retries) {
1372 for (int i = 0; i < retries; ++i) {
1373 dc->Send(DataBuffer(data));
1374 }
1375 }
1376
1377 rtc::Thread* network_thread() { return network_thread_.get(); }
1378
1379 rtc::VirtualSocketServer* virtual_socket_server() { return ss_.get(); }
1380
1381 PeerConnectionWrapper* caller() { return caller_.get(); }
1382
1383 // Set the |caller_| to the |wrapper| passed in and return the
1384 // original |caller_|.
1385 PeerConnectionWrapper* SetCallerPcWrapperAndReturnCurrent(
1386 PeerConnectionWrapper* wrapper) {
1387 PeerConnectionWrapper* old = caller_.release();
1388 caller_.reset(wrapper);
1389 return old;
1390 }
1391
1392 PeerConnectionWrapper* callee() { return callee_.get(); }
1393
1394 // Set the |callee_| to the |wrapper| passed in and return the
1395 // original |callee_|.
1396 PeerConnectionWrapper* SetCalleePcWrapperAndReturnCurrent(
1397 PeerConnectionWrapper* wrapper) {
1398 PeerConnectionWrapper* old = callee_.release();
1399 callee_.reset(wrapper);
1400 return old;
1401 }
1402
Steve Antonede9ca52017-10-16 13:04:27 -07001403 rtc::FirewallSocketServer* firewall() const { return fss_.get(); }
1404
Seth Hampson2f0d7022018-02-20 11:54:42 -08001405 // Expects the provided number of new frames to be received within
1406 // kMaxWaitForFramesMs. The new expected frames are specified in
1407 // |media_expectations|. Returns false if any of the expectations were
1408 // not met.
1409 bool ExpectNewFrames(const MediaExpectations& media_expectations) {
1410 // First initialize the expected frame counts based upon the current
1411 // frame count.
1412 int total_caller_audio_frames_expected = caller()->audio_frames_received();
1413 if (media_expectations.caller_audio_expectation_ ==
1414 MediaExpectations::kExpectSomeFrames) {
1415 total_caller_audio_frames_expected +=
1416 media_expectations.caller_audio_frames_expected_;
1417 }
1418 int total_caller_video_frames_expected =
deadbeef1dcb1642017-03-29 21:08:16 -07001419 caller()->min_video_frames_received_per_track();
Seth Hampson2f0d7022018-02-20 11:54:42 -08001420 if (media_expectations.caller_video_expectation_ ==
1421 MediaExpectations::kExpectSomeFrames) {
1422 total_caller_video_frames_expected +=
1423 media_expectations.caller_video_frames_expected_;
1424 }
1425 int total_callee_audio_frames_expected = callee()->audio_frames_received();
1426 if (media_expectations.callee_audio_expectation_ ==
1427 MediaExpectations::kExpectSomeFrames) {
1428 total_callee_audio_frames_expected +=
1429 media_expectations.callee_audio_frames_expected_;
1430 }
1431 int total_callee_video_frames_expected =
deadbeef1dcb1642017-03-29 21:08:16 -07001432 callee()->min_video_frames_received_per_track();
Seth Hampson2f0d7022018-02-20 11:54:42 -08001433 if (media_expectations.callee_video_expectation_ ==
1434 MediaExpectations::kExpectSomeFrames) {
1435 total_callee_video_frames_expected +=
1436 media_expectations.callee_video_frames_expected_;
1437 }
deadbeef1dcb1642017-03-29 21:08:16 -07001438
Seth Hampson2f0d7022018-02-20 11:54:42 -08001439 // Wait for the expected frames.
deadbeef1dcb1642017-03-29 21:08:16 -07001440 EXPECT_TRUE_WAIT(caller()->audio_frames_received() >=
Seth Hampson2f0d7022018-02-20 11:54:42 -08001441 total_caller_audio_frames_expected &&
deadbeef1dcb1642017-03-29 21:08:16 -07001442 caller()->min_video_frames_received_per_track() >=
Seth Hampson2f0d7022018-02-20 11:54:42 -08001443 total_caller_video_frames_expected &&
deadbeef1dcb1642017-03-29 21:08:16 -07001444 callee()->audio_frames_received() >=
Seth Hampson2f0d7022018-02-20 11:54:42 -08001445 total_callee_audio_frames_expected &&
deadbeef1dcb1642017-03-29 21:08:16 -07001446 callee()->min_video_frames_received_per_track() >=
Seth Hampson2f0d7022018-02-20 11:54:42 -08001447 total_callee_video_frames_expected,
1448 kMaxWaitForFramesMs);
1449 bool expectations_correct =
1450 caller()->audio_frames_received() >=
1451 total_caller_audio_frames_expected &&
1452 caller()->min_video_frames_received_per_track() >=
1453 total_caller_video_frames_expected &&
1454 callee()->audio_frames_received() >=
1455 total_callee_audio_frames_expected &&
1456 callee()->min_video_frames_received_per_track() >=
1457 total_callee_video_frames_expected;
deadbeef1dcb1642017-03-29 21:08:16 -07001458
Seth Hampson2f0d7022018-02-20 11:54:42 -08001459 // After the combined wait, print out a more detailed message upon
1460 // failure.
deadbeef1dcb1642017-03-29 21:08:16 -07001461 EXPECT_GE(caller()->audio_frames_received(),
Seth Hampson2f0d7022018-02-20 11:54:42 -08001462 total_caller_audio_frames_expected);
deadbeef1dcb1642017-03-29 21:08:16 -07001463 EXPECT_GE(caller()->min_video_frames_received_per_track(),
Seth Hampson2f0d7022018-02-20 11:54:42 -08001464 total_caller_video_frames_expected);
deadbeef1dcb1642017-03-29 21:08:16 -07001465 EXPECT_GE(callee()->audio_frames_received(),
Seth Hampson2f0d7022018-02-20 11:54:42 -08001466 total_callee_audio_frames_expected);
deadbeef1dcb1642017-03-29 21:08:16 -07001467 EXPECT_GE(callee()->min_video_frames_received_per_track(),
Seth Hampson2f0d7022018-02-20 11:54:42 -08001468 total_callee_video_frames_expected);
1469
1470 // We want to make sure nothing unexpected was received.
1471 if (media_expectations.caller_audio_expectation_ ==
1472 MediaExpectations::kExpectNoFrames) {
1473 EXPECT_EQ(caller()->audio_frames_received(),
1474 total_caller_audio_frames_expected);
1475 if (caller()->audio_frames_received() !=
1476 total_caller_audio_frames_expected) {
1477 expectations_correct = false;
1478 }
1479 }
1480 if (media_expectations.caller_video_expectation_ ==
1481 MediaExpectations::kExpectNoFrames) {
1482 EXPECT_EQ(caller()->min_video_frames_received_per_track(),
1483 total_caller_video_frames_expected);
1484 if (caller()->min_video_frames_received_per_track() !=
1485 total_caller_video_frames_expected) {
1486 expectations_correct = false;
1487 }
1488 }
1489 if (media_expectations.callee_audio_expectation_ ==
1490 MediaExpectations::kExpectNoFrames) {
1491 EXPECT_EQ(callee()->audio_frames_received(),
1492 total_callee_audio_frames_expected);
1493 if (callee()->audio_frames_received() !=
1494 total_callee_audio_frames_expected) {
1495 expectations_correct = false;
1496 }
1497 }
1498 if (media_expectations.callee_video_expectation_ ==
1499 MediaExpectations::kExpectNoFrames) {
1500 EXPECT_EQ(callee()->min_video_frames_received_per_track(),
1501 total_callee_video_frames_expected);
1502 if (callee()->min_video_frames_received_per_track() !=
1503 total_callee_video_frames_expected) {
1504 expectations_correct = false;
1505 }
1506 }
1507 return expectations_correct;
deadbeef1dcb1642017-03-29 21:08:16 -07001508 }
1509
Taylor Brandstetter5e55fe82018-03-23 11:50:16 -07001510 void TestNegotiatedCipherSuite(
1511 const PeerConnectionFactory::Options& caller_options,
1512 const PeerConnectionFactory::Options& callee_options,
1513 int expected_cipher_suite) {
deadbeef1dcb1642017-03-29 21:08:16 -07001514 ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(caller_options,
1515 callee_options));
1516 rtc::scoped_refptr<webrtc::FakeMetricsObserver> caller_observer =
1517 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1518 caller()->pc()->RegisterUMAObserver(caller_observer);
1519 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08001520 caller()->AddAudioVideoTracks();
1521 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07001522 caller()->CreateAndSetAndSignalOffer();
1523 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1524 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(expected_cipher_suite),
deadbeefd8ad7882017-04-18 16:01:17 -07001525 caller()->OldGetStats()->SrtpCipher(), kDefaultTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -07001526 EXPECT_EQ(
1527 1, caller_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1528 expected_cipher_suite));
1529 caller()->pc()->RegisterUMAObserver(nullptr);
1530 }
1531
Taylor Brandstetter5e55fe82018-03-23 11:50:16 -07001532 void TestGcmNegotiationUsesCipherSuite(bool local_gcm_enabled,
1533 bool remote_gcm_enabled,
1534 int expected_cipher_suite) {
1535 PeerConnectionFactory::Options caller_options;
1536 caller_options.crypto_options.enable_gcm_crypto_suites = local_gcm_enabled;
1537 PeerConnectionFactory::Options callee_options;
1538 callee_options.crypto_options.enable_gcm_crypto_suites = remote_gcm_enabled;
1539 TestNegotiatedCipherSuite(caller_options, callee_options,
1540 expected_cipher_suite);
1541 }
1542
Seth Hampson2f0d7022018-02-20 11:54:42 -08001543 protected:
Steve Anton3acffc32018-04-12 17:21:03 -07001544 SdpSemantics sdp_semantics_;
Seth Hampson2f0d7022018-02-20 11:54:42 -08001545
deadbeef1dcb1642017-03-29 21:08:16 -07001546 private:
1547 // |ss_| is used by |network_thread_| so it must be destroyed later.
deadbeef1dcb1642017-03-29 21:08:16 -07001548 std::unique_ptr<rtc::VirtualSocketServer> ss_;
Steve Antonede9ca52017-10-16 13:04:27 -07001549 std::unique_ptr<rtc::FirewallSocketServer> fss_;
deadbeef1dcb1642017-03-29 21:08:16 -07001550 // |network_thread_| and |worker_thread_| are used by both
1551 // |caller_| and |callee_| so they must be destroyed
1552 // later.
1553 std::unique_ptr<rtc::Thread> network_thread_;
1554 std::unique_ptr<rtc::Thread> worker_thread_;
Seth Hampsonaed71642018-06-11 07:41:32 -07001555 // The turn servers and turn customizers should be accessed & deleted on the
1556 // network thread to avoid a race with the socket read/write that occurs
1557 // on the network thread.
1558 std::vector<std::unique_ptr<cricket::TestTurnServer>> turn_servers_;
1559 std::vector<std::unique_ptr<cricket::TestTurnCustomizer>> turn_customizers_;
deadbeef1dcb1642017-03-29 21:08:16 -07001560 std::unique_ptr<PeerConnectionWrapper> caller_;
1561 std::unique_ptr<PeerConnectionWrapper> callee_;
1562};
1563
Seth Hampson2f0d7022018-02-20 11:54:42 -08001564class PeerConnectionIntegrationTest
1565 : public PeerConnectionIntegrationBaseTest,
1566 public ::testing::WithParamInterface<SdpSemantics> {
1567 protected:
1568 PeerConnectionIntegrationTest()
1569 : PeerConnectionIntegrationBaseTest(GetParam()) {}
1570};
1571
1572class PeerConnectionIntegrationTestPlanB
1573 : public PeerConnectionIntegrationBaseTest {
1574 protected:
1575 PeerConnectionIntegrationTestPlanB()
1576 : PeerConnectionIntegrationBaseTest(SdpSemantics::kPlanB) {}
1577};
1578
1579class PeerConnectionIntegrationTestUnifiedPlan
1580 : public PeerConnectionIntegrationBaseTest {
1581 protected:
1582 PeerConnectionIntegrationTestUnifiedPlan()
1583 : PeerConnectionIntegrationBaseTest(SdpSemantics::kUnifiedPlan) {}
1584};
1585
deadbeef1dcb1642017-03-29 21:08:16 -07001586// Test the OnFirstPacketReceived callback from audio/video RtpReceivers. This
1587// includes testing that the callback is invoked if an observer is connected
1588// after the first packet has already been received.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001589TEST_P(PeerConnectionIntegrationTest,
deadbeef1dcb1642017-03-29 21:08:16 -07001590 RtpReceiverObserverOnFirstPacketReceived) {
1591 ASSERT_TRUE(CreatePeerConnectionWrappers());
1592 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08001593 caller()->AddAudioVideoTracks();
1594 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07001595 // Start offer/answer exchange and wait for it to complete.
1596 caller()->CreateAndSetAndSignalOffer();
1597 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1598 // Should be one receiver each for audio/video.
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02001599 EXPECT_EQ(2U, caller()->rtp_receiver_observers().size());
1600 EXPECT_EQ(2U, callee()->rtp_receiver_observers().size());
deadbeef1dcb1642017-03-29 21:08:16 -07001601 // Wait for all "first packet received" callbacks to be fired.
1602 EXPECT_TRUE_WAIT(
1603 std::all_of(caller()->rtp_receiver_observers().begin(),
1604 caller()->rtp_receiver_observers().end(),
1605 [](const std::unique_ptr<MockRtpReceiverObserver>& o) {
1606 return o->first_packet_received();
1607 }),
1608 kMaxWaitForFramesMs);
1609 EXPECT_TRUE_WAIT(
1610 std::all_of(callee()->rtp_receiver_observers().begin(),
1611 callee()->rtp_receiver_observers().end(),
1612 [](const std::unique_ptr<MockRtpReceiverObserver>& o) {
1613 return o->first_packet_received();
1614 }),
1615 kMaxWaitForFramesMs);
1616 // If new observers are set after the first packet was already received, the
1617 // callback should still be invoked.
1618 caller()->ResetRtpReceiverObservers();
1619 callee()->ResetRtpReceiverObservers();
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02001620 EXPECT_EQ(2U, caller()->rtp_receiver_observers().size());
1621 EXPECT_EQ(2U, callee()->rtp_receiver_observers().size());
deadbeef1dcb1642017-03-29 21:08:16 -07001622 EXPECT_TRUE(
1623 std::all_of(caller()->rtp_receiver_observers().begin(),
1624 caller()->rtp_receiver_observers().end(),
1625 [](const std::unique_ptr<MockRtpReceiverObserver>& o) {
1626 return o->first_packet_received();
1627 }));
1628 EXPECT_TRUE(
1629 std::all_of(callee()->rtp_receiver_observers().begin(),
1630 callee()->rtp_receiver_observers().end(),
1631 [](const std::unique_ptr<MockRtpReceiverObserver>& o) {
1632 return o->first_packet_received();
1633 }));
1634}
1635
1636class DummyDtmfObserver : public DtmfSenderObserverInterface {
1637 public:
1638 DummyDtmfObserver() : completed_(false) {}
1639
1640 // Implements DtmfSenderObserverInterface.
1641 void OnToneChange(const std::string& tone) override {
1642 tones_.push_back(tone);
1643 if (tone.empty()) {
1644 completed_ = true;
1645 }
1646 }
1647
1648 const std::vector<std::string>& tones() const { return tones_; }
1649 bool completed() const { return completed_; }
1650
1651 private:
1652 bool completed_;
1653 std::vector<std::string> tones_;
1654};
1655
1656// Assumes |sender| already has an audio track added and the offer/answer
1657// exchange is done.
1658void TestDtmfFromSenderToReceiver(PeerConnectionWrapper* sender,
1659 PeerConnectionWrapper* receiver) {
Steve Anton15324772018-01-16 10:26:49 -08001660 // We should be able to get a DTMF sender from the local sender.
1661 rtc::scoped_refptr<DtmfSenderInterface> dtmf_sender =
1662 sender->pc()->GetSenders().at(0)->GetDtmfSender();
1663 ASSERT_TRUE(dtmf_sender);
deadbeef1dcb1642017-03-29 21:08:16 -07001664 DummyDtmfObserver observer;
deadbeef1dcb1642017-03-29 21:08:16 -07001665 dtmf_sender->RegisterObserver(&observer);
1666
1667 // Test the DtmfSender object just created.
1668 EXPECT_TRUE(dtmf_sender->CanInsertDtmf());
1669 EXPECT_TRUE(dtmf_sender->InsertDtmf("1a", 100, 50));
1670
1671 EXPECT_TRUE_WAIT(observer.completed(), kDefaultTimeout);
1672 std::vector<std::string> tones = {"1", "a", ""};
1673 EXPECT_EQ(tones, observer.tones());
1674 dtmf_sender->UnregisterObserver();
1675 // TODO(deadbeef): Verify the tones were actually received end-to-end.
1676}
1677
1678// Verifies the DtmfSenderObserver callbacks for a DtmfSender (one in each
1679// direction).
Seth Hampson2f0d7022018-02-20 11:54:42 -08001680TEST_P(PeerConnectionIntegrationTest, DtmfSenderObserver) {
deadbeef1dcb1642017-03-29 21:08:16 -07001681 ASSERT_TRUE(CreatePeerConnectionWrappers());
1682 ConnectFakeSignaling();
1683 // Only need audio for DTMF.
Steve Anton15324772018-01-16 10:26:49 -08001684 caller()->AddAudioTrack();
1685 callee()->AddAudioTrack();
deadbeef1dcb1642017-03-29 21:08:16 -07001686 caller()->CreateAndSetAndSignalOffer();
1687 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
deadbeef71452802017-05-07 17:21:01 -07001688 // DTLS must finish before the DTMF sender can be used reliably.
1689 ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -07001690 TestDtmfFromSenderToReceiver(caller(), callee());
1691 TestDtmfFromSenderToReceiver(callee(), caller());
1692}
1693
1694// Basic end-to-end test, verifying media can be encoded/transmitted/decoded
1695// between two connections, using DTLS-SRTP.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001696TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithDtls) {
deadbeef1dcb1642017-03-29 21:08:16 -07001697 ASSERT_TRUE(CreatePeerConnectionWrappers());
1698 ConnectFakeSignaling();
Harald Alvestrand194939b2018-01-24 16:04:13 +01001699 rtc::scoped_refptr<webrtc::FakeMetricsObserver> caller_observer =
1700 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1701 caller()->pc()->RegisterUMAObserver(caller_observer);
1702
deadbeef1dcb1642017-03-29 21:08:16 -07001703 // Do normal offer/answer and wait for some frames to be received in each
1704 // direction.
Steve Anton15324772018-01-16 10:26:49 -08001705 caller()->AddAudioVideoTracks();
1706 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07001707 caller()->CreateAndSetAndSignalOffer();
1708 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08001709 MediaExpectations media_expectations;
1710 media_expectations.ExpectBidirectionalAudioAndVideo();
1711 ASSERT_TRUE(ExpectNewFrames(media_expectations));
Harald Alvestrand194939b2018-01-24 16:04:13 +01001712 EXPECT_LE(
1713 1, caller_observer->GetEnumCounter(webrtc::kEnumCounterKeyProtocol,
1714 webrtc::kEnumCounterKeyProtocolDtls));
1715 EXPECT_EQ(
1716 0, caller_observer->GetEnumCounter(webrtc::kEnumCounterKeyProtocol,
1717 webrtc::kEnumCounterKeyProtocolSdes));
deadbeef1dcb1642017-03-29 21:08:16 -07001718}
1719
1720// Uses SDES instead of DTLS for key agreement.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001721TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithSdes) {
deadbeef1dcb1642017-03-29 21:08:16 -07001722 PeerConnectionInterface::RTCConfiguration sdes_config;
1723 sdes_config.enable_dtls_srtp.emplace(false);
1724 ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(sdes_config, sdes_config));
1725 ConnectFakeSignaling();
Harald Alvestrand194939b2018-01-24 16:04:13 +01001726 rtc::scoped_refptr<webrtc::FakeMetricsObserver> caller_observer =
1727 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1728 caller()->pc()->RegisterUMAObserver(caller_observer);
deadbeef1dcb1642017-03-29 21:08:16 -07001729
1730 // Do normal offer/answer and wait for some frames to be received in each
1731 // direction.
Steve Anton15324772018-01-16 10:26:49 -08001732 caller()->AddAudioVideoTracks();
1733 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07001734 caller()->CreateAndSetAndSignalOffer();
1735 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08001736 MediaExpectations media_expectations;
1737 media_expectations.ExpectBidirectionalAudioAndVideo();
1738 ASSERT_TRUE(ExpectNewFrames(media_expectations));
Harald Alvestrand194939b2018-01-24 16:04:13 +01001739 EXPECT_LE(
1740 1, caller_observer->GetEnumCounter(webrtc::kEnumCounterKeyProtocol,
1741 webrtc::kEnumCounterKeyProtocolSdes));
1742 EXPECT_EQ(
1743 0, caller_observer->GetEnumCounter(webrtc::kEnumCounterKeyProtocol,
1744 webrtc::kEnumCounterKeyProtocolDtls));
deadbeef1dcb1642017-03-29 21:08:16 -07001745}
1746
Steve Anton8c0f7a72017-10-03 10:03:10 -07001747// Tests that the GetRemoteAudioSSLCertificate method returns the remote DTLS
1748// certificate once the DTLS handshake has finished.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001749TEST_P(PeerConnectionIntegrationTest,
Steve Anton8c0f7a72017-10-03 10:03:10 -07001750 GetRemoteAudioSSLCertificateReturnsExchangedCertificate) {
1751 auto GetRemoteAudioSSLCertificate = [](PeerConnectionWrapper* wrapper) {
1752 auto pci = reinterpret_cast<PeerConnectionProxy*>(wrapper->pc());
1753 auto pc = reinterpret_cast<PeerConnection*>(pci->internal());
1754 return pc->GetRemoteAudioSSLCertificate();
1755 };
Zhi Huang70b820f2018-01-27 14:16:15 -08001756 auto GetRemoteAudioSSLCertChain = [](PeerConnectionWrapper* wrapper) {
1757 auto pci = reinterpret_cast<PeerConnectionProxy*>(wrapper->pc());
1758 auto pc = reinterpret_cast<PeerConnection*>(pci->internal());
1759 return pc->GetRemoteAudioSSLCertChain();
1760 };
Steve Anton8c0f7a72017-10-03 10:03:10 -07001761
1762 auto caller_cert = rtc::RTCCertificate::FromPEM(kRsaPems[0]);
1763 auto callee_cert = rtc::RTCCertificate::FromPEM(kRsaPems[1]);
1764
1765 // Configure each side with a known certificate so they can be compared later.
1766 PeerConnectionInterface::RTCConfiguration caller_config;
1767 caller_config.enable_dtls_srtp.emplace(true);
1768 caller_config.certificates.push_back(caller_cert);
1769 PeerConnectionInterface::RTCConfiguration callee_config;
1770 callee_config.enable_dtls_srtp.emplace(true);
1771 callee_config.certificates.push_back(callee_cert);
1772 ASSERT_TRUE(
1773 CreatePeerConnectionWrappersWithConfig(caller_config, callee_config));
1774 ConnectFakeSignaling();
1775
1776 // When first initialized, there should not be a remote SSL certificate (and
1777 // calling this method should not crash).
1778 EXPECT_EQ(nullptr, GetRemoteAudioSSLCertificate(caller()));
1779 EXPECT_EQ(nullptr, GetRemoteAudioSSLCertificate(callee()));
Zhi Huang70b820f2018-01-27 14:16:15 -08001780 EXPECT_EQ(nullptr, GetRemoteAudioSSLCertChain(caller()));
1781 EXPECT_EQ(nullptr, GetRemoteAudioSSLCertChain(callee()));
Steve Anton8c0f7a72017-10-03 10:03:10 -07001782
Steve Anton15324772018-01-16 10:26:49 -08001783 caller()->AddAudioTrack();
1784 callee()->AddAudioTrack();
Steve Anton8c0f7a72017-10-03 10:03:10 -07001785 caller()->CreateAndSetAndSignalOffer();
1786 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1787 ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout);
1788
1789 // Once DTLS has been connected, each side should return the other's SSL
1790 // certificate when calling GetRemoteAudioSSLCertificate.
1791
1792 auto caller_remote_cert = GetRemoteAudioSSLCertificate(caller());
1793 ASSERT_TRUE(caller_remote_cert);
1794 EXPECT_EQ(callee_cert->ssl_certificate().ToPEMString(),
1795 caller_remote_cert->ToPEMString());
1796
1797 auto callee_remote_cert = GetRemoteAudioSSLCertificate(callee());
1798 ASSERT_TRUE(callee_remote_cert);
1799 EXPECT_EQ(caller_cert->ssl_certificate().ToPEMString(),
1800 callee_remote_cert->ToPEMString());
Zhi Huang70b820f2018-01-27 14:16:15 -08001801
1802 auto caller_remote_cert_chain = GetRemoteAudioSSLCertChain(caller());
1803 ASSERT_TRUE(caller_remote_cert_chain);
1804 ASSERT_EQ(1U, caller_remote_cert_chain->GetSize());
1805 auto remote_cert = &caller_remote_cert_chain->Get(0);
1806 EXPECT_EQ(callee_cert->ssl_certificate().ToPEMString(),
1807 remote_cert->ToPEMString());
1808
1809 auto callee_remote_cert_chain = GetRemoteAudioSSLCertChain(callee());
1810 ASSERT_TRUE(callee_remote_cert_chain);
1811 ASSERT_EQ(1U, callee_remote_cert_chain->GetSize());
1812 remote_cert = &callee_remote_cert_chain->Get(0);
1813 EXPECT_EQ(caller_cert->ssl_certificate().ToPEMString(),
1814 remote_cert->ToPEMString());
Steve Anton8c0f7a72017-10-03 10:03:10 -07001815}
1816
deadbeef1dcb1642017-03-29 21:08:16 -07001817// This test sets up a call between two parties with a source resolution of
1818// 1280x720 and verifies that a 16:9 aspect ratio is received.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001819TEST_P(PeerConnectionIntegrationTest,
deadbeef1dcb1642017-03-29 21:08:16 -07001820 Send1280By720ResolutionAndReceive16To9AspectRatio) {
1821 ASSERT_TRUE(CreatePeerConnectionWrappers());
1822 ConnectFakeSignaling();
1823
Niels Möller5c7efe72018-05-11 10:34:46 +02001824 // Add video tracks with 16:9 aspect ratio, size 1280 x 720.
1825 webrtc::FakePeriodicVideoSource::Config config;
1826 config.width = 1280;
1827 config.height = 720;
1828 caller()->AddTrack(caller()->CreateLocalVideoTrackWithConfig(config));
1829 callee()->AddTrack(callee()->CreateLocalVideoTrackWithConfig(config));
deadbeef1dcb1642017-03-29 21:08:16 -07001830
1831 // Do normal offer/answer and wait for at least one frame to be received in
1832 // each direction.
1833 caller()->CreateAndSetAndSignalOffer();
1834 ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 &&
1835 callee()->min_video_frames_received_per_track() > 0,
1836 kMaxWaitForFramesMs);
1837
1838 // Check rendered aspect ratio.
1839 EXPECT_EQ(16.0 / 9, caller()->local_rendered_aspect_ratio());
1840 EXPECT_EQ(16.0 / 9, caller()->rendered_aspect_ratio());
1841 EXPECT_EQ(16.0 / 9, callee()->local_rendered_aspect_ratio());
1842 EXPECT_EQ(16.0 / 9, callee()->rendered_aspect_ratio());
1843}
1844
1845// This test sets up an one-way call, with media only from caller to
1846// callee.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001847TEST_P(PeerConnectionIntegrationTest, OneWayMediaCall) {
deadbeef1dcb1642017-03-29 21:08:16 -07001848 ASSERT_TRUE(CreatePeerConnectionWrappers());
1849 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08001850 caller()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07001851 caller()->CreateAndSetAndSignalOffer();
Seth Hampson2f0d7022018-02-20 11:54:42 -08001852 MediaExpectations media_expectations;
1853 media_expectations.CalleeExpectsSomeAudioAndVideo();
1854 media_expectations.CallerExpectsNoAudio();
1855 media_expectations.CallerExpectsNoVideo();
1856 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07001857}
1858
1859// This test sets up a audio call initially, with the callee rejecting video
1860// initially. Then later the callee decides to upgrade to audio/video, and
1861// initiates a new offer/answer exchange.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001862TEST_P(PeerConnectionIntegrationTest, AudioToVideoUpgrade) {
deadbeef1dcb1642017-03-29 21:08:16 -07001863 ASSERT_TRUE(CreatePeerConnectionWrappers());
1864 ConnectFakeSignaling();
1865 // Initially, offer an audio/video stream from the caller, but refuse to
1866 // send/receive video on the callee side.
Steve Anton15324772018-01-16 10:26:49 -08001867 caller()->AddAudioVideoTracks();
1868 callee()->AddAudioTrack();
Seth Hampson2f0d7022018-02-20 11:54:42 -08001869 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1870 PeerConnectionInterface::RTCOfferAnswerOptions options;
1871 options.offer_to_receive_video = 0;
1872 callee()->SetOfferAnswerOptions(options);
1873 } else {
1874 callee()->SetRemoteOfferHandler([this] {
1875 callee()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)->Stop();
1876 });
1877 }
deadbeef1dcb1642017-03-29 21:08:16 -07001878 // Do offer/answer and make sure audio is still received end-to-end.
1879 caller()->CreateAndSetAndSignalOffer();
1880 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08001881 {
1882 MediaExpectations media_expectations;
1883 media_expectations.ExpectBidirectionalAudio();
1884 media_expectations.ExpectNoVideo();
1885 ASSERT_TRUE(ExpectNewFrames(media_expectations));
1886 }
deadbeef1dcb1642017-03-29 21:08:16 -07001887 // Sanity check that the callee's description has a rejected video section.
1888 ASSERT_NE(nullptr, callee()->pc()->local_description());
1889 const ContentInfo* callee_video_content =
1890 GetFirstVideoContent(callee()->pc()->local_description()->description());
1891 ASSERT_NE(nullptr, callee_video_content);
1892 EXPECT_TRUE(callee_video_content->rejected);
Seth Hampson2f0d7022018-02-20 11:54:42 -08001893
deadbeef1dcb1642017-03-29 21:08:16 -07001894 // Now negotiate with video and ensure negotiation succeeds, with video
1895 // frames and additional audio frames being received.
Steve Anton15324772018-01-16 10:26:49 -08001896 callee()->AddVideoTrack();
Seth Hampson2f0d7022018-02-20 11:54:42 -08001897 if (sdp_semantics_ == SdpSemantics::kPlanB) {
1898 PeerConnectionInterface::RTCOfferAnswerOptions options;
1899 options.offer_to_receive_video = 1;
1900 callee()->SetOfferAnswerOptions(options);
1901 } else {
1902 callee()->SetRemoteOfferHandler(nullptr);
1903 caller()->SetRemoteOfferHandler([this] {
1904 // The caller creates a new transceiver to receive video on when receiving
1905 // the offer, but by default it is send only.
1906 auto transceivers = caller()->pc()->GetTransceivers();
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02001907 ASSERT_EQ(3U, transceivers.size());
Seth Hampson2f0d7022018-02-20 11:54:42 -08001908 ASSERT_EQ(cricket::MEDIA_TYPE_VIDEO,
1909 transceivers[2]->receiver()->media_type());
1910 transceivers[2]->sender()->SetTrack(caller()->CreateLocalVideoTrack());
1911 transceivers[2]->SetDirection(RtpTransceiverDirection::kSendRecv);
1912 });
1913 }
deadbeef1dcb1642017-03-29 21:08:16 -07001914 callee()->CreateAndSetAndSignalOffer();
1915 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08001916 {
1917 // Expect additional audio frames to be received after the upgrade.
1918 MediaExpectations media_expectations;
1919 media_expectations.ExpectBidirectionalAudioAndVideo();
1920 ASSERT_TRUE(ExpectNewFrames(media_expectations));
1921 }
deadbeef1dcb1642017-03-29 21:08:16 -07001922}
1923
deadbeef4389b4d2017-09-07 09:07:36 -07001924// Simpler than the above test; just add an audio track to an established
1925// video-only connection.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001926TEST_P(PeerConnectionIntegrationTest, AddAudioToVideoOnlyCall) {
deadbeef4389b4d2017-09-07 09:07:36 -07001927 ASSERT_TRUE(CreatePeerConnectionWrappers());
1928 ConnectFakeSignaling();
1929 // Do initial offer/answer with just a video track.
Steve Anton15324772018-01-16 10:26:49 -08001930 caller()->AddVideoTrack();
1931 callee()->AddVideoTrack();
deadbeef4389b4d2017-09-07 09:07:36 -07001932 caller()->CreateAndSetAndSignalOffer();
1933 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1934 // Now add an audio track and do another offer/answer.
Steve Anton15324772018-01-16 10:26:49 -08001935 caller()->AddAudioTrack();
1936 callee()->AddAudioTrack();
deadbeef4389b4d2017-09-07 09:07:36 -07001937 caller()->CreateAndSetAndSignalOffer();
1938 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1939 // Ensure both audio and video frames are received end-to-end.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001940 MediaExpectations media_expectations;
1941 media_expectations.ExpectBidirectionalAudioAndVideo();
1942 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef4389b4d2017-09-07 09:07:36 -07001943}
1944
deadbeef1dcb1642017-03-29 21:08:16 -07001945// This test sets up a call that's transferred to a new caller with a different
1946// DTLS fingerprint.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001947TEST_P(PeerConnectionIntegrationTest, CallTransferredForCallee) {
deadbeef1dcb1642017-03-29 21:08:16 -07001948 ASSERT_TRUE(CreatePeerConnectionWrappers());
1949 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08001950 caller()->AddAudioVideoTracks();
1951 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07001952 caller()->CreateAndSetAndSignalOffer();
1953 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1954
1955 // Keep the original peer around which will still send packets to the
1956 // receiving client. These SRTP packets will be dropped.
1957 std::unique_ptr<PeerConnectionWrapper> original_peer(
1958 SetCallerPcWrapperAndReturnCurrent(
Seth Hampson2f0d7022018-02-20 11:54:42 -08001959 CreatePeerConnectionWrapperWithAlternateKey().release()));
deadbeef1dcb1642017-03-29 21:08:16 -07001960 // TODO(deadbeef): Why do we call Close here? That goes against the comment
1961 // directly above.
1962 original_peer->pc()->Close();
1963
1964 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08001965 caller()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07001966 caller()->CreateAndSetAndSignalOffer();
1967 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1968 // Wait for some additional frames to be transmitted end-to-end.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001969 MediaExpectations media_expectations;
1970 media_expectations.ExpectBidirectionalAudioAndVideo();
1971 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07001972}
1973
1974// This test sets up a call that's transferred to a new callee with a different
1975// DTLS fingerprint.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001976TEST_P(PeerConnectionIntegrationTest, CallTransferredForCaller) {
deadbeef1dcb1642017-03-29 21:08:16 -07001977 ASSERT_TRUE(CreatePeerConnectionWrappers());
1978 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08001979 caller()->AddAudioVideoTracks();
1980 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07001981 caller()->CreateAndSetAndSignalOffer();
1982 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1983
1984 // Keep the original peer around which will still send packets to the
1985 // receiving client. These SRTP packets will be dropped.
1986 std::unique_ptr<PeerConnectionWrapper> original_peer(
1987 SetCalleePcWrapperAndReturnCurrent(
Seth Hampson2f0d7022018-02-20 11:54:42 -08001988 CreatePeerConnectionWrapperWithAlternateKey().release()));
deadbeef1dcb1642017-03-29 21:08:16 -07001989 // TODO(deadbeef): Why do we call Close here? That goes against the comment
1990 // directly above.
1991 original_peer->pc()->Close();
1992
1993 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08001994 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07001995 caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions());
1996 caller()->CreateAndSetAndSignalOffer();
1997 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
1998 // Wait for some additional frames to be transmitted end-to-end.
Seth Hampson2f0d7022018-02-20 11:54:42 -08001999 MediaExpectations media_expectations;
2000 media_expectations.ExpectBidirectionalAudioAndVideo();
2001 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07002002}
2003
2004// This test sets up a non-bundled call and negotiates bundling at the same
2005// time as starting an ICE restart. When bundling is in effect in the restart,
2006// the DTLS-SRTP context should be successfully reset.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002007TEST_P(PeerConnectionIntegrationTest, BundlingEnabledWhileIceRestartOccurs) {
deadbeef1dcb1642017-03-29 21:08:16 -07002008 ASSERT_TRUE(CreatePeerConnectionWrappers());
2009 ConnectFakeSignaling();
2010
Steve Anton15324772018-01-16 10:26:49 -08002011 caller()->AddAudioVideoTracks();
2012 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07002013 // Remove the bundle group from the SDP received by the callee.
2014 callee()->SetReceivedSdpMunger([](cricket::SessionDescription* desc) {
2015 desc->RemoveGroupByName("BUNDLE");
2016 });
2017 caller()->CreateAndSetAndSignalOffer();
2018 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08002019 {
2020 MediaExpectations media_expectations;
2021 media_expectations.ExpectBidirectionalAudioAndVideo();
2022 ASSERT_TRUE(ExpectNewFrames(media_expectations));
2023 }
deadbeef1dcb1642017-03-29 21:08:16 -07002024 // Now stop removing the BUNDLE group, and trigger an ICE restart.
2025 callee()->SetReceivedSdpMunger(nullptr);
2026 caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions());
2027 caller()->CreateAndSetAndSignalOffer();
2028 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2029
2030 // Expect additional frames to be received after the ICE restart.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002031 {
2032 MediaExpectations media_expectations;
2033 media_expectations.ExpectBidirectionalAudioAndVideo();
2034 ASSERT_TRUE(ExpectNewFrames(media_expectations));
2035 }
deadbeef1dcb1642017-03-29 21:08:16 -07002036}
2037
2038// Test CVO (Coordination of Video Orientation). If a video source is rotated
2039// and both peers support the CVO RTP header extension, the actual video frames
2040// don't need to be encoded in different resolutions, since the rotation is
2041// communicated through the RTP header extension.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002042TEST_P(PeerConnectionIntegrationTest, RotatedVideoWithCVOExtension) {
deadbeef1dcb1642017-03-29 21:08:16 -07002043 ASSERT_TRUE(CreatePeerConnectionWrappers());
2044 ConnectFakeSignaling();
2045 // Add rotated video tracks.
Steve Anton15324772018-01-16 10:26:49 -08002046 caller()->AddTrack(
deadbeef1dcb1642017-03-29 21:08:16 -07002047 caller()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_90));
Steve Anton15324772018-01-16 10:26:49 -08002048 callee()->AddTrack(
deadbeef1dcb1642017-03-29 21:08:16 -07002049 callee()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_270));
2050
2051 // Wait for video frames to be received by both sides.
2052 caller()->CreateAndSetAndSignalOffer();
2053 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2054 ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 &&
2055 callee()->min_video_frames_received_per_track() > 0,
2056 kMaxWaitForFramesMs);
2057
2058 // Ensure that the aspect ratio is unmodified.
2059 // TODO(deadbeef): Where does 4:3 come from? Should be explicit in the test,
2060 // not just assumed.
2061 EXPECT_EQ(4.0 / 3, caller()->local_rendered_aspect_ratio());
2062 EXPECT_EQ(4.0 / 3, caller()->rendered_aspect_ratio());
2063 EXPECT_EQ(4.0 / 3, callee()->local_rendered_aspect_ratio());
2064 EXPECT_EQ(4.0 / 3, callee()->rendered_aspect_ratio());
2065 // Ensure that the CVO bits were surfaced to the renderer.
2066 EXPECT_EQ(webrtc::kVideoRotation_270, caller()->rendered_rotation());
2067 EXPECT_EQ(webrtc::kVideoRotation_90, callee()->rendered_rotation());
2068}
2069
2070// Test that when the CVO extension isn't supported, video is rotated the
2071// old-fashioned way, by encoding rotated frames.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002072TEST_P(PeerConnectionIntegrationTest, RotatedVideoWithoutCVOExtension) {
deadbeef1dcb1642017-03-29 21:08:16 -07002073 ASSERT_TRUE(CreatePeerConnectionWrappers());
2074 ConnectFakeSignaling();
2075 // Add rotated video tracks.
Steve Anton15324772018-01-16 10:26:49 -08002076 caller()->AddTrack(
deadbeef1dcb1642017-03-29 21:08:16 -07002077 caller()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_90));
Steve Anton15324772018-01-16 10:26:49 -08002078 callee()->AddTrack(
deadbeef1dcb1642017-03-29 21:08:16 -07002079 callee()->CreateLocalVideoTrackWithRotation(webrtc::kVideoRotation_270));
2080
2081 // Remove the CVO extension from the offered SDP.
2082 callee()->SetReceivedSdpMunger([](cricket::SessionDescription* desc) {
2083 cricket::VideoContentDescription* video =
2084 GetFirstVideoContentDescription(desc);
2085 video->ClearRtpHeaderExtensions();
2086 });
2087 // Wait for video frames to be received by both sides.
2088 caller()->CreateAndSetAndSignalOffer();
2089 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2090 ASSERT_TRUE_WAIT(caller()->min_video_frames_received_per_track() > 0 &&
2091 callee()->min_video_frames_received_per_track() > 0,
2092 kMaxWaitForFramesMs);
2093
2094 // Expect that the aspect ratio is inversed to account for the 90/270 degree
2095 // rotation.
2096 // TODO(deadbeef): Where does 4:3 come from? Should be explicit in the test,
2097 // not just assumed.
2098 EXPECT_EQ(3.0 / 4, caller()->local_rendered_aspect_ratio());
2099 EXPECT_EQ(3.0 / 4, caller()->rendered_aspect_ratio());
2100 EXPECT_EQ(3.0 / 4, callee()->local_rendered_aspect_ratio());
2101 EXPECT_EQ(3.0 / 4, callee()->rendered_aspect_ratio());
2102 // Expect that each endpoint is unaware of the rotation of the other endpoint.
2103 EXPECT_EQ(webrtc::kVideoRotation_0, caller()->rendered_rotation());
2104 EXPECT_EQ(webrtc::kVideoRotation_0, callee()->rendered_rotation());
2105}
2106
deadbeef1dcb1642017-03-29 21:08:16 -07002107// Test that if the answerer rejects the audio m= section, no audio is sent or
2108// received, but video still can be.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002109TEST_P(PeerConnectionIntegrationTest, AnswererRejectsAudioSection) {
deadbeef1dcb1642017-03-29 21:08:16 -07002110 ASSERT_TRUE(CreatePeerConnectionWrappers());
2111 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08002112 caller()->AddAudioVideoTracks();
Seth Hampson2f0d7022018-02-20 11:54:42 -08002113 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2114 // Only add video track for callee, and set offer_to_receive_audio to 0, so
2115 // it will reject the audio m= section completely.
2116 PeerConnectionInterface::RTCOfferAnswerOptions options;
2117 options.offer_to_receive_audio = 0;
2118 callee()->SetOfferAnswerOptions(options);
2119 } else {
2120 // Stopping the audio RtpTransceiver will cause the media section to be
2121 // rejected in the answer.
2122 callee()->SetRemoteOfferHandler([this] {
2123 callee()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_AUDIO)->Stop();
2124 });
2125 }
Steve Anton15324772018-01-16 10:26:49 -08002126 callee()->AddTrack(callee()->CreateLocalVideoTrack());
deadbeef1dcb1642017-03-29 21:08:16 -07002127 // Do offer/answer and wait for successful end-to-end video frames.
2128 caller()->CreateAndSetAndSignalOffer();
2129 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08002130 MediaExpectations media_expectations;
2131 media_expectations.ExpectBidirectionalVideo();
2132 media_expectations.ExpectNoAudio();
2133 ASSERT_TRUE(ExpectNewFrames(media_expectations));
2134
deadbeef1dcb1642017-03-29 21:08:16 -07002135 // Sanity check that the callee's description has a rejected audio section.
2136 ASSERT_NE(nullptr, callee()->pc()->local_description());
2137 const ContentInfo* callee_audio_content =
2138 GetFirstAudioContent(callee()->pc()->local_description()->description());
2139 ASSERT_NE(nullptr, callee_audio_content);
2140 EXPECT_TRUE(callee_audio_content->rejected);
Seth Hampson2f0d7022018-02-20 11:54:42 -08002141 if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) {
2142 // The caller's transceiver should have stopped after receiving the answer.
2143 EXPECT_TRUE(caller()
2144 ->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_AUDIO)
2145 ->stopped());
2146 }
deadbeef1dcb1642017-03-29 21:08:16 -07002147}
2148
2149// Test that if the answerer rejects the video m= section, no video is sent or
2150// received, but audio still can be.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002151TEST_P(PeerConnectionIntegrationTest, AnswererRejectsVideoSection) {
deadbeef1dcb1642017-03-29 21:08:16 -07002152 ASSERT_TRUE(CreatePeerConnectionWrappers());
2153 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08002154 caller()->AddAudioVideoTracks();
Seth Hampson2f0d7022018-02-20 11:54:42 -08002155 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2156 // Only add audio track for callee, and set offer_to_receive_video to 0, so
2157 // it will reject the video m= section completely.
2158 PeerConnectionInterface::RTCOfferAnswerOptions options;
2159 options.offer_to_receive_video = 0;
2160 callee()->SetOfferAnswerOptions(options);
2161 } else {
2162 // Stopping the video RtpTransceiver will cause the media section to be
2163 // rejected in the answer.
2164 callee()->SetRemoteOfferHandler([this] {
2165 callee()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)->Stop();
2166 });
2167 }
Steve Anton15324772018-01-16 10:26:49 -08002168 callee()->AddTrack(callee()->CreateLocalAudioTrack());
deadbeef1dcb1642017-03-29 21:08:16 -07002169 // Do offer/answer and wait for successful end-to-end audio frames.
2170 caller()->CreateAndSetAndSignalOffer();
2171 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08002172 MediaExpectations media_expectations;
2173 media_expectations.ExpectBidirectionalAudio();
2174 media_expectations.ExpectNoVideo();
2175 ASSERT_TRUE(ExpectNewFrames(media_expectations));
2176
deadbeef1dcb1642017-03-29 21:08:16 -07002177 // Sanity check that the callee's description has a rejected video section.
2178 ASSERT_NE(nullptr, callee()->pc()->local_description());
2179 const ContentInfo* callee_video_content =
2180 GetFirstVideoContent(callee()->pc()->local_description()->description());
2181 ASSERT_NE(nullptr, callee_video_content);
2182 EXPECT_TRUE(callee_video_content->rejected);
Seth Hampson2f0d7022018-02-20 11:54:42 -08002183 if (sdp_semantics_ == SdpSemantics::kUnifiedPlan) {
2184 // The caller's transceiver should have stopped after receiving the answer.
2185 EXPECT_TRUE(caller()
2186 ->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)
2187 ->stopped());
2188 }
deadbeef1dcb1642017-03-29 21:08:16 -07002189}
2190
2191// Test that if the answerer rejects both audio and video m= sections, nothing
2192// bad happens.
2193// TODO(deadbeef): Test that a data channel still works. Currently this doesn't
2194// test anything but the fact that negotiation succeeds, which doesn't mean
2195// much.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002196TEST_P(PeerConnectionIntegrationTest, AnswererRejectsAudioAndVideoSections) {
deadbeef1dcb1642017-03-29 21:08:16 -07002197 ASSERT_TRUE(CreatePeerConnectionWrappers());
2198 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08002199 caller()->AddAudioVideoTracks();
Seth Hampson2f0d7022018-02-20 11:54:42 -08002200 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2201 // Don't give the callee any tracks, and set offer_to_receive_X to 0, so it
2202 // will reject both audio and video m= sections.
2203 PeerConnectionInterface::RTCOfferAnswerOptions options;
2204 options.offer_to_receive_audio = 0;
2205 options.offer_to_receive_video = 0;
2206 callee()->SetOfferAnswerOptions(options);
2207 } else {
2208 callee()->SetRemoteOfferHandler([this] {
2209 // Stopping all transceivers will cause all media sections to be rejected.
2210 for (auto transceiver : callee()->pc()->GetTransceivers()) {
2211 transceiver->Stop();
2212 }
2213 });
2214 }
deadbeef1dcb1642017-03-29 21:08:16 -07002215 // Do offer/answer and wait for stable signaling state.
2216 caller()->CreateAndSetAndSignalOffer();
2217 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08002218
deadbeef1dcb1642017-03-29 21:08:16 -07002219 // Sanity check that the callee's description has rejected m= sections.
2220 ASSERT_NE(nullptr, callee()->pc()->local_description());
2221 const ContentInfo* callee_audio_content =
2222 GetFirstAudioContent(callee()->pc()->local_description()->description());
2223 ASSERT_NE(nullptr, callee_audio_content);
2224 EXPECT_TRUE(callee_audio_content->rejected);
2225 const ContentInfo* callee_video_content =
2226 GetFirstVideoContent(callee()->pc()->local_description()->description());
2227 ASSERT_NE(nullptr, callee_video_content);
2228 EXPECT_TRUE(callee_video_content->rejected);
2229}
2230
2231// This test sets up an audio and video call between two parties. After the
2232// call runs for a while, the caller sends an updated offer with video being
2233// rejected. Once the re-negotiation is done, the video flow should stop and
2234// the audio flow should continue.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002235TEST_P(PeerConnectionIntegrationTest, VideoRejectedInSubsequentOffer) {
deadbeef1dcb1642017-03-29 21:08:16 -07002236 ASSERT_TRUE(CreatePeerConnectionWrappers());
2237 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08002238 caller()->AddAudioVideoTracks();
2239 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07002240 caller()->CreateAndSetAndSignalOffer();
2241 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08002242 {
2243 MediaExpectations media_expectations;
2244 media_expectations.ExpectBidirectionalAudioAndVideo();
2245 ASSERT_TRUE(ExpectNewFrames(media_expectations));
2246 }
deadbeef1dcb1642017-03-29 21:08:16 -07002247 // Renegotiate, rejecting the video m= section.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002248 if (sdp_semantics_ == SdpSemantics::kPlanB) {
2249 caller()->SetGeneratedSdpMunger(
2250 [](cricket::SessionDescription* description) {
2251 for (cricket::ContentInfo& content : description->contents()) {
2252 if (cricket::IsVideoContent(&content)) {
2253 content.rejected = true;
2254 }
2255 }
2256 });
2257 } else {
2258 caller()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)->Stop();
2259 }
deadbeef1dcb1642017-03-29 21:08:16 -07002260 caller()->CreateAndSetAndSignalOffer();
2261 ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs);
2262
2263 // Sanity check that the caller's description has a rejected video section.
2264 ASSERT_NE(nullptr, caller()->pc()->local_description());
2265 const ContentInfo* caller_video_content =
2266 GetFirstVideoContent(caller()->pc()->local_description()->description());
2267 ASSERT_NE(nullptr, caller_video_content);
2268 EXPECT_TRUE(caller_video_content->rejected);
deadbeef1dcb1642017-03-29 21:08:16 -07002269 // Wait for some additional audio frames to be received.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002270 {
2271 MediaExpectations media_expectations;
2272 media_expectations.ExpectBidirectionalAudio();
2273 media_expectations.ExpectNoVideo();
2274 ASSERT_TRUE(ExpectNewFrames(media_expectations));
2275 }
deadbeef1dcb1642017-03-29 21:08:16 -07002276}
2277
Taylor Brandstetter60c8dc82018-04-11 15:20:27 -07002278// Do one offer/answer with audio, another that disables it (rejecting the m=
2279// section), and another that re-enables it. Regression test for:
2280// bugs.webrtc.org/6023
2281TEST_F(PeerConnectionIntegrationTestPlanB, EnableAudioAfterRejecting) {
2282 ASSERT_TRUE(CreatePeerConnectionWrappers());
2283 ConnectFakeSignaling();
2284
2285 // Add audio track, do normal offer/answer.
2286 rtc::scoped_refptr<webrtc::AudioTrackInterface> track =
2287 caller()->CreateLocalAudioTrack();
2288 rtc::scoped_refptr<webrtc::RtpSenderInterface> sender =
2289 caller()->pc()->AddTrack(track, {"stream"}).MoveValue();
2290 caller()->CreateAndSetAndSignalOffer();
2291 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2292
2293 // Remove audio track, and set offer_to_receive_audio to false to cause the
2294 // m= section to be completely disabled, not just "recvonly".
2295 caller()->pc()->RemoveTrack(sender);
2296 PeerConnectionInterface::RTCOfferAnswerOptions options;
2297 options.offer_to_receive_audio = 0;
2298 caller()->SetOfferAnswerOptions(options);
2299 caller()->CreateAndSetAndSignalOffer();
2300 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2301
2302 // Add the audio track again, expecting negotiation to succeed and frames to
2303 // flow.
2304 sender = caller()->pc()->AddTrack(track, {"stream"}).MoveValue();
2305 options.offer_to_receive_audio = 1;
2306 caller()->SetOfferAnswerOptions(options);
2307 caller()->CreateAndSetAndSignalOffer();
2308 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2309
2310 MediaExpectations media_expectations;
2311 media_expectations.CalleeExpectsSomeAudio();
2312 EXPECT_TRUE(ExpectNewFrames(media_expectations));
2313}
2314
deadbeef1dcb1642017-03-29 21:08:16 -07002315// Basic end-to-end test, but without SSRC/MSID signaling. This functionality
2316// is needed to support legacy endpoints.
2317// TODO(deadbeef): When we support the MID extension and demuxing on MID, also
2318// add a test for an end-to-end test without MID signaling either (basically,
2319// the minimum acceptable SDP).
Seth Hampson2f0d7022018-02-20 11:54:42 -08002320TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithoutSsrcOrMsidSignaling) {
deadbeef1dcb1642017-03-29 21:08:16 -07002321 ASSERT_TRUE(CreatePeerConnectionWrappers());
2322 ConnectFakeSignaling();
2323 // Add audio and video, testing that packets can be demuxed on payload type.
Steve Anton15324772018-01-16 10:26:49 -08002324 caller()->AddAudioVideoTracks();
2325 callee()->AddAudioVideoTracks();
deadbeefd8ad7882017-04-18 16:01:17 -07002326 // Remove SSRCs and MSIDs from the received offer SDP.
2327 callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids);
deadbeef1dcb1642017-03-29 21:08:16 -07002328 caller()->CreateAndSetAndSignalOffer();
2329 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08002330 MediaExpectations media_expectations;
2331 media_expectations.ExpectBidirectionalAudioAndVideo();
2332 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07002333}
2334
Seth Hampson5897a6e2018-04-03 11:16:33 -07002335// Basic end-to-end test, without SSRC signaling. This means that the track
2336// was created properly and frames are delivered when the MSIDs are communicated
2337// with a=msid lines and no a=ssrc lines.
2338TEST_F(PeerConnectionIntegrationTestUnifiedPlan,
2339 EndToEndCallWithoutSsrcSignaling) {
2340 const char kStreamId[] = "streamId";
2341 ASSERT_TRUE(CreatePeerConnectionWrappers());
2342 ConnectFakeSignaling();
2343 // Add just audio tracks.
2344 caller()->AddTrack(caller()->CreateLocalAudioTrack(), {kStreamId});
2345 callee()->AddAudioTrack();
2346
2347 // Remove SSRCs from the received offer SDP.
2348 callee()->SetReceivedSdpMunger(RemoveSsrcsAndKeepMsids);
2349 caller()->CreateAndSetAndSignalOffer();
2350 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2351 MediaExpectations media_expectations;
2352 media_expectations.ExpectBidirectionalAudio();
2353 ASSERT_TRUE(ExpectNewFrames(media_expectations));
2354}
2355
Steve Antondf527fd2018-04-27 15:52:03 -07002356// Tests that video flows between multiple video tracks when SSRCs are not
2357// signaled. This exercises the MID RTP header extension which is needed to
2358// demux the incoming video tracks.
2359TEST_F(PeerConnectionIntegrationTestUnifiedPlan,
2360 EndToEndCallWithTwoVideoTracksAndNoSignaledSsrc) {
2361 ASSERT_TRUE(CreatePeerConnectionWrappers());
2362 ConnectFakeSignaling();
2363 caller()->AddVideoTrack();
2364 caller()->AddVideoTrack();
2365 callee()->AddVideoTrack();
2366 callee()->AddVideoTrack();
2367
2368 caller()->SetReceivedSdpMunger(&RemoveSsrcsAndKeepMsids);
2369 callee()->SetReceivedSdpMunger(&RemoveSsrcsAndKeepMsids);
2370 caller()->CreateAndSetAndSignalOffer();
2371 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2372 ASSERT_EQ(2u, caller()->pc()->GetReceivers().size());
2373 ASSERT_EQ(2u, callee()->pc()->GetReceivers().size());
2374
2375 // Expect video to be received in both directions on both tracks.
2376 MediaExpectations media_expectations;
2377 media_expectations.ExpectBidirectionalVideo();
2378 EXPECT_TRUE(ExpectNewFrames(media_expectations));
2379}
2380
deadbeef1dcb1642017-03-29 21:08:16 -07002381// Test that if two video tracks are sent (from caller to callee, in this test),
2382// they're transmitted correctly end-to-end.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002383TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithTwoVideoTracks) {
deadbeef1dcb1642017-03-29 21:08:16 -07002384 ASSERT_TRUE(CreatePeerConnectionWrappers());
2385 ConnectFakeSignaling();
2386 // Add one audio/video stream, and one video-only stream.
Steve Anton15324772018-01-16 10:26:49 -08002387 caller()->AddAudioVideoTracks();
2388 caller()->AddVideoTrack();
deadbeef1dcb1642017-03-29 21:08:16 -07002389 caller()->CreateAndSetAndSignalOffer();
2390 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Steve Anton15324772018-01-16 10:26:49 -08002391 ASSERT_EQ(3u, callee()->pc()->GetReceivers().size());
Seth Hampson2f0d7022018-02-20 11:54:42 -08002392
2393 MediaExpectations media_expectations;
2394 media_expectations.CalleeExpectsSomeAudioAndVideo();
2395 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07002396}
2397
2398static void MakeSpecCompliantMaxBundleOffer(cricket::SessionDescription* desc) {
2399 bool first = true;
2400 for (cricket::ContentInfo& content : desc->contents()) {
2401 if (first) {
2402 first = false;
2403 continue;
2404 }
2405 content.bundle_only = true;
2406 }
2407 first = true;
2408 for (cricket::TransportInfo& transport : desc->transport_infos()) {
2409 if (first) {
2410 first = false;
2411 continue;
2412 }
2413 transport.description.ice_ufrag.clear();
2414 transport.description.ice_pwd.clear();
2415 transport.description.connection_role = cricket::CONNECTIONROLE_NONE;
2416 transport.description.identity_fingerprint.reset(nullptr);
2417 }
2418}
2419
2420// Test that if applying a true "max bundle" offer, which uses ports of 0,
2421// "a=bundle-only", omitting "a=fingerprint", "a=setup", "a=ice-ufrag" and
2422// "a=ice-pwd" for all but the audio "m=" section, negotiation still completes
2423// successfully and media flows.
2424// TODO(deadbeef): Update this test to also omit "a=rtcp-mux", once that works.
2425// TODO(deadbeef): Won't need this test once we start generating actual
2426// standards-compliant SDP.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002427TEST_P(PeerConnectionIntegrationTest,
deadbeef1dcb1642017-03-29 21:08:16 -07002428 EndToEndCallWithSpecCompliantMaxBundleOffer) {
2429 ASSERT_TRUE(CreatePeerConnectionWrappers());
2430 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08002431 caller()->AddAudioVideoTracks();
2432 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07002433 // Do the equivalent of setting the port to 0, adding a=bundle-only, and
2434 // removing a=ice-ufrag, a=ice-pwd, a=fingerprint and a=setup from all
2435 // but the first m= section.
2436 callee()->SetReceivedSdpMunger(MakeSpecCompliantMaxBundleOffer);
2437 caller()->CreateAndSetAndSignalOffer();
2438 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08002439 MediaExpectations media_expectations;
2440 media_expectations.ExpectBidirectionalAudioAndVideo();
2441 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07002442}
2443
2444// Test that we can receive the audio output level from a remote audio track.
2445// TODO(deadbeef): Use a fake audio source and verify that the output level is
2446// exactly what the source on the other side was configured with.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002447TEST_P(PeerConnectionIntegrationTest, GetAudioOutputLevelStatsWithOldStatsApi) {
deadbeef1dcb1642017-03-29 21:08:16 -07002448 ASSERT_TRUE(CreatePeerConnectionWrappers());
2449 ConnectFakeSignaling();
2450 // Just add an audio track.
Steve Anton15324772018-01-16 10:26:49 -08002451 caller()->AddAudioTrack();
deadbeef1dcb1642017-03-29 21:08:16 -07002452 caller()->CreateAndSetAndSignalOffer();
2453 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2454
2455 // Get the audio output level stats. Note that the level is not available
2456 // until an RTCP packet has been received.
deadbeefd8ad7882017-04-18 16:01:17 -07002457 EXPECT_TRUE_WAIT(callee()->OldGetStats()->AudioOutputLevel() > 0,
deadbeef1dcb1642017-03-29 21:08:16 -07002458 kMaxWaitForFramesMs);
2459}
2460
2461// Test that an audio input level is reported.
2462// TODO(deadbeef): Use a fake audio source and verify that the input level is
2463// exactly what the source was configured with.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002464TEST_P(PeerConnectionIntegrationTest, GetAudioInputLevelStatsWithOldStatsApi) {
deadbeef1dcb1642017-03-29 21:08:16 -07002465 ASSERT_TRUE(CreatePeerConnectionWrappers());
2466 ConnectFakeSignaling();
2467 // Just add an audio track.
Steve Anton15324772018-01-16 10:26:49 -08002468 caller()->AddAudioTrack();
deadbeef1dcb1642017-03-29 21:08:16 -07002469 caller()->CreateAndSetAndSignalOffer();
2470 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2471
2472 // Get the audio input level stats. The level should be available very
2473 // soon after the test starts.
deadbeefd8ad7882017-04-18 16:01:17 -07002474 EXPECT_TRUE_WAIT(caller()->OldGetStats()->AudioInputLevel() > 0,
deadbeef1dcb1642017-03-29 21:08:16 -07002475 kMaxWaitForStatsMs);
2476}
2477
2478// Test that we can get incoming byte counts from both audio and video tracks.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002479TEST_P(PeerConnectionIntegrationTest, GetBytesReceivedStatsWithOldStatsApi) {
deadbeef1dcb1642017-03-29 21:08:16 -07002480 ASSERT_TRUE(CreatePeerConnectionWrappers());
2481 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08002482 caller()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07002483 // Do offer/answer, wait for the callee to receive some frames.
2484 caller()->CreateAndSetAndSignalOffer();
2485 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08002486
2487 MediaExpectations media_expectations;
2488 media_expectations.CalleeExpectsSomeAudioAndVideo();
2489 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07002490
2491 // Get a handle to the remote tracks created, so they can be used as GetStats
2492 // filters.
Steve Anton15324772018-01-16 10:26:49 -08002493 for (auto receiver : callee()->pc()->GetReceivers()) {
2494 // We received frames, so we definitely should have nonzero "received bytes"
2495 // stats at this point.
2496 EXPECT_GT(callee()->OldGetStatsForTrack(receiver->track())->BytesReceived(),
2497 0);
2498 }
deadbeef1dcb1642017-03-29 21:08:16 -07002499}
2500
2501// Test that we can get outgoing byte counts from both audio and video tracks.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002502TEST_P(PeerConnectionIntegrationTest, GetBytesSentStatsWithOldStatsApi) {
deadbeef1dcb1642017-03-29 21:08:16 -07002503 ASSERT_TRUE(CreatePeerConnectionWrappers());
2504 ConnectFakeSignaling();
2505 auto audio_track = caller()->CreateLocalAudioTrack();
2506 auto video_track = caller()->CreateLocalVideoTrack();
Steve Anton15324772018-01-16 10:26:49 -08002507 caller()->AddTrack(audio_track);
2508 caller()->AddTrack(video_track);
deadbeef1dcb1642017-03-29 21:08:16 -07002509 // Do offer/answer, wait for the callee to receive some frames.
2510 caller()->CreateAndSetAndSignalOffer();
2511 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08002512 MediaExpectations media_expectations;
2513 media_expectations.CalleeExpectsSomeAudioAndVideo();
2514 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07002515
2516 // The callee received frames, so we definitely should have nonzero "sent
2517 // bytes" stats at this point.
deadbeefd8ad7882017-04-18 16:01:17 -07002518 EXPECT_GT(caller()->OldGetStatsForTrack(audio_track)->BytesSent(), 0);
2519 EXPECT_GT(caller()->OldGetStatsForTrack(video_track)->BytesSent(), 0);
2520}
2521
Fredrik Solenberg73276ad2017-09-14 14:46:47 +02002522// Test that we can get capture start ntp time.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002523TEST_P(PeerConnectionIntegrationTest, GetCaptureStartNtpTimeWithOldStatsApi) {
Fredrik Solenberg73276ad2017-09-14 14:46:47 +02002524 ASSERT_TRUE(CreatePeerConnectionWrappers());
2525 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08002526 caller()->AddAudioTrack();
Fredrik Solenberg73276ad2017-09-14 14:46:47 +02002527
Steve Anton15324772018-01-16 10:26:49 -08002528 callee()->AddAudioTrack();
Fredrik Solenberg73276ad2017-09-14 14:46:47 +02002529
2530 // Do offer/answer, wait for the callee to receive some frames.
2531 caller()->CreateAndSetAndSignalOffer();
2532 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2533
2534 // Get the remote audio track created on the receiver, so they can be used as
2535 // GetStats filters.
Steve Antonfc853712018-03-01 13:48:58 -08002536 auto receivers = callee()->pc()->GetReceivers();
2537 ASSERT_EQ(1u, receivers.size());
2538 auto remote_audio_track = receivers[0]->track();
Fredrik Solenberg73276ad2017-09-14 14:46:47 +02002539
2540 // Get the audio output level stats. Note that the level is not available
2541 // until an RTCP packet has been received.
Zhi Huange830e682018-03-30 10:48:35 -07002542 EXPECT_TRUE_WAIT(
2543 callee()->OldGetStatsForTrack(remote_audio_track)->CaptureStartNtpTime() >
2544 0,
2545 2 * kMaxWaitForFramesMs);
Fredrik Solenberg73276ad2017-09-14 14:46:47 +02002546}
2547
deadbeefd8ad7882017-04-18 16:01:17 -07002548// Test that we can get stats (using the new stats implemnetation) for
2549// unsignaled streams. Meaning when SSRCs/MSIDs aren't signaled explicitly in
2550// SDP.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002551TEST_P(PeerConnectionIntegrationTest,
deadbeefd8ad7882017-04-18 16:01:17 -07002552 GetStatsForUnsignaledStreamWithNewStatsApi) {
2553 ASSERT_TRUE(CreatePeerConnectionWrappers());
2554 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08002555 caller()->AddAudioTrack();
deadbeefd8ad7882017-04-18 16:01:17 -07002556 // Remove SSRCs and MSIDs from the received offer SDP.
2557 callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids);
2558 caller()->CreateAndSetAndSignalOffer();
2559 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08002560 MediaExpectations media_expectations;
2561 media_expectations.CalleeExpectsSomeAudio(1);
2562 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeefd8ad7882017-04-18 16:01:17 -07002563
2564 // We received a frame, so we should have nonzero "bytes received" stats for
2565 // the unsignaled stream, if stats are working for it.
2566 rtc::scoped_refptr<const webrtc::RTCStatsReport> report =
2567 callee()->NewGetStats();
2568 ASSERT_NE(nullptr, report);
2569 auto inbound_stream_stats =
2570 report->GetStatsOfType<webrtc::RTCInboundRTPStreamStats>();
2571 ASSERT_EQ(1U, inbound_stream_stats.size());
2572 ASSERT_TRUE(inbound_stream_stats[0]->bytes_received.is_defined());
2573 ASSERT_GT(*inbound_stream_stats[0]->bytes_received, 0U);
zhihuangf8164932017-05-19 13:09:47 -07002574 ASSERT_TRUE(inbound_stream_stats[0]->track_id.is_defined());
2575}
2576
Taylor Brandstettera4653442018-06-19 09:44:26 -07002577// Same as above but for the legacy stats implementation.
2578TEST_P(PeerConnectionIntegrationTest,
2579 GetStatsForUnsignaledStreamWithOldStatsApi) {
2580 ASSERT_TRUE(CreatePeerConnectionWrappers());
2581 ConnectFakeSignaling();
2582 caller()->AddAudioTrack();
2583 // Remove SSRCs and MSIDs from the received offer SDP.
2584 callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids);
2585 caller()->CreateAndSetAndSignalOffer();
2586 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2587
2588 // Note that, since the old stats implementation associates SSRCs with tracks
2589 // using SDP, when SSRCs aren't signaled in SDP these stats won't have an
2590 // associated track ID. So we can't use the track "selector" argument.
2591 //
2592 // Also, we use "EXPECT_TRUE_WAIT" because the stats collector may decide to
2593 // return cached stats if not enough time has passed since the last update.
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02002594 EXPECT_TRUE_WAIT(callee()->OldGetStats()->BytesReceived() > 0,
Taylor Brandstettera4653442018-06-19 09:44:26 -07002595 kDefaultTimeout);
2596}
2597
zhihuangf8164932017-05-19 13:09:47 -07002598// Test that we can successfully get the media related stats (audio level
2599// etc.) for the unsignaled stream.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002600TEST_P(PeerConnectionIntegrationTest,
zhihuangf8164932017-05-19 13:09:47 -07002601 GetMediaStatsForUnsignaledStreamWithNewStatsApi) {
2602 ASSERT_TRUE(CreatePeerConnectionWrappers());
2603 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08002604 caller()->AddAudioVideoTracks();
zhihuangf8164932017-05-19 13:09:47 -07002605 // Remove SSRCs and MSIDs from the received offer SDP.
2606 callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids);
2607 caller()->CreateAndSetAndSignalOffer();
2608 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08002609 MediaExpectations media_expectations;
2610 media_expectations.CalleeExpectsSomeAudio(1);
2611 media_expectations.CalleeExpectsSomeVideo(1);
2612 ASSERT_TRUE(ExpectNewFrames(media_expectations));
zhihuangf8164932017-05-19 13:09:47 -07002613
2614 rtc::scoped_refptr<const webrtc::RTCStatsReport> report =
2615 callee()->NewGetStats();
2616 ASSERT_NE(nullptr, report);
2617
2618 auto media_stats = report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>();
2619 auto audio_index = FindFirstMediaStatsIndexByKind("audio", media_stats);
2620 ASSERT_GE(audio_index, 0);
2621 EXPECT_TRUE(media_stats[audio_index]->audio_level.is_defined());
deadbeef1dcb1642017-03-29 21:08:16 -07002622}
2623
deadbeef4e2deab2017-09-20 13:56:21 -07002624// Helper for test below.
2625void ModifySsrcs(cricket::SessionDescription* desc) {
2626 for (ContentInfo& content : desc->contents()) {
Steve Antondf527fd2018-04-27 15:52:03 -07002627 for (StreamParams& stream :
Steve Antonb1c1de12017-12-21 15:14:30 -08002628 content.media_description()->mutable_streams()) {
deadbeef4e2deab2017-09-20 13:56:21 -07002629 for (uint32_t& ssrc : stream.ssrcs) {
2630 ssrc = rtc::CreateRandomId();
2631 }
2632 }
2633 }
2634}
2635
2636// Test that the "RTCMediaSteamTrackStats" object is updated correctly when
2637// SSRCs are unsignaled, and the SSRC of the received (audio) stream changes.
2638// This should result in two "RTCInboundRTPStreamStats", but only one
2639// "RTCMediaStreamTrackStats", whose counters go up continuously rather than
2640// being reset to 0 once the SSRC change occurs.
2641//
2642// Regression test for this bug:
2643// https://bugs.chromium.org/p/webrtc/issues/detail?id=8158
2644//
2645// The bug causes the track stats to only represent one of the two streams:
2646// whichever one has the higher SSRC. So with this bug, there was a 50% chance
2647// that the track stat counters would reset to 0 when the new stream is
2648// received, and a 50% chance that they'll stop updating (while
2649// "concealed_samples" continues increasing, due to silence being generated for
2650// the inactive stream).
Seth Hampson2f0d7022018-02-20 11:54:42 -08002651TEST_P(PeerConnectionIntegrationTest,
Steve Anton83119dd2017-11-10 16:19:52 -08002652 TrackStatsUpdatedCorrectlyWhenUnsignaledSsrcChanges) {
deadbeef4e2deab2017-09-20 13:56:21 -07002653 ASSERT_TRUE(CreatePeerConnectionWrappers());
2654 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08002655 caller()->AddAudioTrack();
deadbeef4e2deab2017-09-20 13:56:21 -07002656 // Remove SSRCs and MSIDs from the received offer SDP, simulating an endpoint
2657 // that doesn't signal SSRCs (from the callee's perspective).
2658 callee()->SetReceivedSdpMunger(RemoveSsrcsAndMsids);
2659 caller()->CreateAndSetAndSignalOffer();
2660 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2661 // Wait for 50 audio frames (500ms of audio) to be received by the callee.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002662 {
2663 MediaExpectations media_expectations;
2664 media_expectations.CalleeExpectsSomeAudio(50);
2665 ASSERT_TRUE(ExpectNewFrames(media_expectations));
2666 }
deadbeef4e2deab2017-09-20 13:56:21 -07002667 // Some audio frames were received, so we should have nonzero "samples
2668 // received" for the track.
2669 rtc::scoped_refptr<const webrtc::RTCStatsReport> report =
2670 callee()->NewGetStats();
2671 ASSERT_NE(nullptr, report);
2672 auto track_stats = report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>();
2673 ASSERT_EQ(1U, track_stats.size());
2674 ASSERT_TRUE(track_stats[0]->total_samples_received.is_defined());
2675 ASSERT_GT(*track_stats[0]->total_samples_received, 0U);
2676 // uint64_t prev_samples_received = *track_stats[0]->total_samples_received;
2677
2678 // Create a new offer and munge it to cause the caller to use a new SSRC.
2679 caller()->SetGeneratedSdpMunger(ModifySsrcs);
2680 caller()->CreateAndSetAndSignalOffer();
2681 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2682 // Wait for 25 more audio frames (250ms of audio) to be received, from the new
2683 // SSRC.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002684 {
2685 MediaExpectations media_expectations;
2686 media_expectations.CalleeExpectsSomeAudio(25);
2687 ASSERT_TRUE(ExpectNewFrames(media_expectations));
2688 }
deadbeef4e2deab2017-09-20 13:56:21 -07002689
2690 report = callee()->NewGetStats();
2691 ASSERT_NE(nullptr, report);
2692 track_stats = report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>();
2693 ASSERT_EQ(1U, track_stats.size());
2694 ASSERT_TRUE(track_stats[0]->total_samples_received.is_defined());
2695 // The "total samples received" stat should only be greater than it was
2696 // before.
2697 // TODO(deadbeef): Uncomment this assertion once the bug is completely fixed.
2698 // Right now, the new SSRC will cause the counters to reset to 0.
2699 // EXPECT_GT(*track_stats[0]->total_samples_received, prev_samples_received);
2700
2701 // Additionally, the percentage of concealed samples (samples generated to
Steve Anton83119dd2017-11-10 16:19:52 -08002702 // conceal packet loss) should be less than 50%. If it's greater, that's a
deadbeef4e2deab2017-09-20 13:56:21 -07002703 // good sign that we're seeing stats from the old stream that's no longer
2704 // receiving packets, and is generating concealed samples of silence.
Steve Anton83119dd2017-11-10 16:19:52 -08002705 constexpr double kAcceptableConcealedSamplesPercentage = 0.50;
deadbeef4e2deab2017-09-20 13:56:21 -07002706 ASSERT_TRUE(track_stats[0]->concealed_samples.is_defined());
2707 EXPECT_LT(*track_stats[0]->concealed_samples,
2708 *track_stats[0]->total_samples_received *
2709 kAcceptableConcealedSamplesPercentage);
2710
2711 // Also ensure that we have two "RTCInboundRTPStreamStats" as expected, as a
2712 // sanity check that the SSRC really changed.
2713 // TODO(deadbeef): This isn't working right now, because we're not returning
2714 // *any* stats for the inactive stream. Uncomment when the bug is completely
2715 // fixed.
2716 // auto inbound_stream_stats =
2717 // report->GetStatsOfType<webrtc::RTCInboundRTPStreamStats>();
2718 // ASSERT_EQ(2U, inbound_stream_stats.size());
2719}
2720
deadbeef1dcb1642017-03-29 21:08:16 -07002721// Test that DTLS 1.0 is used if both sides only support DTLS 1.0.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002722TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithDtls10) {
deadbeef1dcb1642017-03-29 21:08:16 -07002723 PeerConnectionFactory::Options dtls_10_options;
2724 dtls_10_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
2725 ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(dtls_10_options,
2726 dtls_10_options));
2727 ConnectFakeSignaling();
2728 // Do normal offer/answer and wait for some frames to be received in each
2729 // direction.
Steve Anton15324772018-01-16 10:26:49 -08002730 caller()->AddAudioVideoTracks();
2731 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07002732 caller()->CreateAndSetAndSignalOffer();
2733 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08002734 MediaExpectations media_expectations;
2735 media_expectations.ExpectBidirectionalAudioAndVideo();
2736 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07002737}
2738
2739// Test getting cipher stats and UMA metrics when DTLS 1.0 is negotiated.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002740TEST_P(PeerConnectionIntegrationTest, Dtls10CipherStatsAndUmaMetrics) {
deadbeef1dcb1642017-03-29 21:08:16 -07002741 PeerConnectionFactory::Options dtls_10_options;
2742 dtls_10_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
2743 ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(dtls_10_options,
2744 dtls_10_options));
2745 ConnectFakeSignaling();
2746 // Register UMA observer before signaling begins.
2747 rtc::scoped_refptr<webrtc::FakeMetricsObserver> caller_observer =
2748 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
2749 caller()->pc()->RegisterUMAObserver(caller_observer);
Steve Anton15324772018-01-16 10:26:49 -08002750 caller()->AddAudioVideoTracks();
2751 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07002752 caller()->CreateAndSetAndSignalOffer();
2753 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2754 EXPECT_TRUE_WAIT(rtc::SSLStreamAdapter::IsAcceptableCipher(
deadbeefd8ad7882017-04-18 16:01:17 -07002755 caller()->OldGetStats()->DtlsCipher(), rtc::KT_DEFAULT),
deadbeef1dcb1642017-03-29 21:08:16 -07002756 kDefaultTimeout);
2757 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
deadbeefd8ad7882017-04-18 16:01:17 -07002758 caller()->OldGetStats()->SrtpCipher(), kDefaultTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -07002759 EXPECT_EQ(1,
2760 caller_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
2761 kDefaultSrtpCryptoSuite));
2762}
2763
2764// Test getting cipher stats and UMA metrics when DTLS 1.2 is negotiated.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002765TEST_P(PeerConnectionIntegrationTest, Dtls12CipherStatsAndUmaMetrics) {
deadbeef1dcb1642017-03-29 21:08:16 -07002766 PeerConnectionFactory::Options dtls_12_options;
2767 dtls_12_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
2768 ASSERT_TRUE(CreatePeerConnectionWrappersWithOptions(dtls_12_options,
2769 dtls_12_options));
2770 ConnectFakeSignaling();
2771 // Register UMA observer before signaling begins.
2772 rtc::scoped_refptr<webrtc::FakeMetricsObserver> caller_observer =
2773 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
2774 caller()->pc()->RegisterUMAObserver(caller_observer);
Steve Anton15324772018-01-16 10:26:49 -08002775 caller()->AddAudioVideoTracks();
2776 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07002777 caller()->CreateAndSetAndSignalOffer();
2778 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2779 EXPECT_TRUE_WAIT(rtc::SSLStreamAdapter::IsAcceptableCipher(
deadbeefd8ad7882017-04-18 16:01:17 -07002780 caller()->OldGetStats()->DtlsCipher(), rtc::KT_DEFAULT),
deadbeef1dcb1642017-03-29 21:08:16 -07002781 kDefaultTimeout);
2782 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
deadbeefd8ad7882017-04-18 16:01:17 -07002783 caller()->OldGetStats()->SrtpCipher(), kDefaultTimeout);
deadbeef1dcb1642017-03-29 21:08:16 -07002784 EXPECT_EQ(1,
2785 caller_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
2786 kDefaultSrtpCryptoSuite));
2787}
2788
2789// Test that DTLS 1.0 can be used if the caller supports DTLS 1.2 and the
2790// callee only supports 1.0.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002791TEST_P(PeerConnectionIntegrationTest, CallerDtls12ToCalleeDtls10) {
deadbeef1dcb1642017-03-29 21:08:16 -07002792 PeerConnectionFactory::Options caller_options;
2793 caller_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
2794 PeerConnectionFactory::Options callee_options;
2795 callee_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
2796 ASSERT_TRUE(
2797 CreatePeerConnectionWrappersWithOptions(caller_options, callee_options));
2798 ConnectFakeSignaling();
2799 // Do normal offer/answer and wait for some frames to be received in each
2800 // direction.
Steve Anton15324772018-01-16 10:26:49 -08002801 caller()->AddAudioVideoTracks();
2802 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07002803 caller()->CreateAndSetAndSignalOffer();
2804 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08002805 MediaExpectations media_expectations;
2806 media_expectations.ExpectBidirectionalAudioAndVideo();
2807 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07002808}
2809
2810// Test that DTLS 1.0 can be used if the caller only supports DTLS 1.0 and the
2811// callee supports 1.2.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002812TEST_P(PeerConnectionIntegrationTest, CallerDtls10ToCalleeDtls12) {
deadbeef1dcb1642017-03-29 21:08:16 -07002813 PeerConnectionFactory::Options caller_options;
2814 caller_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_10;
2815 PeerConnectionFactory::Options callee_options;
2816 callee_options.ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
2817 ASSERT_TRUE(
2818 CreatePeerConnectionWrappersWithOptions(caller_options, callee_options));
2819 ConnectFakeSignaling();
2820 // Do normal offer/answer and wait for some frames to be received in each
2821 // direction.
Steve Anton15324772018-01-16 10:26:49 -08002822 caller()->AddAudioVideoTracks();
2823 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07002824 caller()->CreateAndSetAndSignalOffer();
2825 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08002826 MediaExpectations media_expectations;
2827 media_expectations.ExpectBidirectionalAudioAndVideo();
2828 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07002829}
2830
Taylor Brandstetter5e55fe82018-03-23 11:50:16 -07002831// The three tests below verify that "enable_aes128_sha1_32_crypto_cipher"
2832// works as expected; the cipher should only be used if enabled by both sides.
2833TEST_P(PeerConnectionIntegrationTest,
2834 Aes128Sha1_32_CipherNotUsedWhenOnlyCallerSupported) {
2835 PeerConnectionFactory::Options caller_options;
2836 caller_options.crypto_options.enable_aes128_sha1_32_crypto_cipher = true;
2837 PeerConnectionFactory::Options callee_options;
2838 callee_options.crypto_options.enable_aes128_sha1_32_crypto_cipher = false;
2839 int expected_cipher_suite = rtc::SRTP_AES128_CM_SHA1_80;
2840 TestNegotiatedCipherSuite(caller_options, callee_options,
2841 expected_cipher_suite);
2842}
2843
2844TEST_P(PeerConnectionIntegrationTest,
2845 Aes128Sha1_32_CipherNotUsedWhenOnlyCalleeSupported) {
2846 PeerConnectionFactory::Options caller_options;
2847 caller_options.crypto_options.enable_aes128_sha1_32_crypto_cipher = false;
2848 PeerConnectionFactory::Options callee_options;
2849 callee_options.crypto_options.enable_aes128_sha1_32_crypto_cipher = true;
2850 int expected_cipher_suite = rtc::SRTP_AES128_CM_SHA1_80;
2851 TestNegotiatedCipherSuite(caller_options, callee_options,
2852 expected_cipher_suite);
2853}
2854
2855TEST_P(PeerConnectionIntegrationTest, Aes128Sha1_32_CipherUsedWhenSupported) {
2856 PeerConnectionFactory::Options caller_options;
2857 caller_options.crypto_options.enable_aes128_sha1_32_crypto_cipher = true;
2858 PeerConnectionFactory::Options callee_options;
2859 callee_options.crypto_options.enable_aes128_sha1_32_crypto_cipher = true;
2860 int expected_cipher_suite = rtc::SRTP_AES128_CM_SHA1_32;
2861 TestNegotiatedCipherSuite(caller_options, callee_options,
2862 expected_cipher_suite);
2863}
2864
deadbeef1dcb1642017-03-29 21:08:16 -07002865// Test that a non-GCM cipher is used if both sides only support non-GCM.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002866TEST_P(PeerConnectionIntegrationTest, NonGcmCipherUsedWhenGcmNotSupported) {
deadbeef1dcb1642017-03-29 21:08:16 -07002867 bool local_gcm_enabled = false;
2868 bool remote_gcm_enabled = false;
2869 int expected_cipher_suite = kDefaultSrtpCryptoSuite;
2870 TestGcmNegotiationUsesCipherSuite(local_gcm_enabled, remote_gcm_enabled,
2871 expected_cipher_suite);
2872}
2873
2874// Test that a GCM cipher is used if both ends support it.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002875TEST_P(PeerConnectionIntegrationTest, GcmCipherUsedWhenGcmSupported) {
deadbeef1dcb1642017-03-29 21:08:16 -07002876 bool local_gcm_enabled = true;
2877 bool remote_gcm_enabled = true;
2878 int expected_cipher_suite = kDefaultSrtpCryptoSuiteGcm;
2879 TestGcmNegotiationUsesCipherSuite(local_gcm_enabled, remote_gcm_enabled,
2880 expected_cipher_suite);
2881}
2882
2883// Test that GCM isn't used if only the offerer supports it.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002884TEST_P(PeerConnectionIntegrationTest,
deadbeef1dcb1642017-03-29 21:08:16 -07002885 NonGcmCipherUsedWhenOnlyCallerSupportsGcm) {
2886 bool local_gcm_enabled = true;
2887 bool remote_gcm_enabled = false;
2888 int expected_cipher_suite = kDefaultSrtpCryptoSuite;
2889 TestGcmNegotiationUsesCipherSuite(local_gcm_enabled, remote_gcm_enabled,
2890 expected_cipher_suite);
2891}
2892
2893// Test that GCM isn't used if only the answerer supports it.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002894TEST_P(PeerConnectionIntegrationTest,
deadbeef1dcb1642017-03-29 21:08:16 -07002895 NonGcmCipherUsedWhenOnlyCalleeSupportsGcm) {
2896 bool local_gcm_enabled = false;
2897 bool remote_gcm_enabled = true;
2898 int expected_cipher_suite = kDefaultSrtpCryptoSuite;
2899 TestGcmNegotiationUsesCipherSuite(local_gcm_enabled, remote_gcm_enabled,
2900 expected_cipher_suite);
2901}
2902
deadbeef7914b8c2017-04-21 03:23:33 -07002903// Verify that media can be transmitted end-to-end when GCM crypto suites are
2904// enabled. Note that the above tests, such as GcmCipherUsedWhenGcmSupported,
2905// only verify that a GCM cipher is negotiated, and not necessarily that SRTP
2906// works with it.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002907TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithGcmCipher) {
deadbeef7914b8c2017-04-21 03:23:33 -07002908 PeerConnectionFactory::Options gcm_options;
2909 gcm_options.crypto_options.enable_gcm_crypto_suites = true;
2910 ASSERT_TRUE(
2911 CreatePeerConnectionWrappersWithOptions(gcm_options, gcm_options));
2912 ConnectFakeSignaling();
2913 // Do normal offer/answer and wait for some frames to be received in each
2914 // direction.
Steve Anton15324772018-01-16 10:26:49 -08002915 caller()->AddAudioVideoTracks();
2916 callee()->AddAudioVideoTracks();
deadbeef7914b8c2017-04-21 03:23:33 -07002917 caller()->CreateAndSetAndSignalOffer();
2918 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08002919 MediaExpectations media_expectations;
2920 media_expectations.ExpectBidirectionalAudioAndVideo();
2921 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef7914b8c2017-04-21 03:23:33 -07002922}
2923
deadbeef1dcb1642017-03-29 21:08:16 -07002924// This test sets up a call between two parties with audio, video and an RTP
2925// data channel.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002926TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithRtpDataChannel) {
deadbeef1dcb1642017-03-29 21:08:16 -07002927 FakeConstraints setup_constraints;
2928 setup_constraints.SetAllowRtpDataChannels();
2929 ASSERT_TRUE(CreatePeerConnectionWrappersWithConstraints(&setup_constraints,
2930 &setup_constraints));
2931 ConnectFakeSignaling();
2932 // Expect that data channel created on caller side will show up for callee as
2933 // well.
2934 caller()->CreateDataChannel();
Steve Anton15324772018-01-16 10:26:49 -08002935 caller()->AddAudioVideoTracks();
2936 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07002937 caller()->CreateAndSetAndSignalOffer();
2938 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2939 // Ensure the existence of the RTP data channel didn't impede audio/video.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002940 MediaExpectations media_expectations;
2941 media_expectations.ExpectBidirectionalAudioAndVideo();
2942 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07002943 ASSERT_NE(nullptr, caller()->data_channel());
2944 ASSERT_NE(nullptr, callee()->data_channel());
2945 EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
2946 EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
2947
2948 // Ensure data can be sent in both directions.
2949 std::string data = "hello world";
2950 SendRtpDataWithRetries(caller()->data_channel(), data, 5);
2951 EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(),
2952 kDefaultTimeout);
2953 SendRtpDataWithRetries(callee()->data_channel(), data, 5);
2954 EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(),
2955 kDefaultTimeout);
2956}
2957
2958// Ensure that an RTP data channel is signaled as closed for the caller when
2959// the callee rejects it in a subsequent offer.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002960TEST_P(PeerConnectionIntegrationTest,
deadbeef1dcb1642017-03-29 21:08:16 -07002961 RtpDataChannelSignaledClosedInCalleeOffer) {
2962 // Same procedure as above test.
2963 FakeConstraints setup_constraints;
2964 setup_constraints.SetAllowRtpDataChannels();
2965 ASSERT_TRUE(CreatePeerConnectionWrappersWithConstraints(&setup_constraints,
2966 &setup_constraints));
2967 ConnectFakeSignaling();
2968 caller()->CreateDataChannel();
Steve Anton15324772018-01-16 10:26:49 -08002969 caller()->AddAudioVideoTracks();
2970 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07002971 caller()->CreateAndSetAndSignalOffer();
2972 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2973 ASSERT_NE(nullptr, caller()->data_channel());
2974 ASSERT_NE(nullptr, callee()->data_channel());
2975 ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
2976 ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
2977
2978 // Close the data channel on the callee, and do an updated offer/answer.
2979 callee()->data_channel()->Close();
2980 callee()->CreateAndSetAndSignalOffer();
2981 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
2982 EXPECT_FALSE(caller()->data_observer()->IsOpen());
2983 EXPECT_FALSE(callee()->data_observer()->IsOpen());
2984}
2985
2986// Tests that data is buffered in an RTP data channel until an observer is
2987// registered for it.
2988//
2989// NOTE: RTP data channels can receive data before the underlying
2990// transport has detected that a channel is writable and thus data can be
2991// received before the data channel state changes to open. That is hard to test
2992// but the same buffering is expected to be used in that case.
Seth Hampson2f0d7022018-02-20 11:54:42 -08002993TEST_P(PeerConnectionIntegrationTest,
deadbeef1dcb1642017-03-29 21:08:16 -07002994 DataBufferedUntilRtpDataChannelObserverRegistered) {
2995 // Use fake clock and simulated network delay so that we predictably can wait
2996 // until an SCTP message has been delivered without "sleep()"ing.
2997 rtc::ScopedFakeClock fake_clock;
2998 // Some things use a time of "0" as a special value, so we need to start out
2999 // the fake clock at a nonzero time.
3000 // TODO(deadbeef): Fix this.
Sebastian Jansson5f83cf02018-05-08 14:52:22 +02003001 fake_clock.AdvanceTime(webrtc::TimeDelta::seconds(1));
deadbeef1dcb1642017-03-29 21:08:16 -07003002 virtual_socket_server()->set_delay_mean(5); // 5 ms per hop.
3003 virtual_socket_server()->UpdateDelayDistribution();
3004
3005 FakeConstraints constraints;
3006 constraints.SetAllowRtpDataChannels();
3007 ASSERT_TRUE(
3008 CreatePeerConnectionWrappersWithConstraints(&constraints, &constraints));
3009 ConnectFakeSignaling();
3010 caller()->CreateDataChannel();
3011 caller()->CreateAndSetAndSignalOffer();
3012 ASSERT_TRUE(caller()->data_channel() != nullptr);
3013 ASSERT_TRUE_SIMULATED_WAIT(callee()->data_channel() != nullptr,
3014 kDefaultTimeout, fake_clock);
3015 ASSERT_TRUE_SIMULATED_WAIT(caller()->data_observer()->IsOpen(),
3016 kDefaultTimeout, fake_clock);
3017 ASSERT_EQ_SIMULATED_WAIT(DataChannelInterface::kOpen,
3018 callee()->data_channel()->state(), kDefaultTimeout,
3019 fake_clock);
3020
3021 // Unregister the observer which is normally automatically registered.
3022 callee()->data_channel()->UnregisterObserver();
3023 // Send data and advance fake clock until it should have been received.
3024 std::string data = "hello world";
3025 caller()->data_channel()->Send(DataBuffer(data));
3026 SIMULATED_WAIT(false, 50, fake_clock);
3027
3028 // Attach data channel and expect data to be received immediately. Note that
3029 // EXPECT_EQ_WAIT is used, such that the simulated clock is not advanced any
3030 // further, but data can be received even if the callback is asynchronous.
3031 MockDataChannelObserver new_observer(callee()->data_channel());
3032 EXPECT_EQ_SIMULATED_WAIT(data, new_observer.last_message(), kDefaultTimeout,
3033 fake_clock);
Seth Hampson1d4a76d2018-06-19 14:31:41 -07003034 // Closing the PeerConnections destroys the ports before the ScopedFakeClock.
3035 // If this is not done a DCHECK can be hit in ports.cc, because a large
3036 // negative number is calculated for the rtt due to the global clock changing.
3037 caller()->pc()->Close();
3038 callee()->pc()->Close();
deadbeef1dcb1642017-03-29 21:08:16 -07003039}
3040
3041// This test sets up a call between two parties with audio, video and but only
3042// the caller client supports RTP data channels.
Seth Hampson2f0d7022018-02-20 11:54:42 -08003043TEST_P(PeerConnectionIntegrationTest, RtpDataChannelsRejectedByCallee) {
deadbeef1dcb1642017-03-29 21:08:16 -07003044 FakeConstraints setup_constraints_1;
3045 setup_constraints_1.SetAllowRtpDataChannels();
3046 // Must disable DTLS to make negotiation succeed.
3047 setup_constraints_1.SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
3048 false);
3049 FakeConstraints setup_constraints_2;
3050 setup_constraints_2.SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp,
3051 false);
3052 ASSERT_TRUE(CreatePeerConnectionWrappersWithConstraints(
3053 &setup_constraints_1, &setup_constraints_2));
3054 ConnectFakeSignaling();
3055 caller()->CreateDataChannel();
Steve Anton15324772018-01-16 10:26:49 -08003056 caller()->AddAudioVideoTracks();
3057 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07003058 caller()->CreateAndSetAndSignalOffer();
3059 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3060 // The caller should still have a data channel, but it should be closed, and
3061 // one should ever have been created for the callee.
3062 EXPECT_TRUE(caller()->data_channel() != nullptr);
3063 EXPECT_FALSE(caller()->data_observer()->IsOpen());
3064 EXPECT_EQ(nullptr, callee()->data_channel());
3065}
3066
3067// This test sets up a call between two parties with audio, and video. When
3068// audio and video is setup and flowing, an RTP data channel is negotiated.
Seth Hampson2f0d7022018-02-20 11:54:42 -08003069TEST_P(PeerConnectionIntegrationTest, AddRtpDataChannelInSubsequentOffer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003070 FakeConstraints setup_constraints;
3071 setup_constraints.SetAllowRtpDataChannels();
3072 ASSERT_TRUE(CreatePeerConnectionWrappersWithConstraints(&setup_constraints,
3073 &setup_constraints));
3074 ConnectFakeSignaling();
3075 // Do initial offer/answer with audio/video.
Steve Anton15324772018-01-16 10:26:49 -08003076 caller()->AddAudioVideoTracks();
3077 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07003078 caller()->CreateAndSetAndSignalOffer();
3079 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3080 // Create data channel and do new offer and answer.
3081 caller()->CreateDataChannel();
3082 caller()->CreateAndSetAndSignalOffer();
3083 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3084 ASSERT_NE(nullptr, caller()->data_channel());
3085 ASSERT_NE(nullptr, callee()->data_channel());
3086 EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
3087 EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
3088 // Ensure data can be sent in both directions.
3089 std::string data = "hello world";
3090 SendRtpDataWithRetries(caller()->data_channel(), data, 5);
3091 EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(),
3092 kDefaultTimeout);
3093 SendRtpDataWithRetries(callee()->data_channel(), data, 5);
3094 EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(),
3095 kDefaultTimeout);
3096}
3097
3098#ifdef HAVE_SCTP
3099
3100// This test sets up a call between two parties with audio, video and an SCTP
3101// data channel.
Seth Hampson2f0d7022018-02-20 11:54:42 -08003102TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithSctpDataChannel) {
deadbeef1dcb1642017-03-29 21:08:16 -07003103 ASSERT_TRUE(CreatePeerConnectionWrappers());
3104 ConnectFakeSignaling();
3105 // Expect that data channel created on caller side will show up for callee as
3106 // well.
3107 caller()->CreateDataChannel();
Steve Anton15324772018-01-16 10:26:49 -08003108 caller()->AddAudioVideoTracks();
3109 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07003110 caller()->CreateAndSetAndSignalOffer();
3111 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3112 // Ensure the existence of the SCTP data channel didn't impede audio/video.
Seth Hampson2f0d7022018-02-20 11:54:42 -08003113 MediaExpectations media_expectations;
3114 media_expectations.ExpectBidirectionalAudioAndVideo();
3115 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07003116 // Caller data channel should already exist (it created one). Callee data
3117 // channel may not exist yet, since negotiation happens in-band, not in SDP.
3118 ASSERT_NE(nullptr, caller()->data_channel());
3119 ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout);
3120 EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
3121 EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
3122
3123 // Ensure data can be sent in both directions.
3124 std::string data = "hello world";
3125 caller()->data_channel()->Send(DataBuffer(data));
3126 EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(),
3127 kDefaultTimeout);
3128 callee()->data_channel()->Send(DataBuffer(data));
3129 EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(),
3130 kDefaultTimeout);
3131}
3132
3133// Ensure that when the callee closes an SCTP data channel, the closing
3134// procedure results in the data channel being closed for the caller as well.
Seth Hampson2f0d7022018-02-20 11:54:42 -08003135TEST_P(PeerConnectionIntegrationTest, CalleeClosesSctpDataChannel) {
deadbeef1dcb1642017-03-29 21:08:16 -07003136 // Same procedure as above test.
3137 ASSERT_TRUE(CreatePeerConnectionWrappers());
3138 ConnectFakeSignaling();
3139 caller()->CreateDataChannel();
Steve Anton15324772018-01-16 10:26:49 -08003140 caller()->AddAudioVideoTracks();
3141 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07003142 caller()->CreateAndSetAndSignalOffer();
3143 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3144 ASSERT_NE(nullptr, caller()->data_channel());
3145 ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout);
3146 ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
3147 ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
3148
3149 // Close the data channel on the callee side, and wait for it to reach the
3150 // "closed" state on both sides.
3151 callee()->data_channel()->Close();
3152 EXPECT_TRUE_WAIT(!caller()->data_observer()->IsOpen(), kDefaultTimeout);
3153 EXPECT_TRUE_WAIT(!callee()->data_observer()->IsOpen(), kDefaultTimeout);
3154}
3155
Seth Hampson2f0d7022018-02-20 11:54:42 -08003156TEST_P(PeerConnectionIntegrationTest, SctpDataChannelConfigSentToOtherSide) {
Steve Antonda6c0952017-10-23 11:41:54 -07003157 ASSERT_TRUE(CreatePeerConnectionWrappers());
3158 ConnectFakeSignaling();
3159 webrtc::DataChannelInit init;
3160 init.id = 53;
3161 init.maxRetransmits = 52;
3162 caller()->CreateDataChannel("data-channel", &init);
Steve Anton15324772018-01-16 10:26:49 -08003163 caller()->AddAudioVideoTracks();
3164 callee()->AddAudioVideoTracks();
Steve Antonda6c0952017-10-23 11:41:54 -07003165 caller()->CreateAndSetAndSignalOffer();
3166 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Steve Anton074dece2017-10-24 13:04:12 -07003167 ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout);
3168 ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
Steve Antonda6c0952017-10-23 11:41:54 -07003169 EXPECT_EQ(init.id, callee()->data_channel()->id());
3170 EXPECT_EQ("data-channel", callee()->data_channel()->label());
3171 EXPECT_EQ(init.maxRetransmits, callee()->data_channel()->maxRetransmits());
3172 EXPECT_FALSE(callee()->data_channel()->negotiated());
3173}
3174
deadbeef1dcb1642017-03-29 21:08:16 -07003175// Test usrsctp's ability to process unordered data stream, where data actually
3176// arrives out of order using simulated delays. Previously there have been some
3177// bugs in this area.
Seth Hampson2f0d7022018-02-20 11:54:42 -08003178TEST_P(PeerConnectionIntegrationTest, StressTestUnorderedSctpDataChannel) {
deadbeef1dcb1642017-03-29 21:08:16 -07003179 // Introduce random network delays.
3180 // Otherwise it's not a true "unordered" test.
3181 virtual_socket_server()->set_delay_mean(20);
3182 virtual_socket_server()->set_delay_stddev(5);
3183 virtual_socket_server()->UpdateDelayDistribution();
3184 // Normal procedure, but with unordered data channel config.
3185 ASSERT_TRUE(CreatePeerConnectionWrappers());
3186 ConnectFakeSignaling();
3187 webrtc::DataChannelInit init;
3188 init.ordered = false;
3189 caller()->CreateDataChannel(&init);
3190 caller()->CreateAndSetAndSignalOffer();
3191 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3192 ASSERT_NE(nullptr, caller()->data_channel());
3193 ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout);
3194 ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
3195 ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
3196
3197 static constexpr int kNumMessages = 100;
3198 // Deliberately chosen to be larger than the MTU so messages get fragmented.
3199 static constexpr size_t kMaxMessageSize = 4096;
3200 // Create and send random messages.
3201 std::vector<std::string> sent_messages;
3202 for (int i = 0; i < kNumMessages; ++i) {
3203 size_t length =
3204 (rand() % kMaxMessageSize) + 1; // NOLINT (rand_r instead of rand)
3205 std::string message;
3206 ASSERT_TRUE(rtc::CreateRandomString(length, &message));
3207 caller()->data_channel()->Send(DataBuffer(message));
3208 callee()->data_channel()->Send(DataBuffer(message));
3209 sent_messages.push_back(message);
3210 }
3211
3212 // Wait for all messages to be received.
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003213 EXPECT_EQ_WAIT(rtc::checked_cast<size_t>(kNumMessages),
deadbeef1dcb1642017-03-29 21:08:16 -07003214 caller()->data_observer()->received_message_count(),
3215 kDefaultTimeout);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003216 EXPECT_EQ_WAIT(rtc::checked_cast<size_t>(kNumMessages),
deadbeef1dcb1642017-03-29 21:08:16 -07003217 callee()->data_observer()->received_message_count(),
3218 kDefaultTimeout);
3219
3220 // Sort and compare to make sure none of the messages were corrupted.
3221 std::vector<std::string> caller_received_messages =
3222 caller()->data_observer()->messages();
3223 std::vector<std::string> callee_received_messages =
3224 callee()->data_observer()->messages();
3225 std::sort(sent_messages.begin(), sent_messages.end());
3226 std::sort(caller_received_messages.begin(), caller_received_messages.end());
3227 std::sort(callee_received_messages.begin(), callee_received_messages.end());
3228 EXPECT_EQ(sent_messages, caller_received_messages);
3229 EXPECT_EQ(sent_messages, callee_received_messages);
3230}
3231
3232// This test sets up a call between two parties with audio, and video. When
3233// audio and video are setup and flowing, an SCTP data channel is negotiated.
Seth Hampson2f0d7022018-02-20 11:54:42 -08003234TEST_P(PeerConnectionIntegrationTest, AddSctpDataChannelInSubsequentOffer) {
deadbeef1dcb1642017-03-29 21:08:16 -07003235 ASSERT_TRUE(CreatePeerConnectionWrappers());
3236 ConnectFakeSignaling();
3237 // Do initial offer/answer with audio/video.
Steve Anton15324772018-01-16 10:26:49 -08003238 caller()->AddAudioVideoTracks();
3239 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07003240 caller()->CreateAndSetAndSignalOffer();
3241 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3242 // Create data channel and do new offer and answer.
3243 caller()->CreateDataChannel();
3244 caller()->CreateAndSetAndSignalOffer();
3245 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3246 // Caller data channel should already exist (it created one). Callee data
3247 // channel may not exist yet, since negotiation happens in-band, not in SDP.
3248 ASSERT_NE(nullptr, caller()->data_channel());
3249 ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout);
3250 EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
3251 EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
3252 // Ensure data can be sent in both directions.
3253 std::string data = "hello world";
3254 caller()->data_channel()->Send(DataBuffer(data));
3255 EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(),
3256 kDefaultTimeout);
3257 callee()->data_channel()->Send(DataBuffer(data));
3258 EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(),
3259 kDefaultTimeout);
3260}
3261
deadbeef7914b8c2017-04-21 03:23:33 -07003262// Set up a connection initially just using SCTP data channels, later upgrading
3263// to audio/video, ensuring frames are received end-to-end. Effectively the
3264// inverse of the test above.
3265// This was broken in M57; see https://crbug.com/711243
Seth Hampson2f0d7022018-02-20 11:54:42 -08003266TEST_P(PeerConnectionIntegrationTest, SctpDataChannelToAudioVideoUpgrade) {
deadbeef7914b8c2017-04-21 03:23:33 -07003267 ASSERT_TRUE(CreatePeerConnectionWrappers());
3268 ConnectFakeSignaling();
3269 // Do initial offer/answer with just data channel.
3270 caller()->CreateDataChannel();
3271 caller()->CreateAndSetAndSignalOffer();
3272 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3273 // Wait until data can be sent over the data channel.
3274 ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout);
3275 ASSERT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
3276 ASSERT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
3277
3278 // Do subsequent offer/answer with two-way audio and video. Audio and video
3279 // should end up bundled on the DTLS/ICE transport already used for data.
Steve Anton15324772018-01-16 10:26:49 -08003280 caller()->AddAudioVideoTracks();
3281 callee()->AddAudioVideoTracks();
deadbeef7914b8c2017-04-21 03:23:33 -07003282 caller()->CreateAndSetAndSignalOffer();
3283 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08003284 MediaExpectations media_expectations;
3285 media_expectations.ExpectBidirectionalAudioAndVideo();
3286 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef7914b8c2017-04-21 03:23:33 -07003287}
3288
deadbeef8b7e9ad2017-05-25 09:38:55 -07003289static void MakeSpecCompliantSctpOffer(cricket::SessionDescription* desc) {
deadbeef8b7e9ad2017-05-25 09:38:55 -07003290 cricket::DataContentDescription* dcd_offer =
Steve Antonb1c1de12017-12-21 15:14:30 -08003291 GetFirstDataContentDescription(desc);
3292 ASSERT_TRUE(dcd_offer);
deadbeef8b7e9ad2017-05-25 09:38:55 -07003293 dcd_offer->set_use_sctpmap(false);
3294 dcd_offer->set_protocol("UDP/DTLS/SCTP");
3295}
3296
3297// Test that the data channel works when a spec-compliant SCTP m= section is
3298// offered (using "a=sctp-port" instead of "a=sctpmap", and using
3299// "UDP/DTLS/SCTP" as the protocol).
Seth Hampson2f0d7022018-02-20 11:54:42 -08003300TEST_P(PeerConnectionIntegrationTest,
deadbeef8b7e9ad2017-05-25 09:38:55 -07003301 DataChannelWorksWhenSpecCompliantSctpOfferReceived) {
3302 ASSERT_TRUE(CreatePeerConnectionWrappers());
3303 ConnectFakeSignaling();
3304 caller()->CreateDataChannel();
3305 caller()->SetGeneratedSdpMunger(MakeSpecCompliantSctpOffer);
3306 caller()->CreateAndSetAndSignalOffer();
3307 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3308 ASSERT_TRUE_WAIT(callee()->data_channel() != nullptr, kDefaultTimeout);
3309 EXPECT_TRUE_WAIT(caller()->data_observer()->IsOpen(), kDefaultTimeout);
3310 EXPECT_TRUE_WAIT(callee()->data_observer()->IsOpen(), kDefaultTimeout);
3311
3312 // Ensure data can be sent in both directions.
3313 std::string data = "hello world";
3314 caller()->data_channel()->Send(DataBuffer(data));
3315 EXPECT_EQ_WAIT(data, callee()->data_observer()->last_message(),
3316 kDefaultTimeout);
3317 callee()->data_channel()->Send(DataBuffer(data));
3318 EXPECT_EQ_WAIT(data, caller()->data_observer()->last_message(),
3319 kDefaultTimeout);
3320}
3321
deadbeef1dcb1642017-03-29 21:08:16 -07003322#endif // HAVE_SCTP
3323
3324// Test that the ICE connection and gathering states eventually reach
3325// "complete".
Seth Hampson2f0d7022018-02-20 11:54:42 -08003326TEST_P(PeerConnectionIntegrationTest, IceStatesReachCompletion) {
deadbeef1dcb1642017-03-29 21:08:16 -07003327 ASSERT_TRUE(CreatePeerConnectionWrappers());
3328 ConnectFakeSignaling();
3329 // Do normal offer/answer.
Steve Anton15324772018-01-16 10:26:49 -08003330 caller()->AddAudioVideoTracks();
3331 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07003332 caller()->CreateAndSetAndSignalOffer();
3333 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3334 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete,
3335 caller()->ice_gathering_state(), kMaxWaitForFramesMs);
3336 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceGatheringComplete,
3337 callee()->ice_gathering_state(), kMaxWaitForFramesMs);
3338 // After the best candidate pair is selected and all candidates are signaled,
3339 // the ICE connection state should reach "complete".
3340 // TODO(deadbeef): Currently, the ICE "controlled" agent (the
3341 // answerer/"callee" by default) only reaches "connected". When this is
3342 // fixed, this test should be updated.
3343 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
3344 caller()->ice_connection_state(), kDefaultTimeout);
3345 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
3346 callee()->ice_connection_state(), kDefaultTimeout);
3347}
3348
Steve Antonede9ca52017-10-16 13:04:27 -07003349// Test that firewalling the ICE connection causes the clients to identify the
3350// disconnected state and then removing the firewall causes them to reconnect.
3351class PeerConnectionIntegrationIceStatesTest
Seth Hampson2f0d7022018-02-20 11:54:42 -08003352 : public PeerConnectionIntegrationBaseTest,
3353 public ::testing::WithParamInterface<
3354 std::tuple<SdpSemantics, std::tuple<std::string, uint32_t>>> {
Steve Antonede9ca52017-10-16 13:04:27 -07003355 protected:
Seth Hampson2f0d7022018-02-20 11:54:42 -08003356 PeerConnectionIntegrationIceStatesTest()
3357 : PeerConnectionIntegrationBaseTest(std::get<0>(GetParam())) {
3358 port_allocator_flags_ = std::get<1>(std::get<1>(GetParam()));
Steve Antonede9ca52017-10-16 13:04:27 -07003359 }
3360
3361 void StartStunServer(const SocketAddress& server_address) {
3362 stun_server_.reset(
3363 cricket::TestStunServer::Create(network_thread(), server_address));
3364 }
3365
3366 bool TestIPv6() {
3367 return (port_allocator_flags_ & cricket::PORTALLOCATOR_ENABLE_IPV6);
3368 }
3369
3370 void SetPortAllocatorFlags() {
Qingsi Wanga2d60672018-04-11 16:57:45 -07003371 network_thread()->Invoke<void>(
3372 RTC_FROM_HERE,
3373 rtc::Bind(&cricket::PortAllocator::set_flags,
3374 caller()->port_allocator(), port_allocator_flags_));
3375 network_thread()->Invoke<void>(
3376 RTC_FROM_HERE,
3377 rtc::Bind(&cricket::PortAllocator::set_flags,
3378 callee()->port_allocator(), port_allocator_flags_));
Steve Antonede9ca52017-10-16 13:04:27 -07003379 }
3380
3381 std::vector<SocketAddress> CallerAddresses() {
3382 std::vector<SocketAddress> addresses;
3383 addresses.push_back(SocketAddress("1.1.1.1", 0));
3384 if (TestIPv6()) {
3385 addresses.push_back(SocketAddress("1111:0:a:b:c:d:e:f", 0));
3386 }
3387 return addresses;
3388 }
3389
3390 std::vector<SocketAddress> CalleeAddresses() {
3391 std::vector<SocketAddress> addresses;
3392 addresses.push_back(SocketAddress("2.2.2.2", 0));
3393 if (TestIPv6()) {
3394 addresses.push_back(SocketAddress("2222:0:a:b:c:d:e:f", 0));
3395 }
3396 return addresses;
3397 }
3398
3399 void SetUpNetworkInterfaces() {
3400 // Remove the default interfaces added by the test infrastructure.
3401 caller()->network()->RemoveInterface(kDefaultLocalAddress);
3402 callee()->network()->RemoveInterface(kDefaultLocalAddress);
3403
3404 // Add network addresses for test.
3405 for (const auto& caller_address : CallerAddresses()) {
3406 caller()->network()->AddInterface(caller_address);
3407 }
3408 for (const auto& callee_address : CalleeAddresses()) {
3409 callee()->network()->AddInterface(callee_address);
3410 }
3411 }
3412
3413 private:
3414 uint32_t port_allocator_flags_;
3415 std::unique_ptr<cricket::TestStunServer> stun_server_;
3416};
3417
3418// Tests that the PeerConnection goes through all the ICE gathering/connection
3419// states over the duration of the call. This includes Disconnected and Failed
3420// states, induced by putting a firewall between the peers and waiting for them
3421// to time out.
Steve Anton83119dd2017-11-10 16:19:52 -08003422TEST_P(PeerConnectionIntegrationIceStatesTest, VerifyIceStates) {
3423 // TODO(bugs.webrtc.org/8295): When using a ScopedFakeClock, this test will
3424 // sometimes hit a DCHECK in platform_thread.cc about the PacerThread being
3425 // too busy. For now, revert to running without a fake clock.
Steve Antonede9ca52017-10-16 13:04:27 -07003426
3427 const SocketAddress kStunServerAddress =
3428 SocketAddress("99.99.99.1", cricket::STUN_SERVER_PORT);
3429 StartStunServer(kStunServerAddress);
3430
3431 PeerConnectionInterface::RTCConfiguration config;
3432 PeerConnectionInterface::IceServer ice_stun_server;
3433 ice_stun_server.urls.push_back(
3434 "stun:" + kStunServerAddress.HostAsURIString() + ":" +
3435 kStunServerAddress.PortAsString());
3436 config.servers.push_back(ice_stun_server);
3437
3438 ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config));
3439 ConnectFakeSignaling();
3440 SetPortAllocatorFlags();
3441 SetUpNetworkInterfaces();
Steve Anton15324772018-01-16 10:26:49 -08003442 caller()->AddAudioVideoTracks();
3443 callee()->AddAudioVideoTracks();
Steve Antonede9ca52017-10-16 13:04:27 -07003444
3445 // Initial state before anything happens.
3446 ASSERT_EQ(PeerConnectionInterface::kIceGatheringNew,
3447 caller()->ice_gathering_state());
3448 ASSERT_EQ(PeerConnectionInterface::kIceConnectionNew,
3449 caller()->ice_connection_state());
3450
3451 // Start the call by creating the offer, setting it as the local description,
3452 // then sending it to the peer who will respond with an answer. This happens
3453 // asynchronously so that we can watch the states as it runs in the
3454 // background.
3455 caller()->CreateAndSetAndSignalOffer();
3456
Steve Anton83119dd2017-11-10 16:19:52 -08003457 ASSERT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3458 caller()->ice_connection_state(), kDefaultTimeout);
Steve Antonede9ca52017-10-16 13:04:27 -07003459
3460 // Verify that the observer was notified of the intermediate transitions.
3461 EXPECT_THAT(caller()->ice_connection_state_history(),
3462 ElementsAre(PeerConnectionInterface::kIceConnectionChecking,
3463 PeerConnectionInterface::kIceConnectionConnected,
3464 PeerConnectionInterface::kIceConnectionCompleted));
3465 EXPECT_THAT(caller()->ice_gathering_state_history(),
3466 ElementsAre(PeerConnectionInterface::kIceGatheringGathering,
3467 PeerConnectionInterface::kIceGatheringComplete));
3468
3469 // Block connections to/from the caller and wait for ICE to become
3470 // disconnected.
3471 for (const auto& caller_address : CallerAddresses()) {
3472 firewall()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, caller_address);
3473 }
Mirko Bonadei675513b2017-11-09 11:09:25 +01003474 RTC_LOG(LS_INFO) << "Firewall rules applied";
Steve Anton83119dd2017-11-10 16:19:52 -08003475 ASSERT_EQ_WAIT(PeerConnectionInterface::kIceConnectionDisconnected,
3476 caller()->ice_connection_state(), kDefaultTimeout);
Steve Antonede9ca52017-10-16 13:04:27 -07003477
3478 // Let ICE re-establish by removing the firewall rules.
3479 firewall()->ClearRules();
Mirko Bonadei675513b2017-11-09 11:09:25 +01003480 RTC_LOG(LS_INFO) << "Firewall rules cleared";
Steve Anton83119dd2017-11-10 16:19:52 -08003481 ASSERT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3482 caller()->ice_connection_state(), kDefaultTimeout);
Steve Antonede9ca52017-10-16 13:04:27 -07003483
3484 // According to RFC7675, if there is no response within 30 seconds then the
3485 // peer should consider the other side to have rejected the connection. This
Steve Anton83119dd2017-11-10 16:19:52 -08003486 // is signaled by the state transitioning to "failed".
Steve Antonede9ca52017-10-16 13:04:27 -07003487 constexpr int kConsentTimeout = 30000;
3488 for (const auto& caller_address : CallerAddresses()) {
3489 firewall()->AddRule(false, rtc::FP_ANY, rtc::FD_ANY, caller_address);
3490 }
Mirko Bonadei675513b2017-11-09 11:09:25 +01003491 RTC_LOG(LS_INFO) << "Firewall rules applied again";
Steve Anton83119dd2017-11-10 16:19:52 -08003492 ASSERT_EQ_WAIT(PeerConnectionInterface::kIceConnectionFailed,
3493 caller()->ice_connection_state(), kConsentTimeout);
Steve Antonede9ca52017-10-16 13:04:27 -07003494}
3495
3496// Tests that the best connection is set to the appropriate IPv4/IPv6 connection
3497// and that the statistics in the metric observers are updated correctly.
3498TEST_P(PeerConnectionIntegrationIceStatesTest, VerifyBestConnection) {
3499 ASSERT_TRUE(CreatePeerConnectionWrappers());
3500 ConnectFakeSignaling();
3501 SetPortAllocatorFlags();
3502 SetUpNetworkInterfaces();
Steve Anton15324772018-01-16 10:26:49 -08003503 caller()->AddAudioVideoTracks();
3504 callee()->AddAudioVideoTracks();
Steve Antonede9ca52017-10-16 13:04:27 -07003505
3506 rtc::scoped_refptr<webrtc::FakeMetricsObserver> metrics_observer(
3507 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>());
3508 caller()->pc()->RegisterUMAObserver(metrics_observer.get());
3509
3510 caller()->CreateAndSetAndSignalOffer();
3511
3512 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3513
3514 const int num_best_ipv4 = metrics_observer->GetEnumCounter(
3515 webrtc::kEnumCounterAddressFamily, webrtc::kBestConnections_IPv4);
3516 const int num_best_ipv6 = metrics_observer->GetEnumCounter(
3517 webrtc::kEnumCounterAddressFamily, webrtc::kBestConnections_IPv6);
3518 if (TestIPv6()) {
3519 // When IPv6 is enabled, we should prefer an IPv6 connection over an IPv4
3520 // connection.
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003521 EXPECT_EQ(0, num_best_ipv4);
3522 EXPECT_EQ(1, num_best_ipv6);
Steve Antonede9ca52017-10-16 13:04:27 -07003523 } else {
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003524 EXPECT_EQ(1, num_best_ipv4);
3525 EXPECT_EQ(0, num_best_ipv6);
Steve Antonede9ca52017-10-16 13:04:27 -07003526 }
3527
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003528 EXPECT_EQ(0, metrics_observer->GetEnumCounter(
Steve Antonede9ca52017-10-16 13:04:27 -07003529 webrtc::kEnumCounterIceCandidatePairTypeUdp,
3530 webrtc::kIceCandidatePairHostHost));
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003531 EXPECT_EQ(1, metrics_observer->GetEnumCounter(
Steve Antonede9ca52017-10-16 13:04:27 -07003532 webrtc::kEnumCounterIceCandidatePairTypeUdp,
3533 webrtc::kIceCandidatePairHostPublicHostPublic));
3534}
3535
3536constexpr uint32_t kFlagsIPv4NoStun = cricket::PORTALLOCATOR_DISABLE_TCP |
3537 cricket::PORTALLOCATOR_DISABLE_STUN |
3538 cricket::PORTALLOCATOR_DISABLE_RELAY;
3539constexpr uint32_t kFlagsIPv6NoStun =
3540 cricket::PORTALLOCATOR_DISABLE_TCP | cricket::PORTALLOCATOR_DISABLE_STUN |
3541 cricket::PORTALLOCATOR_ENABLE_IPV6 | cricket::PORTALLOCATOR_DISABLE_RELAY;
3542constexpr uint32_t kFlagsIPv4Stun =
3543 cricket::PORTALLOCATOR_DISABLE_TCP | cricket::PORTALLOCATOR_DISABLE_RELAY;
3544
Seth Hampson2f0d7022018-02-20 11:54:42 -08003545INSTANTIATE_TEST_CASE_P(
3546 PeerConnectionIntegrationTest,
3547 PeerConnectionIntegrationIceStatesTest,
3548 Combine(Values(SdpSemantics::kPlanB, SdpSemantics::kUnifiedPlan),
3549 Values(std::make_pair("IPv4 no STUN", kFlagsIPv4NoStun),
3550 std::make_pair("IPv6 no STUN", kFlagsIPv6NoStun),
3551 std::make_pair("IPv4 with STUN", kFlagsIPv4Stun))));
Steve Antonede9ca52017-10-16 13:04:27 -07003552
deadbeef1dcb1642017-03-29 21:08:16 -07003553// This test sets up a call between two parties with audio and video.
3554// During the call, the caller restarts ICE and the test verifies that
3555// new ICE candidates are generated and audio and video still can flow, and the
3556// ICE state reaches completed again.
Seth Hampson2f0d7022018-02-20 11:54:42 -08003557TEST_P(PeerConnectionIntegrationTest, MediaContinuesFlowingAfterIceRestart) {
deadbeef1dcb1642017-03-29 21:08:16 -07003558 ASSERT_TRUE(CreatePeerConnectionWrappers());
3559 ConnectFakeSignaling();
3560 // Do normal offer/answer and wait for ICE to complete.
Steve Anton15324772018-01-16 10:26:49 -08003561 caller()->AddAudioVideoTracks();
3562 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07003563 caller()->CreateAndSetAndSignalOffer();
3564 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3565 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
3566 caller()->ice_connection_state(), kMaxWaitForFramesMs);
3567 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
3568 callee()->ice_connection_state(), kMaxWaitForFramesMs);
3569
3570 // To verify that the ICE restart actually occurs, get
3571 // ufrag/password/candidates before and after restart.
3572 // Create an SDP string of the first audio candidate for both clients.
3573 const webrtc::IceCandidateCollection* audio_candidates_caller =
3574 caller()->pc()->local_description()->candidates(0);
3575 const webrtc::IceCandidateCollection* audio_candidates_callee =
3576 callee()->pc()->local_description()->candidates(0);
3577 ASSERT_GT(audio_candidates_caller->count(), 0u);
3578 ASSERT_GT(audio_candidates_callee->count(), 0u);
3579 std::string caller_candidate_pre_restart;
3580 ASSERT_TRUE(
3581 audio_candidates_caller->at(0)->ToString(&caller_candidate_pre_restart));
3582 std::string callee_candidate_pre_restart;
3583 ASSERT_TRUE(
3584 audio_candidates_callee->at(0)->ToString(&callee_candidate_pre_restart));
3585 const cricket::SessionDescription* desc =
3586 caller()->pc()->local_description()->description();
3587 std::string caller_ufrag_pre_restart =
3588 desc->transport_infos()[0].description.ice_ufrag;
3589 desc = callee()->pc()->local_description()->description();
3590 std::string callee_ufrag_pre_restart =
3591 desc->transport_infos()[0].description.ice_ufrag;
3592
3593 // Have the caller initiate an ICE restart.
3594 caller()->SetOfferAnswerOptions(IceRestartOfferAnswerOptions());
3595 caller()->CreateAndSetAndSignalOffer();
3596 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3597 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
3598 caller()->ice_connection_state(), kMaxWaitForFramesMs);
3599 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
3600 callee()->ice_connection_state(), kMaxWaitForFramesMs);
3601
3602 // Grab the ufrags/candidates again.
3603 audio_candidates_caller = caller()->pc()->local_description()->candidates(0);
3604 audio_candidates_callee = callee()->pc()->local_description()->candidates(0);
3605 ASSERT_GT(audio_candidates_caller->count(), 0u);
3606 ASSERT_GT(audio_candidates_callee->count(), 0u);
3607 std::string caller_candidate_post_restart;
3608 ASSERT_TRUE(
3609 audio_candidates_caller->at(0)->ToString(&caller_candidate_post_restart));
3610 std::string callee_candidate_post_restart;
3611 ASSERT_TRUE(
3612 audio_candidates_callee->at(0)->ToString(&callee_candidate_post_restart));
3613 desc = caller()->pc()->local_description()->description();
3614 std::string caller_ufrag_post_restart =
3615 desc->transport_infos()[0].description.ice_ufrag;
3616 desc = callee()->pc()->local_description()->description();
3617 std::string callee_ufrag_post_restart =
3618 desc->transport_infos()[0].description.ice_ufrag;
3619 // Sanity check that an ICE restart was actually negotiated in SDP.
3620 ASSERT_NE(caller_candidate_pre_restart, caller_candidate_post_restart);
3621 ASSERT_NE(callee_candidate_pre_restart, callee_candidate_post_restart);
3622 ASSERT_NE(caller_ufrag_pre_restart, caller_ufrag_post_restart);
3623 ASSERT_NE(callee_ufrag_pre_restart, callee_ufrag_post_restart);
3624
3625 // Ensure that additional frames are received after the ICE restart.
Seth Hampson2f0d7022018-02-20 11:54:42 -08003626 MediaExpectations media_expectations;
3627 media_expectations.ExpectBidirectionalAudioAndVideo();
3628 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07003629}
3630
3631// Verify that audio/video can be received end-to-end when ICE renomination is
3632// enabled.
Seth Hampson2f0d7022018-02-20 11:54:42 -08003633TEST_P(PeerConnectionIntegrationTest, EndToEndCallWithIceRenomination) {
deadbeef1dcb1642017-03-29 21:08:16 -07003634 PeerConnectionInterface::RTCConfiguration config;
3635 config.enable_ice_renomination = true;
3636 ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(config, config));
3637 ConnectFakeSignaling();
3638 // Do normal offer/answer and wait for some frames to be received in each
3639 // direction.
Steve Anton15324772018-01-16 10:26:49 -08003640 caller()->AddAudioVideoTracks();
3641 callee()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07003642 caller()->CreateAndSetAndSignalOffer();
3643 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3644 // Sanity check that ICE renomination was actually negotiated.
3645 const cricket::SessionDescription* desc =
3646 caller()->pc()->local_description()->description();
3647 for (const cricket::TransportInfo& info : desc->transport_infos()) {
deadbeef30952b42017-04-21 02:41:29 -07003648 ASSERT_NE(
3649 info.description.transport_options.end(),
3650 std::find(info.description.transport_options.begin(),
3651 info.description.transport_options.end(), "renomination"));
deadbeef1dcb1642017-03-29 21:08:16 -07003652 }
3653 desc = callee()->pc()->local_description()->description();
3654 for (const cricket::TransportInfo& info : desc->transport_infos()) {
deadbeef30952b42017-04-21 02:41:29 -07003655 ASSERT_NE(
3656 info.description.transport_options.end(),
3657 std::find(info.description.transport_options.begin(),
3658 info.description.transport_options.end(), "renomination"));
deadbeef1dcb1642017-03-29 21:08:16 -07003659 }
Seth Hampson2f0d7022018-02-20 11:54:42 -08003660 MediaExpectations media_expectations;
3661 media_expectations.ExpectBidirectionalAudioAndVideo();
3662 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07003663}
3664
Steve Anton6f25b092017-10-23 09:39:20 -07003665// With a max bundle policy and RTCP muxing, adding a new media description to
3666// the connection should not affect ICE at all because the new media will use
3667// the existing connection.
Seth Hampson2f0d7022018-02-20 11:54:42 -08003668TEST_P(PeerConnectionIntegrationTest,
Steve Anton83119dd2017-11-10 16:19:52 -08003669 AddMediaToConnectedBundleDoesNotRestartIce) {
Steve Anton6f25b092017-10-23 09:39:20 -07003670 PeerConnectionInterface::RTCConfiguration config;
3671 config.bundle_policy = PeerConnectionInterface::kBundlePolicyMaxBundle;
3672 config.rtcp_mux_policy = PeerConnectionInterface::kRtcpMuxPolicyRequire;
3673 ASSERT_TRUE(CreatePeerConnectionWrappersWithConfig(
3674 config, PeerConnectionInterface::RTCConfiguration()));
3675 ConnectFakeSignaling();
3676
Steve Anton15324772018-01-16 10:26:49 -08003677 caller()->AddAudioTrack();
Steve Anton6f25b092017-10-23 09:39:20 -07003678 caller()->CreateAndSetAndSignalOffer();
3679 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Steve Antonff52f1b2017-10-26 12:24:50 -07003680 ASSERT_EQ_WAIT(PeerConnectionInterface::kIceConnectionCompleted,
3681 caller()->ice_connection_state(), kDefaultTimeout);
Steve Anton6f25b092017-10-23 09:39:20 -07003682
3683 caller()->clear_ice_connection_state_history();
3684
Steve Anton15324772018-01-16 10:26:49 -08003685 caller()->AddVideoTrack();
Steve Anton6f25b092017-10-23 09:39:20 -07003686 caller()->CreateAndSetAndSignalOffer();
3687 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3688
3689 EXPECT_EQ(0u, caller()->ice_connection_state_history().size());
3690}
3691
deadbeef1dcb1642017-03-29 21:08:16 -07003692// This test sets up a call between two parties with audio and video. It then
3693// renegotiates setting the video m-line to "port 0", then later renegotiates
3694// again, enabling video.
Seth Hampson2f0d7022018-02-20 11:54:42 -08003695TEST_P(PeerConnectionIntegrationTest,
deadbeef1dcb1642017-03-29 21:08:16 -07003696 VideoFlowsAfterMediaSectionIsRejectedAndRecycled) {
3697 ASSERT_TRUE(CreatePeerConnectionWrappers());
3698 ConnectFakeSignaling();
3699
3700 // Do initial negotiation, only sending media from the caller. Will result in
3701 // video and audio recvonly "m=" sections.
Steve Anton15324772018-01-16 10:26:49 -08003702 caller()->AddAudioVideoTracks();
deadbeef1dcb1642017-03-29 21:08:16 -07003703 caller()->CreateAndSetAndSignalOffer();
3704 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3705
3706 // Negotiate again, disabling the video "m=" section (the callee will set the
3707 // port to 0 due to offer_to_receive_video = 0).
Seth Hampson2f0d7022018-02-20 11:54:42 -08003708 if (sdp_semantics_ == SdpSemantics::kPlanB) {
3709 PeerConnectionInterface::RTCOfferAnswerOptions options;
3710 options.offer_to_receive_video = 0;
3711 callee()->SetOfferAnswerOptions(options);
3712 } else {
3713 callee()->SetRemoteOfferHandler([this] {
3714 callee()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO)->Stop();
3715 });
3716 }
deadbeef1dcb1642017-03-29 21:08:16 -07003717 caller()->CreateAndSetAndSignalOffer();
3718 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
3719 // Sanity check that video "m=" section was actually rejected.
3720 const ContentInfo* answer_video_content = cricket::GetFirstVideoContent(
3721 callee()->pc()->local_description()->description());
3722 ASSERT_NE(nullptr, answer_video_content);
3723 ASSERT_TRUE(answer_video_content->rejected);
3724
3725 // Enable video and do negotiation again, making sure video is received
3726 // end-to-end, also adding media stream to callee.
Seth Hampson2f0d7022018-02-20 11:54:42 -08003727 if (sdp_semantics_ == SdpSemantics::kPlanB) {
3728 PeerConnectionInterface::RTCOfferAnswerOptions options;
3729 options.offer_to_receive_video = 1;
3730 callee()->SetOfferAnswerOptions(options);
3731 } else {
3732 // The caller's transceiver is stopped, so we need to add another track.
3733 auto caller_transceiver =
3734 caller()->GetFirstTransceiverOfType(cricket::MEDIA_TYPE_VIDEO);
3735 EXPECT_TRUE(caller_transceiver->stopped());
3736 caller()->AddVideoTrack();
3737 }
3738 callee()->AddVideoTrack();
3739 callee()->SetRemoteOfferHandler(nullptr);
deadbeef1dcb1642017-03-29 21:08:16 -07003740 caller()->CreateAndSetAndSignalOffer();
3741 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08003742
deadbeef1dcb1642017-03-29 21:08:16 -07003743 // Verify the caller receives frames from the newly added stream, and the
3744 // callee receives additional frames from the re-enabled video m= section.
Seth Hampson2f0d7022018-02-20 11:54:42 -08003745 MediaExpectations media_expectations;
3746 media_expectations.CalleeExpectsSomeAudio();
3747 media_expectations.ExpectBidirectionalVideo();
3748 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07003749}
3750
deadbeef1dcb1642017-03-29 21:08:16 -07003751// This tests that if we negotiate after calling CreateSender but before we
3752// have a track, then set a track later, frames from the newly-set track are
3753// received end-to-end.
Seth Hampson2f0d7022018-02-20 11:54:42 -08003754TEST_F(PeerConnectionIntegrationTestPlanB,
deadbeef1dcb1642017-03-29 21:08:16 -07003755 MediaFlowsAfterEarlyWarmupWithCreateSender) {
3756 ASSERT_TRUE(CreatePeerConnectionWrappers());
3757 ConnectFakeSignaling();
3758 auto caller_audio_sender =
3759 caller()->pc()->CreateSender("audio", "caller_stream");
3760 auto caller_video_sender =
3761 caller()->pc()->CreateSender("video", "caller_stream");
3762 auto callee_audio_sender =
3763 callee()->pc()->CreateSender("audio", "callee_stream");
3764 auto callee_video_sender =
3765 callee()->pc()->CreateSender("video", "callee_stream");
3766 caller()->CreateAndSetAndSignalOffer();
3767 ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs);
3768 // Wait for ICE to complete, without any tracks being set.
3769 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
3770 caller()->ice_connection_state(), kMaxWaitForFramesMs);
3771 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
3772 callee()->ice_connection_state(), kMaxWaitForFramesMs);
3773 // Now set the tracks, and expect frames to immediately start flowing.
3774 EXPECT_TRUE(caller_audio_sender->SetTrack(caller()->CreateLocalAudioTrack()));
3775 EXPECT_TRUE(caller_video_sender->SetTrack(caller()->CreateLocalVideoTrack()));
3776 EXPECT_TRUE(callee_audio_sender->SetTrack(callee()->CreateLocalAudioTrack()));
3777 EXPECT_TRUE(callee_video_sender->SetTrack(callee()->CreateLocalVideoTrack()));
Seth Hampson2f0d7022018-02-20 11:54:42 -08003778 MediaExpectations media_expectations;
3779 media_expectations.ExpectBidirectionalAudioAndVideo();
3780 ASSERT_TRUE(ExpectNewFrames(media_expectations));
3781}
3782
3783// This tests that if we negotiate after calling AddTransceiver but before we
3784// have a track, then set a track later, frames from the newly-set tracks are
3785// received end-to-end.
3786TEST_F(PeerConnectionIntegrationTestUnifiedPlan,
3787 MediaFlowsAfterEarlyWarmupWithAddTransceiver) {
3788 ASSERT_TRUE(CreatePeerConnectionWrappers());
3789 ConnectFakeSignaling();
3790 auto audio_result = caller()->pc()->AddTransceiver(cricket::MEDIA_TYPE_AUDIO);
3791 ASSERT_EQ(RTCErrorType::NONE, audio_result.error().type());
3792 auto caller_audio_sender = audio_result.MoveValue()->sender();
3793 auto video_result = caller()->pc()->AddTransceiver(cricket::MEDIA_TYPE_VIDEO);
3794 ASSERT_EQ(RTCErrorType::NONE, video_result.error().type());
3795 auto caller_video_sender = video_result.MoveValue()->sender();
3796 callee()->SetRemoteOfferHandler([this] {
3797 ASSERT_EQ(2u, callee()->pc()->GetTransceivers().size());
3798 callee()->pc()->GetTransceivers()[0]->SetDirection(
3799 RtpTransceiverDirection::kSendRecv);
3800 callee()->pc()->GetTransceivers()[1]->SetDirection(
3801 RtpTransceiverDirection::kSendRecv);
3802 });
3803 caller()->CreateAndSetAndSignalOffer();
3804 ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs);
3805 // Wait for ICE to complete, without any tracks being set.
3806 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionCompleted,
3807 caller()->ice_connection_state(), kMaxWaitForFramesMs);
3808 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
3809 callee()->ice_connection_state(), kMaxWaitForFramesMs);
3810 // Now set the tracks, and expect frames to immediately start flowing.
3811 auto callee_audio_sender = callee()->pc()->GetSenders()[0];
3812 auto callee_video_sender = callee()->pc()->GetSenders()[1];
3813 ASSERT_TRUE(caller_audio_sender->SetTrack(caller()->CreateLocalAudioTrack()));
3814 ASSERT_TRUE(caller_video_sender->SetTrack(caller()->CreateLocalVideoTrack()));
3815 ASSERT_TRUE(callee_audio_sender->SetTrack(callee()->CreateLocalAudioTrack()));
3816 ASSERT_TRUE(callee_video_sender->SetTrack(callee()->CreateLocalVideoTrack()));
3817 MediaExpectations media_expectations;
3818 media_expectations.ExpectBidirectionalAudioAndVideo();
3819 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07003820}
3821
3822// This test verifies that a remote video track can be added via AddStream,
3823// and sent end-to-end. For this particular test, it's simply echoed back
3824// from the caller to the callee, rather than being forwarded to a third
3825// PeerConnection.
Seth Hampson2f0d7022018-02-20 11:54:42 -08003826TEST_F(PeerConnectionIntegrationTestPlanB, CanSendRemoteVideoTrack) {
deadbeef1dcb1642017-03-29 21:08:16 -07003827 ASSERT_TRUE(CreatePeerConnectionWrappers());
3828 ConnectFakeSignaling();
3829 // Just send a video track from the caller.
Steve Anton15324772018-01-16 10:26:49 -08003830 caller()->AddVideoTrack();
deadbeef1dcb1642017-03-29 21:08:16 -07003831 caller()->CreateAndSetAndSignalOffer();
3832 ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs);
Mirko Bonadeie12c1fe2018-07-03 12:53:23 +02003833 ASSERT_EQ(1U, callee()->remote_streams()->count());
deadbeef1dcb1642017-03-29 21:08:16 -07003834
3835 // Echo the stream back, and do a new offer/anwer (initiated by callee this
3836 // time).
3837 callee()->pc()->AddStream(callee()->remote_streams()->at(0));
3838 callee()->CreateAndSetAndSignalOffer();
3839 ASSERT_TRUE_WAIT(SignalingStateStable(), kMaxWaitForActivationMs);
3840
Seth Hampson2f0d7022018-02-20 11:54:42 -08003841 MediaExpectations media_expectations;
3842 media_expectations.ExpectBidirectionalVideo();
3843 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeef1dcb1642017-03-29 21:08:16 -07003844}
3845
3846// Test that we achieve the expected end-to-end connection time, using a
3847// fake clock and simulated latency on the media and signaling paths.
3848// We use a TURN<->TURN connection because this is usually the quickest to
3849// set up initially, especially when we're confident the connection will work
3850// and can start sending media before we get a STUN response.
3851//
3852// With various optimizations enabled, here are the network delays we expect to
3853// be on the critical path:
3854// 1. 2 signaling trips: Signaling offer and offerer's TURN candidate, then
3855// signaling answer (with DTLS fingerprint).
3856// 2. 9 media hops: Rest of the DTLS handshake. 3 hops in each direction when
3857// using TURN<->TURN pair, and DTLS exchange is 4 packets,
3858// the first of which should have arrived before the answer.
Seth Hampson2f0d7022018-02-20 11:54:42 -08003859TEST_P(PeerConnectionIntegrationTest, EndToEndConnectionTimeWithTurnTurnPair) {
deadbeef1dcb1642017-03-29 21:08:16 -07003860 rtc::ScopedFakeClock fake_clock;
3861 // Some things use a time of "0" as a special value, so we need to start out
3862 // the fake clock at a nonzero time.
3863 // TODO(deadbeef): Fix this.
Sebastian Jansson5f83cf02018-05-08 14:52:22 +02003864 fake_clock.AdvanceTime(webrtc::TimeDelta::seconds(1));
deadbeef1dcb1642017-03-29 21:08:16 -07003865
3866 static constexpr int media_hop_delay_ms = 50;
3867 static constexpr int signaling_trip_delay_ms = 500;
3868 // For explanation of these values, see comment above.
3869 static constexpr int required_media_hops = 9;
3870 static constexpr int required_signaling_trips = 2;
3871 // For internal delays (such as posting an event asychronously).
3872 static constexpr int allowed_internal_delay_ms = 20;
3873 static constexpr int total_connection_time_ms =
3874 media_hop_delay_ms * required_media_hops +
3875 signaling_trip_delay_ms * required_signaling_trips +
3876 allowed_internal_delay_ms;
3877
3878 static const rtc::SocketAddress turn_server_1_internal_address{"88.88.88.0",
3879 3478};
3880 static const rtc::SocketAddress turn_server_1_external_address{"88.88.88.1",
3881 0};
3882 static const rtc::SocketAddress turn_server_2_internal_address{"99.99.99.0",
3883 3478};
3884 static const rtc::SocketAddress turn_server_2_external_address{"99.99.99.1",
3885 0};
Seth Hampsonaed71642018-06-11 07:41:32 -07003886 cricket::TestTurnServer* turn_server_1 = CreateTurnServer(
3887 turn_server_1_internal_address, turn_server_1_external_address);
Jonas Orelandbdcee282017-10-10 14:01:40 +02003888
Seth Hampsonaed71642018-06-11 07:41:32 -07003889 cricket::TestTurnServer* turn_server_2 = CreateTurnServer(
3890 turn_server_2_internal_address, turn_server_2_external_address);
deadbeef1dcb1642017-03-29 21:08:16 -07003891 // Bypass permission check on received packets so media can be sent before
3892 // the candidate is signaled.
Seth Hampsonaed71642018-06-11 07:41:32 -07003893 network_thread()->Invoke<void>(RTC_FROM_HERE, [turn_server_1] {
3894 turn_server_1->set_enable_permission_checks(false);
3895 });
3896 network_thread()->Invoke<void>(RTC_FROM_HERE, [turn_server_2] {
3897 turn_server_2->set_enable_permission_checks(false);
3898 });
deadbeef1dcb1642017-03-29 21:08:16 -07003899
3900 PeerConnectionInterface::RTCConfiguration client_1_config;
3901 webrtc::PeerConnectionInterface::IceServer ice_server_1;
3902 ice_server_1.urls.push_back("turn:88.88.88.0:3478");
3903 ice_server_1.username = "test";
3904 ice_server_1.password = "test";
3905 client_1_config.servers.push_back(ice_server_1);
3906 client_1_config.type = webrtc::PeerConnectionInterface::kRelay;
3907 client_1_config.presume_writable_when_fully_relayed = true;
3908
3909 PeerConnectionInterface::RTCConfiguration client_2_config;
3910 webrtc::PeerConnectionInterface::IceServer ice_server_2;
3911 ice_server_2.urls.push_back("turn:99.99.99.0:3478");
3912 ice_server_2.username = "test";
3913 ice_server_2.password = "test";
3914 client_2_config.servers.push_back(ice_server_2);
3915 client_2_config.type = webrtc::PeerConnectionInterface::kRelay;
3916 client_2_config.presume_writable_when_fully_relayed = true;
3917
3918 ASSERT_TRUE(
3919 CreatePeerConnectionWrappersWithConfig(client_1_config, client_2_config));
3920 // Set up the simulated delays.
3921 SetSignalingDelayMs(signaling_trip_delay_ms);
3922 ConnectFakeSignaling();
3923 virtual_socket_server()->set_delay_mean(media_hop_delay_ms);
3924 virtual_socket_server()->UpdateDelayDistribution();
3925
3926 // Set "offer to receive audio/video" without adding any tracks, so we just
3927 // set up ICE/DTLS with no media.
3928 PeerConnectionInterface::RTCOfferAnswerOptions options;
3929 options.offer_to_receive_audio = 1;
3930 options.offer_to_receive_video = 1;
3931 caller()->SetOfferAnswerOptions(options);
3932 caller()->CreateAndSetAndSignalOffer();
deadbeef71452802017-05-07 17:21:01 -07003933 EXPECT_TRUE_SIMULATED_WAIT(DtlsConnected(), total_connection_time_ms,
3934 fake_clock);
Seth Hampson1d4a76d2018-06-19 14:31:41 -07003935 // Closing the PeerConnections destroys the ports before the ScopedFakeClock.
3936 // If this is not done a DCHECK can be hit in ports.cc, because a large
3937 // negative number is calculated for the rtt due to the global clock changing.
3938 caller()->pc()->Close();
3939 callee()->pc()->Close();
deadbeef1dcb1642017-03-29 21:08:16 -07003940}
3941
Jonas Orelandbdcee282017-10-10 14:01:40 +02003942// Verify that a TurnCustomizer passed in through RTCConfiguration
3943// is actually used by the underlying TURN candidate pair.
3944// Note that turnport_unittest.cc contains more detailed, lower-level tests.
Seth Hampson2f0d7022018-02-20 11:54:42 -08003945TEST_P(PeerConnectionIntegrationTest, TurnCustomizerUsedForTurnConnections) {
Jonas Orelandbdcee282017-10-10 14:01:40 +02003946 static const rtc::SocketAddress turn_server_1_internal_address{"88.88.88.0",
3947 3478};
3948 static const rtc::SocketAddress turn_server_1_external_address{"88.88.88.1",
3949 0};
3950 static const rtc::SocketAddress turn_server_2_internal_address{"99.99.99.0",
3951 3478};
3952 static const rtc::SocketAddress turn_server_2_external_address{"99.99.99.1",
3953 0};
Seth Hampsonaed71642018-06-11 07:41:32 -07003954 CreateTurnServer(turn_server_1_internal_address,
3955 turn_server_1_external_address);
3956 CreateTurnServer(turn_server_2_internal_address,
3957 turn_server_2_external_address);
Jonas Orelandbdcee282017-10-10 14:01:40 +02003958
3959 PeerConnectionInterface::RTCConfiguration client_1_config;
3960 webrtc::PeerConnectionInterface::IceServer ice_server_1;
3961 ice_server_1.urls.push_back("turn:88.88.88.0:3478");
3962 ice_server_1.username = "test";
3963 ice_server_1.password = "test";
3964 client_1_config.servers.push_back(ice_server_1);
3965 client_1_config.type = webrtc::PeerConnectionInterface::kRelay;
Seth Hampsonaed71642018-06-11 07:41:32 -07003966 auto* customizer1 = CreateTurnCustomizer();
3967 client_1_config.turn_customizer = customizer1;
Jonas Orelandbdcee282017-10-10 14:01:40 +02003968
3969 PeerConnectionInterface::RTCConfiguration client_2_config;
3970 webrtc::PeerConnectionInterface::IceServer ice_server_2;
3971 ice_server_2.urls.push_back("turn:99.99.99.0:3478");
3972 ice_server_2.username = "test";
3973 ice_server_2.password = "test";
3974 client_2_config.servers.push_back(ice_server_2);
3975 client_2_config.type = webrtc::PeerConnectionInterface::kRelay;
Seth Hampsonaed71642018-06-11 07:41:32 -07003976 auto* customizer2 = CreateTurnCustomizer();
3977 client_2_config.turn_customizer = customizer2;
Jonas Orelandbdcee282017-10-10 14:01:40 +02003978
3979 ASSERT_TRUE(
3980 CreatePeerConnectionWrappersWithConfig(client_1_config, client_2_config));
3981 ConnectFakeSignaling();
3982
3983 // Set "offer to receive audio/video" without adding any tracks, so we just
3984 // set up ICE/DTLS with no media.
3985 PeerConnectionInterface::RTCOfferAnswerOptions options;
3986 options.offer_to_receive_audio = 1;
3987 options.offer_to_receive_video = 1;
3988 caller()->SetOfferAnswerOptions(options);
3989 caller()->CreateAndSetAndSignalOffer();
3990 ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout);
3991
Seth Hampsonaed71642018-06-11 07:41:32 -07003992 ExpectTurnCustomizerCountersIncremented(customizer1);
3993 ExpectTurnCustomizerCountersIncremented(customizer2);
Jonas Orelandbdcee282017-10-10 14:01:40 +02003994}
3995
Benjamin Wright2d5f3cb2018-05-22 14:46:06 -07003996// Verifies that you can use TCP instead of UDP to connect to a TURN server and
3997// send media between the caller and the callee.
3998TEST_P(PeerConnectionIntegrationTest, TCPUsedForTurnConnections) {
3999 static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0",
4000 3478};
4001 static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0};
4002
4003 // Enable TCP for the fake turn server.
Seth Hampsonaed71642018-06-11 07:41:32 -07004004 CreateTurnServer(turn_server_internal_address, turn_server_external_address,
4005 cricket::PROTO_TCP);
Benjamin Wright2d5f3cb2018-05-22 14:46:06 -07004006
4007 webrtc::PeerConnectionInterface::IceServer ice_server;
4008 ice_server.urls.push_back("turn:88.88.88.0:3478?transport=tcp");
4009 ice_server.username = "test";
4010 ice_server.password = "test";
4011
4012 PeerConnectionInterface::RTCConfiguration client_1_config;
4013 client_1_config.servers.push_back(ice_server);
4014 client_1_config.type = webrtc::PeerConnectionInterface::kRelay;
4015
4016 PeerConnectionInterface::RTCConfiguration client_2_config;
4017 client_2_config.servers.push_back(ice_server);
4018 client_2_config.type = webrtc::PeerConnectionInterface::kRelay;
4019
4020 ASSERT_TRUE(
4021 CreatePeerConnectionWrappersWithConfig(client_1_config, client_2_config));
4022
4023 // Do normal offer/answer and wait for ICE to complete.
4024 ConnectFakeSignaling();
4025 caller()->AddAudioVideoTracks();
4026 callee()->AddAudioVideoTracks();
4027 caller()->CreateAndSetAndSignalOffer();
4028 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
4029 EXPECT_EQ_WAIT(webrtc::PeerConnectionInterface::kIceConnectionConnected,
4030 callee()->ice_connection_state(), kMaxWaitForFramesMs);
4031
4032 MediaExpectations media_expectations;
4033 media_expectations.ExpectBidirectionalAudioAndVideo();
4034 EXPECT_TRUE(ExpectNewFrames(media_expectations));
4035}
4036
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07004037// Verify that a SSLCertificateVerifier passed in through
4038// PeerConnectionDependencies is actually used by the underlying SSL
4039// implementation to determine whether a certificate presented by the TURN
4040// server is accepted by the client. Note that openssladapter_unittest.cc
4041// contains more detailed, lower-level tests.
4042TEST_P(PeerConnectionIntegrationTest,
4043 SSLCertificateVerifierUsedForTurnConnections) {
4044 static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0",
4045 3478};
4046 static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0};
4047
4048 // Enable TCP-TLS for the fake turn server. We need to pass in 88.88.88.0 so
4049 // that host name verification passes on the fake certificate.
Seth Hampsonaed71642018-06-11 07:41:32 -07004050 CreateTurnServer(turn_server_internal_address, turn_server_external_address,
4051 cricket::PROTO_TLS, "88.88.88.0");
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07004052
4053 webrtc::PeerConnectionInterface::IceServer ice_server;
4054 ice_server.urls.push_back("turns:88.88.88.0:3478?transport=tcp");
4055 ice_server.username = "test";
4056 ice_server.password = "test";
4057
4058 PeerConnectionInterface::RTCConfiguration client_1_config;
4059 client_1_config.servers.push_back(ice_server);
4060 client_1_config.type = webrtc::PeerConnectionInterface::kRelay;
4061
4062 PeerConnectionInterface::RTCConfiguration client_2_config;
4063 client_2_config.servers.push_back(ice_server);
4064 // Setting the type to kRelay forces the connection to go through a TURN
4065 // server.
4066 client_2_config.type = webrtc::PeerConnectionInterface::kRelay;
4067
4068 // Get a copy to the pointer so we can verify calls later.
4069 rtc::TestCertificateVerifier* client_1_cert_verifier =
4070 new rtc::TestCertificateVerifier();
4071 client_1_cert_verifier->verify_certificate_ = true;
4072 rtc::TestCertificateVerifier* client_2_cert_verifier =
4073 new rtc::TestCertificateVerifier();
4074 client_2_cert_verifier->verify_certificate_ = true;
4075
4076 // Create the dependencies with the test certificate verifier.
4077 webrtc::PeerConnectionDependencies client_1_deps(nullptr);
4078 client_1_deps.tls_cert_verifier =
4079 std::unique_ptr<rtc::TestCertificateVerifier>(client_1_cert_verifier);
4080 webrtc::PeerConnectionDependencies client_2_deps(nullptr);
4081 client_2_deps.tls_cert_verifier =
4082 std::unique_ptr<rtc::TestCertificateVerifier>(client_2_cert_verifier);
4083
4084 ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndDeps(
4085 client_1_config, std::move(client_1_deps), client_2_config,
4086 std::move(client_2_deps)));
4087 ConnectFakeSignaling();
4088
4089 // Set "offer to receive audio/video" without adding any tracks, so we just
4090 // set up ICE/DTLS with no media.
4091 PeerConnectionInterface::RTCOfferAnswerOptions options;
4092 options.offer_to_receive_audio = 1;
4093 options.offer_to_receive_video = 1;
4094 caller()->SetOfferAnswerOptions(options);
4095 caller()->CreateAndSetAndSignalOffer();
4096 ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout);
4097
4098 EXPECT_GT(client_1_cert_verifier->call_count_, 0u);
4099 EXPECT_GT(client_2_cert_verifier->call_count_, 0u);
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07004100}
4101
4102TEST_P(PeerConnectionIntegrationTest,
4103 SSLCertificateVerifierFailureUsedForTurnConnectionsFailsConnection) {
4104 static const rtc::SocketAddress turn_server_internal_address{"88.88.88.0",
4105 3478};
4106 static const rtc::SocketAddress turn_server_external_address{"88.88.88.1", 0};
4107
4108 // Enable TCP-TLS for the fake turn server. We need to pass in 88.88.88.0 so
4109 // that host name verification passes on the fake certificate.
Seth Hampsonaed71642018-06-11 07:41:32 -07004110 CreateTurnServer(turn_server_internal_address, turn_server_external_address,
4111 cricket::PROTO_TLS, "88.88.88.0");
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07004112
4113 webrtc::PeerConnectionInterface::IceServer ice_server;
4114 ice_server.urls.push_back("turns:88.88.88.0:3478?transport=tcp");
4115 ice_server.username = "test";
4116 ice_server.password = "test";
4117
4118 PeerConnectionInterface::RTCConfiguration client_1_config;
4119 client_1_config.servers.push_back(ice_server);
4120 client_1_config.type = webrtc::PeerConnectionInterface::kRelay;
4121
4122 PeerConnectionInterface::RTCConfiguration client_2_config;
4123 client_2_config.servers.push_back(ice_server);
4124 // Setting the type to kRelay forces the connection to go through a TURN
4125 // server.
4126 client_2_config.type = webrtc::PeerConnectionInterface::kRelay;
4127
4128 // Get a copy to the pointer so we can verify calls later.
4129 rtc::TestCertificateVerifier* client_1_cert_verifier =
4130 new rtc::TestCertificateVerifier();
4131 client_1_cert_verifier->verify_certificate_ = false;
4132 rtc::TestCertificateVerifier* client_2_cert_verifier =
4133 new rtc::TestCertificateVerifier();
4134 client_2_cert_verifier->verify_certificate_ = false;
4135
4136 // Create the dependencies with the test certificate verifier.
4137 webrtc::PeerConnectionDependencies client_1_deps(nullptr);
4138 client_1_deps.tls_cert_verifier =
4139 std::unique_ptr<rtc::TestCertificateVerifier>(client_1_cert_verifier);
4140 webrtc::PeerConnectionDependencies client_2_deps(nullptr);
4141 client_2_deps.tls_cert_verifier =
4142 std::unique_ptr<rtc::TestCertificateVerifier>(client_2_cert_verifier);
4143
4144 ASSERT_TRUE(CreatePeerConnectionWrappersWithConfigAndDeps(
4145 client_1_config, std::move(client_1_deps), client_2_config,
4146 std::move(client_2_deps)));
4147 ConnectFakeSignaling();
4148
4149 // Set "offer to receive audio/video" without adding any tracks, so we just
4150 // set up ICE/DTLS with no media.
4151 PeerConnectionInterface::RTCOfferAnswerOptions options;
4152 options.offer_to_receive_audio = 1;
4153 options.offer_to_receive_video = 1;
4154 caller()->SetOfferAnswerOptions(options);
4155 caller()->CreateAndSetAndSignalOffer();
4156 bool wait_res = true;
4157 // TODO(bugs.webrtc.org/9219): When IceConnectionState is implemented
4158 // properly, should be able to just wait for a state of "failed" instead of
4159 // waiting a fixed 10 seconds.
4160 WAIT_(DtlsConnected(), kDefaultTimeout, wait_res);
4161 ASSERT_FALSE(wait_res);
4162
4163 EXPECT_GT(client_1_cert_verifier->call_count_, 0u);
4164 EXPECT_GT(client_2_cert_verifier->call_count_, 0u);
Benjamin Wrightd6f86e82018-05-08 13:12:25 -07004165}
4166
deadbeefc964d0b2017-04-03 10:03:35 -07004167// Test that audio and video flow end-to-end when codec names don't use the
4168// expected casing, given that they're supposed to be case insensitive. To test
4169// this, all but one codec is removed from each media description, and its
4170// casing is changed.
4171//
4172// In the past, this has regressed and caused crashes/black video, due to the
4173// fact that code at some layers was doing case-insensitive comparisons and
4174// code at other layers was not.
Seth Hampson2f0d7022018-02-20 11:54:42 -08004175TEST_P(PeerConnectionIntegrationTest, CodecNamesAreCaseInsensitive) {
deadbeefc964d0b2017-04-03 10:03:35 -07004176 ASSERT_TRUE(CreatePeerConnectionWrappers());
4177 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08004178 caller()->AddAudioVideoTracks();
4179 callee()->AddAudioVideoTracks();
deadbeefc964d0b2017-04-03 10:03:35 -07004180
4181 // Remove all but one audio/video codec (opus and VP8), and change the
4182 // casing of the caller's generated offer.
4183 caller()->SetGeneratedSdpMunger([](cricket::SessionDescription* description) {
4184 cricket::AudioContentDescription* audio =
4185 GetFirstAudioContentDescription(description);
4186 ASSERT_NE(nullptr, audio);
4187 auto audio_codecs = audio->codecs();
4188 audio_codecs.erase(std::remove_if(audio_codecs.begin(), audio_codecs.end(),
4189 [](const cricket::AudioCodec& codec) {
4190 return codec.name != "opus";
4191 }),
4192 audio_codecs.end());
4193 ASSERT_EQ(1u, audio_codecs.size());
4194 audio_codecs[0].name = "OpUs";
4195 audio->set_codecs(audio_codecs);
4196
4197 cricket::VideoContentDescription* video =
4198 GetFirstVideoContentDescription(description);
4199 ASSERT_NE(nullptr, video);
4200 auto video_codecs = video->codecs();
4201 video_codecs.erase(std::remove_if(video_codecs.begin(), video_codecs.end(),
4202 [](const cricket::VideoCodec& codec) {
4203 return codec.name != "VP8";
4204 }),
4205 video_codecs.end());
4206 ASSERT_EQ(1u, video_codecs.size());
4207 video_codecs[0].name = "vP8";
4208 video->set_codecs(video_codecs);
4209 });
4210
4211 caller()->CreateAndSetAndSignalOffer();
4212 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
4213
4214 // Verify frames are still received end-to-end.
Seth Hampson2f0d7022018-02-20 11:54:42 -08004215 MediaExpectations media_expectations;
4216 media_expectations.ExpectBidirectionalAudioAndVideo();
4217 ASSERT_TRUE(ExpectNewFrames(media_expectations));
deadbeefc964d0b2017-04-03 10:03:35 -07004218}
4219
Seth Hampson2f0d7022018-02-20 11:54:42 -08004220TEST_P(PeerConnectionIntegrationTest, GetSources) {
hbos8d609f62017-04-10 07:39:05 -07004221 ASSERT_TRUE(CreatePeerConnectionWrappers());
4222 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08004223 caller()->AddAudioTrack();
hbos8d609f62017-04-10 07:39:05 -07004224 caller()->CreateAndSetAndSignalOffer();
4225 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
deadbeefd8ad7882017-04-18 16:01:17 -07004226 // Wait for one audio frame to be received by the callee.
Seth Hampson2f0d7022018-02-20 11:54:42 -08004227 MediaExpectations media_expectations;
4228 media_expectations.CalleeExpectsSomeAudio(1);
4229 ASSERT_TRUE(ExpectNewFrames(media_expectations));
hbos8d609f62017-04-10 07:39:05 -07004230 ASSERT_GT(callee()->pc()->GetReceivers().size(), 0u);
4231 auto receiver = callee()->pc()->GetReceivers()[0];
4232 ASSERT_EQ(receiver->media_type(), cricket::MEDIA_TYPE_AUDIO);
4233
4234 auto contributing_sources = receiver->GetSources();
4235 ASSERT_GT(receiver->GetParameters().encodings.size(), 0u);
4236 EXPECT_EQ(receiver->GetParameters().encodings[0].ssrc,
4237 contributing_sources[0].source_id());
4238}
4239
deadbeef2f425aa2017-04-14 10:41:32 -07004240// Test that if a track is removed and added again with a different stream ID,
4241// the new stream ID is successfully communicated in SDP and media continues to
4242// flow end-to-end.
Seth Hampson2f0d7022018-02-20 11:54:42 -08004243// TODO(webrtc.bugs.org/8734): This test does not work for Unified Plan because
4244// it will not reuse a transceiver that has already been sending. After creating
4245// a new transceiver it tries to create an offer with two senders of the same
4246// track ids and it fails.
4247TEST_F(PeerConnectionIntegrationTestPlanB, RemoveAndAddTrackWithNewStreamId) {
deadbeef2f425aa2017-04-14 10:41:32 -07004248 ASSERT_TRUE(CreatePeerConnectionWrappers());
4249 ConnectFakeSignaling();
4250
4251 rtc::scoped_refptr<MediaStreamInterface> stream_1 =
4252 caller()->pc_factory()->CreateLocalMediaStream("stream_1");
4253 rtc::scoped_refptr<MediaStreamInterface> stream_2 =
4254 caller()->pc_factory()->CreateLocalMediaStream("stream_2");
4255
4256 // Add track using stream 1, do offer/answer.
4257 rtc::scoped_refptr<webrtc::AudioTrackInterface> track =
4258 caller()->CreateLocalAudioTrack();
4259 rtc::scoped_refptr<webrtc::RtpSenderInterface> sender =
4260 caller()->pc()->AddTrack(track, {stream_1.get()});
4261 caller()->CreateAndSetAndSignalOffer();
4262 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08004263 {
4264 MediaExpectations media_expectations;
4265 media_expectations.CalleeExpectsSomeAudio(1);
4266 ASSERT_TRUE(ExpectNewFrames(media_expectations));
4267 }
deadbeef2f425aa2017-04-14 10:41:32 -07004268 // Remove the sender, and create a new one with the new stream.
4269 caller()->pc()->RemoveTrack(sender);
4270 sender = caller()->pc()->AddTrack(track, {stream_2.get()});
4271 caller()->CreateAndSetAndSignalOffer();
4272 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
4273 // Wait for additional audio frames to be received by the callee.
Seth Hampson2f0d7022018-02-20 11:54:42 -08004274 {
4275 MediaExpectations media_expectations;
4276 media_expectations.CalleeExpectsSomeAudio();
4277 ASSERT_TRUE(ExpectNewFrames(media_expectations));
4278 }
deadbeef2f425aa2017-04-14 10:41:32 -07004279}
4280
Seth Hampson2f0d7022018-02-20 11:54:42 -08004281TEST_P(PeerConnectionIntegrationTest, RtcEventLogOutputWriteCalled) {
Elad Alon99c3fe52017-10-13 16:29:40 +02004282 ASSERT_TRUE(CreatePeerConnectionWrappers());
4283 ConnectFakeSignaling();
4284
4285 auto output = rtc::MakeUnique<testing::NiceMock<MockRtcEventLogOutput>>();
4286 ON_CALL(*output, IsActive()).WillByDefault(testing::Return(true));
4287 ON_CALL(*output, Write(::testing::_)).WillByDefault(testing::Return(true));
4288 EXPECT_CALL(*output, Write(::testing::_)).Times(::testing::AtLeast(1));
Bjorn Tereliusde939432017-11-20 17:38:14 +01004289 EXPECT_TRUE(caller()->pc()->StartRtcEventLog(
4290 std::move(output), webrtc::RtcEventLog::kImmediateOutput));
Elad Alon99c3fe52017-10-13 16:29:40 +02004291
Steve Anton15324772018-01-16 10:26:49 -08004292 caller()->AddAudioVideoTracks();
Elad Alon99c3fe52017-10-13 16:29:40 +02004293 caller()->CreateAndSetAndSignalOffer();
4294 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
4295}
4296
Steve Antonede9ca52017-10-16 13:04:27 -07004297// Test that if candidates are only signaled by applying full session
4298// descriptions (instead of using AddIceCandidate), the peers can connect to
4299// each other and exchange media.
Seth Hampson2f0d7022018-02-20 11:54:42 -08004300TEST_P(PeerConnectionIntegrationTest, MediaFlowsWhenCandidatesSetOnlyInSdp) {
Steve Antonede9ca52017-10-16 13:04:27 -07004301 ASSERT_TRUE(CreatePeerConnectionWrappers());
4302 // Each side will signal the session descriptions but not candidates.
4303 ConnectFakeSignalingForSdpOnly();
4304
4305 // Add audio video track and exchange the initial offer/answer with media
4306 // information only. This will start ICE gathering on each side.
Steve Anton15324772018-01-16 10:26:49 -08004307 caller()->AddAudioVideoTracks();
4308 callee()->AddAudioVideoTracks();
Steve Antonede9ca52017-10-16 13:04:27 -07004309 caller()->CreateAndSetAndSignalOffer();
4310
4311 // Wait for all candidates to be gathered on both the caller and callee.
4312 ASSERT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
4313 caller()->ice_gathering_state(), kDefaultTimeout);
4314 ASSERT_EQ_WAIT(PeerConnectionInterface::kIceGatheringComplete,
4315 callee()->ice_gathering_state(), kDefaultTimeout);
4316
4317 // The candidates will now be included in the session description, so
4318 // signaling them will start the ICE connection.
4319 caller()->CreateAndSetAndSignalOffer();
4320 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
4321
4322 // Ensure that media flows in both directions.
Seth Hampson2f0d7022018-02-20 11:54:42 -08004323 MediaExpectations media_expectations;
4324 media_expectations.ExpectBidirectionalAudioAndVideo();
4325 ASSERT_TRUE(ExpectNewFrames(media_expectations));
Steve Antonede9ca52017-10-16 13:04:27 -07004326}
4327
henrika5f6bf242017-11-01 11:06:56 +01004328// Test that SetAudioPlayout can be used to disable audio playout from the
4329// start, then later enable it. This may be useful, for example, if the caller
4330// needs to play a local ringtone until some event occurs, after which it
4331// switches to playing the received audio.
Seth Hampson2f0d7022018-02-20 11:54:42 -08004332TEST_P(PeerConnectionIntegrationTest, DisableAndEnableAudioPlayout) {
henrika5f6bf242017-11-01 11:06:56 +01004333 ASSERT_TRUE(CreatePeerConnectionWrappers());
4334 ConnectFakeSignaling();
4335
4336 // Set up audio-only call where audio playout is disabled on caller's side.
4337 caller()->pc()->SetAudioPlayout(false);
Steve Anton15324772018-01-16 10:26:49 -08004338 caller()->AddAudioTrack();
4339 callee()->AddAudioTrack();
henrika5f6bf242017-11-01 11:06:56 +01004340 caller()->CreateAndSetAndSignalOffer();
4341 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
4342
4343 // Pump messages for a second.
4344 WAIT(false, 1000);
4345 // Since audio playout is disabled, the caller shouldn't have received
4346 // anything (at the playout level, at least).
4347 EXPECT_EQ(0, caller()->audio_frames_received());
4348 // As a sanity check, make sure the callee (for which playout isn't disabled)
4349 // did still see frames on its audio level.
4350 ASSERT_GT(callee()->audio_frames_received(), 0);
4351
4352 // Enable playout again, and ensure audio starts flowing.
4353 caller()->pc()->SetAudioPlayout(true);
Seth Hampson2f0d7022018-02-20 11:54:42 -08004354 MediaExpectations media_expectations;
4355 media_expectations.ExpectBidirectionalAudio();
4356 ASSERT_TRUE(ExpectNewFrames(media_expectations));
henrika5f6bf242017-11-01 11:06:56 +01004357}
4358
4359double GetAudioEnergyStat(PeerConnectionWrapper* pc) {
4360 auto report = pc->NewGetStats();
4361 auto track_stats_list =
4362 report->GetStatsOfType<webrtc::RTCMediaStreamTrackStats>();
4363 const webrtc::RTCMediaStreamTrackStats* remote_track_stats = nullptr;
4364 for (const auto* track_stats : track_stats_list) {
4365 if (track_stats->remote_source.is_defined() &&
4366 *track_stats->remote_source) {
4367 remote_track_stats = track_stats;
4368 break;
4369 }
4370 }
4371
4372 if (!remote_track_stats->total_audio_energy.is_defined()) {
4373 return 0.0;
4374 }
4375 return *remote_track_stats->total_audio_energy;
4376}
4377
4378// Test that if audio playout is disabled via the SetAudioPlayout() method, then
4379// incoming audio is still processed and statistics are generated.
Seth Hampson2f0d7022018-02-20 11:54:42 -08004380TEST_P(PeerConnectionIntegrationTest,
henrika5f6bf242017-11-01 11:06:56 +01004381 DisableAudioPlayoutStillGeneratesAudioStats) {
4382 ASSERT_TRUE(CreatePeerConnectionWrappers());
4383 ConnectFakeSignaling();
4384
4385 // Set up audio-only call where playout is disabled but audio-processing is
4386 // still active.
Steve Anton15324772018-01-16 10:26:49 -08004387 caller()->AddAudioTrack();
4388 callee()->AddAudioTrack();
henrika5f6bf242017-11-01 11:06:56 +01004389 caller()->pc()->SetAudioPlayout(false);
4390
4391 caller()->CreateAndSetAndSignalOffer();
4392 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
4393
4394 // Wait for the callee to receive audio stats.
4395 EXPECT_TRUE_WAIT(GetAudioEnergyStat(caller()) > 0, kMaxWaitForFramesMs);
4396}
4397
henrika4f167df2017-11-01 14:45:55 +01004398// Test that SetAudioRecording can be used to disable audio recording from the
4399// start, then later enable it. This may be useful, for example, if the caller
4400// wants to ensure that no audio resources are active before a certain state
4401// is reached.
Seth Hampson2f0d7022018-02-20 11:54:42 -08004402TEST_P(PeerConnectionIntegrationTest, DisableAndEnableAudioRecording) {
henrika4f167df2017-11-01 14:45:55 +01004403 ASSERT_TRUE(CreatePeerConnectionWrappers());
4404 ConnectFakeSignaling();
4405
4406 // Set up audio-only call where audio recording is disabled on caller's side.
4407 caller()->pc()->SetAudioRecording(false);
Steve Anton15324772018-01-16 10:26:49 -08004408 caller()->AddAudioTrack();
4409 callee()->AddAudioTrack();
henrika4f167df2017-11-01 14:45:55 +01004410 caller()->CreateAndSetAndSignalOffer();
4411 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
4412
4413 // Pump messages for a second.
4414 WAIT(false, 1000);
4415 // Since caller has disabled audio recording, the callee shouldn't have
4416 // received anything.
4417 EXPECT_EQ(0, callee()->audio_frames_received());
4418 // As a sanity check, make sure the caller did still see frames on its
4419 // audio level since audio recording is enabled on the calle side.
4420 ASSERT_GT(caller()->audio_frames_received(), 0);
4421
4422 // Enable audio recording again, and ensure audio starts flowing.
4423 caller()->pc()->SetAudioRecording(true);
Seth Hampson2f0d7022018-02-20 11:54:42 -08004424 MediaExpectations media_expectations;
4425 media_expectations.ExpectBidirectionalAudio();
4426 ASSERT_TRUE(ExpectNewFrames(media_expectations));
henrika4f167df2017-11-01 14:45:55 +01004427}
4428
Taylor Brandstetter389a97c2018-01-03 16:26:06 -08004429// Test that after closing PeerConnections, they stop sending any packets (ICE,
4430// DTLS, RTP...).
Seth Hampson2f0d7022018-02-20 11:54:42 -08004431TEST_P(PeerConnectionIntegrationTest, ClosingConnectionStopsPacketFlow) {
Taylor Brandstetter389a97c2018-01-03 16:26:06 -08004432 // Set up audio/video/data, wait for some frames to be received.
4433 ASSERT_TRUE(CreatePeerConnectionWrappers());
4434 ConnectFakeSignaling();
Steve Anton15324772018-01-16 10:26:49 -08004435 caller()->AddAudioVideoTracks();
Taylor Brandstetter389a97c2018-01-03 16:26:06 -08004436#ifdef HAVE_SCTP
4437 caller()->CreateDataChannel();
4438#endif
4439 caller()->CreateAndSetAndSignalOffer();
4440 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
Seth Hampson2f0d7022018-02-20 11:54:42 -08004441 MediaExpectations media_expectations;
4442 media_expectations.CalleeExpectsSomeAudioAndVideo();
4443 ASSERT_TRUE(ExpectNewFrames(media_expectations));
Taylor Brandstetter389a97c2018-01-03 16:26:06 -08004444 // Close PeerConnections.
4445 caller()->pc()->Close();
4446 callee()->pc()->Close();
4447 // Pump messages for a second, and ensure no new packets end up sent.
4448 uint32_t sent_packets_a = virtual_socket_server()->sent_packets();
4449 WAIT(false, 1000);
4450 uint32_t sent_packets_b = virtual_socket_server()->sent_packets();
4451 EXPECT_EQ(sent_packets_a, sent_packets_b);
4452}
4453
Steve Anton7eca0932018-03-30 15:18:41 -07004454// Test that transport stats are generated by the RTCStatsCollector for a
4455// connection that only involves data channels. This is a regression test for
4456// crbug.com/826972.
4457#ifdef HAVE_SCTP
4458TEST_P(PeerConnectionIntegrationTest,
4459 TransportStatsReportedForDataChannelOnlyConnection) {
4460 ASSERT_TRUE(CreatePeerConnectionWrappers());
4461 ConnectFakeSignaling();
4462 caller()->CreateDataChannel();
4463
4464 caller()->CreateAndSetAndSignalOffer();
4465 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
4466 ASSERT_TRUE_WAIT(callee()->data_channel(), kDefaultTimeout);
4467
4468 auto caller_report = caller()->NewGetStats();
4469 EXPECT_EQ(1u, caller_report->GetStatsOfType<RTCTransportStats>().size());
4470 auto callee_report = callee()->NewGetStats();
4471 EXPECT_EQ(1u, callee_report->GetStatsOfType<RTCTransportStats>().size());
4472}
4473#endif // HAVE_SCTP
4474
Qingsi Wang7685e862018-06-11 20:15:46 -07004475TEST_P(PeerConnectionIntegrationTest,
4476 IceEventsGeneratedAndLoggedInRtcEventLog) {
4477 ASSERT_TRUE(CreatePeerConnectionWrappersWithFakeRtcEventLog());
4478 ConnectFakeSignaling();
4479 PeerConnectionInterface::RTCOfferAnswerOptions options;
4480 options.offer_to_receive_audio = 1;
4481 caller()->SetOfferAnswerOptions(options);
4482 caller()->CreateAndSetAndSignalOffer();
4483 ASSERT_TRUE_WAIT(DtlsConnected(), kDefaultTimeout);
4484 ASSERT_NE(nullptr, caller()->event_log_factory());
4485 ASSERT_NE(nullptr, callee()->event_log_factory());
4486 webrtc::FakeRtcEventLog* caller_event_log =
4487 static_cast<webrtc::FakeRtcEventLog*>(
4488 caller()->event_log_factory()->last_log_created());
4489 webrtc::FakeRtcEventLog* callee_event_log =
4490 static_cast<webrtc::FakeRtcEventLog*>(
4491 callee()->event_log_factory()->last_log_created());
4492 ASSERT_NE(nullptr, caller_event_log);
4493 ASSERT_NE(nullptr, callee_event_log);
4494 int caller_ice_config_count = caller_event_log->GetEventCount(
4495 webrtc::RtcEvent::Type::IceCandidatePairConfig);
4496 int caller_ice_event_count = caller_event_log->GetEventCount(
4497 webrtc::RtcEvent::Type::IceCandidatePairEvent);
4498 int callee_ice_config_count = callee_event_log->GetEventCount(
4499 webrtc::RtcEvent::Type::IceCandidatePairConfig);
4500 int callee_ice_event_count = callee_event_log->GetEventCount(
4501 webrtc::RtcEvent::Type::IceCandidatePairEvent);
4502 EXPECT_LT(0, caller_ice_config_count);
4503 EXPECT_LT(0, caller_ice_event_count);
4504 EXPECT_LT(0, callee_ice_config_count);
4505 EXPECT_LT(0, callee_ice_event_count);
4506}
4507
Seth Hampson2f0d7022018-02-20 11:54:42 -08004508INSTANTIATE_TEST_CASE_P(PeerConnectionIntegrationTest,
4509 PeerConnectionIntegrationTest,
4510 Values(SdpSemantics::kPlanB,
4511 SdpSemantics::kUnifiedPlan));
Steve Antond3679212018-01-17 17:41:02 -08004512
Steve Anton74255ff2018-01-24 18:32:57 -08004513// Tests that verify interoperability between Plan B and Unified Plan
4514// PeerConnections.
4515class PeerConnectionIntegrationInteropTest
Seth Hampson2f0d7022018-02-20 11:54:42 -08004516 : public PeerConnectionIntegrationBaseTest,
Steve Anton74255ff2018-01-24 18:32:57 -08004517 public ::testing::WithParamInterface<
4518 std::tuple<SdpSemantics, SdpSemantics>> {
4519 protected:
Seth Hampson2f0d7022018-02-20 11:54:42 -08004520 // Setting the SdpSemantics for the base test to kDefault does not matter
4521 // because we specify not to use the test semantics when creating
4522 // PeerConnectionWrappers.
Steve Anton74255ff2018-01-24 18:32:57 -08004523 PeerConnectionIntegrationInteropTest()
Steve Anton3acffc32018-04-12 17:21:03 -07004524 : PeerConnectionIntegrationBaseTest(SdpSemantics::kPlanB),
Seth Hampson2f0d7022018-02-20 11:54:42 -08004525 caller_semantics_(std::get<0>(GetParam())),
Steve Anton74255ff2018-01-24 18:32:57 -08004526 callee_semantics_(std::get<1>(GetParam())) {}
4527
4528 bool CreatePeerConnectionWrappersWithSemantics() {
Steve Anton3acffc32018-04-12 17:21:03 -07004529 return CreatePeerConnectionWrappersWithSdpSemantics(caller_semantics_,
4530 callee_semantics_);
Steve Anton74255ff2018-01-24 18:32:57 -08004531 }
4532
4533 const SdpSemantics caller_semantics_;
4534 const SdpSemantics callee_semantics_;
4535};
4536
4537TEST_P(PeerConnectionIntegrationInteropTest, NoMediaLocalToNoMediaRemote) {
4538 ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics());
4539 ConnectFakeSignaling();
4540
4541 caller()->CreateAndSetAndSignalOffer();
4542 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
4543}
4544
4545TEST_P(PeerConnectionIntegrationInteropTest, OneAudioLocalToNoMediaRemote) {
4546 ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics());
4547 ConnectFakeSignaling();
4548 auto audio_sender = caller()->AddAudioTrack();
4549
4550 caller()->CreateAndSetAndSignalOffer();
4551 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
4552
4553 // Verify that one audio receiver has been created on the remote and that it
4554 // has the same track ID as the sending track.
4555 auto receivers = callee()->pc()->GetReceivers();
4556 ASSERT_EQ(1u, receivers.size());
4557 EXPECT_EQ(cricket::MEDIA_TYPE_AUDIO, receivers[0]->media_type());
4558 EXPECT_EQ(receivers[0]->track()->id(), audio_sender->track()->id());
4559
Seth Hampson2f0d7022018-02-20 11:54:42 -08004560 MediaExpectations media_expectations;
4561 media_expectations.CalleeExpectsSomeAudio();
4562 ASSERT_TRUE(ExpectNewFrames(media_expectations));
Steve Anton74255ff2018-01-24 18:32:57 -08004563}
4564
4565TEST_P(PeerConnectionIntegrationInteropTest, OneAudioOneVideoToNoMediaRemote) {
4566 ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics());
4567 ConnectFakeSignaling();
4568 auto video_sender = caller()->AddVideoTrack();
4569 auto audio_sender = caller()->AddAudioTrack();
4570
4571 caller()->CreateAndSetAndSignalOffer();
4572 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
4573
4574 // Verify that one audio and one video receiver have been created on the
4575 // remote and that they have the same track IDs as the sending tracks.
4576 auto audio_receivers =
4577 callee()->GetReceiversOfType(cricket::MEDIA_TYPE_AUDIO);
4578 ASSERT_EQ(1u, audio_receivers.size());
4579 EXPECT_EQ(audio_receivers[0]->track()->id(), audio_sender->track()->id());
4580 auto video_receivers =
4581 callee()->GetReceiversOfType(cricket::MEDIA_TYPE_VIDEO);
4582 ASSERT_EQ(1u, video_receivers.size());
4583 EXPECT_EQ(video_receivers[0]->track()->id(), video_sender->track()->id());
4584
Seth Hampson2f0d7022018-02-20 11:54:42 -08004585 MediaExpectations media_expectations;
4586 media_expectations.CalleeExpectsSomeAudioAndVideo();
4587 ASSERT_TRUE(ExpectNewFrames(media_expectations));
Steve Anton74255ff2018-01-24 18:32:57 -08004588}
4589
4590TEST_P(PeerConnectionIntegrationInteropTest,
4591 OneAudioOneVideoLocalToOneAudioOneVideoRemote) {
4592 ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics());
4593 ConnectFakeSignaling();
4594 caller()->AddAudioVideoTracks();
4595 callee()->AddAudioVideoTracks();
4596
4597 caller()->CreateAndSetAndSignalOffer();
4598 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
4599
Seth Hampson2f0d7022018-02-20 11:54:42 -08004600 MediaExpectations media_expectations;
4601 media_expectations.ExpectBidirectionalAudioAndVideo();
4602 ASSERT_TRUE(ExpectNewFrames(media_expectations));
Steve Anton74255ff2018-01-24 18:32:57 -08004603}
4604
4605TEST_P(PeerConnectionIntegrationInteropTest,
4606 ReverseRolesOneAudioLocalToOneVideoRemote) {
4607 ASSERT_TRUE(CreatePeerConnectionWrappersWithSemantics());
4608 ConnectFakeSignaling();
4609 caller()->AddAudioTrack();
4610 callee()->AddVideoTrack();
4611
4612 caller()->CreateAndSetAndSignalOffer();
4613 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
4614
4615 // Verify that only the audio track has been negotiated.
4616 EXPECT_EQ(0u, caller()->GetReceiversOfType(cricket::MEDIA_TYPE_VIDEO).size());
4617 // Might also check that the callee's NegotiationNeeded flag is set.
4618
4619 // Reverse roles.
4620 callee()->CreateAndSetAndSignalOffer();
4621 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
4622
Seth Hampson2f0d7022018-02-20 11:54:42 -08004623 MediaExpectations media_expectations;
4624 media_expectations.CallerExpectsSomeVideo();
4625 media_expectations.CalleeExpectsSomeAudio();
4626 ASSERT_TRUE(ExpectNewFrames(media_expectations));
Steve Anton74255ff2018-01-24 18:32:57 -08004627}
4628
Steve Antonba42e992018-04-09 14:10:01 -07004629INSTANTIATE_TEST_CASE_P(
4630 PeerConnectionIntegrationTest,
4631 PeerConnectionIntegrationInteropTest,
4632 Values(std::make_tuple(SdpSemantics::kPlanB, SdpSemantics::kUnifiedPlan),
4633 std::make_tuple(SdpSemantics::kUnifiedPlan, SdpSemantics::kPlanB)));
4634
4635// Test that if the Unified Plan side offers two video tracks then the Plan B
4636// side will only see the first one and ignore the second.
4637TEST_F(PeerConnectionIntegrationTestPlanB, TwoVideoUnifiedPlanToNoMediaPlanB) {
Steve Anton3acffc32018-04-12 17:21:03 -07004638 ASSERT_TRUE(CreatePeerConnectionWrappersWithSdpSemantics(
4639 SdpSemantics::kUnifiedPlan, SdpSemantics::kPlanB));
Steve Anton74255ff2018-01-24 18:32:57 -08004640 ConnectFakeSignaling();
4641 auto first_sender = caller()->AddVideoTrack();
4642 caller()->AddVideoTrack();
4643
4644 caller()->CreateAndSetAndSignalOffer();
4645 ASSERT_TRUE_WAIT(SignalingStateStable(), kDefaultTimeout);
4646
4647 // Verify that there is only one receiver and it corresponds to the first
4648 // added track.
4649 auto receivers = callee()->pc()->GetReceivers();
4650 ASSERT_EQ(1u, receivers.size());
4651 EXPECT_TRUE(receivers[0]->track()->enabled());
4652 EXPECT_EQ(first_sender->track()->id(), receivers[0]->track()->id());
4653
Seth Hampson2f0d7022018-02-20 11:54:42 -08004654 MediaExpectations media_expectations;
4655 media_expectations.CalleeExpectsSomeVideo();
4656 ASSERT_TRUE(ExpectNewFrames(media_expectations));
Steve Anton74255ff2018-01-24 18:32:57 -08004657}
4658
deadbeef1dcb1642017-03-29 21:08:16 -07004659} // namespace
4660
4661#endif // if !defined(THREAD_SANITIZER)