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

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

Issue 336863002: Moving input device hotplug event processing outside of ui/display (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include <vector>
6
7 #include "ash/display/display_info.h"
8 #include "ash/touch/touchscreen_util.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/events/device_data_manager.h"
11 #include "ui/events/device_hotplug_event_observer.h"
12
13 namespace ash {
14
15 class TouchscreenUtilTest : public testing::Test {
16 public:
17 TouchscreenUtilTest() {
18 ui::DeviceDataManager::CreateInstance();
19 device_delegate_ = ui::DeviceDataManager::GetInstance();
20 }
21 virtual ~TouchscreenUtilTest() {}
22
23 virtual void SetUp() OVERRIDE {
24 // Internal display will always match to internal touchscreen. If internal
25 // touchscreen can't be detected, it is then associated to a touch screen
26 // with matching size.
27 {
28 DisplayInfo display(1, std::string(), false);
29 DisplayMode mode(gfx::Size(1920, 1080), 60.0, false, true);
30 mode.native = true;
31 std::vector<DisplayMode> modes(1, mode);
32 display.set_display_modes(modes);
33 displays_.push_back(display);
34 gfx::Display::SetInternalDisplayId(1);
35 }
36
37 {
38 DisplayInfo display(2, std::string(), false);
39 DisplayMode mode(gfx::Size(800, 600), 60.0, false, true);
40 mode.native = true;
41 std::vector<DisplayMode> modes(1, mode);
42 display.set_display_modes(modes);
43 displays_.push_back(display);
44 }
45
46 // Display without native mode. Must not be matched to any touch screen.
47 {
48 DisplayInfo display(3, std::string(), false);
49 displays_.push_back(display);
50 }
51
52 {
53 DisplayInfo display(4, std::string(), false);
54 DisplayMode mode(gfx::Size(1024, 768), 60.0, false, true);
55 mode.native = true;
56 std::vector<DisplayMode> modes(1, mode);
57 display.set_display_modes(modes);
58 displays_.push_back(display);
59 }
60 }
61
62 virtual void TearDown() OVERRIDE {
63 displays_.clear();
64 device_delegate_->OnTouchscreenDevices(
65 std::vector<ui::TouchscreenDevice>());
66 }
67
68 protected:
69 std::vector<DisplayInfo> displays_;
70 ui::DeviceHotplugEventObserver* device_delegate_;
71
72 private:
73 DISALLOW_COPY_AND_ASSIGN(TouchscreenUtilTest);
74 };
75
76 TEST_F(TouchscreenUtilTest, NoTouchscreens) {
77 AssociateTouchscreens(&displays_);
78
79 for (size_t i = 0; i < displays_.size(); ++i)
80 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId,
81 displays_[i].touch_device_id());
82 }
83
84 TEST_F(TouchscreenUtilTest, OneToOneMapping) {
85 std::vector<ui::TouchscreenDevice> devices;
86 devices.push_back(ui::TouchscreenDevice(1, gfx::Size(800, 600), false));
87 devices.push_back(ui::TouchscreenDevice(2, gfx::Size(1024, 768), false));
88 device_delegate_->OnTouchscreenDevices(devices);
89
90 AssociateTouchscreens(&displays_);
91
92 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId, displays_[0].touch_device_id());
93 EXPECT_EQ(1, displays_[1].touch_device_id());
94 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId, displays_[2].touch_device_id());
95 EXPECT_EQ(2, displays_[3].touch_device_id());
96 }
97
98 TEST_F(TouchscreenUtilTest, MapToCorrectDisplaySize) {
99 std::vector<ui::TouchscreenDevice> devices;
100 devices.push_back(ui::TouchscreenDevice(2, gfx::Size(1024, 768), false));
101 device_delegate_->OnTouchscreenDevices(devices);
102
103 AssociateTouchscreens(&displays_);
104
105 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId, displays_[0].touch_device_id());
106 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId, displays_[1].touch_device_id());
107 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId, displays_[2].touch_device_id());
108 EXPECT_EQ(2, displays_[3].touch_device_id());
109 }
110
111 TEST_F(TouchscreenUtilTest, MapWhenSizeDiffersByOne) {
112 std::vector<ui::TouchscreenDevice> devices;
113 devices.push_back(ui::TouchscreenDevice(1, gfx::Size(801, 600), false));
114 devices.push_back(ui::TouchscreenDevice(2, gfx::Size(1023, 768), false));
115 device_delegate_->OnTouchscreenDevices(devices);
116
117 AssociateTouchscreens(&displays_);
118
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());
123 }
124
125 TEST_F(TouchscreenUtilTest, MapWhenSizesDoNotMatch) {
126 std::vector<ui::TouchscreenDevice> devices;
127 devices.push_back(ui::TouchscreenDevice(1, gfx::Size(1022, 768), false));
128 devices.push_back(ui::TouchscreenDevice(2, gfx::Size(802, 600), false));
129 device_delegate_->OnTouchscreenDevices(devices);
130
131 AssociateTouchscreens(&displays_);
132
133 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId, displays_[0].touch_device_id());
134 EXPECT_EQ(1, displays_[1].touch_device_id());
135 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId, displays_[2].touch_device_id());
136 EXPECT_EQ(2, displays_[3].touch_device_id());
137 }
138
139 TEST_F(TouchscreenUtilTest, MapInternalTouchscreen) {
140 std::vector<ui::TouchscreenDevice> devices;
141 devices.push_back(ui::TouchscreenDevice(1, gfx::Size(1920, 1080), false));
142 devices.push_back(ui::TouchscreenDevice(2, gfx::Size(9999, 888), true));
143 device_delegate_->OnTouchscreenDevices(devices);
144
145 AssociateTouchscreens(&displays_);
146
147 // Internal touchscreen is always mapped to internal display.
148 EXPECT_EQ(2, displays_[0].touch_device_id());
149 EXPECT_EQ(1, displays_[1].touch_device_id());
150 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId, displays_[2].touch_device_id());
151 EXPECT_EQ(ui::TouchscreenDevice::kInvalidId, displays_[3].touch_device_id());
152 }
153
154 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698