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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
|
// Copyright 2014 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 <string>
#include <vector>
#include "ash/display/display_info.h"
#include "ash/test/ash_test_base.h"
#include "ash/test/display_manager_test_api.h"
#include "ash/touch/touchscreen_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/events/devices/input_device.h"
namespace ash {
class TouchscreenUtilTest : public test::AshTestBase {
public:
TouchscreenUtilTest() {}
~TouchscreenUtilTest() override {}
void SetUp() override {
test::AshTestBase::SetUp();
// Internal display will always match to internal touchscreen. If internal
// touchscreen can't be detected, it is then associated to a touch screen
// with matching size.
{
DisplayInfo display(1, std::string(), false);
DisplayMode mode(gfx::Size(1920, 1080), 60.0, false, true);
mode.native = true;
std::vector<DisplayMode> modes(1, mode);
display.SetDisplayModes(modes);
displays_.push_back(display);
}
{
DisplayInfo display(2, std::string(), false);
DisplayMode mode(gfx::Size(800, 600), 60.0, false, true);
mode.native = true;
std::vector<DisplayMode> modes(1, mode);
display.SetDisplayModes(modes);
displays_.push_back(display);
}
// Display without native mode. Must not be matched to any touch screen.
{
DisplayInfo display(3, std::string(), false);
displays_.push_back(display);
}
{
DisplayInfo display(4, std::string(), false);
DisplayMode mode(gfx::Size(1024, 768), 60.0, false, true);
mode.native = true;
std::vector<DisplayMode> modes(1, mode);
display.SetDisplayModes(modes);
displays_.push_back(display);
}
}
void TearDown() override {
displays_.clear();
test::AshTestBase::TearDown();
}
protected:
std::vector<DisplayInfo> displays_;
private:
DISALLOW_COPY_AND_ASSIGN(TouchscreenUtilTest);
};
TEST_F(TouchscreenUtilTest, NoTouchscreens) {
std::vector<ui::TouchscreenDevice> devices;
test::ScopedSetInternalDisplayId set_internal(displays_[0].id());
AssociateTouchscreens(&displays_, devices);
for (size_t i = 0; i < displays_.size(); ++i)
EXPECT_EQ(0u, displays_[i].input_devices().size());
}
TEST_F(TouchscreenUtilTest, OneToOneMapping) {
std::vector<ui::TouchscreenDevice> devices;
devices.push_back(
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
gfx::Size(800, 600), 0));
devices.push_back(
ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
gfx::Size(1024, 768), 0));
test::ScopedSetInternalDisplayId set_internal(displays_[0].id());
AssociateTouchscreens(&displays_, devices);
EXPECT_EQ(0u, displays_[0].input_devices().size());
EXPECT_EQ(1u, displays_[1].input_devices().size());
EXPECT_EQ(1, displays_[1].input_devices()[0]);
EXPECT_EQ(0u, displays_[2].input_devices().size());
EXPECT_EQ(1u, displays_[3].input_devices().size());
EXPECT_EQ(2, displays_[3].input_devices()[0]);
}
TEST_F(TouchscreenUtilTest, MapToCorrectDisplaySize) {
std::vector<ui::TouchscreenDevice> devices;
devices.push_back(
ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
gfx::Size(1024, 768), 0));
test::ScopedSetInternalDisplayId set_internal(displays_[0].id());
AssociateTouchscreens(&displays_, devices);
EXPECT_EQ(0u, displays_[0].input_devices().size());
EXPECT_EQ(0u, displays_[1].input_devices().size());
EXPECT_EQ(0u, displays_[2].input_devices().size());
EXPECT_EQ(1u, displays_[3].input_devices().size());
EXPECT_EQ(2, displays_[3].input_devices()[0]);
}
TEST_F(TouchscreenUtilTest, MapWhenSizeDiffersByOne) {
std::vector<ui::TouchscreenDevice> devices;
devices.push_back(
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
gfx::Size(801, 600), 0));
devices.push_back(
ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
gfx::Size(1023, 768), 0));
test::ScopedSetInternalDisplayId set_internal(displays_[0].id());
AssociateTouchscreens(&displays_, devices);
EXPECT_EQ(0u, displays_[0].input_devices().size());
EXPECT_EQ(1u, displays_[1].input_devices().size());
EXPECT_EQ(1, displays_[1].input_devices()[0]);
EXPECT_EQ(0u, displays_[2].input_devices().size());
EXPECT_EQ(1u, displays_[3].input_devices().size());
EXPECT_EQ(2, displays_[3].input_devices()[0]);
}
TEST_F(TouchscreenUtilTest, MapWhenSizesDoNotMatch) {
std::vector<ui::TouchscreenDevice> devices;
devices.push_back(
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
gfx::Size(1022, 768), 0));
devices.push_back(
ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
gfx::Size(802, 600), 0));
test::ScopedSetInternalDisplayId set_internal(displays_[0].id());
AssociateTouchscreens(&displays_, devices);
EXPECT_EQ(0u, displays_[0].input_devices().size());
EXPECT_EQ(1u, displays_[1].input_devices().size());
EXPECT_EQ(1, displays_[1].input_devices()[0]);
EXPECT_EQ(0u, displays_[2].input_devices().size());
EXPECT_EQ(1u, displays_[3].input_devices().size());
EXPECT_EQ(2, displays_[3].input_devices()[0]);
}
TEST_F(TouchscreenUtilTest, MapInternalTouchscreen) {
std::vector<ui::TouchscreenDevice> devices;
devices.push_back(
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
gfx::Size(1920, 1080), 0));
devices.push_back(
ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "",
gfx::Size(9999, 888), 0));
test::ScopedSetInternalDisplayId set_internal(displays_[0].id());
AssociateTouchscreens(&displays_, devices);
// Internal touchscreen is always mapped to internal display.
EXPECT_EQ(1u, displays_[0].input_devices().size());
EXPECT_EQ(2, displays_[0].input_devices()[0]);
EXPECT_EQ(1u, displays_[1].input_devices().size());
EXPECT_EQ(1, displays_[1].input_devices()[0]);
EXPECT_EQ(0u, displays_[2].input_devices().size());
EXPECT_EQ(0u, displays_[3].input_devices().size());
}
TEST_F(TouchscreenUtilTest, MultipleInternal) {
std::vector<ui::TouchscreenDevice> devices;
devices.push_back(
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "",
gfx::Size(1920, 1080), 0));
devices.push_back(
ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "",
gfx::Size(1920, 1080), 0));
test::ScopedSetInternalDisplayId set_internal(displays_[0].id());
AssociateTouchscreens(&displays_, devices);
EXPECT_EQ(2u, displays_[0].input_devices().size());
EXPECT_EQ(0u, displays_[1].input_devices().size());
EXPECT_EQ(0u, displays_[2].input_devices().size());
EXPECT_EQ(0u, displays_[3].input_devices().size());
}
TEST_F(TouchscreenUtilTest, MultipleInternalAndExternal) {
std::vector<ui::TouchscreenDevice> devices;
devices.push_back(
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "",
gfx::Size(1920, 1080), 0));
devices.push_back(
ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "",
gfx::Size(1920, 1080), 0));
devices.push_back(
ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
gfx::Size(1024, 768), 0));
test::ScopedSetInternalDisplayId set_internal(displays_[0].id());
AssociateTouchscreens(&displays_, devices);
EXPECT_EQ(2u, displays_[0].input_devices().size());
EXPECT_EQ(0u, displays_[1].input_devices().size());
EXPECT_EQ(0u, displays_[2].input_devices().size());
EXPECT_EQ(1u, displays_[3].input_devices().size());
}
// crbug.com/515201
TEST_F(TouchscreenUtilTest, TestWithNoInternalDisplay) {
std::vector<ui::TouchscreenDevice> devices;
devices.push_back(
ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
gfx::Size(1920, 1080), 0));
devices.push_back(
ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "",
gfx::Size(9999, 888), 0));
AssociateTouchscreens(&displays_, devices);
EXPECT_EQ(1u, displays_[0].input_devices().size());
EXPECT_EQ(1, displays_[0].input_devices()[0]);
EXPECT_EQ(1u, displays_[1].input_devices().size());
EXPECT_EQ(2, displays_[1].input_devices()[0]);
EXPECT_EQ(0u, displays_[2].input_devices().size());
EXPECT_EQ(0u, displays_[3].input_devices().size());
}
} // namespace ash
|