chromium/remoting/host/client_session_unittest.cc

// Copyright 2012 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 "remoting/host/client_session.h"

#include <stdint.h>

#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "base/containers/contains.h"
#include "base/functional/bind.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/test/task_environment.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "remoting/base/auto_thread_task_runner.h"
#include "remoting/base/constants.h"
#include "remoting/base/local_session_policies_provider.h"
#include "remoting/base/session_policies.h"
#include "remoting/codec/video_encoder_verbatim.h"
#include "remoting/host/desktop_environment.h"
#include "remoting/host/fake_desktop_environment.h"
#include "remoting/host/fake_host_extension.h"
#include "remoting/host/fake_mouse_cursor_monitor.h"
#include "remoting/host/host_extension.h"
#include "remoting/host/host_extension_session.h"
#include "remoting/host/host_mock_objects.h"
#include "remoting/protocol/capability_names.h"
#include "remoting/protocol/fake_connection_to_client.h"
#include "remoting/protocol/fake_desktop_capturer.h"
#include "remoting/protocol/fake_message_pipe.h"
#include "remoting/protocol/fake_session.h"
#include "remoting/protocol/protocol_mock_objects.h"
#include "remoting/protocol/test_event_matchers.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/webrtc/modules/desktop_capture/desktop_geometry.h"
#include "ui/events/event.h"

namespace remoting {

FakeSession;
MockClientStub;
MockHostStub;
MockInputStub;
MockVideoStub;
SessionConfig;
EqualsClipboardEvent;
EqualsKeyEvent;
EqualsMouseButtonEvent;
EqualsMouseMoveEvent;

_;
AtLeast;
Eq;
Not;
ReturnRef;
StrictMock;

namespace {

constexpr char kTestDataChannelCallbackName[] =;

// Use large fake screen-ids on 64-bit systems, to detect errors caused by
// inadvertent casts to 32-bits.
constexpr bool kUse64BitDisplayId =;

const SessionPolicies kInitialLocalPolicies =;

// Matches a |protocol::Capabilities| argument against a list of capabilities
// formatted as a space-separated string.
MATCHER_P(IncludesCapabilities, expected_capabilities, "") {}

MATCHER_P(ScreenIdMatches, expected_id, "") {}

protocol::MouseEvent MakeMouseMoveEvent(int x, int y) {}

protocol::KeyEvent MakeKeyEvent(bool pressed, uint32_t keycode) {}

protocol::ClipboardEvent MakeClipboardEvent(const std::string& text) {}

}  // namespace

class ClientSessionTest : public testing::Test {};

void ClientSessionTest::SetUp() {}

void ClientSessionTest::TearDown() {}

void ClientSessionTest::CreateClientSession(
    std::unique_ptr<protocol::FakeSession> session) {}

void ClientSessionTest::CreateClientSession() {}

void ClientSessionTest::ConnectClientSession() {}

void ClientSessionTest::SendOnVideoSizeChanged(int width,
                                               int height,
                                               int dpi_x,
                                               int dpi_y) {}

void ClientSessionTest::NotifyVideoSize(int display_index) {}

void ClientSessionTest::NotifyVideoSizeAll() {}

void ClientSessionTest::AddDisplayToLayout(protocol::VideoLayout* displays,
                                           int x,
                                           int y,
                                           int width,
                                           int height,
                                           int dpi_x,
                                           int dpi_y,
                                           int64_t display_id) {}

void ClientSessionTest::NotifyDesktopDisplaySize(
    std::unique_ptr<protocol::VideoLayout> displays) {}

void ClientSessionTest::NotifySelectDesktopDisplay(std::string id) {}

void ClientSessionTest::ResetDisplayInfo() {}

// Set up a single display (default size).
void ClientSessionTest::SetupSingleDisplay() {}

// Set up multiple displays:
// +-----------+
// |  800x600  |---------------+
// |     0     |   1024x768    |
// +-----------+       1       |
//             |               |
//             +---------------+
void ClientSessionTest::SetupMultiDisplay() {}

// Set up multiple displays that are the same size:
// +-----------+
// |  800x600  |-----------+
// |     0     |  800x600  |
// +-----------+     1     |
//             +-----------+
void ClientSessionTest::SetupMultiDisplay_SameSize() {}

void ClientSessionTest::MultiMon_SelectFirstDisplay() {}

void ClientSessionTest::MultiMon_SelectSecondDisplay() {}

void ClientSessionTest::MultiMon_SelectAllDisplays() {}

void ClientSessionTest::MultiMon_SelectDisplay(std::string display_id) {}

webrtc::ScreenId ClientSessionTest::GetSelectedSourceDisplayId() {}

TEST_F(ClientSessionTest,
       OnLocalPoliciesChanged_DoesNotDisconnectIfEffectivePoliciesNotChanged) {}

TEST_F(ClientSessionTest,
       OnLocalPoliciesChanged_DisconnectsIfEffectivePoliciesChanged) {}

TEST_F(ClientSessionTest, DisconnectsAfterMaxSessionDurationIsReached) {}

TEST_F(ClientSessionTest,
       EffectivePoliciesImplicitlyAllowFileTransfer_HasCapability) {}

TEST_F(ClientSessionTest,
       EffectivePoliciesExplicitlyAllowFileTransfer_HasCapability) {}

TEST_F(ClientSessionTest,
       EffectivePoliciesDisallowFileTransfer_DoesNotHaveCapability) {}

TEST_F(ClientSessionTest, MultiMonMouseMove) {}

TEST_F(ClientSessionTest, MultiMonMouseMove_SameSize) {}

TEST_F(ClientSessionTest, DisableInputs) {}

TEST_F(ClientSessionTest, LocalInputTest) {}

TEST_F(ClientSessionTest, DisconnectOnLocalInputTest) {}

TEST_F(ClientSessionTest, RestoreEventState) {}

TEST_F(ClientSessionTest, ClampMouseEvents) {}

// Verifies that clients can have extensions registered, resulting in the
// correct capabilities being reported, and messages delivered correctly.
// The extension system is tested more extensively in the
// HostExtensionSessionManager unit-tests.
TEST_F(ClientSessionTest, Extensions) {}

TEST_F(ClientSessionTest, DataChannelCallbackIsCalled) {}

TEST_F(ClientSessionTest, ForwardHostSessionOptions1) {}

TEST_F(ClientSessionTest, ForwardHostSessionOptions2) {}

TEST_F(ClientSessionTest, ActiveDisplayMessageSent) {}

// Display selection behaves quite differently if capturing of the full desktop
// is enabled or not. To simplify things these tests only handle the ChromeOS
// situation, where full desktop capturing is disabled.
#if BUILDFLAG(IS_CHROMEOS)
TEST_F(ClientSessionTest, ShouldSelectFirstDesktopByDefault) {
  CreateClientSession();
  ConnectClientSession();

  SetupMultiDisplay();

  EXPECT_THAT(GetSelectedSourceDisplayId(), Eq(kDisplay1Id));
}

TEST_F(ClientSessionTest,
       ShouldChangeSelectedSourceDisplayWhenSwitchingDisplay) {
  CreateClientSession();
  ConnectClientSession();
  SetupMultiDisplay();

  MultiMon_SelectSecondDisplay();
  EXPECT_THAT(GetSelectedSourceDisplayId(), Eq(kDisplay2Id));

  MultiMon_SelectFirstDisplay();
  EXPECT_THAT(GetSelectedSourceDisplayId(), Eq(kDisplay1Id));
}

TEST_F(ClientSessionTest,
       ShouldFallBackToPrimaryDisplayWhenSwitchingToInvalidDisplay) {
  CreateClientSession();
  ConnectClientSession();
  SetupMultiDisplay();

  MultiMon_SelectDisplay("Not an integer");
  EXPECT_THAT(GetSelectedSourceDisplayId(), Eq(kDisplay1Id));

  MultiMon_SelectDisplay("123456");  // There is no display with this id.
  EXPECT_THAT(GetSelectedSourceDisplayId(), Eq(kDisplay1Id));

  // Full desktop capturing is not supported on ChromeOS.
  MultiMon_SelectDisplay("all");
  EXPECT_THAT(GetSelectedSourceDisplayId(), Eq(kDisplay1Id));
}

TEST_F(ClientSessionTest,
       ShouldFallBackToPrimaryDisplayWhenSelectedDisplayIsDisconnected) {
  CreateClientSession();
  ConnectClientSession();
  SetupMultiDisplay();
  MultiMon_SelectSecondDisplay();

  SetupSingleDisplay();
  EXPECT_THAT(GetSelectedSourceDisplayId(), Eq(kDisplay1Id));
}
#endif  // if BUILDFLAG(IS_CHROMEOS)

}  // namespace remoting