Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(97)

Side by Side Diff: ash/touch/touchscreen_util_unittest.cc

Issue 2270553002: Move ash::DisplayInfo to ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: build Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "ash/common/display/display_info.h"
9 #include "ash/test/ash_test_base.h" 8 #include "ash/test/ash_test_base.h"
10 #include "ash/test/display_manager_test_api.h" 9 #include "ash/test/display_manager_test_api.h"
11 #include "ash/touch/touchscreen_util.h" 10 #include "ash/touch/touchscreen_util.h"
12 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/display/manager/managed_display_info.h"
13 #include "ui/events/devices/input_device.h" 13 #include "ui/events/devices/input_device.h"
14 14
15 namespace ash { 15 namespace ash {
16 16
17 using DisplayInfoList = std::vector<ui::ManagedDisplayInfo>;
18
17 class TouchscreenUtilTest : public test::AshTestBase { 19 class TouchscreenUtilTest : public test::AshTestBase {
18 public: 20 public:
19 TouchscreenUtilTest() {} 21 TouchscreenUtilTest() {}
20 ~TouchscreenUtilTest() override {} 22 ~TouchscreenUtilTest() override {}
21 23
22 void SetUp() override { 24 void SetUp() override {
23 test::AshTestBase::SetUp(); 25 test::AshTestBase::SetUp();
24 // Internal display will always match to internal touchscreen. If internal 26 // Internal display will always match to internal touchscreen. If internal
25 // touchscreen can't be detected, it is then associated to a touch screen 27 // touchscreen can't be detected, it is then associated to a touch screen
26 // with matching size. 28 // with matching size.
27 { 29 {
28 DisplayInfo display(1, "1", false); 30 ui::ManagedDisplayInfo display(1, "1", false);
29 scoped_refptr<ManagedDisplayMode> mode(new ManagedDisplayMode( 31 scoped_refptr<ui::ManagedDisplayMode> mode(new ui::ManagedDisplayMode(
30 gfx::Size(1920, 1080), 60.0, false /* interlaced */, 32 gfx::Size(1920, 1080), 60.0, false /* interlaced */,
31 true /* native */, 1.0 /* ui_scale */, 33 true /* native */, 1.0 /* ui_scale */,
32 1.0 /* device_scale_factor */)); 34 1.0 /* device_scale_factor */));
33 DisplayInfo::ManagedDisplayModeList modes(1, mode); 35 ui::ManagedDisplayInfo::ManagedDisplayModeList modes(1, mode);
34 display.SetManagedDisplayModes(modes); 36 display.SetManagedDisplayModes(modes);
35 displays_.push_back(display); 37 displays_.push_back(display);
36 } 38 }
37 39
38 { 40 {
39 DisplayInfo display(2, "2", false); 41 ui::ManagedDisplayInfo display(2, "2", false);
40 42
41 scoped_refptr<ManagedDisplayMode> mode(new ManagedDisplayMode( 43 scoped_refptr<ui::ManagedDisplayMode> mode(new ui::ManagedDisplayMode(
42 gfx::Size(800, 600), 60.0, false /* interlaced */, true /* native */, 44 gfx::Size(800, 600), 60.0, false /* interlaced */, true /* native */,
43 1.0 /* ui_scale */, 1.0 /* device_scale_factor */)); 45 1.0 /* ui_scale */, 1.0 /* device_scale_factor */));
44 DisplayInfo::ManagedDisplayModeList modes(1, mode); 46 ui::ManagedDisplayInfo::ManagedDisplayModeList modes(1, mode);
45 display.SetManagedDisplayModes(modes); 47 display.SetManagedDisplayModes(modes);
46 displays_.push_back(display); 48 displays_.push_back(display);
47 } 49 }
48 50
49 // Display without native mode. Must not be matched to any touch screen. 51 // Display without native mode. Must not be matched to any touch screen.
50 { 52 {
51 DisplayInfo display(3, "3", false); 53 ui::ManagedDisplayInfo display(3, "3", false);
52 displays_.push_back(display); 54 displays_.push_back(display);
53 } 55 }
54 56
55 { 57 {
56 DisplayInfo display(4, "4", false); 58 ui::ManagedDisplayInfo display(4, "4", false);
57 59
58 scoped_refptr<ManagedDisplayMode> mode(new ManagedDisplayMode( 60 scoped_refptr<ui::ManagedDisplayMode> mode(new ui::ManagedDisplayMode(
59 gfx::Size(1024, 768), 60.0, false /* interlaced */, 61 gfx::Size(1024, 768), 60.0, false /* interlaced */,
60 /* native */ true, 1.0 /* ui_scale */, 62 /* native */ true, 1.0 /* ui_scale */,
61 1.0 /* device_scale_factor */)); 63 1.0 /* device_scale_factor */));
62 DisplayInfo::ManagedDisplayModeList modes(1, mode); 64 ui::ManagedDisplayInfo::ManagedDisplayModeList modes(1, mode);
63 display.SetManagedDisplayModes(modes); 65 display.SetManagedDisplayModes(modes);
64 displays_.push_back(display); 66 displays_.push_back(display);
65 } 67 }
66 } 68 }
67 69
68 void TearDown() override { 70 void TearDown() override {
69 displays_.clear(); 71 displays_.clear();
70 test::AshTestBase::TearDown(); 72 test::AshTestBase::TearDown();
71 } 73 }
72 74
73 protected: 75 protected:
74 std::vector<DisplayInfo> displays_; 76 DisplayInfoList displays_;
75 77
76 private: 78 private:
77 DISALLOW_COPY_AND_ASSIGN(TouchscreenUtilTest); 79 DISALLOW_COPY_AND_ASSIGN(TouchscreenUtilTest);
78 }; 80 };
79 81
80 TEST_F(TouchscreenUtilTest, NoTouchscreens) { 82 TEST_F(TouchscreenUtilTest, NoTouchscreens) {
81 std::vector<ui::TouchscreenDevice> devices; 83 std::vector<ui::TouchscreenDevice> devices;
82 84
83 test::ScopedSetInternalDisplayId set_internal(displays_[0].id()); 85 test::ScopedSetInternalDisplayId set_internal(displays_[0].id());
84 AssociateTouchscreens(&displays_, devices); 86 AssociateTouchscreens(&displays_, devices);
85 87
86 for (size_t i = 0; i < displays_.size(); ++i) 88 for (size_t i = 0; i < displays_.size(); ++i)
87 EXPECT_EQ(0u, displays_[i].input_devices().size()); 89 EXPECT_EQ(0u, displays_[i].input_devices().size());
88 } 90 }
89 91
90 // Verify that if there are a lot of touchscreens, they will all get associated 92 // Verify that if there are a lot of touchscreens, they will all get associated
91 // with a display. 93 // with a display.
92 TEST_F(TouchscreenUtilTest, ManyTouchscreens) { 94 TEST_F(TouchscreenUtilTest, ManyTouchscreens) {
93 std::vector<ui::TouchscreenDevice> devices; 95 std::vector<ui::TouchscreenDevice> devices;
94 for (int i = 0; i < 5; ++i) { 96 for (int i = 0; i < 5; ++i) {
95 devices.push_back( 97 devices.push_back(
96 ui::TouchscreenDevice(i, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "", 98 ui::TouchscreenDevice(i, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "",
97 gfx::Size(256, 256), 0)); 99 gfx::Size(256, 256), 0));
98 } 100 }
99 101
100 std::vector<DisplayInfo> displays; 102 DisplayInfoList displays;
101 displays.push_back(displays_[3]); 103 displays.push_back(displays_[3]);
102 104
103 test::ScopedSetInternalDisplayId set_internal(displays_[0].id()); 105 test::ScopedSetInternalDisplayId set_internal(displays_[0].id());
104 AssociateTouchscreens(&displays, devices); 106 AssociateTouchscreens(&displays, devices);
105 107
106 for (int i = 0; i < 5; ++i) 108 for (int i = 0; i < 5; ++i)
107 EXPECT_EQ(i, displays[0].input_devices()[i]); 109 EXPECT_EQ(i, displays[0].input_devices()[i]);
108 } 110 }
109 111
110 TEST_F(TouchscreenUtilTest, OneToOneMapping) { 112 TEST_F(TouchscreenUtilTest, OneToOneMapping) {
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 167
166 TEST_F(TouchscreenUtilTest, MapWhenSizesDoNotMatch) { 168 TEST_F(TouchscreenUtilTest, MapWhenSizesDoNotMatch) {
167 std::vector<ui::TouchscreenDevice> devices; 169 std::vector<ui::TouchscreenDevice> devices;
168 devices.push_back( 170 devices.push_back(
169 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "1", 171 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "1",
170 gfx::Size(1022, 768), 0)); 172 gfx::Size(1022, 768), 0));
171 devices.push_back( 173 devices.push_back(
172 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "2", 174 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "2",
173 gfx::Size(802, 600), 0)); 175 gfx::Size(802, 600), 0));
174 176
175 std::vector<DisplayInfo> displays; 177 DisplayInfoList displays;
176 displays.push_back(displays_[0]); 178 displays.push_back(displays_[0]);
177 displays.push_back(displays_[1]); 179 displays.push_back(displays_[1]);
178 180
179 test::ScopedSetInternalDisplayId set_internal(displays[0].id()); 181 test::ScopedSetInternalDisplayId set_internal(displays[0].id());
180 AssociateTouchscreens(&displays, devices); 182 AssociateTouchscreens(&displays, devices);
181 183
182 EXPECT_EQ(0u, displays[0].input_devices().size()); 184 EXPECT_EQ(0u, displays[0].input_devices().size());
183 EXPECT_EQ(2u, displays[1].input_devices().size()); 185 EXPECT_EQ(2u, displays[1].input_devices().size());
184 EXPECT_EQ(1, displays[1].input_devices()[0]); 186 EXPECT_EQ(1, displays[1].input_devices()[0]);
185 EXPECT_EQ(2, displays[1].input_devices()[1]); 187 EXPECT_EQ(2, displays[1].input_devices()[1]);
186 } 188 }
187 189
188 TEST_F(TouchscreenUtilTest, MapInternalTouchscreen) { 190 TEST_F(TouchscreenUtilTest, MapInternalTouchscreen) {
189 std::vector<ui::TouchscreenDevice> devices; 191 std::vector<ui::TouchscreenDevice> devices;
190 devices.push_back( 192 devices.push_back(
191 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "1", 193 ui::TouchscreenDevice(1, ui::InputDeviceType::INPUT_DEVICE_EXTERNAL, "1",
192 gfx::Size(1920, 1080), 0)); 194 gfx::Size(1920, 1080), 0));
193 devices.push_back( 195 devices.push_back(
194 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "2", 196 ui::TouchscreenDevice(2, ui::InputDeviceType::INPUT_DEVICE_INTERNAL, "2",
195 gfx::Size(9999, 888), 0)); 197 gfx::Size(9999, 888), 0));
196 198
197 std::vector<DisplayInfo> displays; 199 DisplayInfoList displays;
198 displays.push_back(displays_[0]); 200 displays.push_back(displays_[0]);
199 displays.push_back(displays_[1]); 201 displays.push_back(displays_[1]);
200 202
201 test::ScopedSetInternalDisplayId set_internal(displays[0].id()); 203 test::ScopedSetInternalDisplayId set_internal(displays[0].id());
202 AssociateTouchscreens(&displays, devices); 204 AssociateTouchscreens(&displays, devices);
203 205
204 // Internal touchscreen is always mapped to internal display. 206 // Internal touchscreen is always mapped to internal display.
205 EXPECT_EQ(1u, displays[0].input_devices().size()); 207 EXPECT_EQ(1u, displays[0].input_devices().size());
206 EXPECT_EQ(2, displays[0].input_devices()[0]); 208 EXPECT_EQ(2, displays[0].input_devices()[0]);
207 EXPECT_EQ(1u, displays[1].input_devices().size()); 209 EXPECT_EQ(1u, displays[1].input_devices().size());
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 AssociateTouchscreens(&displays_, devices); 266 AssociateTouchscreens(&displays_, devices);
265 267
266 EXPECT_EQ(1u, displays_[0].input_devices().size()); 268 EXPECT_EQ(1u, displays_[0].input_devices().size());
267 EXPECT_EQ(1, displays_[0].input_devices()[0]); 269 EXPECT_EQ(1, displays_[0].input_devices()[0]);
268 EXPECT_EQ(0u, displays_[1].input_devices().size()); 270 EXPECT_EQ(0u, displays_[1].input_devices().size());
269 EXPECT_EQ(0u, displays_[2].input_devices().size()); 271 EXPECT_EQ(0u, displays_[2].input_devices().size());
270 EXPECT_EQ(0u, displays_[3].input_devices().size()); 272 EXPECT_EQ(0u, displays_[3].input_devices().size());
271 } 273 }
272 274
273 } // namespace ash 275 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698