cc: Clip projected tile priorities viewport to padded bounds.
[chromium-blink-merge.git] / ash / touch / touchscreen_util_unittest.cc
blobce1470278b192d815e78402be7747deb61ee56b3
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(ui::TouchscreenDevice::kInvalidId,
74 displays_[i].touch_device_id());
77 TEST_F(TouchscreenUtilTest, OneToOneMapping) {
78 std::vector<ui::TouchscreenDevice> devices;
79 devices.push_back(
80 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
81 gfx::Size(800, 600), 0));
82 devices.push_back(
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;
96 devices.push_back(
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;
110 devices.push_back(
111 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
112 gfx::Size(801, 600), 0));
113 devices.push_back(
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;
127 devices.push_back(
128 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
129 gfx::Size(1022, 768), 0));
130 devices.push_back(
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;
144 devices.push_back(
145 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
146 gfx::Size(1920, 1080), 0));
147 devices.push_back(
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());
160 } // namespace ash