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

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: Fix ordering 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 "chromeos/display/native_display_delegate_x11.h"
11 #include "chromeos/display/native_display_event_dispatcher_x11.h"
12 #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"
13 #include "ui/display/chromeos/x11/native_display_delegate_x11.h"
14 #include "ui/display/chromeos/x11/native_display_event_dispatcher_x11.h"
13 15
14 namespace chromeos { 16 namespace ui {
15 17
16 namespace { 18 namespace {
17 19
18 OutputConfigurator::OutputSnapshot CreateOutput( 20 const DisplayModeX11 kDefaultDisplayMode(gfx::Size(1, 1), false, 60.0f, 20);
19 RROutput output, RRCrtc crtc, RRMode mode) { 21
20 OutputConfigurator::OutputSnapshot snapshot; 22 DisplaySnapshotX11* CreateOutput(RROutput output, RRCrtc crtc) {
21 snapshot.output = output; 23 DisplaySnapshotX11* snapshot = new DisplaySnapshotX11(
22 snapshot.crtc = crtc; 24 0,
23 snapshot.current_mode = mode; 25 false,
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);
24 36
25 return snapshot; 37 return snapshot;
26 } 38 }
27 39
28 class TestHelperDelegate : public NativeDisplayDelegateX11::HelperDelegate { 40 class TestHelperDelegate : public NativeDisplayDelegateX11::HelperDelegate {
29 public: 41 public:
30 TestHelperDelegate(); 42 TestHelperDelegate();
31 virtual ~TestHelperDelegate(); 43 virtual ~TestHelperDelegate();
32 44
33 int num_calls_update_xrandr_config() const { 45 int num_calls_update_xrandr_config() const {
34 return num_calls_update_xrandr_config_; 46 return num_calls_update_xrandr_config_;
35 } 47 }
36 48
37 int num_calls_notify_observers() const { 49 int num_calls_notify_observers() const { return num_calls_notify_observers_; }
38 return num_calls_notify_observers_;
39 }
40 50
41 void set_cached_outputs( 51 void set_cached_outputs(const std::vector<DisplaySnapshot*>& outputs) {
42 const std::vector<OutputConfigurator::OutputSnapshot>& outputs) {
43 cached_outputs_ = outputs; 52 cached_outputs_ = outputs;
44 } 53 }
45 54
46 // NativeDisplayDelegateX11::HelperDelegate overrides: 55 // NativeDisplayDelegateX11::HelperDelegate overrides:
47 virtual void UpdateXRandRConfiguration( 56 virtual void UpdateXRandRConfiguration(const base::NativeEvent& event)
48 const base::NativeEvent& event) OVERRIDE; 57 OVERRIDE;
49 virtual const std::vector<OutputConfigurator::OutputSnapshot>& 58 virtual const std::vector<DisplaySnapshot*>& GetCachedOutputs() const
50 GetCachedOutputs() const OVERRIDE; 59 OVERRIDE;
51 virtual void NotifyDisplayObservers() OVERRIDE; 60 virtual void NotifyDisplayObservers() OVERRIDE;
52 61
53 private: 62 private:
54 int num_calls_update_xrandr_config_; 63 int num_calls_update_xrandr_config_;
55 int num_calls_notify_observers_; 64 int num_calls_notify_observers_;
56 65
57 std::vector<OutputConfigurator::OutputSnapshot> cached_outputs_; 66 std::vector<DisplaySnapshot*> cached_outputs_;
58 67
59 DISALLOW_COPY_AND_ASSIGN(TestHelperDelegate); 68 DISALLOW_COPY_AND_ASSIGN(TestHelperDelegate);
60 }; 69 };
61 70
62 TestHelperDelegate::TestHelperDelegate() 71 TestHelperDelegate::TestHelperDelegate()
63 : num_calls_update_xrandr_config_(0), 72 : num_calls_update_xrandr_config_(0), num_calls_notify_observers_(0) {}
64 num_calls_notify_observers_(0) {}
65 73
66 TestHelperDelegate::~TestHelperDelegate() {} 74 TestHelperDelegate::~TestHelperDelegate() {}
67 75
68 void TestHelperDelegate::UpdateXRandRConfiguration( 76 void TestHelperDelegate::UpdateXRandRConfiguration(
69 const base::NativeEvent& event) { 77 const base::NativeEvent& event) {
70 ++num_calls_update_xrandr_config_; 78 ++num_calls_update_xrandr_config_;
71 } 79 }
72 80
73 const std::vector<OutputConfigurator::OutputSnapshot>& 81 const std::vector<DisplaySnapshot*>& TestHelperDelegate::GetCachedOutputs()
74 TestHelperDelegate::GetCachedOutputs() const { 82 const {
75 return cached_outputs_; 83 return cached_outputs_;
76 } 84 }
77 85
78 void TestHelperDelegate::NotifyDisplayObservers() { 86 void TestHelperDelegate::NotifyDisplayObservers() {
79 ++num_calls_notify_observers_; 87 ++num_calls_notify_observers_;
80 } 88 }
81 89
82 //////////////////////////////////////////////////////////////////////////////// 90 ////////////////////////////////////////////////////////////////////////////////
83 // NativeDisplayEventDispatcherX11Test 91 // NativeDisplayEventDispatcherX11Test
84 92
85 class NativeDisplayEventDispatcherX11Test : public testing::Test { 93 class NativeDisplayEventDispatcherX11Test : public testing::Test {
86 public: 94 public:
87 NativeDisplayEventDispatcherX11Test(); 95 NativeDisplayEventDispatcherX11Test();
88 virtual ~NativeDisplayEventDispatcherX11Test(); 96 virtual ~NativeDisplayEventDispatcherX11Test();
89 97
90 protected: 98 protected:
91 void DispatchScreenChangeEvent(); 99 void DispatchScreenChangeEvent();
92 void DispatchOutputChangeEvent( 100 void DispatchOutputChangeEvent(RROutput output,
93 RROutput output, RRCrtc crtc, RRMode mode, bool connected); 101 RRCrtc crtc,
102 RRMode mode,
103 bool connected);
94 104
95 int xrandr_event_base_; 105 int xrandr_event_base_;
96 scoped_ptr<TestHelperDelegate> helper_delegate_; 106 scoped_ptr<TestHelperDelegate> helper_delegate_;
97 scoped_ptr<NativeDisplayEventDispatcherX11> dispatcher_; 107 scoped_ptr<NativeDisplayEventDispatcherX11> dispatcher_;
98 108
99 private: 109 private:
100 DISALLOW_COPY_AND_ASSIGN(NativeDisplayEventDispatcherX11Test); 110 DISALLOW_COPY_AND_ASSIGN(NativeDisplayEventDispatcherX11Test);
101 }; 111 };
102 112
103 NativeDisplayEventDispatcherX11Test::NativeDisplayEventDispatcherX11Test() 113 NativeDisplayEventDispatcherX11Test::NativeDisplayEventDispatcherX11Test()
104 : xrandr_event_base_(10), 114 : xrandr_event_base_(10),
105 helper_delegate_(new TestHelperDelegate()), 115 helper_delegate_(new TestHelperDelegate()),
106 dispatcher_(new NativeDisplayEventDispatcherX11(helper_delegate_.get(), 116 dispatcher_(new NativeDisplayEventDispatcherX11(helper_delegate_.get(),
107 xrandr_event_base_)) { 117 xrandr_event_base_)) {}
108 }
109 118
110 NativeDisplayEventDispatcherX11Test::~NativeDisplayEventDispatcherX11Test() {} 119 NativeDisplayEventDispatcherX11Test::~NativeDisplayEventDispatcherX11Test() {}
111 120
112 void NativeDisplayEventDispatcherX11Test::DispatchScreenChangeEvent() { 121 void NativeDisplayEventDispatcherX11Test::DispatchScreenChangeEvent() {
113 XRRScreenChangeNotifyEvent event = {0}; 122 XRRScreenChangeNotifyEvent event = {0};
114 event.type = xrandr_event_base_ + RRScreenChangeNotify; 123 event.type = xrandr_event_base_ + RRScreenChangeNotify;
115 124
116 dispatcher_->Dispatch(reinterpret_cast<const base::NativeEvent>(&event)); 125 dispatcher_->Dispatch(reinterpret_cast<const base::NativeEvent>(&event));
117 } 126 }
118 127
119 void NativeDisplayEventDispatcherX11Test::DispatchOutputChangeEvent( 128 void NativeDisplayEventDispatcherX11Test::DispatchOutputChangeEvent(
120 RROutput output, RRCrtc crtc, RRMode mode, bool connected) { 129 RROutput output,
130 RRCrtc crtc,
131 RRMode mode,
132 bool connected) {
121 XRROutputChangeNotifyEvent event = {0}; 133 XRROutputChangeNotifyEvent event = {0};
122 event.type = xrandr_event_base_ + RRNotify; 134 event.type = xrandr_event_base_ + RRNotify;
123 event.subtype = RRNotify_OutputChange; 135 event.subtype = RRNotify_OutputChange;
124 event.output = output; 136 event.output = output;
125 event.crtc = crtc; 137 event.crtc = crtc;
126 event.mode = mode; 138 event.mode = mode;
127 event.connection = connected ? RR_Connected : RR_Disconnected; 139 event.connection = connected ? RR_Connected : RR_Disconnected;
128 140
129 dispatcher_->Dispatch(reinterpret_cast<const base::NativeEvent>(&event)); 141 dispatcher_->Dispatch(reinterpret_cast<const base::NativeEvent>(&event));
130 } 142 }
131 143
132 } // namespace 144 } // namespace
133 145
134 TEST_F(NativeDisplayEventDispatcherX11Test, OnScreenChangedEvent) { 146 TEST_F(NativeDisplayEventDispatcherX11Test, OnScreenChangedEvent) {
135 DispatchScreenChangeEvent(); 147 DispatchScreenChangeEvent();
136 EXPECT_EQ(1, helper_delegate_->num_calls_update_xrandr_config()); 148 EXPECT_EQ(1, helper_delegate_->num_calls_update_xrandr_config());
137 EXPECT_EQ(0, helper_delegate_->num_calls_notify_observers()); 149 EXPECT_EQ(0, helper_delegate_->num_calls_notify_observers());
138 } 150 }
139 151
140 TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationOnFirstEvent) { 152 TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationOnFirstEvent) {
141 DispatchOutputChangeEvent(1, 10, 20, true); 153 DispatchOutputChangeEvent(1, 10, 20, true);
142 EXPECT_EQ(0, helper_delegate_->num_calls_update_xrandr_config()); 154 EXPECT_EQ(0, helper_delegate_->num_calls_update_xrandr_config());
143 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); 155 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers());
144 } 156 }
145 157
146 TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationAfterSecondEvent) { 158 TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationAfterSecondEvent) {
147 DispatchOutputChangeEvent(1, 10, 20, true); 159 DispatchOutputChangeEvent(1, 10, 20, true);
148 160
149 // Simulate addition of the first output to the cached output list. 161 // Simulate addition of the first output to the cached output list.
150 std::vector<OutputConfigurator::OutputSnapshot> outputs; 162 ScopedVector<DisplaySnapshot> outputs;
151 outputs.push_back(CreateOutput(1, 10, 20)); 163 outputs.push_back(CreateOutput(1, 10));
152 helper_delegate_->set_cached_outputs(outputs); 164 helper_delegate_->set_cached_outputs(outputs.get());
153 165
154 DispatchOutputChangeEvent(2, 11, 20, true); 166 DispatchOutputChangeEvent(2, 11, 20, true);
155 EXPECT_EQ(2, helper_delegate_->num_calls_notify_observers()); 167 EXPECT_EQ(2, helper_delegate_->num_calls_notify_observers());
156 } 168 }
157 169
158 TEST_F(NativeDisplayEventDispatcherX11Test, AvoidNotificationOnDuplicateEvent) { 170 TEST_F(NativeDisplayEventDispatcherX11Test, AvoidNotificationOnDuplicateEvent) {
159 std::vector<OutputConfigurator::OutputSnapshot> outputs; 171 ScopedVector<DisplaySnapshot> outputs;
160 outputs.push_back(CreateOutput(1, 10, 20)); 172 outputs.push_back(CreateOutput(1, 10));
161 helper_delegate_->set_cached_outputs(outputs); 173 helper_delegate_->set_cached_outputs(outputs.get());
162 174
163 DispatchOutputChangeEvent(1, 10, 20, true); 175 DispatchOutputChangeEvent(1, 10, 20, true);
164 EXPECT_EQ(0, helper_delegate_->num_calls_notify_observers()); 176 EXPECT_EQ(0, helper_delegate_->num_calls_notify_observers());
165 } 177 }
166 178
167 TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationOnDisconnect) { 179 TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationOnDisconnect) {
168 std::vector<OutputConfigurator::OutputSnapshot> outputs; 180 ScopedVector<DisplaySnapshot> outputs;
169 outputs.push_back(CreateOutput(1, 10, 20)); 181 outputs.push_back(CreateOutput(1, 10));
170 helper_delegate_->set_cached_outputs(outputs); 182 helper_delegate_->set_cached_outputs(outputs.get());
171 183
172 DispatchOutputChangeEvent(1, 10, 20, false); 184 DispatchOutputChangeEvent(1, 10, 20, false);
173 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); 185 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers());
174 } 186 }
175 187
176 TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationOnModeChange) { 188 TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationOnModeChange) {
177 std::vector<OutputConfigurator::OutputSnapshot> outputs; 189 ScopedVector<DisplaySnapshot> outputs;
178 outputs.push_back(CreateOutput(1, 10, 20)); 190 outputs.push_back(CreateOutput(1, 10));
179 helper_delegate_->set_cached_outputs(outputs); 191 helper_delegate_->set_cached_outputs(outputs.get());
180 192
181 DispatchOutputChangeEvent(1, 10, 21, true); 193 DispatchOutputChangeEvent(1, 10, 21, true);
182 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); 194 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers());
183 } 195 }
184 196
185 TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationOnSecondOutput) { 197 TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationOnSecondOutput) {
186 std::vector<OutputConfigurator::OutputSnapshot> outputs; 198 ScopedVector<DisplaySnapshot> outputs;
187 outputs.push_back(CreateOutput(1, 10, 20)); 199 outputs.push_back(CreateOutput(1, 10));
188 helper_delegate_->set_cached_outputs(outputs); 200 helper_delegate_->set_cached_outputs(outputs.get());
189 201
190 DispatchOutputChangeEvent(2, 11, 20, true); 202 DispatchOutputChangeEvent(2, 11, 20, true);
191 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); 203 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers());
192 } 204 }
193 205
194 TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationOnDifferentCrtc) { 206 TEST_F(NativeDisplayEventDispatcherX11Test, CheckNotificationOnDifferentCrtc) {
195 std::vector<OutputConfigurator::OutputSnapshot> outputs; 207 ScopedVector<DisplaySnapshot> outputs;
196 outputs.push_back(CreateOutput(1, 10, 20)); 208 outputs.push_back(CreateOutput(1, 10));
197 helper_delegate_->set_cached_outputs(outputs); 209 helper_delegate_->set_cached_outputs(outputs.get());
198 210
199 DispatchOutputChangeEvent(1, 11, 20, true); 211 DispatchOutputChangeEvent(1, 11, 20, true);
200 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); 212 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers());
201 } 213 }
202 214
203 TEST_F(NativeDisplayEventDispatcherX11Test, 215 TEST_F(NativeDisplayEventDispatcherX11Test,
204 CheckNotificationOnSecondOutputDisconnect) { 216 CheckNotificationOnSecondOutputDisconnect) {
205 std::vector<OutputConfigurator::OutputSnapshot> outputs; 217 ScopedVector<DisplaySnapshot> outputs;
206 outputs.push_back(CreateOutput(1, 10, 20)); 218 outputs.push_back(CreateOutput(1, 10));
207 outputs.push_back(CreateOutput(2, 11, 20)); 219 outputs.push_back(CreateOutput(2, 11));
208 helper_delegate_->set_cached_outputs(outputs); 220 helper_delegate_->set_cached_outputs(outputs.get());
209 221
210 DispatchOutputChangeEvent(2, 11, 20, false); 222 DispatchOutputChangeEvent(2, 11, 20, false);
211 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); 223 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers());
212 } 224 }
213 225
214 TEST_F(NativeDisplayEventDispatcherX11Test, 226 TEST_F(NativeDisplayEventDispatcherX11Test,
215 AvoidDuplicateNotificationOnSecondOutputDisconnect) { 227 AvoidDuplicateNotificationOnSecondOutputDisconnect) {
216 std::vector<OutputConfigurator::OutputSnapshot> outputs; 228 ScopedVector<DisplaySnapshot> outputs;
217 outputs.push_back(CreateOutput(1, 10, 20)); 229 outputs.push_back(CreateOutput(1, 10));
218 outputs.push_back(CreateOutput(2, 11, 20)); 230 outputs.push_back(CreateOutput(2, 11));
219 helper_delegate_->set_cached_outputs(outputs); 231 helper_delegate_->set_cached_outputs(outputs.get());
220 232
221 DispatchOutputChangeEvent(2, 11, 20, false); 233 DispatchOutputChangeEvent(2, 11, 20, false);
222 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); 234 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers());
223 235
224 // Simulate removal of second output from cached output list. 236 // Simulate removal of second output from cached output list.
225 outputs.erase(outputs.begin() + 1); 237 outputs.erase(outputs.begin() + 1);
226 helper_delegate_->set_cached_outputs(outputs); 238 helper_delegate_->set_cached_outputs(outputs.get());
227 239
228 DispatchOutputChangeEvent(2, 11, 20, false); 240 DispatchOutputChangeEvent(2, 11, 20, false);
229 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers()); 241 EXPECT_EQ(1, helper_delegate_->num_calls_notify_observers());
230 } 242 }
231 243
232 } // namespace chromeos 244 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698