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

Side by Side Diff: ui/display/chromeos/touchscreen_delegate_impl_unittest.cc

Issue 508303002: Move touchscreen device caching to DeviceDataManager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove PlatformEventObserver 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
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 <vector> 5 #include <vector>
6 6
7 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
8 #include "base/memory/scoped_vector.h" 8 #include "base/memory/scoped_vector.h"
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 #include "ui/display/chromeos/display_configurator.h" 10 #include "ui/display/chromeos/display_configurator.h"
11 #include "ui/display/chromeos/test/test_display_snapshot.h" 11 #include "ui/display/chromeos/test/test_display_snapshot.h"
12 #include "ui/display/chromeos/touchscreen_delegate_impl.h" 12 #include "ui/display/chromeos/touchscreen_delegate_impl.h"
13 #include "ui/display/types/chromeos/touchscreen_device_manager.h" 13 #include "ui/events/device_data_manager.h"
14 #include "ui/events/device_hotplug_event_observer.h"
14 15
15 namespace ui { 16 namespace ui {
16 17
17 namespace {
18
19 class MockTouchscreenDeviceManager : public TouchscreenDeviceManager {
20 public:
21 MockTouchscreenDeviceManager() {}
22 virtual ~MockTouchscreenDeviceManager() {}
23
24 void AddDevice(const TouchscreenDevice& device) {
25 devices_.push_back(device);
26 }
27
28 // TouchscreenDeviceManager overrides:
29 virtual std::vector<TouchscreenDevice> GetDevices() OVERRIDE {
30 return devices_;
31 }
32
33 private:
34 std::vector<TouchscreenDevice> devices_;
35
36 DISALLOW_COPY_AND_ASSIGN(MockTouchscreenDeviceManager);
37 };
38
39 } // namespace
40
41 class TouchscreenDelegateImplTest : public testing::Test { 18 class TouchscreenDelegateImplTest : public testing::Test {
42 public: 19 public:
43 TouchscreenDelegateImplTest() {} 20 TouchscreenDelegateImplTest() {
21 DeviceDataManager::CreateInstance();
22 device_delegate_ = DeviceDataManager::GetInstance();
23 }
44 virtual ~TouchscreenDelegateImplTest() {} 24 virtual ~TouchscreenDelegateImplTest() {}
45 25
46 virtual void SetUp() OVERRIDE { 26 virtual void SetUp() OVERRIDE {
47 device_manager_ = new MockTouchscreenDeviceManager(); 27 touchscreen_delegate_.reset(new TouchscreenDelegateImpl());
48 delegate_.reset(new TouchscreenDelegateImpl(
49 scoped_ptr<TouchscreenDeviceManager>(device_manager_)));
50 28
51 // Internal display will always match to internal touchscreen. If internal 29 // Internal display will always match to internal touchscreen. If internal
52 // touchscreen can't be detected, it is then associated to a touch screen 30 // touchscreen can't be detected, it is then associated to a touch screen
53 // with matching size. 31 // with matching size.
54 TestDisplaySnapshot* snapshot = new TestDisplaySnapshot(); 32 TestDisplaySnapshot* snapshot = new TestDisplaySnapshot();
55 DisplayMode* mode = new DisplayMode(gfx::Size(1920, 1080), false, 60.0); 33 DisplayMode* mode = new DisplayMode(gfx::Size(1920, 1080), false, 60.0);
56 snapshot->set_type(DISPLAY_CONNECTION_TYPE_INTERNAL); 34 snapshot->set_type(DISPLAY_CONNECTION_TYPE_INTERNAL);
57 snapshot->set_modes(std::vector<const DisplayMode*>(1, mode)); 35 snapshot->set_modes(std::vector<const DisplayMode*>(1, mode));
58 snapshot->set_native_mode(mode); 36 snapshot->set_native_mode(mode);
59 displays_.push_back(snapshot); 37 displays_.push_back(snapshot);
(...skipping 15 matching lines...) Expand all
75 } 53 }
76 54
77 virtual void TearDown() OVERRIDE { 55 virtual void TearDown() OVERRIDE {
78 // The snapshots do not own the modes, so we need to delete them. 56 // The snapshots do not own the modes, so we need to delete them.
79 for (size_t i = 0; i < displays_.size(); ++i) { 57 for (size_t i = 0; i < displays_.size(); ++i) {
80 if (displays_[i]->native_mode()) 58 if (displays_[i]->native_mode())
81 delete displays_[i]->native_mode(); 59 delete displays_[i]->native_mode();
82 } 60 }
83 61
84 displays_.clear(); 62 displays_.clear();
63 device_delegate_->OnTouchscreenDevices(std::vector<TouchscreenDevice>());
85 } 64 }
86 65
87 std::vector<DisplayConfigurator::DisplayState> GetDisplayStates() { 66 std::vector<DisplayConfigurator::DisplayState> GetDisplayStates() {
88 std::vector<DisplayConfigurator::DisplayState> states(displays_.size()); 67 std::vector<DisplayConfigurator::DisplayState> states(displays_.size());
89 for (size_t i = 0; i < displays_.size(); ++i) 68 for (size_t i = 0; i < displays_.size(); ++i)
90 states[i].display = displays_[i]; 69 states[i].display = displays_[i];
91 70
92 return states; 71 return states;
93 } 72 }
94 73
95 protected: 74 protected:
96 MockTouchscreenDeviceManager* device_manager_; // Not owned. 75 scoped_ptr<TouchscreenDelegateImpl> touchscreen_delegate_;
97 scoped_ptr<TouchscreenDelegateImpl> delegate_;
98 ScopedVector<DisplaySnapshot> displays_; 76 ScopedVector<DisplaySnapshot> displays_;
77 DeviceHotplugEventObserver* device_delegate_;
Daniel Erat 2014/09/10 16:51:24 nit: add a "// Not owned." comment here
dnicoara 2014/09/10 18:05:36 Done.
99 78
100 private: 79 private:
101 DISALLOW_COPY_AND_ASSIGN(TouchscreenDelegateImplTest); 80 DISALLOW_COPY_AND_ASSIGN(TouchscreenDelegateImplTest);
102 }; 81 };
103 82
104 TEST_F(TouchscreenDelegateImplTest, NoTouchscreens) { 83 TEST_F(TouchscreenDelegateImplTest, NoTouchscreens) {
105 std::vector<DisplayConfigurator::DisplayState> display_states = 84 std::vector<DisplayConfigurator::DisplayState> display_states =
106 GetDisplayStates(); 85 GetDisplayStates();
107 delegate_->AssociateTouchscreens(&display_states); 86 touchscreen_delegate_->AssociateTouchscreens(&display_states);
108 87
109 for (size_t i = 0; i < display_states.size(); ++i) 88 for (size_t i = 0; i < display_states.size(); ++i)
110 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[i].touch_device_id); 89 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[i].touch_device_id);
111 } 90 }
112 91
113 TEST_F(TouchscreenDelegateImplTest, OneToOneMapping) { 92 TEST_F(TouchscreenDelegateImplTest, OneToOneMapping) {
114 device_manager_->AddDevice(TouchscreenDevice(1, gfx::Size(800, 600), false)); 93 std::vector<TouchscreenDevice> devices;
115 device_manager_->AddDevice(TouchscreenDevice(2, gfx::Size(1024, 768), false)); 94 devices.push_back(TouchscreenDevice(1, gfx::Size(800, 600), false));
95 devices.push_back(TouchscreenDevice(2, gfx::Size(1024, 768), false));
96 device_delegate_->OnTouchscreenDevices(devices);
116 97
117 std::vector<DisplayConfigurator::DisplayState> display_states = 98 std::vector<DisplayConfigurator::DisplayState> display_states =
118 GetDisplayStates(); 99 GetDisplayStates();
119 delegate_->AssociateTouchscreens(&display_states); 100 touchscreen_delegate_->AssociateTouchscreens(&display_states);
120 101
121 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id); 102 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id);
122 EXPECT_EQ(1, display_states[1].touch_device_id); 103 EXPECT_EQ(1, display_states[1].touch_device_id);
123 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id); 104 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id);
124 EXPECT_EQ(2, display_states[3].touch_device_id); 105 EXPECT_EQ(2, display_states[3].touch_device_id);
125 } 106 }
126 107
127 TEST_F(TouchscreenDelegateImplTest, MapToCorrectDisplaySize) { 108 TEST_F(TouchscreenDelegateImplTest, MapToCorrectDisplaySize) {
128 device_manager_->AddDevice(TouchscreenDevice(2, gfx::Size(1024, 768), false)); 109 std::vector<TouchscreenDevice> devices;
110 devices.push_back(TouchscreenDevice(2, gfx::Size(1024, 768), false));
111 device_delegate_->OnTouchscreenDevices(devices);
129 112
130 std::vector<DisplayConfigurator::DisplayState> display_states = 113 std::vector<DisplayConfigurator::DisplayState> display_states =
131 GetDisplayStates(); 114 GetDisplayStates();
132 delegate_->AssociateTouchscreens(&display_states); 115 touchscreen_delegate_->AssociateTouchscreens(&display_states);
133 116
134 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id); 117 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id);
135 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[1].touch_device_id); 118 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[1].touch_device_id);
136 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id); 119 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id);
137 EXPECT_EQ(2, display_states[3].touch_device_id); 120 EXPECT_EQ(2, display_states[3].touch_device_id);
138 } 121 }
139 122
140 TEST_F(TouchscreenDelegateImplTest, MapWhenSizeDiffersByOne) { 123 TEST_F(TouchscreenDelegateImplTest, MapWhenSizeDiffersByOne) {
141 device_manager_->AddDevice(TouchscreenDevice(1, gfx::Size(801, 600), false)); 124 std::vector<TouchscreenDevice> devices;
142 device_manager_->AddDevice(TouchscreenDevice(2, gfx::Size(1023, 768), false)); 125 devices.push_back(TouchscreenDevice(1, gfx::Size(801, 600), false));
126 devices.push_back(TouchscreenDevice(2, gfx::Size(1023, 768), false));
127 device_delegate_->OnTouchscreenDevices(devices);
143 128
144 std::vector<DisplayConfigurator::DisplayState> display_states = 129 std::vector<DisplayConfigurator::DisplayState> display_states =
145 GetDisplayStates(); 130 GetDisplayStates();
146 delegate_->AssociateTouchscreens(&display_states); 131 touchscreen_delegate_->AssociateTouchscreens(&display_states);
147 132
148 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id); 133 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id);
149 EXPECT_EQ(1, display_states[1].touch_device_id); 134 EXPECT_EQ(1, display_states[1].touch_device_id);
150 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id); 135 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id);
151 EXPECT_EQ(2, display_states[3].touch_device_id); 136 EXPECT_EQ(2, display_states[3].touch_device_id);
152 } 137 }
153 138
154 TEST_F(TouchscreenDelegateImplTest, MapWhenSizesDoNotMatch) { 139 TEST_F(TouchscreenDelegateImplTest, MapWhenSizesDoNotMatch) {
155 device_manager_->AddDevice(TouchscreenDevice(1, gfx::Size(1022, 768), false)); 140 std::vector<TouchscreenDevice> devices;
156 device_manager_->AddDevice(TouchscreenDevice(2, gfx::Size(802, 600), false)); 141 devices.push_back(TouchscreenDevice(1, gfx::Size(1022, 768), false));
142 devices.push_back(TouchscreenDevice(2, gfx::Size(802, 600), false));
143 device_delegate_->OnTouchscreenDevices(devices);
157 144
158 std::vector<DisplayConfigurator::DisplayState> display_states = 145 std::vector<DisplayConfigurator::DisplayState> display_states =
159 GetDisplayStates(); 146 GetDisplayStates();
160 delegate_->AssociateTouchscreens(&display_states); 147 touchscreen_delegate_->AssociateTouchscreens(&display_states);
161 148
162 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id); 149 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[0].touch_device_id);
163 EXPECT_EQ(1, display_states[1].touch_device_id); 150 EXPECT_EQ(1, display_states[1].touch_device_id);
164 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id); 151 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id);
165 EXPECT_EQ(2, display_states[3].touch_device_id); 152 EXPECT_EQ(2, display_states[3].touch_device_id);
166 } 153 }
167 154
168 TEST_F(TouchscreenDelegateImplTest, MapInternalTouchscreen) { 155 TEST_F(TouchscreenDelegateImplTest, MapInternalTouchscreen) {
169 device_manager_->AddDevice( 156 std::vector<TouchscreenDevice> devices;
170 TouchscreenDevice(1, gfx::Size(1920, 1080), false)); 157 devices.push_back(TouchscreenDevice(1, gfx::Size(1920, 1080), false));
171 device_manager_->AddDevice(TouchscreenDevice(2, gfx::Size(9999, 888), true)); 158 devices.push_back(TouchscreenDevice(2, gfx::Size(9999, 888), true));
159 device_delegate_->OnTouchscreenDevices(devices);
172 160
173 std::vector<DisplayConfigurator::DisplayState> display_states = 161 std::vector<DisplayConfigurator::DisplayState> display_states =
174 GetDisplayStates(); 162 GetDisplayStates();
175 delegate_->AssociateTouchscreens(&display_states); 163 touchscreen_delegate_->AssociateTouchscreens(&display_states);
176 164
177 // Internal touchscreen is always mapped to internal display. 165 // Internal touchscreen is always mapped to internal display.
178 EXPECT_EQ(2, display_states[0].touch_device_id); 166 EXPECT_EQ(2, display_states[0].touch_device_id);
179 EXPECT_EQ(1, display_states[1].touch_device_id); 167 EXPECT_EQ(1, display_states[1].touch_device_id);
180 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id); 168 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[2].touch_device_id);
181 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[3].touch_device_id); 169 EXPECT_EQ(TouchscreenDevice::kInvalidId, display_states[3].touch_device_id);
182 } 170 }
183 171
184 } // namespace ui 172 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698