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

Side by Side Diff: ui/display/chromeos/touchscreen_delegate_impl_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: Remove TouchscreenDelegate references from display_unittests 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 "base/memory/scoped_ptr.h"
8 #include "base/memory/scoped_vector.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/display/chromeos/display_configurator.h"
11 #include "ui/display/chromeos/test/test_display_snapshot.h"
12 #include "ui/display/chromeos/touchscreen_delegate_impl.h"
13 #include "ui/events/device_data_manager.h"
14 #include "ui/events/device_hotplug_event_observer.h"
15
16 namespace ui {
17
18 class TouchscreenDelegateImplTest : public testing::Test {
19 public:
20 TouchscreenDelegateImplTest() {
21 DeviceDataManager::CreateInstance();
22 device_delegate_ = DeviceDataManager::GetInstance();
23 }
24 virtual ~TouchscreenDelegateImplTest() {}
25
26 virtual void SetUp() OVERRIDE {
27 touchscreen_delegate_.reset(new TouchscreenDelegateImpl());
28
29 // Internal display will always match to internal touchscreen. If internal
30 // touchscreen can't be detected, it is then associated to a touch screen
31 // with matching size.
32 TestDisplaySnapshot* snapshot = new TestDisplaySnapshot();
33 DisplayMode* mode = new DisplayMode(gfx::Size(1920, 1080), false, 60.0);
34 snapshot->set_type(DISPLAY_CONNECTION_TYPE_INTERNAL);
35 snapshot->set_modes(std::vector<const DisplayMode*>(1, mode));
36 snapshot->set_native_mode(mode);
37 displays_.push_back(snapshot);
38
39 snapshot = new TestDisplaySnapshot();
40 mode = new DisplayMode(gfx::Size(800, 600), false, 60.0);
41 snapshot->set_modes(std::vector<const DisplayMode*>(1, mode));
42 snapshot->set_native_mode(mode);
43 displays_.push_back(snapshot);
44
45 // Display without native mode. Must not be matched to any touch screen.
46 displays_.push_back(new TestDisplaySnapshot());
47
48 snapshot = new TestDisplaySnapshot();
49 mode = new DisplayMode(gfx::Size(1024, 768), false, 60.0);
50 snapshot->set_modes(std::vector<const DisplayMode*>(1, mode));
51 snapshot->set_native_mode(mode);
52 displays_.push_back(snapshot);
53 }
54
55 virtual void TearDown() OVERRIDE {
56 // The snapshots do not own the modes, so we need to delete them.
57 for (size_t i = 0; i < displays_.size(); ++i) {
58 if (displays_[i]->native_mode())
59 delete displays_[i]->native_mode();
60 }
61
62 displays_.clear();
63 device_delegate_->OnTouchscreenDevicesUpdated(
64 std::vector<TouchscreenDevice>());
65 }
66
67 std::vector<DisplayConfigurator::DisplayState> GetDisplayStates() {
68 std::vector<DisplayConfigurator::DisplayState> states(displays_.size());
69 for (size_t i = 0; i < displays_.size(); ++i)
70 states[i].display = displays_[i];
71
72 return states;
73 }
74
75 protected:
76 scoped_ptr<TouchscreenDelegateImpl> touchscreen_delegate_;
77 ScopedVector<DisplaySnapshot> displays_;
78 DeviceHotplugEventObserver* device_delegate_; // Not owned.
79
80 private:
81 DISALLOW_COPY_AND_ASSIGN(TouchscreenDelegateImplTest);
82 };
83
84 TEST_F(TouchscreenDelegateImplTest, NoTouchscreens) {
85 std::vector<DisplayConfigurator::DisplayState> display_states =
86 GetDisplayStates();
87 touchscreen_delegate_->AssociateTouchscreens(&display_states);
88
89 for (size_t i = 0; i < display_states.size(); ++i)
90 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[i].touch_device_id);
91 }
92
93 TEST_F(TouchscreenDelegateImplTest, OneToOneMapping) {
94 std::vector<TouchscreenDevice> devices;
95 devices.push_back(TouchscreenDevice(1, gfx::Size(800, 600), false));
96 devices.push_back(TouchscreenDevice(2, gfx::Size(1024, 768), false));
97 device_delegate_->OnTouchscreenDevicesUpdated(devices);
98
99 std::vector<DisplayConfigurator::DisplayState> display_states =
100 GetDisplayStates();
101 touchscreen_delegate_->AssociateTouchscreens(&display_states);
102
103 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id);
104 EXPECT_EQ(1, display_states[1].touch_device_id);
105 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id);
106 EXPECT_EQ(2, display_states[3].touch_device_id);
107 }
108
109 TEST_F(TouchscreenDelegateImplTest, MapToCorrectDisplaySize) {
110 std::vector<TouchscreenDevice> devices;
111 devices.push_back(TouchscreenDevice(2, gfx::Size(1024, 768), false));
112 device_delegate_->OnTouchscreenDevicesUpdated(devices);
113
114 std::vector<DisplayConfigurator::DisplayState> display_states =
115 GetDisplayStates();
116 touchscreen_delegate_->AssociateTouchscreens(&display_states);
117
118 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id);
119 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[1].touch_device_id);
120 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id);
121 EXPECT_EQ(2, display_states[3].touch_device_id);
122 }
123
124 TEST_F(TouchscreenDelegateImplTest, MapWhenSizeDiffersByOne) {
125 std::vector<TouchscreenDevice> devices;
126 devices.push_back(TouchscreenDevice(1, gfx::Size(801, 600), false));
127 devices.push_back(TouchscreenDevice(2, gfx::Size(1023, 768), false));
128 device_delegate_->OnTouchscreenDevicesUpdated(devices);
129
130 std::vector<DisplayConfigurator::DisplayState> display_states =
131 GetDisplayStates();
132 touchscreen_delegate_->AssociateTouchscreens(&display_states);
133
134 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id);
135 EXPECT_EQ(1, display_states[1].touch_device_id);
136 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id);
137 EXPECT_EQ(2, display_states[3].touch_device_id);
138 }
139
140 TEST_F(TouchscreenDelegateImplTest, MapWhenSizesDoNotMatch) {
141 std::vector<TouchscreenDevice> devices;
142 devices.push_back(TouchscreenDevice(1, gfx::Size(1022, 768), false));
143 devices.push_back(TouchscreenDevice(2, gfx::Size(802, 600), false));
144 device_delegate_->OnTouchscreenDevicesUpdated(devices);
145
146 std::vector<DisplayConfigurator::DisplayState> display_states =
147 GetDisplayStates();
148 touchscreen_delegate_->AssociateTouchscreens(&display_states);
149
150 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id);
151 EXPECT_EQ(1, display_states[1].touch_device_id);
152 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id);
153 EXPECT_EQ(2, display_states[3].touch_device_id);
154 }
155
156 TEST_F(TouchscreenDelegateImplTest, MapInternalTouchscreen) {
157 std::vector<TouchscreenDevice> devices;
158 devices.push_back(TouchscreenDevice(1, gfx::Size(1920, 1080), false));
159 devices.push_back(TouchscreenDevice(2, gfx::Size(9999, 888), true));
160 device_delegate_->OnTouchscreenDevicesUpdated(devices);
161
162 std::vector<DisplayConfigurator::DisplayState> display_states =
163 GetDisplayStates();
164 touchscreen_delegate_->AssociateTouchscreens(&display_states);
165
166 // Internal touchscreen is always mapped to internal display.
167 EXPECT_EQ(2, display_states[0].touch_device_id);
168 EXPECT_EQ(1, display_states[1].touch_device_id);
169 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id);
170 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[3].touch_device_id);
171 }
172
173 } // namespace ui
OLDNEW
« no previous file with comments | « ui/display/chromeos/touchscreen_delegate_impl.cc ('k') | ui/display/chromeos/x11/native_display_delegate_x11.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698