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
;
79 devices
.push_back(ui::TouchscreenDevice(
80 1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL
, gfx::Size(800, 600), 0));
81 devices
.push_back(ui::TouchscreenDevice(
82 2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL
, gfx::Size(1024, 768), 0));
84 AssociateTouchscreens(&displays_
, devices
);
86 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId
, displays_
[0].touch_device_id());
87 EXPECT_EQ(1u, displays_
[1].touch_device_id());
88 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId
, displays_
[2].touch_device_id());
89 EXPECT_EQ(2u, displays_
[3].touch_device_id());
92 TEST_F(TouchscreenUtilTest
, MapToCorrectDisplaySize
) {
93 std::vector
<ui::TouchscreenDevice
> devices
;
94 devices
.push_back(ui::TouchscreenDevice(
95 2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL
, gfx::Size(1024, 768), 0));
97 AssociateTouchscreens(&displays_
, devices
);
99 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId
, displays_
[0].touch_device_id());
100 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId
, displays_
[1].touch_device_id());
101 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId
, displays_
[2].touch_device_id());
102 EXPECT_EQ(2u, displays_
[3].touch_device_id());
105 TEST_F(TouchscreenUtilTest
, MapWhenSizeDiffersByOne
) {
106 std::vector
<ui::TouchscreenDevice
> devices
;
107 devices
.push_back(ui::TouchscreenDevice(
108 1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL
, gfx::Size(801, 600), 0));
109 devices
.push_back(ui::TouchscreenDevice(
110 2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL
, gfx::Size(1023, 768), 0));
112 AssociateTouchscreens(&displays_
, devices
);
114 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId
, displays_
[0].touch_device_id());
115 EXPECT_EQ(1u, displays_
[1].touch_device_id());
116 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId
, displays_
[2].touch_device_id());
117 EXPECT_EQ(2u, displays_
[3].touch_device_id());
120 TEST_F(TouchscreenUtilTest
, MapWhenSizesDoNotMatch
) {
121 std::vector
<ui::TouchscreenDevice
> devices
;
122 devices
.push_back(ui::TouchscreenDevice(
123 1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL
, gfx::Size(1022, 768), 0));
124 devices
.push_back(ui::TouchscreenDevice(
125 2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL
, gfx::Size(802, 600), 0));
127 AssociateTouchscreens(&displays_
, devices
);
129 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId
, displays_
[0].touch_device_id());
130 EXPECT_EQ(1u, displays_
[1].touch_device_id());
131 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId
, displays_
[2].touch_device_id());
132 EXPECT_EQ(2u, displays_
[3].touch_device_id());
135 TEST_F(TouchscreenUtilTest
, MapInternalTouchscreen
) {
136 std::vector
<ui::TouchscreenDevice
> devices
;
137 devices
.push_back(ui::TouchscreenDevice(
138 1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL
, gfx::Size(1920, 1080), 0));
139 devices
.push_back(ui::TouchscreenDevice(
140 2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL
, gfx::Size(9999, 888), 0));
142 AssociateTouchscreens(&displays_
, devices
);
144 // Internal touchscreen is always mapped to internal display.
145 EXPECT_EQ(2u, displays_
[0].touch_device_id());
146 EXPECT_EQ(1u, displays_
[1].touch_device_id());
147 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId
, displays_
[2].touch_device_id());
148 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId
, displays_
[3].touch_device_id());