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

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

Powered by Google App Engine
This is Rietveld 408576698