OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
12 #include "services/ui/display/platform_screen.h" | 12 #include "services/ui/display/screen_manager.h" |
13 #include "services/ui/display/platform_screen_ozone.h" | 13 #include "services/ui/display/screen_manager_ozone.h" |
14 #include "services/ui/display/viewport_metrics.h" | 14 #include "services/ui/display/viewport_metrics.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 15 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "ui/display/display_switches.h" | 17 #include "ui/display/display_switches.h" |
18 #include "ui/display/fake_display_snapshot.h" | 18 #include "ui/display/fake_display_snapshot.h" |
19 #include "ui/display/types/display_constants.h" | 19 #include "ui/display/types/display_constants.h" |
20 #include "ui/display/types/display_mode.h" | 20 #include "ui/display/types/display_mode.h" |
21 #include "ui/display/types/display_snapshot.h" | 21 #include "ui/display/types/display_snapshot.h" |
22 #include "ui/ozone/public/ozone_platform.h" | 22 #include "ui/ozone/public/ozone_platform.h" |
23 | 23 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 std::unique_ptr<DisplaySnapshot> MakeSnapshot(int64_t id, | 56 std::unique_ptr<DisplaySnapshot> MakeSnapshot(int64_t id, |
57 const gfx::Size& size) { | 57 const gfx::Size& size) { |
58 return FakeDisplaySnapshot::Builder() | 58 return FakeDisplaySnapshot::Builder() |
59 .SetId(id) | 59 .SetId(id) |
60 .SetNativeMode(size) | 60 .SetNativeMode(size) |
61 .SetCurrentMode(size) | 61 .SetCurrentMode(size) |
62 .Build(); | 62 .Build(); |
63 } | 63 } |
64 | 64 |
65 // Test delegate to track what functions calls the delegate receives. | 65 // Test delegate to track what functions calls the delegate receives. |
66 class TestPlatformScreenDelegate : public PlatformScreenDelegate { | 66 class TestScreenManagerDelegate : public ScreenManagerDelegate { |
67 public: | 67 public: |
68 TestPlatformScreenDelegate() {} | 68 TestScreenManagerDelegate() {} |
69 ~TestPlatformScreenDelegate() override {} | 69 ~TestScreenManagerDelegate() override {} |
70 | 70 |
71 const std::vector<DisplayState>& added() const { return added_; } | 71 const std::vector<DisplayState>& added() const { return added_; } |
72 const std::vector<DisplayState>& modified() const { return modified_; } | 72 const std::vector<DisplayState>& modified() const { return modified_; } |
73 | 73 |
74 // Returns a string containing the function calls that PlatformScreenDelegate | 74 // Returns a string containing the function calls that ScreenManagerDelegate |
75 // has received in the order they occured. Each function call will be in the | 75 // has received in the order they occured. Each function call will be in the |
76 // form "<action>(<id>)" and multiple function calls will be separated by ";". | 76 // form "<action>(<id>)" and multiple function calls will be separated by ";". |
77 // For example, if display 2 was added then display 1 was modified, changes() | 77 // For example, if display 2 was added then display 1 was modified, changes() |
78 // would return "Added(2);Modified(1)". | 78 // would return "Added(2);Modified(1)". |
79 const std::string& changes() const { return changes_; } | 79 const std::string& changes() const { return changes_; } |
80 | 80 |
81 void Reset() { | 81 void Reset() { |
82 added_.clear(); | 82 added_.clear(); |
83 modified_.clear(); | 83 modified_.clear(); |
84 changes_.clear(); | 84 changes_.clear(); |
(...skipping 21 matching lines...) Expand all Loading... |
106 } | 106 } |
107 | 107 |
108 void OnPrimaryDisplayChanged(int64_t primary_display_id) override { | 108 void OnPrimaryDisplayChanged(int64_t primary_display_id) override { |
109 AddChange("Primary", base::Int64ToString(primary_display_id)); | 109 AddChange("Primary", base::Int64ToString(primary_display_id)); |
110 } | 110 } |
111 | 111 |
112 std::vector<DisplayState> added_; | 112 std::vector<DisplayState> added_; |
113 std::vector<DisplayState> modified_; | 113 std::vector<DisplayState> modified_; |
114 std::string changes_; | 114 std::string changes_; |
115 | 115 |
116 DISALLOW_COPY_AND_ASSIGN(TestPlatformScreenDelegate); | 116 DISALLOW_COPY_AND_ASSIGN(TestScreenManagerDelegate); |
117 }; | 117 }; |
118 | 118 |
119 } // namespace | 119 } // namespace |
120 | 120 |
121 // Test fixture with helpers to act like ui::DisplayConfigurator and send | 121 // Test fixture with helpers to act like ui::DisplayConfigurator and send |
122 // OnDisplayModeChanged() to PlatformScreenOzone. | 122 // OnDisplayModeChanged() to ScreenManagerOzone. |
123 class PlatformScreenOzoneTest : public testing::Test { | 123 class ScreenManagerOzoneTest : public testing::Test { |
124 public: | 124 public: |
125 PlatformScreenOzoneTest() {} | 125 ScreenManagerOzoneTest() {} |
126 ~PlatformScreenOzoneTest() override {} | 126 ~ScreenManagerOzoneTest() override {} |
127 | 127 |
128 PlatformScreenOzone* platform_screen() { return platform_screen_.get(); } | 128 ScreenManagerOzone* screen_manager() { return screen_manager_.get(); } |
129 TestPlatformScreenDelegate* delegate() { return &delegate_; } | 129 TestScreenManagerDelegate* delegate() { return &delegate_; } |
130 | 130 |
131 // Adds a display snapshot with specified ID and default size. | 131 // Adds a display snapshot with specified ID and default size. |
132 void AddDisplay(int64_t id) { return AddDisplay(id, gfx::Size(1024, 768)); } | 132 void AddDisplay(int64_t id) { return AddDisplay(id, gfx::Size(1024, 768)); } |
133 | 133 |
134 // Adds a display snapshot with specified ID and size to list of snapshots. | 134 // Adds a display snapshot with specified ID and size to list of snapshots. |
135 void AddDisplay(int64_t id, const gfx::Size& size) { | 135 void AddDisplay(int64_t id, const gfx::Size& size) { |
136 snapshots_.push_back(MakeSnapshot(id, size)); | 136 snapshots_.push_back(MakeSnapshot(id, size)); |
137 TriggerOnDisplayModeChanged(); | 137 TriggerOnDisplayModeChanged(); |
138 } | 138 } |
139 | 139 |
(...skipping 27 matching lines...) Expand all Loading... |
167 snapshot->set_current_mode(new_mode); | 167 snapshot->set_current_mode(new_mode); |
168 TriggerOnDisplayModeChanged(); | 168 TriggerOnDisplayModeChanged(); |
169 } | 169 } |
170 | 170 |
171 // Calls OnDisplayModeChanged with our list of display snapshots. | 171 // Calls OnDisplayModeChanged with our list of display snapshots. |
172 void TriggerOnDisplayModeChanged() { | 172 void TriggerOnDisplayModeChanged() { |
173 std::vector<DisplaySnapshot*> snapshots_ptrs; | 173 std::vector<DisplaySnapshot*> snapshots_ptrs; |
174 for (auto& snapshot : snapshots_) { | 174 for (auto& snapshot : snapshots_) { |
175 snapshots_ptrs.push_back(snapshot.get()); | 175 snapshots_ptrs.push_back(snapshot.get()); |
176 } | 176 } |
177 platform_screen_->OnDisplayModeChanged(snapshots_ptrs); | 177 screen_manager_->OnDisplayModeChanged(snapshots_ptrs); |
178 } | 178 } |
179 | 179 |
180 private: | 180 private: |
181 DisplaySnapshot* GetSnapshotById(int64_t id) { | 181 DisplaySnapshot* GetSnapshotById(int64_t id) { |
182 for (auto& snapshot : snapshots_) { | 182 for (auto& snapshot : snapshots_) { |
183 if (snapshot->display_id() == id) | 183 if (snapshot->display_id() == id) |
184 return snapshot.get(); | 184 return snapshot.get(); |
185 } | 185 } |
186 return nullptr; | 186 return nullptr; |
187 } | 187 } |
188 | 188 |
189 // testing::Test: | 189 // testing::Test: |
190 void SetUp() override { | 190 void SetUp() override { |
191 base::CommandLine::ForCurrentProcess()->AppendSwitchNative( | 191 base::CommandLine::ForCurrentProcess()->AppendSwitchNative( |
192 switches::kScreenConfig, "none"); | 192 switches::kScreenConfig, "none"); |
193 | 193 |
194 testing::Test::SetUp(); | 194 testing::Test::SetUp(); |
195 ui::OzonePlatform::InitializeForUI(); | 195 ui::OzonePlatform::InitializeForUI(); |
196 platform_screen_ = base::MakeUnique<PlatformScreenOzone>(); | 196 screen_manager_ = base::MakeUnique<ScreenManagerOzone>(); |
197 platform_screen_->Init(&delegate_); | 197 screen_manager_->Init(&delegate_); |
198 | 198 |
199 // Have all tests start with a 1024x768 display by default. | 199 // Have all tests start with a 1024x768 display by default. |
200 AddDisplay(1, gfx::Size(1024, 768)); | 200 AddDisplay(1, gfx::Size(1024, 768)); |
201 TriggerOnDisplayModeChanged(); | 201 TriggerOnDisplayModeChanged(); |
202 | 202 |
203 // Double check the expected display exists and clear counters. | 203 // Double check the expected display exists and clear counters. |
204 ASSERT_THAT(delegate()->added(), SizeIs(1)); | 204 ASSERT_THAT(delegate()->added(), SizeIs(1)); |
205 ASSERT_THAT(delegate_.added()[0], DisplayId(1)); | 205 ASSERT_THAT(delegate_.added()[0], DisplayId(1)); |
206 ASSERT_THAT(delegate_.added()[0], DisplayOrigin("0,0")); | 206 ASSERT_THAT(delegate_.added()[0], DisplayOrigin("0,0")); |
207 ASSERT_THAT(delegate_.added()[0], DisplaySize("1024x768")); | 207 ASSERT_THAT(delegate_.added()[0], DisplaySize("1024x768")); |
208 ASSERT_EQ("Added(1);Primary(1)", delegate()->changes()); | 208 ASSERT_EQ("Added(1);Primary(1)", delegate()->changes()); |
209 delegate_.Reset(); | 209 delegate_.Reset(); |
210 } | 210 } |
211 | 211 |
212 void TearDown() override { | 212 void TearDown() override { |
213 snapshots_.clear(); | 213 snapshots_.clear(); |
214 delegate_.Reset(); | 214 delegate_.Reset(); |
215 platform_screen_.reset(); | 215 screen_manager_.reset(); |
216 } | 216 } |
217 | 217 |
218 TestPlatformScreenDelegate delegate_; | 218 TestScreenManagerDelegate delegate_; |
219 std::unique_ptr<PlatformScreenOzone> platform_screen_; | 219 std::unique_ptr<ScreenManagerOzone> screen_manager_; |
220 std::vector<std::unique_ptr<DisplaySnapshot>> snapshots_; | 220 std::vector<std::unique_ptr<DisplaySnapshot>> snapshots_; |
221 }; | 221 }; |
222 | 222 |
223 TEST_F(PlatformScreenOzoneTest, AddDisplay) { | 223 TEST_F(ScreenManagerOzoneTest, AddDisplay) { |
224 AddDisplay(2); | 224 AddDisplay(2); |
225 | 225 |
226 // Check that display 2 was added. | 226 // Check that display 2 was added. |
227 EXPECT_EQ("Added(2)", delegate()->changes()); | 227 EXPECT_EQ("Added(2)", delegate()->changes()); |
228 } | 228 } |
229 | 229 |
230 TEST_F(PlatformScreenOzoneTest, RemoveDisplay) { | 230 TEST_F(ScreenManagerOzoneTest, RemoveDisplay) { |
231 AddDisplay(2); | 231 AddDisplay(2); |
232 delegate()->Reset(); | 232 delegate()->Reset(); |
233 | 233 |
234 RemoveDisplay(2); | 234 RemoveDisplay(2); |
235 | 235 |
236 // Check that display 2 was removed. | 236 // Check that display 2 was removed. |
237 EXPECT_EQ("Removed(2)", delegate()->changes()); | 237 EXPECT_EQ("Removed(2)", delegate()->changes()); |
238 } | 238 } |
239 | 239 |
240 TEST_F(PlatformScreenOzoneTest, RemoveFirstDisplay) { | 240 TEST_F(ScreenManagerOzoneTest, RemoveFirstDisplay) { |
241 AddDisplay(2); | 241 AddDisplay(2); |
242 delegate()->Reset(); | 242 delegate()->Reset(); |
243 | 243 |
244 RemoveDisplay(1); | 244 RemoveDisplay(1); |
245 | 245 |
246 // Check that display 1 was removed and display 2 was modified due to the | 246 // Check that display 1 was removed and display 2 was modified due to the |
247 // origin changing. | 247 // origin changing. |
248 EXPECT_EQ("Primary(2);Removed(1);Modified(2)", delegate()->changes()); | 248 EXPECT_EQ("Primary(2);Removed(1);Modified(2)", delegate()->changes()); |
249 ASSERT_THAT(delegate()->modified(), SizeIs(1)); | 249 ASSERT_THAT(delegate()->modified(), SizeIs(1)); |
250 EXPECT_THAT(delegate()->modified()[0], DisplayId(2)); | 250 EXPECT_THAT(delegate()->modified()[0], DisplayId(2)); |
251 EXPECT_THAT(delegate()->modified()[0], DisplayOrigin("0,0")); | 251 EXPECT_THAT(delegate()->modified()[0], DisplayOrigin("0,0")); |
252 } | 252 } |
253 | 253 |
254 TEST_F(PlatformScreenOzoneTest, RemoveMultipleDisplay) { | 254 TEST_F(ScreenManagerOzoneTest, RemoveMultipleDisplay) { |
255 AddDisplay(2); | 255 AddDisplay(2); |
256 AddDisplay(3); | 256 AddDisplay(3); |
257 delegate()->Reset(); | 257 delegate()->Reset(); |
258 | 258 |
259 RemoveDisplay(2); | 259 RemoveDisplay(2); |
260 RemoveDisplay(3); | 260 RemoveDisplay(3); |
261 | 261 |
262 // Check that display 2 was removed and display 3 is modifed (origin change), | 262 // Check that display 2 was removed and display 3 is modifed (origin change), |
263 // then display 3 was removed. | 263 // then display 3 was removed. |
264 EXPECT_EQ("Removed(2);Modified(3);Removed(3)", delegate()->changes()); | 264 EXPECT_EQ("Removed(2);Modified(3);Removed(3)", delegate()->changes()); |
265 } | 265 } |
266 | 266 |
267 TEST_F(PlatformScreenOzoneTest, ModifyDisplaySize) { | 267 TEST_F(ScreenManagerOzoneTest, ModifyDisplaySize) { |
268 const gfx::Size size1(1920, 1200); | 268 const gfx::Size size1(1920, 1200); |
269 const gfx::Size size2(1680, 1050); | 269 const gfx::Size size2(1680, 1050); |
270 | 270 |
271 AddDisplay(2, size1); | 271 AddDisplay(2, size1); |
272 | 272 |
273 // Check that display 2 was added with expected size. | 273 // Check that display 2 was added with expected size. |
274 ASSERT_THAT(delegate()->added(), SizeIs(1)); | 274 ASSERT_THAT(delegate()->added(), SizeIs(1)); |
275 EXPECT_THAT(delegate()->added()[0], DisplayId(2)); | 275 EXPECT_THAT(delegate()->added()[0], DisplayId(2)); |
276 EXPECT_THAT(delegate()->added()[0], DisplaySize(size1.ToString())); | 276 EXPECT_THAT(delegate()->added()[0], DisplaySize(size1.ToString())); |
277 EXPECT_EQ("Added(2)", delegate()->changes()); | 277 EXPECT_EQ("Added(2)", delegate()->changes()); |
278 delegate()->Reset(); | 278 delegate()->Reset(); |
279 | 279 |
280 ModifyDisplay(2, size2); | 280 ModifyDisplay(2, size2); |
281 | 281 |
282 // Check that display 2 was modified to have the new expected size. | 282 // Check that display 2 was modified to have the new expected size. |
283 ASSERT_THAT(delegate()->modified(), SizeIs(1)); | 283 ASSERT_THAT(delegate()->modified(), SizeIs(1)); |
284 EXPECT_THAT(delegate()->modified()[0], DisplayId(2)); | 284 EXPECT_THAT(delegate()->modified()[0], DisplayId(2)); |
285 EXPECT_THAT(delegate()->modified()[0], DisplaySize(size2.ToString())); | 285 EXPECT_THAT(delegate()->modified()[0], DisplaySize(size2.ToString())); |
286 EXPECT_EQ("Modified(2)", delegate()->changes()); | 286 EXPECT_EQ("Modified(2)", delegate()->changes()); |
287 } | 287 } |
288 | 288 |
289 TEST_F(PlatformScreenOzoneTest, ModifyFirstDisplaySize) { | 289 TEST_F(ScreenManagerOzoneTest, ModifyFirstDisplaySize) { |
290 const gfx::Size size(1920, 1200); | 290 const gfx::Size size(1920, 1200); |
291 | 291 |
292 AddDisplay(2, size); | 292 AddDisplay(2, size); |
293 | 293 |
294 // Check that display 2 has the expected initial origin. | 294 // Check that display 2 has the expected initial origin. |
295 EXPECT_EQ("Added(2)", delegate()->changes()); | 295 EXPECT_EQ("Added(2)", delegate()->changes()); |
296 ASSERT_THAT(delegate()->added(), SizeIs(1)); | 296 ASSERT_THAT(delegate()->added(), SizeIs(1)); |
297 EXPECT_THAT(delegate()->added()[0], DisplayOrigin("1024,0")); | 297 EXPECT_THAT(delegate()->added()[0], DisplayOrigin("1024,0")); |
298 delegate()->Reset(); | 298 delegate()->Reset(); |
299 | 299 |
300 ModifyDisplay(1, size); | 300 ModifyDisplay(1, size); |
301 | 301 |
302 // Check that display 1 was modified with a new size and display 2 origin was | 302 // Check that display 1 was modified with a new size and display 2 origin was |
303 // modified after. | 303 // modified after. |
304 EXPECT_EQ("Modified(1);Modified(2)", delegate()->changes()); | 304 EXPECT_EQ("Modified(1);Modified(2)", delegate()->changes()); |
305 ASSERT_THAT(delegate()->modified(), SizeIs(2)); | 305 ASSERT_THAT(delegate()->modified(), SizeIs(2)); |
306 EXPECT_THAT(delegate()->modified()[0], DisplayId(1)); | 306 EXPECT_THAT(delegate()->modified()[0], DisplayId(1)); |
307 EXPECT_THAT(delegate()->modified()[0], DisplaySize(size.ToString())); | 307 EXPECT_THAT(delegate()->modified()[0], DisplaySize(size.ToString())); |
308 EXPECT_THAT(delegate()->modified()[1], DisplayId(2)); | 308 EXPECT_THAT(delegate()->modified()[1], DisplayId(2)); |
309 EXPECT_THAT(delegate()->modified()[1], DisplayOrigin("1920,0")); | 309 EXPECT_THAT(delegate()->modified()[1], DisplayOrigin("1920,0")); |
310 } | 310 } |
311 | 311 |
312 TEST_F(PlatformScreenOzoneTest, RemovePrimaryDisplay) { | 312 TEST_F(ScreenManagerOzoneTest, RemovePrimaryDisplay) { |
313 AddDisplay(2); | 313 AddDisplay(2); |
314 delegate()->Reset(); | 314 delegate()->Reset(); |
315 | 315 |
316 RemoveDisplay(1); | 316 RemoveDisplay(1); |
317 | 317 |
318 // Check the primary display changed because the old primary was removed. | 318 // Check the primary display changed because the old primary was removed. |
319 EXPECT_EQ("Primary(2);Removed(1);Modified(2)", delegate()->changes()); | 319 EXPECT_EQ("Primary(2);Removed(1);Modified(2)", delegate()->changes()); |
320 } | 320 } |
321 | 321 |
322 TEST_F(PlatformScreenOzoneTest, RemoveLastDisplay) { | 322 TEST_F(ScreenManagerOzoneTest, RemoveLastDisplay) { |
323 RemoveDisplay(1); | 323 RemoveDisplay(1); |
324 | 324 |
325 // Check that display 1 is removed and no updates for the primary display are | 325 // Check that display 1 is removed and no updates for the primary display are |
326 // received. | 326 // received. |
327 EXPECT_EQ("Removed(1)", delegate()->changes()); | 327 EXPECT_EQ("Removed(1)", delegate()->changes()); |
328 } | 328 } |
329 | 329 |
330 TEST_F(PlatformScreenOzoneTest, SwapPrimaryDisplay) { | 330 TEST_F(ScreenManagerOzoneTest, SwapPrimaryDisplay) { |
331 AddDisplay(2); | 331 AddDisplay(2); |
332 delegate()->Reset(); | 332 delegate()->Reset(); |
333 | 333 |
334 platform_screen()->SwapPrimaryDisplay(); | 334 screen_manager()->SwapPrimaryDisplay(); |
335 EXPECT_EQ("Primary(2)", delegate()->changes()); | 335 EXPECT_EQ("Primary(2)", delegate()->changes()); |
336 } | 336 } |
337 | 337 |
338 TEST_F(PlatformScreenOzoneTest, SwapPrimaryThreeDisplays) { | 338 TEST_F(ScreenManagerOzoneTest, SwapPrimaryThreeDisplays) { |
339 AddDisplay(2); | 339 AddDisplay(2); |
340 AddDisplay(3); | 340 AddDisplay(3); |
341 EXPECT_EQ("Added(2);Added(3)", delegate()->changes()); | 341 EXPECT_EQ("Added(2);Added(3)", delegate()->changes()); |
342 delegate()->Reset(); | 342 delegate()->Reset(); |
343 | 343 |
344 platform_screen()->SwapPrimaryDisplay(); | 344 screen_manager()->SwapPrimaryDisplay(); |
345 platform_screen()->SwapPrimaryDisplay(); | 345 screen_manager()->SwapPrimaryDisplay(); |
346 platform_screen()->SwapPrimaryDisplay(); | 346 screen_manager()->SwapPrimaryDisplay(); |
347 EXPECT_EQ("Primary(2);Primary(3);Primary(1)", delegate()->changes()); | 347 EXPECT_EQ("Primary(2);Primary(3);Primary(1)", delegate()->changes()); |
348 } | 348 } |
349 | 349 |
350 } // namespace display | 350 } // namespace display |
OLD | NEW |