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

Side by Side Diff: ash/display/resolution_notification_controller_unittest.cc

Issue 2270553002: Move ash::DisplayInfo to ui (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: build Created 4 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "ash/display/resolution_notification_controller.h" 5 #include "ash/display/resolution_notification_controller.h"
6 6
7 #include "ash/display/display_manager.h" 7 #include "ash/display/display_manager.h"
8 #include "ash/screen_util.h" 8 #include "ash/screen_util.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/test/ash_test_base.h" 10 #include "ash/test/ash_test_base.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 ash::test::AshTestBase::SetUp(); 56 ash::test::AshTestBase::SetUp();
57 ResolutionNotificationController::SuppressTimerForTest(); 57 ResolutionNotificationController::SuppressTimerForTest();
58 } 58 }
59 59
60 void SetDisplayResolutionAndNotifyWithResolution( 60 void SetDisplayResolutionAndNotifyWithResolution(
61 const display::Display& display, 61 const display::Display& display,
62 const gfx::Size& new_resolution, 62 const gfx::Size& new_resolution,
63 const gfx::Size& actual_new_resolution) { 63 const gfx::Size& actual_new_resolution) {
64 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); 64 DisplayManager* display_manager = Shell::GetInstance()->display_manager();
65 65
66 const DisplayInfo& info = display_manager->GetDisplayInfo(display.id()); 66 const ui::ManagedDisplayInfo& info =
67 scoped_refptr<ManagedDisplayMode> old_mode( 67 display_manager->GetDisplayInfo(display.id());
68 new ManagedDisplayMode(info.size_in_pixel(), 60 /* refresh_rate */, 68 scoped_refptr<ui::ManagedDisplayMode> old_mode(
69 false /* interlaced */, false /* native */)); 69 new ui::ManagedDisplayMode(info.size_in_pixel(), 60 /* refresh_rate */,
70 scoped_refptr<ManagedDisplayMode> new_mode(new ManagedDisplayMode( 70 false /* interlaced */, false /* native */));
71 scoped_refptr<ui::ManagedDisplayMode> new_mode(new ui::ManagedDisplayMode(
71 new_resolution, old_mode->refresh_rate(), old_mode->is_interlaced(), 72 new_resolution, old_mode->refresh_rate(), old_mode->is_interlaced(),
72 old_mode->native(), old_mode->ui_scale(), 73 old_mode->native(), old_mode->ui_scale(),
73 old_mode->device_scale_factor())); 74 old_mode->device_scale_factor()));
74 75
75 if (display_manager->SetDisplayMode(display.id(), new_mode)) { 76 if (display_manager->SetDisplayMode(display.id(), new_mode)) {
76 controller()->PrepareNotification( 77 controller()->PrepareNotification(
77 display.id(), old_mode, new_mode, 78 display.id(), old_mode, new_mode,
78 base::Bind(&ResolutionNotificationControllerTest::OnAccepted, 79 base::Bind(&ResolutionNotificationControllerTest::OnAccepted,
79 base::Unretained(this))); 80 base::Unretained(this)));
80 } 81 }
81 82
82 // OnConfigurationChanged event won't be emitted in the test environment, 83 // OnConfigurationChanged event won't be emitted in the test environment,
83 // so invoke UpdateDisplay() to emit that event explicitly. 84 // so invoke UpdateDisplay() to emit that event explicitly.
84 std::vector<DisplayInfo> info_list; 85 std::vector<ui::ManagedDisplayInfo> info_list;
85 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { 86 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) {
86 int64_t id = display_manager->GetDisplayAt(i).id(); 87 int64_t id = display_manager->GetDisplayAt(i).id();
87 DisplayInfo info = display_manager->GetDisplayInfo(id); 88 ui::ManagedDisplayInfo info = display_manager->GetDisplayInfo(id);
88 if (display.id() == id) { 89 if (display.id() == id) {
89 gfx::Rect bounds = info.bounds_in_native(); 90 gfx::Rect bounds = info.bounds_in_native();
90 bounds.set_size(actual_new_resolution); 91 bounds.set_size(actual_new_resolution);
91 info.SetBounds(bounds); 92 info.SetBounds(bounds);
92 } 93 }
93 info_list.push_back(info); 94 info_list.push_back(info);
94 } 95 }
95 display_manager->OnNativeDisplaysChanged(info_list); 96 display_manager->OnNativeDisplaysChanged(info_list);
96 RunAllPendingInMessageLoop(); 97 RunAllPendingInMessageLoop();
97 } 98 }
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
166 ASSERT_EQ(0, accept_count()); 167 ASSERT_EQ(0, accept_count());
167 EXPECT_FALSE(IsNotificationVisible()); 168 EXPECT_FALSE(IsNotificationVisible());
168 169
169 // Changes the resolution and apply the result. 170 // Changes the resolution and apply the result.
170 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), 171 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(),
171 gfx::Size(200, 200)); 172 gfx::Size(200, 200));
172 EXPECT_TRUE(IsNotificationVisible()); 173 EXPECT_TRUE(IsNotificationVisible());
173 EXPECT_FALSE(controller()->DoesNotificationTimeout()); 174 EXPECT_FALSE(controller()->DoesNotificationTimeout());
174 EXPECT_EQ(ExpectedNotificationMessage(id2, gfx::Size(200, 200)), 175 EXPECT_EQ(ExpectedNotificationMessage(id2, gfx::Size(200, 200)),
175 GetNotificationMessage()); 176 GetNotificationMessage());
176 scoped_refptr<ManagedDisplayMode> mode = 177 scoped_refptr<ui::ManagedDisplayMode> mode =
177 display_manager->GetSelectedModeForDisplayId(id2); 178 display_manager->GetSelectedModeForDisplayId(id2);
178 EXPECT_TRUE(!!mode); 179 EXPECT_TRUE(!!mode);
179 EXPECT_EQ("200x200", mode->size().ToString()); 180 EXPECT_EQ("200x200", mode->size().ToString());
180 EXPECT_EQ(60.0, mode->refresh_rate()); 181 EXPECT_EQ(60.0, mode->refresh_rate());
181 182
182 // Click the revert button, which reverts to the best resolution. 183 // Click the revert button, which reverts to the best resolution.
183 ClickOnNotificationButton(0); 184 ClickOnNotificationButton(0);
184 RunAllPendingInMessageLoop(); 185 RunAllPendingInMessageLoop();
185 EXPECT_FALSE(IsNotificationVisible()); 186 EXPECT_FALSE(IsNotificationVisible());
186 EXPECT_EQ(0, accept_count()); 187 EXPECT_EQ(0, accept_count());
(...skipping 12 matching lines...) Expand all
199 ash::DisplayManager* display_manager = 200 ash::DisplayManager* display_manager =
200 ash::Shell::GetInstance()->display_manager(); 201 ash::Shell::GetInstance()->display_manager();
201 ASSERT_EQ(0, accept_count()); 202 ASSERT_EQ(0, accept_count());
202 EXPECT_FALSE(IsNotificationVisible()); 203 EXPECT_FALSE(IsNotificationVisible());
203 204
204 // Changes the resolution and apply the result. 205 // Changes the resolution and apply the result.
205 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), 206 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(),
206 gfx::Size(200, 200)); 207 gfx::Size(200, 200));
207 EXPECT_TRUE(IsNotificationVisible()); 208 EXPECT_TRUE(IsNotificationVisible());
208 EXPECT_FALSE(controller()->DoesNotificationTimeout()); 209 EXPECT_FALSE(controller()->DoesNotificationTimeout());
209 scoped_refptr<ManagedDisplayMode> mode = 210 scoped_refptr<ui::ManagedDisplayMode> mode =
210 display_manager->GetSelectedModeForDisplayId(id2); 211 display_manager->GetSelectedModeForDisplayId(id2);
211 EXPECT_TRUE(!!mode); 212 EXPECT_TRUE(!!mode);
212 EXPECT_EQ("200x200", mode->size().ToString()); 213 EXPECT_EQ("200x200", mode->size().ToString());
213 EXPECT_EQ(60.0, mode->refresh_rate()); 214 EXPECT_EQ(60.0, mode->refresh_rate());
214 215
215 // Click the revert button, which reverts the resolution. 216 // Click the revert button, which reverts the resolution.
216 ClickOnNotification(); 217 ClickOnNotification();
217 RunAllPendingInMessageLoop(); 218 RunAllPendingInMessageLoop();
218 EXPECT_FALSE(IsNotificationVisible()); 219 EXPECT_FALSE(IsNotificationVisible());
219 EXPECT_EQ(1, accept_count()); 220 EXPECT_EQ(1, accept_count());
(...skipping 16 matching lines...) Expand all
236 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); 237 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200));
237 EXPECT_TRUE(IsNotificationVisible()); 238 EXPECT_TRUE(IsNotificationVisible());
238 239
239 // If there's a single display only, it will have timeout and the first button 240 // If there's a single display only, it will have timeout and the first button
240 // becomes accept. 241 // becomes accept.
241 EXPECT_TRUE(controller()->DoesNotificationTimeout()); 242 EXPECT_TRUE(controller()->DoesNotificationTimeout());
242 ClickOnNotificationButton(0); 243 ClickOnNotificationButton(0);
243 EXPECT_FALSE(IsNotificationVisible()); 244 EXPECT_FALSE(IsNotificationVisible());
244 EXPECT_EQ(1, accept_count()); 245 EXPECT_EQ(1, accept_count());
245 246
246 scoped_refptr<ManagedDisplayMode> mode = 247 scoped_refptr<ui::ManagedDisplayMode> mode =
247 display_manager->GetSelectedModeForDisplayId(display.id()); 248 display_manager->GetSelectedModeForDisplayId(display.id());
248 EXPECT_TRUE(!!mode); 249 EXPECT_TRUE(!!mode);
249 250
250 EXPECT_EQ("200x200", mode->size().ToString()); 251 EXPECT_EQ("200x200", mode->size().ToString());
251 EXPECT_EQ(60.0f, mode->refresh_rate()); 252 EXPECT_EQ(60.0f, mode->refresh_rate());
252 253
253 // In that case the second button is revert. 254 // In that case the second button is revert.
254 UpdateDisplay("300x300#300x300%59|200x200%60"); 255 UpdateDisplay("300x300#300x300%59|200x200%60");
255 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200)); 256 SetDisplayResolutionAndNotify(display, gfx::Size(200, 200));
256 EXPECT_TRUE(IsNotificationVisible()); 257 EXPECT_TRUE(IsNotificationVisible());
(...skipping 18 matching lines...) Expand all
275 ash::DisplayManager* display_manager = 276 ash::DisplayManager* display_manager =
276 ash::Shell::GetInstance()->display_manager(); 277 ash::Shell::GetInstance()->display_manager();
277 ASSERT_EQ(0, accept_count()); 278 ASSERT_EQ(0, accept_count());
278 EXPECT_FALSE(IsNotificationVisible()); 279 EXPECT_FALSE(IsNotificationVisible());
279 280
280 // Changes the resolution and apply the result. 281 // Changes the resolution and apply the result.
281 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), 282 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(),
282 gfx::Size(200, 200)); 283 gfx::Size(200, 200));
283 EXPECT_TRUE(IsNotificationVisible()); 284 EXPECT_TRUE(IsNotificationVisible());
284 EXPECT_FALSE(controller()->DoesNotificationTimeout()); 285 EXPECT_FALSE(controller()->DoesNotificationTimeout());
285 scoped_refptr<ManagedDisplayMode> mode = 286 scoped_refptr<ui::ManagedDisplayMode> mode =
286 display_manager->GetSelectedModeForDisplayId(id2); 287 display_manager->GetSelectedModeForDisplayId(id2);
287 EXPECT_TRUE(!!mode); 288 EXPECT_TRUE(!!mode);
288 EXPECT_EQ("200x200", mode->size().ToString()); 289 EXPECT_EQ("200x200", mode->size().ToString());
289 EXPECT_EQ(60.0f, mode->refresh_rate()); 290 EXPECT_EQ(60.0f, mode->refresh_rate());
290 291
291 // Close the notification (imitates clicking [x] button). Also verifies if 292 // Close the notification (imitates clicking [x] button). Also verifies if
292 // this does not cause a crash. See crbug.com/271784 293 // this does not cause a crash. See crbug.com/271784
293 CloseNotification(); 294 CloseNotification();
294 RunAllPendingInMessageLoop(); 295 RunAllPendingInMessageLoop();
295 EXPECT_FALSE(IsNotificationVisible()); 296 EXPECT_FALSE(IsNotificationVisible());
(...skipping 12 matching lines...) Expand all
308 for (int i = 0; i < ResolutionNotificationController::kTimeoutInSec; ++i) { 309 for (int i = 0; i < ResolutionNotificationController::kTimeoutInSec; ++i) {
309 EXPECT_TRUE(IsNotificationVisible()) << "notification is closed after " << i 310 EXPECT_TRUE(IsNotificationVisible()) << "notification is closed after " << i
310 << "-th timer tick"; 311 << "-th timer tick";
311 TickTimer(); 312 TickTimer();
312 RunAllPendingInMessageLoop(); 313 RunAllPendingInMessageLoop();
313 } 314 }
314 EXPECT_FALSE(IsNotificationVisible()); 315 EXPECT_FALSE(IsNotificationVisible());
315 EXPECT_EQ(0, accept_count()); 316 EXPECT_EQ(0, accept_count());
316 ash::DisplayManager* display_manager = 317 ash::DisplayManager* display_manager =
317 ash::Shell::GetInstance()->display_manager(); 318 ash::Shell::GetInstance()->display_manager();
318 scoped_refptr<ManagedDisplayMode> mode = 319 scoped_refptr<ui::ManagedDisplayMode> mode =
319 display_manager->GetSelectedModeForDisplayId(display.id()); 320 display_manager->GetSelectedModeForDisplayId(display.id());
320 EXPECT_TRUE(!!mode); 321 EXPECT_TRUE(!!mode);
321 EXPECT_EQ("300x300", mode->size().ToString()); 322 EXPECT_EQ("300x300", mode->size().ToString());
322 EXPECT_EQ(59.0f, mode->refresh_rate()); 323 EXPECT_EQ(59.0f, mode->refresh_rate());
323 } 324 }
324 325
325 TEST_F(ResolutionNotificationControllerTest, DisplayDisconnected) { 326 TEST_F(ResolutionNotificationControllerTest, DisplayDisconnected) {
326 if (!SupportsMultipleDisplays()) 327 if (!SupportsMultipleDisplays())
327 return; 328 return;
328 329
329 UpdateDisplay( 330 UpdateDisplay(
330 "300x300#300x300%56|200x200%57," 331 "300x300#300x300%56|200x200%57,"
331 "200x200#250x250%58|200x200%59|100x100%60"); 332 "200x200#250x250%58|200x200%59|100x100%60");
332 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); 333 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id();
333 ash::DisplayManager* display_manager = 334 ash::DisplayManager* display_manager =
334 ash::Shell::GetInstance()->display_manager(); 335 ash::Shell::GetInstance()->display_manager();
335 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), 336 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(),
336 gfx::Size(100, 100)); 337 gfx::Size(100, 100));
337 ASSERT_TRUE(IsNotificationVisible()); 338 ASSERT_TRUE(IsNotificationVisible());
338 339
339 // Disconnects the secondary display and verifies it doesn't cause crashes. 340 // Disconnects the secondary display and verifies it doesn't cause crashes.
340 UpdateDisplay("300x300#300x300%56|200x200%57"); 341 UpdateDisplay("300x300#300x300%56|200x200%57");
341 RunAllPendingInMessageLoop(); 342 RunAllPendingInMessageLoop();
342 EXPECT_FALSE(IsNotificationVisible()); 343 EXPECT_FALSE(IsNotificationVisible());
343 EXPECT_EQ(0, accept_count()); 344 EXPECT_EQ(0, accept_count());
344 scoped_refptr<ManagedDisplayMode> mode = 345 scoped_refptr<ui::ManagedDisplayMode> mode =
345 display_manager->GetSelectedModeForDisplayId(id2); 346 display_manager->GetSelectedModeForDisplayId(id2);
346 EXPECT_TRUE(!!mode); 347 EXPECT_TRUE(!!mode);
347 gfx::Size resolution; 348 gfx::Size resolution;
348 EXPECT_EQ("200x200", mode->size().ToString()); 349 EXPECT_EQ("200x200", mode->size().ToString());
349 EXPECT_EQ(59.0f, mode->refresh_rate()); 350 EXPECT_EQ(59.0f, mode->refresh_rate());
350 } 351 }
351 352
352 TEST_F(ResolutionNotificationControllerTest, MultipleResolutionChange) { 353 TEST_F(ResolutionNotificationControllerTest, MultipleResolutionChange) {
353 if (!SupportsMultipleDisplays()) 354 if (!SupportsMultipleDisplays())
354 return; 355 return;
355 356
356 UpdateDisplay( 357 UpdateDisplay(
357 "300x300#300x300%56|200x200%57," 358 "300x300#300x300%56|200x200%57,"
358 "250x250#250x250%58|200x200%59"); 359 "250x250#250x250%58|200x200%59");
359 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id(); 360 int64_t id2 = ash::ScreenUtil::GetSecondaryDisplay().id();
360 ash::DisplayManager* display_manager = 361 ash::DisplayManager* display_manager =
361 ash::Shell::GetInstance()->display_manager(); 362 ash::Shell::GetInstance()->display_manager();
362 363
363 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), 364 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(),
364 gfx::Size(200, 200)); 365 gfx::Size(200, 200));
365 EXPECT_TRUE(IsNotificationVisible()); 366 EXPECT_TRUE(IsNotificationVisible());
366 EXPECT_FALSE(controller()->DoesNotificationTimeout()); 367 EXPECT_FALSE(controller()->DoesNotificationTimeout());
367 scoped_refptr<ManagedDisplayMode> mode = 368 scoped_refptr<ui::ManagedDisplayMode> mode =
368 display_manager->GetSelectedModeForDisplayId(id2); 369 display_manager->GetSelectedModeForDisplayId(id2);
369 EXPECT_TRUE(!!mode); 370 EXPECT_TRUE(!!mode);
370 EXPECT_EQ("200x200", mode->size().ToString()); 371 EXPECT_EQ("200x200", mode->size().ToString());
371 EXPECT_EQ(59.0f, mode->refresh_rate()); 372 EXPECT_EQ(59.0f, mode->refresh_rate());
372 373
373 // Invokes SetDisplayResolutionAndNotify during the previous notification is 374 // Invokes SetDisplayResolutionAndNotify during the previous notification is
374 // visible. 375 // visible.
375 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(), 376 SetDisplayResolutionAndNotify(ScreenUtil::GetSecondaryDisplay(),
376 gfx::Size(250, 250)); 377 gfx::Size(250, 250));
377 mode = display_manager->GetSelectedModeForDisplayId(id2); 378 mode = display_manager->GetSelectedModeForDisplayId(id2);
(...skipping 29 matching lines...) Expand all
407 408
408 // Changes the resolution and apply the result. 409 // Changes the resolution and apply the result.
409 SetDisplayResolutionAndNotifyWithResolution(ScreenUtil::GetSecondaryDisplay(), 410 SetDisplayResolutionAndNotifyWithResolution(ScreenUtil::GetSecondaryDisplay(),
410 gfx::Size(220, 220), 411 gfx::Size(220, 220),
411 gfx::Size(200, 200)); 412 gfx::Size(200, 200));
412 EXPECT_TRUE(IsNotificationVisible()); 413 EXPECT_TRUE(IsNotificationVisible());
413 EXPECT_FALSE(controller()->DoesNotificationTimeout()); 414 EXPECT_FALSE(controller()->DoesNotificationTimeout());
414 EXPECT_EQ(ExpectedFallbackNotificationMessage(id2, gfx::Size(220, 220), 415 EXPECT_EQ(ExpectedFallbackNotificationMessage(id2, gfx::Size(220, 220),
415 gfx::Size(200, 200)), 416 gfx::Size(200, 200)),
416 GetNotificationMessage()); 417 GetNotificationMessage());
417 scoped_refptr<ManagedDisplayMode> mode = 418 scoped_refptr<ui::ManagedDisplayMode> mode =
418 display_manager->GetSelectedModeForDisplayId(id2); 419 display_manager->GetSelectedModeForDisplayId(id2);
419 EXPECT_TRUE(!!mode); 420 EXPECT_TRUE(!!mode);
420 EXPECT_EQ("200x200", mode->size().ToString()); 421 EXPECT_EQ("200x200", mode->size().ToString());
421 EXPECT_EQ(60.0f, mode->refresh_rate()); 422 EXPECT_EQ(60.0f, mode->refresh_rate());
422 423
423 // Click the revert button, which reverts to the best resolution. 424 // Click the revert button, which reverts to the best resolution.
424 ClickOnNotificationButton(0); 425 ClickOnNotificationButton(0);
425 RunAllPendingInMessageLoop(); 426 RunAllPendingInMessageLoop();
426 EXPECT_FALSE(IsNotificationVisible()); 427 EXPECT_FALSE(IsNotificationVisible());
427 EXPECT_EQ(0, accept_count()); 428 EXPECT_EQ(0, accept_count());
428 429
429 mode = display_manager->GetSelectedModeForDisplayId(id2); 430 mode = display_manager->GetSelectedModeForDisplayId(id2);
430 EXPECT_TRUE(!!mode); 431 EXPECT_TRUE(!!mode);
431 EXPECT_EQ("250x250", mode->size().ToString()); 432 EXPECT_EQ("250x250", mode->size().ToString());
432 EXPECT_EQ(58.0f, mode->refresh_rate()); 433 EXPECT_EQ(58.0f, mode->refresh_rate());
433 } 434 }
434 435
435 } // namespace ash 436 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698