1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/macros.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7 #include "ui/events/ozone/chromeos/cursor_controller.h"
8
9 namespace ui {
10
11 namespace {
12
13 const gfx::AcceleratedWidget kTestWindow = 1;
14
15 } // namespace
16
17 class CursorControllerTest : public testing::Test {
18 public:
CursorControllerTest()19 CursorControllerTest() {}
~CursorControllerTest()20 ~CursorControllerTest() override {}
21
TearDown()22 void TearDown() override {
23 ui::CursorController::GetInstance()->ClearCursorConfigForWindow(
24 kTestWindow);
25 }
26
27 DISALLOW_COPY_AND_ASSIGN(CursorControllerTest);
28 };
29
TEST_F(CursorControllerTest,UnconfiguredIdentity)30 TEST_F(CursorControllerTest, UnconfiguredIdentity) {
31 ui::CursorController* cursor_controller = CursorController::GetInstance();
32
33 // Check that unconfigured windows use identity.
34 gfx::Vector2dF delta(2.f, 3.f);
35 cursor_controller->ApplyCursorConfigForWindow(kTestWindow, &delta);
36 EXPECT_FLOAT_EQ(2.f, delta.x());
37 EXPECT_FLOAT_EQ(3.f, delta.y());
38 }
39
TEST_F(CursorControllerTest,ClearedIdentity)40 TEST_F(CursorControllerTest, ClearedIdentity) {
41 ui::CursorController* cursor_controller = CursorController::GetInstance();
42
43 // Check that configured & cleared windows use identity.
44 cursor_controller->SetCursorConfigForWindow(
45 kTestWindow, display::Display::ROTATE_180, 3.2f);
46 cursor_controller->ClearCursorConfigForWindow(kTestWindow);
47 gfx::Vector2dF delta(3.f, 5.f);
48 cursor_controller->ApplyCursorConfigForWindow(kTestWindow, &delta);
49 EXPECT_FLOAT_EQ(3.f, delta.x());
50 EXPECT_FLOAT_EQ(5.f, delta.y());
51 }
52
TEST_F(CursorControllerTest,RotatedHighDpi)53 TEST_F(CursorControllerTest, RotatedHighDpi) {
54 ui::CursorController* cursor_controller = CursorController::GetInstance();
55
56 // Check that 90deg rotated highdpi window transforms correctly.
57 cursor_controller->SetCursorConfigForWindow(kTestWindow,
58 display::Display::ROTATE_90, 2.f);
59 gfx::Vector2dF delta(3.f, 5.f);
60 cursor_controller->ApplyCursorConfigForWindow(kTestWindow, &delta);
61 EXPECT_FLOAT_EQ(-10.f, delta.x());
62 EXPECT_FLOAT_EQ(6.f, delta.y());
63 }
64
65 } // namespace ui
66