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

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

Powered by Google App Engine
This is Rietveld 408576698