Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / ash / touch / touchscreen_util_unittest.cc
blobe5bb0b8fef0e848affafdc3347a8ea8a758e847f
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/touch/touchscreen_util.h"
10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/events/devices/input_device.h"
13 namespace ash {
15 class TouchscreenUtilTest : public testing::Test {
16 public:
17 TouchscreenUtilTest() {}
18 ~TouchscreenUtilTest() override {}
20 void SetUp() override {
21 // Internal display will always match to internal touchscreen. If internal
22 // touchscreen can't be detected, it is then associated to a touch screen
23 // with matching size.
25 DisplayInfo display(1, std::string(), false);
26 DisplayMode mode(gfx::Size(1920, 1080), 60.0, false, true);
27 mode.native = true;
28 std::vector<DisplayMode> modes(1, mode);
29 display.SetDisplayModes(modes);
30 displays_.push_back(display);
31 gfx::Display::SetInternalDisplayId(1);
35 DisplayInfo display(2, std::string(), false);
36 DisplayMode mode(gfx::Size(800, 600), 60.0, false, true);
37 mode.native = true;
38 std::vector<DisplayMode> modes(1, mode);
39 display.SetDisplayModes(modes);
40 displays_.push_back(display);
43 // Display without native mode. Must not be matched to any touch screen.
45 DisplayInfo display(3, std::string(), false);
46 displays_.push_back(display);
50 DisplayInfo display(4, std::string(), false);
51 DisplayMode mode(gfx::Size(1024, 768), 60.0, false, true);
52 mode.native = true;
53 std::vector<DisplayMode> modes(1, mode);
54 display.SetDisplayModes(modes);
55 displays_.push_back(display);
59 void TearDown() override { displays_.clear(); }
61 protected:
62 std::vector<DisplayInfo> displays_;
64 private:
65 DISALLOW_COPY_AND_ASSIGN(TouchscreenUtilTest);
68 TEST_F(TouchscreenUtilTest, NoTouchscreens) {
69 std::vector<ui::TouchscreenDevice> devices;
70 AssociateTouchscreens(&displays_, devices);
72 for (size_t i = 0; i < displays_.size(); ++i)
73 EXPECT_EQ(0u, displays_[i].input_devices().size());
76 TEST_F(TouchscreenUtilTest, OneToOneMapping) {
77 std::vector<ui::TouchscreenDevice> devices;
78 devices.push_back(
79 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
80 gfx::Size(800, 600), 0));
81 devices.push_back(
82 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
83 gfx::Size(1024, 768), 0));
85 AssociateTouchscreens(&displays_, devices);
87 EXPECT_EQ(0u, displays_[0].input_devices().size());
88 EXPECT_EQ(1u, displays_[1].input_devices().size());
89 EXPECT_EQ(1, displays_[1].input_devices()[0]);
90 EXPECT_EQ(0u, displays_[2].input_devices().size());
91 EXPECT_EQ(1u, displays_[3].input_devices().size());
92 EXPECT_EQ(2, displays_[3].input_devices()[0]);
95 TEST_F(TouchscreenUtilTest, MapToCorrectDisplaySize) {
96 std::vector<ui::TouchscreenDevice> devices;
97 devices.push_back(
98 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
99 gfx::Size(1024, 768), 0));
101 AssociateTouchscreens(&displays_, devices);
103 EXPECT_EQ(0u, displays_[0].input_devices().size());
104 EXPECT_EQ(0u, displays_[1].input_devices().size());
105 EXPECT_EQ(0u, displays_[2].input_devices().size());
106 EXPECT_EQ(1u, displays_[3].input_devices().size());
107 EXPECT_EQ(2, displays_[3].input_devices()[0]);
110 TEST_F(TouchscreenUtilTest, MapWhenSizeDiffersByOne) {
111 std::vector<ui::TouchscreenDevice> devices;
112 devices.push_back(
113 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
114 gfx::Size(801, 600), 0));
115 devices.push_back(
116 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
117 gfx::Size(1023, 768), 0));
119 AssociateTouchscreens(&displays_, devices);
121 EXPECT_EQ(0u, displays_[0].input_devices().size());
122 EXPECT_EQ(1u, displays_[1].input_devices().size());
123 EXPECT_EQ(1, displays_[1].input_devices()[0]);
124 EXPECT_EQ(0u, displays_[2].input_devices().size());
125 EXPECT_EQ(1u, displays_[3].input_devices().size());
126 EXPECT_EQ(2, displays_[3].input_devices()[0]);
129 TEST_F(TouchscreenUtilTest, MapWhenSizesDoNotMatch) {
130 std::vector<ui::TouchscreenDevice> devices;
131 devices.push_back(
132 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
133 gfx::Size(1022, 768), 0));
134 devices.push_back(
135 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
136 gfx::Size(802, 600), 0));
138 AssociateTouchscreens(&displays_, devices);
140 EXPECT_EQ(0u, displays_[0].input_devices().size());
141 EXPECT_EQ(1u, displays_[1].input_devices().size());
142 EXPECT_EQ(1, displays_[1].input_devices()[0]);
143 EXPECT_EQ(0u, displays_[2].input_devices().size());
144 EXPECT_EQ(1u, displays_[3].input_devices().size());
145 EXPECT_EQ(2, displays_[3].input_devices()[0]);
148 TEST_F(TouchscreenUtilTest, MapInternalTouchscreen) {
149 std::vector<ui::TouchscreenDevice> devices;
150 devices.push_back(
151 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
152 gfx::Size(1920, 1080), 0));
153 devices.push_back(
154 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "",
155 gfx::Size(9999, 888), 0));
157 AssociateTouchscreens(&displays_, devices);
159 // Internal touchscreen is always mapped to internal display.
160 EXPECT_EQ(1u, displays_[0].input_devices().size());
161 EXPECT_EQ(2, displays_[0].input_devices()[0]);
162 EXPECT_EQ(1u, displays_[1].input_devices().size());
163 EXPECT_EQ(1, displays_[1].input_devices()[0]);
164 EXPECT_EQ(0u, displays_[2].input_devices().size());
165 EXPECT_EQ(0u, displays_[3].input_devices().size());
168 TEST_F(TouchscreenUtilTest, MultipleInternal) {
169 std::vector<ui::TouchscreenDevice> devices;
170 devices.push_back(
171 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "",
172 gfx::Size(1920, 1080), 0));
173 devices.push_back(
174 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "",
175 gfx::Size(1920, 1080), 0));
177 AssociateTouchscreens(&displays_, devices);
179 EXPECT_EQ(2u, displays_[0].input_devices().size());
180 EXPECT_EQ(0u, displays_[1].input_devices().size());
181 EXPECT_EQ(0u, displays_[2].input_devices().size());
182 EXPECT_EQ(0u, displays_[3].input_devices().size());
185 TEST_F(TouchscreenUtilTest, MultipleInternalAndExternal) {
186 std::vector<ui::TouchscreenDevice> devices;
187 devices.push_back(
188 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "",
189 gfx::Size(1920, 1080), 0));
190 devices.push_back(
191 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "",
192 gfx::Size(1920, 1080), 0));
193 devices.push_back(
194 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
195 gfx::Size(1024, 768), 0));
197 AssociateTouchscreens(&displays_, devices);
199 EXPECT_EQ(2u, displays_[0].input_devices().size());
200 EXPECT_EQ(0u, displays_[1].input_devices().size());
201 EXPECT_EQ(0u, displays_[2].input_devices().size());
202 EXPECT_EQ(1u, displays_[3].input_devices().size());
205 } // namespace ash