Implement finding BLE connections in chrome://proximity-auth.
[chromium-blink-merge.git] / ash / touch / touchscreen_util_unittest.cc
blobff6d799124520891ba85f490041143f99c8dc86b
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.
5 #include <string>
6 #include <vector>
8 #include "ash/display/display_info.h"
9 #include "ash/test/ash_test_base.h"
10 #include "ash/test/display_manager_test_api.h"
11 #include "ash/touch/touchscreen_util.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/events/devices/input_device.h"
15 namespace ash {
17 class TouchscreenUtilTest : public test::AshTestBase {
18 public:
19 TouchscreenUtilTest() {}
20 ~TouchscreenUtilTest() override {}
22 void SetUp() override {
23 test::AshTestBase::SetUp();
24 // Internal display will always match to internal touchscreen. If internal
25 // touchscreen can't be detected, it is then associated to a touch screen
26 // with matching size.
28 DisplayInfo display(1, std::string(), false);
29 DisplayMode mode(gfx::Size(1920, 1080), 60.0, false, true);
30 mode.native = true;
31 std::vector<DisplayMode> modes(1, mode);
32 display.SetDisplayModes(modes);
33 displays_.push_back(display);
37 DisplayInfo display(2, std::string(), false);
38 DisplayMode mode(gfx::Size(800, 600), 60.0, false, true);
39 mode.native = true;
40 std::vector<DisplayMode> modes(1, mode);
41 display.SetDisplayModes(modes);
42 displays_.push_back(display);
45 // Display without native mode. Must not be matched to any touch screen.
47 DisplayInfo display(3, std::string(), false);
48 displays_.push_back(display);
52 DisplayInfo display(4, std::string(), false);
53 DisplayMode mode(gfx::Size(1024, 768), 60.0, false, true);
54 mode.native = true;
55 std::vector<DisplayMode> modes(1, mode);
56 display.SetDisplayModes(modes);
57 displays_.push_back(display);
61 void TearDown() override {
62 displays_.clear();
63 test::AshTestBase::TearDown();
66 protected:
67 std::vector<DisplayInfo> displays_;
69 private:
70 DISALLOW_COPY_AND_ASSIGN(TouchscreenUtilTest);
73 TEST_F(TouchscreenUtilTest, NoTouchscreens) {
74 std::vector<ui::TouchscreenDevice> devices;
76 test::ScopedSetInternalDisplayId set_internal(displays_[0].id());
77 AssociateTouchscreens(&displays_, devices);
79 for (size_t i = 0; i < displays_.size(); ++i)
80 EXPECT_EQ(0u, displays_[i].input_devices().size());
83 TEST_F(TouchscreenUtilTest, OneToOneMapping) {
84 std::vector<ui::TouchscreenDevice> devices;
85 devices.push_back(
86 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
87 gfx::Size(800, 600), 0));
88 devices.push_back(
89 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
90 gfx::Size(1024, 768), 0));
92 test::ScopedSetInternalDisplayId set_internal(displays_[0].id());
93 AssociateTouchscreens(&displays_, devices);
95 EXPECT_EQ(0u, displays_[0].input_devices().size());
96 EXPECT_EQ(1u, displays_[1].input_devices().size());
97 EXPECT_EQ(1, displays_[1].input_devices()[0]);
98 EXPECT_EQ(0u, displays_[2].input_devices().size());
99 EXPECT_EQ(1u, displays_[3].input_devices().size());
100 EXPECT_EQ(2, displays_[3].input_devices()[0]);
103 TEST_F(TouchscreenUtilTest, MapToCorrectDisplaySize) {
104 std::vector<ui::TouchscreenDevice> devices;
105 devices.push_back(
106 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
107 gfx::Size(1024, 768), 0));
109 test::ScopedSetInternalDisplayId set_internal(displays_[0].id());
110 AssociateTouchscreens(&displays_, devices);
112 EXPECT_EQ(0u, displays_[0].input_devices().size());
113 EXPECT_EQ(0u, displays_[1].input_devices().size());
114 EXPECT_EQ(0u, displays_[2].input_devices().size());
115 EXPECT_EQ(1u, displays_[3].input_devices().size());
116 EXPECT_EQ(2, displays_[3].input_devices()[0]);
119 TEST_F(TouchscreenUtilTest, MapWhenSizeDiffersByOne) {
120 std::vector<ui::TouchscreenDevice> devices;
121 devices.push_back(
122 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
123 gfx::Size(801, 600), 0));
124 devices.push_back(
125 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
126 gfx::Size(1023, 768), 0));
128 test::ScopedSetInternalDisplayId set_internal(displays_[0].id());
129 AssociateTouchscreens(&displays_, devices);
131 EXPECT_EQ(0u, displays_[0].input_devices().size());
132 EXPECT_EQ(1u, displays_[1].input_devices().size());
133 EXPECT_EQ(1, displays_[1].input_devices()[0]);
134 EXPECT_EQ(0u, displays_[2].input_devices().size());
135 EXPECT_EQ(1u, displays_[3].input_devices().size());
136 EXPECT_EQ(2, displays_[3].input_devices()[0]);
139 TEST_F(TouchscreenUtilTest, MapWhenSizesDoNotMatch) {
140 std::vector<ui::TouchscreenDevice> devices;
141 devices.push_back(
142 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
143 gfx::Size(1022, 768), 0));
144 devices.push_back(
145 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
146 gfx::Size(802, 600), 0));
148 test::ScopedSetInternalDisplayId set_internal(displays_[0].id());
149 AssociateTouchscreens(&displays_, devices);
151 EXPECT_EQ(0u, displays_[0].input_devices().size());
152 EXPECT_EQ(1u, displays_[1].input_devices().size());
153 EXPECT_EQ(1, displays_[1].input_devices()[0]);
154 EXPECT_EQ(0u, displays_[2].input_devices().size());
155 EXPECT_EQ(1u, displays_[3].input_devices().size());
156 EXPECT_EQ(2, displays_[3].input_devices()[0]);
159 TEST_F(TouchscreenUtilTest, MapInternalTouchscreen) {
160 std::vector<ui::TouchscreenDevice> devices;
161 devices.push_back(
162 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
163 gfx::Size(1920, 1080), 0));
164 devices.push_back(
165 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "",
166 gfx::Size(9999, 888), 0));
168 test::ScopedSetInternalDisplayId set_internal(displays_[0].id());
169 AssociateTouchscreens(&displays_, devices);
171 // Internal touchscreen is always mapped to internal display.
172 EXPECT_EQ(1u, displays_[0].input_devices().size());
173 EXPECT_EQ(2, displays_[0].input_devices()[0]);
174 EXPECT_EQ(1u, displays_[1].input_devices().size());
175 EXPECT_EQ(1, displays_[1].input_devices()[0]);
176 EXPECT_EQ(0u, displays_[2].input_devices().size());
177 EXPECT_EQ(0u, displays_[3].input_devices().size());
180 TEST_F(TouchscreenUtilTest, MultipleInternal) {
181 std::vector<ui::TouchscreenDevice> devices;
182 devices.push_back(
183 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "",
184 gfx::Size(1920, 1080), 0));
185 devices.push_back(
186 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "",
187 gfx::Size(1920, 1080), 0));
189 test::ScopedSetInternalDisplayId set_internal(displays_[0].id());
190 AssociateTouchscreens(&displays_, devices);
192 EXPECT_EQ(2u, displays_[0].input_devices().size());
193 EXPECT_EQ(0u, displays_[1].input_devices().size());
194 EXPECT_EQ(0u, displays_[2].input_devices().size());
195 EXPECT_EQ(0u, displays_[3].input_devices().size());
198 TEST_F(TouchscreenUtilTest, MultipleInternalAndExternal) {
199 std::vector<ui::TouchscreenDevice> devices;
200 devices.push_back(
201 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "",
202 gfx::Size(1920, 1080), 0));
203 devices.push_back(
204 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "",
205 gfx::Size(1920, 1080), 0));
206 devices.push_back(
207 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
208 gfx::Size(1024, 768), 0));
210 test::ScopedSetInternalDisplayId set_internal(displays_[0].id());
211 AssociateTouchscreens(&displays_, devices);
213 EXPECT_EQ(2u, displays_[0].input_devices().size());
214 EXPECT_EQ(0u, displays_[1].input_devices().size());
215 EXPECT_EQ(0u, displays_[2].input_devices().size());
216 EXPECT_EQ(1u, displays_[3].input_devices().size());
219 // crbug.com/515201
220 TEST_F(TouchscreenUtilTest, TestWithNoInternalDisplay) {
221 std::vector<ui::TouchscreenDevice> devices;
222 devices.push_back(
223 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
224 gfx::Size(1920, 1080), 0));
225 devices.push_back(
226 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "",
227 gfx::Size(9999, 888), 0));
229 // Internal touchscreen should not be associated with any display
230 AssociateTouchscreens(&displays_, devices);
232 EXPECT_EQ(1u, displays_[0].input_devices().size());
233 EXPECT_EQ(1, displays_[0].input_devices()[0]);
234 EXPECT_EQ(0u, displays_[1].input_devices().size());
235 EXPECT_EQ(0u, displays_[2].input_devices().size());
236 EXPECT_EQ(0u, displays_[3].input_devices().size());
239 } // namespace ash