forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcast_touch_device_manager_unittest.cc
128 lines (109 loc) · 4.54 KB
/
cast_touch_device_manager_unittest.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chromecast/browser/cast_touch_device_manager.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/devices/device_data_manager.h"
#include "ui/events/devices/device_hotplug_event_observer.h"
#include "ui/gfx/geometry/rect.h"
namespace {
constexpr int64_t kDisplayId = 1;
constexpr int kTouchDeviceId = 100;
} // namespace
class CastTouchDeviceManagerTest : public testing::Test {
public:
CastTouchDeviceManagerTest() {}
void SetUp() override {
ui::DeviceDataManager::CreateInstance();
touch_device_manager_ =
std::make_unique<chromecast::shell::CastTouchDeviceManager>();
}
void TearDown() override {
touch_device_manager_.reset();
ui::DeviceDataManager::DeleteInstance();
}
ui::DeviceHotplugEventObserver* GetHotplugObserver() {
return ui::DeviceDataManager::GetInstance();
}
protected:
std::unique_ptr<chromecast::shell::CastTouchDeviceManager>
touch_device_manager_;
};
TEST_F(CastTouchDeviceManagerTest, CheckOneToOneMapping) {
std::vector<ui::TouchscreenDevice> touchscreens;
const gfx::Size display_size = gfx::Size(1280, 720);
touch_device_manager_->OnDisplayConfigured(
kDisplayId, display::Display::ROTATE_0, gfx::Rect(display_size));
touchscreens.push_back(ui::TouchscreenDevice(kTouchDeviceId,
ui::INPUT_DEVICE_INTERNAL,
"Touchscreen", display_size, 1));
GetHotplugObserver()->OnTouchscreenDevicesUpdated(touchscreens);
// 1:1 mapping for touch coordinates to display coordinates.
{
float x = display_size.width(), y = display_size.height();
ui::DeviceDataManager::GetInstance()->ApplyTouchTransformer(kTouchDeviceId,
&x, &y);
EXPECT_EQ(display_size.width(), x);
EXPECT_EQ(display_size.height(), y);
}
{
float x = display_size.width(), y = 0;
ui::DeviceDataManager::GetInstance()->ApplyTouchTransformer(kTouchDeviceId,
&x, &y);
EXPECT_EQ(display_size.width(), x);
EXPECT_EQ(0, y);
}
{
float x = 0, y = display_size.height();
ui::DeviceDataManager::GetInstance()->ApplyTouchTransformer(kTouchDeviceId,
&x, &y);
EXPECT_EQ(0, x);
EXPECT_EQ(display_size.height(), y);
}
{
float x = display_size.width() / 2, y = display_size.height() / 2;
ui::DeviceDataManager::GetInstance()->ApplyTouchTransformer(1, &x, &y);
EXPECT_EQ(display_size.width() / 2, x);
EXPECT_EQ(display_size.height() / 2, y);
}
}
TEST_F(CastTouchDeviceManagerTest, CheckMappingWithLargerTouchscreen) {
std::vector<ui::TouchscreenDevice> touchscreens;
const gfx::Size display_size = gfx::Size(1280, 720);
touch_device_manager_->OnDisplayConfigured(
kDisplayId, display::Display::ROTATE_0, gfx::Rect(display_size));
touchscreens.push_back(ui::TouchscreenDevice(
kTouchDeviceId, ui::INPUT_DEVICE_INTERNAL, "Touchscreen",
gfx::ScaleToRoundedSize(display_size, 2, 2), 1));
GetHotplugObserver()->OnTouchscreenDevicesUpdated(touchscreens);
// Touch screen is twice the size, so transformed events will be half the
// reported value.
{
float x = display_size.width(), y = display_size.height();
ui::DeviceDataManager::GetInstance()->ApplyTouchTransformer(kTouchDeviceId,
&x, &y);
EXPECT_EQ(display_size.width() / 2, x);
EXPECT_EQ(display_size.height() / 2, y);
}
{
float x = display_size.width(), y = 0;
ui::DeviceDataManager::GetInstance()->ApplyTouchTransformer(kTouchDeviceId,
&x, &y);
EXPECT_EQ(display_size.width() / 2, x);
EXPECT_EQ(0, y);
}
{
float x = 0, y = display_size.height();
ui::DeviceDataManager::GetInstance()->ApplyTouchTransformer(kTouchDeviceId,
&x, &y);
EXPECT_EQ(0, x);
EXPECT_EQ(display_size.height() / 2, y);
}
{
float x = display_size.width() / 2, y = display_size.height() / 2;
ui::DeviceDataManager::GetInstance()->ApplyTouchTransformer(kTouchDeviceId,
&x, &y);
EXPECT_EQ(display_size.width() / 4, x);
EXPECT_EQ(display_size.height() / 4, y);
}
}