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

Side by Side Diff: ui/display/chromeos/x11/native_display_event_dispatcher_x11_unittest.cc

Issue 187073002: Refactoring display configuration state to allow generic state objects (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 6 years, 9 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
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 <X11/extensions/Xrandr.h> 5 #include <X11/extensions/Xrandr.h>
6 6
7 #undef Bool 7 #undef Bool
8 #undef None 8 #undef None
9 9
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/display/chromeos/x11/display_mode_x11.h"
12 #include "ui/display/chromeos/x11/display_snapshot_x11.h"
11 #include "ui/display/chromeos/x11/native_display_delegate_x11.h" 13 #include "ui/display/chromeos/x11/native_display_delegate_x11.h"
12 #include "ui/display/chromeos/x11/native_display_event_dispatcher_x11.h" 14 #include "ui/display/chromeos/x11/native_display_event_dispatcher_x11.h"
13 15
14 namespace ui { 16 namespace ui {
15 17
16 namespace { 18 namespace {
17 19
18 OutputConfigurator::OutputSnapshot CreateOutput(RROutput output, 20 const DisplayModeX11 kDefaultDisplayMode(gfx::Size(1, 1), false, 60.0f, 20);
19 RRCrtc crtc, 21
20 RRMode mode) { 22 DisplaySnapshotX11* CreateOutput(RROutput output, RRCrtc crtc) {
21 OutputConfigurator::OutputSnapshot snapshot; 23 DisplaySnapshotX11* snapshot = new DisplaySnapshotX11(
22 snapshot.output = output; 24 0,
23 snapshot.crtc = crtc; 25 false,
24 snapshot.current_mode = mode; 26 gfx::Point(0, 0),
27 gfx::Size(0, 0),
28 OUTPUT_TYPE_UNKNOWN,
29 false,
30 std::vector<const DisplayMode*>(1, &kDefaultDisplayMode),
31 &kDefaultDisplayMode,
32 NULL,
33 output,
34 crtc,
35 0);
25 36
26 return snapshot; 37 return snapshot;
27 } 38 }
28 39
29 class TestHelperDelegate : public NativeDisplayDelegateX11::HelperDelegate { 40 class TestHelperDelegate : public NativeDisplayDelegateX11::HelperDelegate {
30 public: 41 public:
31 TestHelperDelegate(); 42 TestHelperDelegate();
32 virtual ~TestHelperDelegate(); 43 virtual ~TestHelperDelegate();
33 44
34 int num_calls_update_xrandr_config() const { 45 int num_calls_update_xrandr_config() const {
35 return num_calls_update_xrandr_config_; 46 return num_calls_update_xrandr_config_;
36 } 47 }
37 48
38 int num_calls_notify_observers() const { return num_calls_notify_observers_; } 49 int num_calls_notify_observers() const { return num_calls_notify_observers_; }
39 50
40 void set_cached_outputs( 51 void set_cached_outputs(const std::vector<DisplaySnapshot*>& outputs) {
41 const std::vector<OutputConfigurator::OutputSnapshot>& outputs) {
42 cached_outputs_ = outputs; 52 cached_outputs_ = outputs;
43 } 53 }
44 54
45 // NativeDisplayDelegateX11::HelperDelegate overrides: 55 // NativeDisplayDelegateX11::HelperDelegate overrides:
46 virtual void UpdateXRandRConfiguration(const base::NativeEvent& event) 56 virtual void UpdateXRandRConfiguration(const base::NativeEvent& event)
47 OVERRIDE; 57 OVERRIDE;
48 virtual const std::vector<OutputConfigurator::OutputSnapshot>& 58 virtual const std::vector<DisplaySnapshot*>& GetCachedOutputs() const
49 GetCachedOutputs() const OVERRIDE; 59 OVERRIDE;
50 virtual void NotifyDisplayObservers() OVERRIDE; 60 virtual void NotifyDisplayObservers() OVERRIDE;
51 61
52 private: 62 private:
53 int num_calls_update_xrandr_config_; 63 int num_calls_update_xrandr_config_;
54 int num_calls_notify_observers_; 64 int num_calls_notify_observers_;
55 65
56 std::vector<OutputConfigurator::OutputSnapshot> cached_outputs_; 66 std::vector<DisplaySnapshot*> cached_outputs_;
57 67
58 DISALLOW_COPY_AND_ASSIGN(TestHelperDelegate); 68 DISALLOW_COPY_AND_ASSIGN(TestHelperDelegate);
59 }; 69 };
60 70
61 TestHelperDelegate::TestHelperDelegate() 71 TestHelperDelegate::TestHelperDelegate()
62 : num_calls_update_xrandr_config_(0), num_calls_notify_observers_(0) {} 72 : num_calls_update_xrandr_config_(0), num_calls_notify_observers_(0) {}
63 73
64 TestHelperDelegate::~TestHelperDelegate() {} 74 TestHelperDelegate::~TestHelperDelegate() {}
65 75
66 void TestHelperDelegate::UpdateXRandRConfiguration( 76 void TestHelperDelegate::UpdateXRandRConfiguration(
67 const base::NativeEvent& event) { 77 const base::NativeEvent& event) {
68 ++num_calls_update_xrandr_config_; 78 ++num_calls_update_xrandr_config_;
69 } 79 }
70 80
71 const std::vector<OutputConfigurator::OutputSnapshot>& 81 const std::vector<DisplaySnapshot*>& TestHelperDelegate::GetCachedOutputs()
72 TestHelperDelegate::GetCachedOutputs() const { 82 const {
73 return cached_outputs_; 83 return cached_outputs_;
74 } 84 }
75 85
76 void TestHelperDelegate::NotifyDisplayObservers() { 86 void TestHelperDelegate::NotifyDisplayObservers() {
77 ++num_calls_notify_observers_; 87 ++num_calls_notify_observers_;
78 } 88 }
79 89
80 //////////////////////////////////////////////////////////////////////////////// 90 ////////////////////////////////////////////////////////////////////////////////
81 // NativeDisplayEventDispatcherX11Test 91 // NativeDisplayEventDispatcherX11Test
82 92
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationOnFirstEvent) { 152 TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationOnFirstEvent) {
143 DispatchOutputChangeEvent(1, 10, 20, true); 153 DispatchOutputChangeEvent(1, 10, 20, true);
144 EXPECT_EQ(0, helper_delegate_->num_calls_update_xrandr_config()); 154 EXPECT_EQ(0, helper_delegate_->num_calls_update_xrandr_config());
145 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); 155 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers());
146 } 156 }
147 157
148 TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationAfterSecondEvent) { 158 TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationAfterSecondEvent) {
149 DispatchOutputChangeEvent(1, 10, 20, true); 159 DispatchOutputChangeEvent(1, 10, 20, true);
150 160
151 // Simulate addition of the first output to the cached output list. 161 // Simulate addition of the first output to the cached output list.
152 std::vector<OutputConfigurator::OutputSnapshot> outputs; 162 ScopedVector<DisplaySnapshot> outputs;
153 outputs.push_back(CreateOutput(1, 10, 20)); 163 outputs.push_back(CreateOutput(1, 10));
154 helper_delegate_->set_cached_outputs(outputs); 164 helper_delegate_->set_cached_outputs(outputs.get());
155 165
156 DispatchOutputChangeEvent(2, 11, 20, true); 166 DispatchOutputChangeEvent(2, 11, 20, true);
157 EXPECT_EQ(2, helper_delegate_->num_calls_notify_observers()); 167 EXPECT_EQ(2, helper_delegate_->num_calls_notify_observers());
158 } 168 }
159 169
160 TEST_F(NativeDisplayEventDispatcherX11Test, AvoidNotificationOnDuplicateEvent) { 170 TEST_F(NativeDisplayEventDispatcherX11Test, AvoidNotificationOnDuplicateEvent) {
161 std::vector<OutputConfigurator::OutputSnapshot> outputs; 171 ScopedVector<DisplaySnapshot> outputs;
162 outputs.push_back(CreateOutput(1, 10, 20)); 172 outputs.push_back(CreateOutput(1, 10));
163 helper_delegate_->set_cached_outputs(outputs); 173 helper_delegate_->set_cached_outputs(outputs.get());
164 174
165 DispatchOutputChangeEvent(1, 10, 20, true); 175 DispatchOutputChangeEvent(1, 10, 20, true);
166 EXPECT_EQ(0, helper_delegate_->num_calls_notify_observers()); 176 EXPECT_EQ(0, helper_delegate_->num_calls_notify_observers());
167 } 177 }
168 178
169 TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationOnDisconnect) { 179 TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationOnDisconnect) {
170 std::vector<OutputConfigurator::OutputSnapshot> outputs; 180 ScopedVector<DisplaySnapshot> outputs;
171 outputs.push_back(CreateOutput(1, 10, 20)); 181 outputs.push_back(CreateOutput(1, 10));
172 helper_delegate_->set_cached_outputs(outputs); 182 helper_delegate_->set_cached_outputs(outputs.get());
173 183
174 DispatchOutputChangeEvent(1, 10, 20, false); 184 DispatchOutputChangeEvent(1, 10, 20, false);
175 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); 185 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers());
176 } 186 }
177 187
178 TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationOnModeChange) { 188 TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationOnModeChange) {
179 std::vector<OutputConfigurator::OutputSnapshot> outputs; 189 ScopedVector<DisplaySnapshot> outputs;
180 outputs.push_back(CreateOutput(1, 10, 20)); 190 outputs.push_back(CreateOutput(1, 10));
181 helper_delegate_->set_cached_outputs(outputs); 191 helper_delegate_->set_cached_outputs(outputs.get());
182 192
183 DispatchOutputChangeEvent(1, 10, 21, true); 193 DispatchOutputChangeEvent(1, 10, 21, true);
184 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); 194 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers());
185 } 195 }
186 196
187 TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationOnSecondOutput) { 197 TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationOnSecondOutput) {
188 std::vector<OutputConfigurator::OutputSnapshot> outputs; 198 ScopedVector<DisplaySnapshot> outputs;
189 outputs.push_back(CreateOutput(1, 10, 20)); 199 outputs.push_back(CreateOutput(1, 10));
190 helper_delegate_->set_cached_outputs(outputs); 200 helper_delegate_->set_cached_outputs(outputs.get());
191 201
192 DispatchOutputChangeEvent(2, 11, 20, true); 202 DispatchOutputChangeEvent(2, 11, 20, true);
193 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); 203 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers());
194 } 204 }
195 205
196 TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationOnDifferentCrtc) { 206 TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationOnDifferentCrtc) {
197 std::vector<OutputConfigurator::OutputSnapshot> outputs; 207 ScopedVector<DisplaySnapshot> outputs;
198 outputs.push_back(CreateOutput(1, 10, 20)); 208 outputs.push_back(CreateOutput(1, 10));
199 helper_delegate_->set_cached_outputs(outputs); 209 helper_delegate_->set_cached_outputs(outputs.get());
200 210
201 DispatchOutputChangeEvent(1, 11, 20, true); 211 DispatchOutputChangeEvent(1, 11, 20, true);
202 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); 212 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers());
203 } 213 }
204 214
205 TEST_F(NativeDisplayEventDispatcherX11Test, 215 TEST_F(NativeDisplayEventDispatcherX11Test,
206 CheckNotificationOnSecondOutputDisconnect) { 216 CheckNotificationOnSecondOutputDisconnect) {
207 std::vector<OutputConfigurator::OutputSnapshot> outputs; 217 ScopedVector<DisplaySnapshot> outputs;
208 outputs.push_back(CreateOutput(1, 10, 20)); 218 outputs.push_back(CreateOutput(1, 10));
209 outputs.push_back(CreateOutput(2, 11, 20)); 219 outputs.push_back(CreateOutput(2, 11));
210 helper_delegate_->set_cached_outputs(outputs); 220 helper_delegate_->set_cached_outputs(outputs.get());
211 221
212 DispatchOutputChangeEvent(2, 11, 20, false); 222 DispatchOutputChangeEvent(2, 11, 20, false);
213 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); 223 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers());
214 } 224 }
215 225
216 TEST_F(NativeDisplayEventDispatcherX11Test, 226 TEST_F(NativeDisplayEventDispatcherX11Test,
217 AvoidDuplicateNotificationOnSecondOutputDisconnect) { 227 AvoidDuplicateNotificationOnSecondOutputDisconnect) {
218 std::vector<OutputConfigurator::OutputSnapshot> outputs; 228 ScopedVector<DisplaySnapshot> outputs;
219 outputs.push_back(CreateOutput(1, 10, 20)); 229 outputs.push_back(CreateOutput(1, 10));
220 outputs.push_back(CreateOutput(2, 11, 20)); 230 outputs.push_back(CreateOutput(2, 11));
221 helper_delegate_->set_cached_outputs(outputs); 231 helper_delegate_->set_cached_outputs(outputs.get());
222 232
223 DispatchOutputChangeEvent(2, 11, 20, false); 233 DispatchOutputChangeEvent(2, 11, 20, false);
224 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); 234 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers());
225 235
226 // Simulate removal of second output from cached output list. 236 // Simulate removal of second output from cached output list.
227 outputs.erase(outputs.begin() + 1); 237 outputs.erase(outputs.begin() + 1);
228 helper_delegate_->set_cached_outputs(outputs); 238 helper_delegate_->set_cached_outputs(outputs.get());
229 239
230 DispatchOutputChangeEvent(2, 11, 20, false); 240 DispatchOutputChangeEvent(2, 11, 20, false);
231 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); 241 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers());
232 } 242 }
233 243
234 } // namespace ui 244 } // namespace ui
OLDNEW
« no previous file with comments | « ui/display/chromeos/x11/native_display_event_dispatcher_x11.cc ('k') | ui/display/chromeos/x11/touchscreen_delegate_x11.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698