chromium/remoting/protocol/connection_unittest.cc

// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include <memory>
#include <numbers>
#include <utility>

#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/numerics/math_constants.h"
#include "base/run_loop.h"
#include "base/test/task_environment.h"
#include "base/threading/thread.h"
#include "base/threading/thread_checker.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "build/build_config.h"
#include "remoting/base/constants.h"
#include "remoting/proto/audio.pb.h"
#include "remoting/protocol/audio_source.h"
#include "remoting/protocol/audio_stream.h"
#include "remoting/protocol/audio_stub.h"
#include "remoting/protocol/desktop_capturer.h"
#include "remoting/protocol/fake_session.h"
#include "remoting/protocol/fake_video_renderer.h"
#include "remoting/protocol/ice_connection_to_client.h"
#include "remoting/protocol/ice_connection_to_host.h"
#include "remoting/protocol/network_settings.h"
#include "remoting/protocol/protocol_mock_objects.h"
#include "remoting/protocol/transport_context.h"
#include "remoting/protocol/video_stream.h"
#include "remoting/protocol/webrtc_connection_to_client.h"
#include "remoting/protocol/webrtc_connection_to_host.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_frame.h"

_;
InvokeWithoutArgs;
NotNull;
StrictMock;

namespace remoting::protocol {

namespace {

MATCHER_P(EqualsCapabilitiesMessage, message, "") {}

MATCHER_P(EqualsKeyEvent, event, "") {}

ACTION_P(QuitRunLoop, run_loop) {}

class MockConnectionToHostEventCallback
    : public ConnectionToHost::HostEventCallback {};

class TestScreenCapturer : public DesktopCapturer {};

static const int kAudioSampleRate = AudioPacket::SAMPLING_RATE_48000;
static const int kAudioPacketDurationMs =;
static constexpr int kSamplesPerAudioPacket =;
static constexpr base::TimeDelta kAudioPacketDuration =;

static const int kAudioChannels =;

static const int kTestAudioSignalFrequencyLeftHz =;
static const int kTestAudioSignalFrequencyRightHz =;

class TestAudioSource : public AudioSource {};

class FakeAudioPlayer : public AudioStub {};

}  // namespace

class ConnectionTest : public testing::Test,
                       public testing::WithParamInterface<bool> {};

INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();

TEST_P(ConnectionTest, RejectConnection) {}

// crbug.com/1224862: Tests are flaky on Mac.
#if BUILDFLAG(IS_MAC)
#define MAYBE_Disconnect
#else
#define MAYBE_Disconnect
#endif
TEST_P(ConnectionTest, MAYBE_Disconnect) {}

// crbug.com/1224862: Tests are flaky on Mac.
#if BUILDFLAG(IS_MAC)
#define MAYBE_Control
#else
#define MAYBE_Control
#endif
TEST_P(ConnectionTest, MAYBE_Control) {}

// crbug.com/1224862: Tests are flaky on Mac.
#if BUILDFLAG(IS_MAC)
#define MAYBE_Events
#else
#define MAYBE_Events
#endif
TEST_P(ConnectionTest, MAYBE_Events) {}

// crbug.com/1224862: Tests are flaky on Mac.
#if BUILDFLAG(IS_MAC)
#define MAYBE_Video
#else
#define MAYBE_Video
#endif
TEST_P(ConnectionTest, MAYBE_Video) {}

// crbug.com/1224862: Tests are flaky on Mac.
#if BUILDFLAG(IS_MAC)
#define MAYBE_VideoWithSlowSignaling
#else
#define MAYBE_VideoWithSlowSignaling
#endif
// Verifies that the VideoStream doesn't lose any video frames while the
// connection is being established.
TEST_P(ConnectionTest, MAYBE_VideoWithSlowSignaling) {}

// crbug.com/1224862: Tests are flaky on Mac.
#if BUILDFLAG(IS_MAC)
#define MAYBE_DestroyOnIncomingMessage
#else
#define MAYBE_DestroyOnIncomingMessage
#endif
TEST_P(ConnectionTest, MAYBE_DestroyOnIncomingMessage) {}

// TODO(crbug.com/40729981): Test is flaky.
TEST_P(ConnectionTest, DISABLED_VideoStats) {}

// Slow/fails on Linux ASan/TSan (crbug.com/1045344) and flaky on Mac
// (crbug.com/1237376) and Windows (crbug.com/1503680).
#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) &&               \
        (defined(ADDRESS_SANITIZER) || defined(THREAD_SANITIZER)) || \
    BUILDFLAG(IS_MAC) || BUILDFLAG(IS_WIN)
#define MAYBE_Audio
#else
#define MAYBE_Audio
#endif
TEST_P(ConnectionTest, MAYBE_Audio) {}

// Flaky on multiple platforms
// https://crbug.com/1143671
TEST_P(ConnectionTest, DISABLED_FirstCaptureFailed) {}

// Flaky on multiple platforms
// https://crbug.com/1143671
TEST_P(ConnectionTest, DISABLED_SecondCaptureFailed) {}

}  // namespace remoting::protocol