chromium/remoting/protocol/fractional_input_filter_unittest.cc

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

#include "remoting/protocol/fractional_input_filter.h"

#include "base/containers/span.h"
#include "remoting/protocol/protocol_mock_objects.h"
#include "remoting/protocol/test_event_matchers.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

using ::testing::_;

namespace remoting::protocol {

EqualsMouseMoveEvent;
EqualsTouchEvent;

namespace {

struct Screen {};

// o--------------+
// | screen_id 1  |
// | 200x100      |
// +--------------+------------------+
//                | screen_id 2      |
//                | 300x200          |
//                |                  |
//                +------------------+
constexpr Screen kSimpleLayout[] =;

VideoLayout BuildLayout(base::span<const Screen> screens) {}

FractionalCoordinate BuildFractionalCoordinates(int id, float x, float y) {}

MouseEvent MouseMoveEvent(int id, float x, float y) {}

}  // namespace

class FractionalInputFilterTest : public testing::Test {};

TEST_F() {
  filter_.set_video_layout(BuildLayout(kSimpleLayout));

  EXPECT_CALL();
  filter_.InjectMouseEvent(MouseMoveEvent(1, 0.0, 0.0));

  EXPECT_CALL();
  filter_.InjectMouseEvent(MouseMoveEvent(1, 0.5, 0.5));

  EXPECT_CALL();
  filter_.InjectMouseEvent(MouseMoveEvent(1, 1.0, 1.0));

  EXPECT_CALL();
  filter_.InjectMouseEvent(MouseMoveEvent(2, 0.0, 0.0));

  EXPECT_CALL();
  filter_.InjectMouseEvent(MouseMoveEvent(2, 0.5, 0.5));

  EXPECT_CALL();
  filter_.InjectMouseEvent(MouseMoveEvent(2, 1.0, 1.0));
}

TEST_F() {
  MouseEvent event;
  event.set_x(42);
  event.set_y(99);

  EXPECT_CALL();
  filter_.InjectMouseEvent(event);
}

TEST_F() {
  filter_.set_video_layout(BuildLayout(kSimpleLayout));

  EXPECT_CALL().Times(0);
  filter_.InjectMouseEvent(MouseMoveEvent(9, 0.5, 0.5));
}

TEST_F() {
  filter_.set_video_layout(BuildLayout(kSimpleLayout));

  TouchEvent event;
  TouchEventPoint* p = event.add_touch_points();
  *p->mutable_fractional_coordinate() = BuildFractionalCoordinates(1, 0.5, 0.5);
  p = event.add_touch_points();
  *p->mutable_fractional_coordinate() = BuildFractionalCoordinates(2, 0.5, 0.5);

  TouchEvent expected_event(event);
  expected_event.mutable_touch_points(0)->set_x(100);
  expected_event.mutable_touch_points(0)->set_y(50);
  expected_event.mutable_touch_points(1)->set_x(350);
  expected_event.mutable_touch_points(1)->set_y(200);

  EXPECT_CALL();
  filter_.InjectTouchEvent(event);
}

TEST_F() {
  TouchEvent event;
  TouchEventPoint* p = event.add_touch_points();
  p->set_x(10);
  p->set_y(20);
  p = event.add_touch_points();
  p->set_x(30);
  p->set_y(40);

  EXPECT_CALL();
  filter_.InjectTouchEvent(event);
}

TEST_F() {
  filter_.set_video_layout(BuildLayout(kSimpleLayout));

  TouchEvent event;
  TouchEventPoint* p = event.add_touch_points();
  *p->mutable_fractional_coordinate() = BuildFractionalCoordinates(1, 0.5, 0.5);
  p = event.add_touch_points();
  *p->mutable_fractional_coordinate() = BuildFractionalCoordinates(9, 0.5, 0.5);

  EXPECT_CALL().Times(0);
  filter_.InjectTouchEvent(event);
}

TEST_F() {
  filter_.set_video_layout(BuildLayout(kSimpleLayout));
  filter_.set_fallback_geometry(
      webrtc::DesktopRect::MakeXYWH(200, 100, 300, 200));

  EXPECT_CALL();
  filter_.InjectMouseEvent(MouseMoveEvent(0, 0.5, 0.5));
}

TEST_F() {
  filter_.set_video_layout(BuildLayout(kSimpleLayout));
  filter_.set_fallback_geometry({});

  EXPECT_CALL().Times(0);
  filter_.InjectMouseEvent(MouseMoveEvent(0, 0.5, 0.5));
}

}  // namespace remoting::protocol