#ifdef UNSAFE_BUFFERS_BUILD
#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[] = …;
constexpr bool kUse64BitDisplayId = …;
const SessionPolicies kInitialLocalPolicies = …;
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) { … }
}
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() { … }
void ClientSessionTest::SetupSingleDisplay() { … }
void ClientSessionTest::SetupMultiDisplay() { … }
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) { … }
TEST_F(ClientSessionTest, Extensions) { … }
TEST_F(ClientSessionTest, DataChannelCallbackIsCalled) { … }
TEST_F(ClientSessionTest, ForwardHostSessionOptions1) { … }
TEST_F(ClientSessionTest, ForwardHostSessionOptions2) { … }
TEST_F(ClientSessionTest, ActiveDisplayMessageSent) { … }
#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");
EXPECT_THAT(GetSelectedSourceDisplayId(), Eq(kDisplay1Id));
MultiMon_SelectDisplay("all");
EXPECT_THAT(GetSelectedSourceDisplayId(), Eq(kDisplay1Id));
}
TEST_F(ClientSessionTest,
ShouldFallBackToPrimaryDisplayWhenSelectedDisplayIsDisconnected) {
CreateClientSession();
ConnectClientSession();
SetupMultiDisplay();
MultiMon_SelectSecondDisplay();
SetupSingleDisplay();
EXPECT_THAT(GetSelectedSourceDisplayId(), Eq(kDisplay1Id));
}
#endif
}