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.
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"
15 class TouchscreenUtilTest
: public testing::Test
{
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);
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);
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);
53 std::vector
<DisplayMode
> modes(1, mode
);
54 display
.SetDisplayModes(modes
);
55 displays_
.push_back(display
);
59 void TearDown() override
{ displays_
.clear(); }
62 std::vector
<DisplayInfo
> displays_
;
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(ui::TouchscreenDevice::kInvalidId
,
74 displays_
[i
].touch_device_id());
77 TEST_F(TouchscreenUtilTest
, OneToOneMapping
) {
78 std::vector
<ui::TouchscreenDevice
> devices
;
80 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL
, "",
81 gfx::Size(800, 600), 0));
83 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL
, "",
84 gfx::Size(1024, 768), 0));
86 AssociateTouchscreens(&displays_
, devices
);
88 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId
, displays_
[0].touch_device_id());
89 EXPECT_EQ(1, displays_
[1].touch_device_id());
90 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId
, displays_
[2].touch_device_id());
91 EXPECT_EQ(2, displays_
[3].touch_device_id());
94 TEST_F(TouchscreenUtilTest
, MapToCorrectDisplaySize
) {
95 std::vector
<ui::TouchscreenDevice
> devices
;
97 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL
, "",
98 gfx::Size(1024, 768), 0));
100 AssociateTouchscreens(&displays_
, devices
);
102 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId
, displays_
[0].touch_device_id());
103 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId
, displays_
[1].touch_device_id());
104 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId
, displays_
[2].touch_device_id());
105 EXPECT_EQ(2, displays_
[3].touch_device_id());
108 TEST_F(TouchscreenUtilTest
, MapWhenSizeDiffersByOne
) {
109 std::vector
<ui::TouchscreenDevice
> devices
;
111 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL
, "",
112 gfx::Size(801, 600), 0));
114 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL
, "",
115 gfx::Size(1023, 768), 0));
117 AssociateTouchscreens(&displays_
, devices
);
119 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId
, displays_
[0].touch_device_id());
120 EXPECT_EQ(1, displays_
[1].touch_device_id());
121 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId
, displays_
[2].touch_device_id());
122 EXPECT_EQ(2, displays_
[3].touch_device_id());
125 TEST_F(TouchscreenUtilTest
, MapWhenSizesDoNotMatch
) {
126 std::vector
<ui::TouchscreenDevice
> devices
;
128 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL
, "",
129 gfx::Size(1022, 768), 0));
131 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL
, "",
132 gfx::Size(802, 600), 0));
134 AssociateTouchscreens(&displays_
, devices
);
136 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId
, displays_
[0].touch_device_id());
137 EXPECT_EQ(1, displays_
[1].touch_device_id());
138 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId
, displays_
[2].touch_device_id());
139 EXPECT_EQ(2, displays_
[3].touch_device_id());
142 TEST_F(TouchscreenUtilTest
, MapInternalTouchscreen
) {
143 std::vector
<ui::TouchscreenDevice
> devices
;
145 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL
, "",
146 gfx::Size(1920, 1080), 0));
148 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL
, "",
149 gfx::Size(9999, 888), 0));
151 AssociateTouchscreens(&displays_
, devices
);
153 // Internal touchscreen is always mapped to internal display.
154 EXPECT_EQ(2, displays_
[0].touch_device_id());
155 EXPECT_EQ(1, displays_
[1].touch_device_id());
156 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId
, displays_
[2].touch_device_id());
157 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId
, displays_
[3].touch_device_id());