OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/desktop_background/desktop_background_controller.h" | 5 #include "ash/desktop_background/desktop_background_controller.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <cstdlib> | 8 #include <cstdlib> |
9 | 9 |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
11 #include "ash/desktop_background/desktop_background_controller_observer.h" | 11 #include "ash/desktop_background/desktop_background_controller_observer.h" |
12 #include "ash/desktop_background/desktop_background_widget_controller.h" | 12 #include "ash/desktop_background/desktop_background_widget_controller.h" |
13 #include "ash/root_window_controller.h" | 13 #include "ash/root_window_controller.h" |
14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
15 #include "ash/shell_window_ids.h" | 15 #include "ash/shell_window_ids.h" |
16 #include "ash/test/ash_test_base.h" | 16 #include "ash/test/ash_test_base.h" |
17 #include "ash/test/display_manager_test_api.h" | 17 #include "ash/test/display_manager_test_api.h" |
18 #include "ash/test/test_user_wallpaper_delegate.h" | 18 #include "ash/test/test_user_wallpaper_delegate.h" |
19 #include "base/command_line.h" | 19 #include "base/command_line.h" |
20 #include "base/file_util.h" | 20 #include "base/file_util.h" |
21 #include "base/files/file_path.h" | 21 #include "base/files/file_path.h" |
22 #include "base/files/scoped_temp_dir.h" | 22 #include "base/files/scoped_temp_dir.h" |
23 #include "base/message_loop/message_loop.h" | 23 #include "base/message_loop/message_loop.h" |
| 24 #include "content/public/browser/browser_thread.h" |
24 #include "content/public/test/test_browser_thread.h" | 25 #include "content/public/test/test_browser_thread.h" |
| 26 #include "content/public/test/test_utils.h" |
25 #include "third_party/skia/include/core/SkBitmap.h" | 27 #include "third_party/skia/include/core/SkBitmap.h" |
26 #include "third_party/skia/include/core/SkColor.h" | 28 #include "third_party/skia/include/core/SkColor.h" |
27 #include "ui/aura/root_window.h" | 29 #include "ui/aura/root_window.h" |
28 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 30 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
29 #include "ui/compositor/test/layer_animator_test_controller.h" | 31 #include "ui/compositor/test/layer_animator_test_controller.h" |
30 #include "ui/gfx/codec/jpeg_codec.h" | 32 #include "ui/gfx/codec/jpeg_codec.h" |
31 #include "ui/gfx/point.h" | 33 #include "ui/gfx/point.h" |
32 #include "ui/gfx/rect.h" | 34 #include "ui/gfx/rect.h" |
33 | 35 |
34 using aura::RootWindow; | 36 using aura::RootWindow; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 static const SkColor kLargeWallpaperColor = SK_ColorRED; | 126 static const SkColor kLargeWallpaperColor = SK_ColorRED; |
125 static const SkColor kSmallWallpaperColor = SK_ColorGREEN; | 127 static const SkColor kSmallWallpaperColor = SK_ColorGREEN; |
126 static const SkColor kLargeGuestWallpaperColor = SK_ColorBLUE; | 128 static const SkColor kLargeGuestWallpaperColor = SK_ColorBLUE; |
127 static const SkColor kSmallGuestWallpaperColor = SK_ColorYELLOW; | 129 static const SkColor kSmallGuestWallpaperColor = SK_ColorYELLOW; |
128 | 130 |
129 // Dimension used for width and height of default wallpaper images. A | 131 // Dimension used for width and height of default wallpaper images. A |
130 // small value is used to minimize the amount of time spent compressing | 132 // small value is used to minimize the amount of time spent compressing |
131 // and writing images. | 133 // and writing images. |
132 static const int kWallpaperSize = 2; | 134 static const int kWallpaperSize = 2; |
133 | 135 |
| 136 // Creates an image of size |size|. |
| 137 gfx::ImageSkia CreateImage(int width, int height) { |
| 138 SkBitmap bitmap; |
| 139 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
| 140 bitmap.allocPixels(); |
| 141 gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
| 142 image.MakeThreadSafe(); |
| 143 return image; |
| 144 } |
| 145 |
134 // Runs kAnimatingDesktopController's animation to completion. | 146 // Runs kAnimatingDesktopController's animation to completion. |
135 // TODO(bshe): Don't require tests to run animations; it's slow. | 147 // TODO(bshe): Don't require tests to run animations; it's slow. |
136 void RunDesktopControllerAnimation() { | 148 void RunDesktopControllerAnimation() { |
137 internal::DesktopBackgroundWidgetController* controller = | 149 internal::DesktopBackgroundWidgetController* controller = |
138 Shell::GetPrimaryRootWindowController()-> | 150 Shell::GetPrimaryRootWindowController()-> |
139 animating_wallpaper_controller()->GetController(false); | 151 animating_wallpaper_controller()->GetController(false); |
140 ASSERT_NO_FATAL_FAILURE(RunAnimationForWidget(controller->widget())); | 152 ASSERT_NO_FATAL_FAILURE(RunAnimationForWidget(controller->widget())); |
141 } | 153 } |
142 | 154 |
143 // Returns true if the color at the center of |image| is close to | 155 // Returns true if the color at the center of |image| is close to |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 // The desktop controller should be the last created animating controller. | 431 // The desktop controller should be the last created animating controller. |
420 EXPECT_EQ(animating_controller, | 432 EXPECT_EQ(animating_controller, |
421 root_window_controller->wallpaper_controller()); | 433 root_window_controller->wallpaper_controller()); |
422 } | 434 } |
423 | 435 |
424 TEST_F(DesktopBackgroundControllerTest, DisplayChange) { | 436 TEST_F(DesktopBackgroundControllerTest, DisplayChange) { |
425 // TODO(derat|oshima|bshe): Host windows can't be resized on Win8. | 437 // TODO(derat|oshima|bshe): Host windows can't be resized on Win8. |
426 if (!SupportsHostWindowResize()) | 438 if (!SupportsHostWindowResize()) |
427 return; | 439 return; |
428 | 440 |
429 test::DisplayManagerTestApi display_manager_test_api( | 441 // Set the wallpaper to ensure that UpdateWallpaper() will be called when the |
430 Shell::GetInstance()->display_manager()); | 442 // display configuration changes. |
| 443 gfx::ImageSkia image = CreateImage(640, 480); |
| 444 wallpaper_delegate_->set_custom_wallpaper(image); |
| 445 controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH); |
431 | 446 |
432 // Small wallpaper images should be used for configurations less than or | 447 // Small wallpaper images should be used for configurations less than or |
433 // equal to kSmallWallpaperMaxWidth by kSmallWallpaperMaxHeight, even if | 448 // equal to kSmallWallpaperMaxWidth by kSmallWallpaperMaxHeight, even if |
434 // multiple displays are connected. | 449 // multiple displays are connected. |
| 450 test::DisplayManagerTestApi display_manager_test_api( |
| 451 Shell::GetInstance()->display_manager()); |
435 display_manager_test_api.UpdateDisplay("800x600"); | 452 display_manager_test_api.UpdateDisplay("800x600"); |
436 RunAllPendingInMessageLoop(); | 453 RunAllPendingInMessageLoop(); |
437 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, | 454 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, |
438 controller_->GetAppropriateResolution()); | 455 controller_->GetAppropriateResolution()); |
439 EXPECT_EQ(0, | 456 EXPECT_EQ(0, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
440 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
441 | 457 |
442 display_manager_test_api.UpdateDisplay("800x600,800x600"); | 458 display_manager_test_api.UpdateDisplay("800x600,800x600"); |
443 RunAllPendingInMessageLoop(); | 459 RunAllPendingInMessageLoop(); |
444 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, | 460 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, |
445 controller_->GetAppropriateResolution()); | 461 controller_->GetAppropriateResolution()); |
446 EXPECT_EQ(0, | 462 EXPECT_EQ(0, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
447 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
448 | 463 |
449 display_manager_test_api.UpdateDisplay("1366x800"); | 464 display_manager_test_api.UpdateDisplay("1366x800"); |
450 RunAllPendingInMessageLoop(); | 465 RunAllPendingInMessageLoop(); |
451 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, | 466 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, |
452 controller_->GetAppropriateResolution()); | 467 controller_->GetAppropriateResolution()); |
453 EXPECT_EQ(1, | 468 EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
454 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
455 | 469 |
456 // At larger sizes, large wallpapers should be used. | 470 // At larger sizes, large wallpapers should be used. |
457 display_manager_test_api.UpdateDisplay("1367x800"); | 471 display_manager_test_api.UpdateDisplay("1367x800"); |
458 RunAllPendingInMessageLoop(); | 472 RunAllPendingInMessageLoop(); |
459 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, | 473 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, |
460 controller_->GetAppropriateResolution()); | 474 controller_->GetAppropriateResolution()); |
461 EXPECT_EQ(1, | 475 EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
462 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
463 | 476 |
464 display_manager_test_api.UpdateDisplay("1367x801"); | 477 display_manager_test_api.UpdateDisplay("1367x801"); |
465 RunAllPendingInMessageLoop(); | 478 RunAllPendingInMessageLoop(); |
466 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, | 479 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, |
467 controller_->GetAppropriateResolution()); | 480 controller_->GetAppropriateResolution()); |
468 EXPECT_EQ(1, | 481 EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
469 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
470 | 482 |
471 display_manager_test_api.UpdateDisplay("2560x1700"); | 483 display_manager_test_api.UpdateDisplay("2560x1700"); |
472 RunAllPendingInMessageLoop(); | 484 RunAllPendingInMessageLoop(); |
473 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, | 485 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, |
474 controller_->GetAppropriateResolution()); | 486 controller_->GetAppropriateResolution()); |
475 EXPECT_EQ(1, | 487 EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
476 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
477 | 488 |
478 // Rotated smaller screen may use larger image. | 489 // Rotated smaller screen may use larger image. |
479 display_manager_test_api.UpdateDisplay("800x600/r"); | 490 display_manager_test_api.UpdateDisplay("800x600/r"); |
480 RunAllPendingInMessageLoop(); | 491 RunAllPendingInMessageLoop(); |
481 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, | 492 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, |
482 controller_->GetAppropriateResolution()); | 493 controller_->GetAppropriateResolution()); |
483 EXPECT_EQ(1, | 494 EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
484 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
485 | 495 |
486 display_manager_test_api.UpdateDisplay("800x600/r,800x600"); | 496 display_manager_test_api.UpdateDisplay("800x600/r,800x600"); |
487 RunAllPendingInMessageLoop(); | 497 RunAllPendingInMessageLoop(); |
488 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, | 498 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, |
489 controller_->GetAppropriateResolution()); | 499 controller_->GetAppropriateResolution()); |
490 EXPECT_EQ(1, | 500 EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
491 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
492 display_manager_test_api.UpdateDisplay("1366x800/r"); | 501 display_manager_test_api.UpdateDisplay("1366x800/r"); |
493 RunAllPendingInMessageLoop(); | 502 RunAllPendingInMessageLoop(); |
494 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, | 503 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, |
495 controller_->GetAppropriateResolution()); | 504 controller_->GetAppropriateResolution()); |
496 EXPECT_EQ(1, | 505 EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
497 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
498 | 506 |
499 // Max display size didn't chagne. | 507 // Max display size didn't chagne. |
500 display_manager_test_api.UpdateDisplay("900x800/r,400x1366"); | 508 display_manager_test_api.UpdateDisplay("900x800/r,400x1366"); |
501 RunAllPendingInMessageLoop(); | 509 RunAllPendingInMessageLoop(); |
502 EXPECT_EQ(0, | 510 EXPECT_EQ(0, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
503 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
504 | |
505 } | 511 } |
506 | 512 |
507 // Test that DesktopBackgroundController loads the appropriate wallpaper | 513 // Test that DesktopBackgroundController loads the appropriate wallpaper |
508 // images as specified via command-line flags in various situations. | 514 // images as specified via command-line flags in various situations. |
509 // Splitting these into separate tests avoids needing to run animations. | 515 // Splitting these into separate tests avoids needing to run animations. |
510 // TODO(derat): Combine these into a single test -- see | 516 // TODO(derat): Combine these into a single test -- see |
511 // RunDesktopControllerAnimation()'s TODO. | 517 // RunDesktopControllerAnimation()'s TODO. |
512 TEST_F(DesktopBackgroundControllerTest, SmallDefaultWallpaper) { | 518 TEST_F(DesktopBackgroundControllerTest, SmallDefaultWallpaper) { |
513 if (!SupportsMultipleDisplays()) | 519 if (!SupportsMultipleDisplays()) |
514 return; | 520 return; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 TestObserver observer(controller_); | 588 TestObserver observer(controller_); |
583 test::DisplayManagerTestApi display_manager_test_api( | 589 test::DisplayManagerTestApi display_manager_test_api( |
584 Shell::GetInstance()->display_manager()); | 590 Shell::GetInstance()->display_manager()); |
585 display_manager_test_api.UpdateDisplay("1600x1200"); | 591 display_manager_test_api.UpdateDisplay("1600x1200"); |
586 ASSERT_TRUE(controller_->SetDefaultWallpaper(true)); | 592 ASSERT_TRUE(controller_->SetDefaultWallpaper(true)); |
587 observer.WaitForWallpaperDataChanged(); | 593 observer.WaitForWallpaperDataChanged(); |
588 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), | 594 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), |
589 kLargeGuestWallpaperColor)); | 595 kLargeGuestWallpaperColor)); |
590 } | 596 } |
591 | 597 |
| 598 TEST_F(DesktopBackgroundControllerTest, ResizeCustomWallpaper) { |
| 599 if (!SupportsMultipleDisplays()) |
| 600 return; |
| 601 |
| 602 test::DisplayManagerTestApi display_manager_test_api( |
| 603 Shell::GetInstance()->display_manager()); |
| 604 display_manager_test_api.UpdateDisplay("320x200"); |
| 605 |
| 606 gfx::ImageSkia image = CreateImage(640, 480); |
| 607 |
| 608 // Set the image as custom wallpaper, wait for the resize to finish, and check |
| 609 // that the resized image is the expected size. |
| 610 controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH); |
| 611 EXPECT_TRUE(image.BackedBySameObjectAs(controller_->GetWallpaper())); |
| 612 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 613 content::RunAllPendingInMessageLoop(); |
| 614 gfx::ImageSkia resized_image = controller_->GetWallpaper(); |
| 615 EXPECT_FALSE(image.BackedBySameObjectAs(resized_image)); |
| 616 EXPECT_EQ(gfx::Size(320, 200).ToString(), resized_image.size().ToString()); |
| 617 |
| 618 // Load the original wallpaper again and check that we're still using the |
| 619 // previously-resized image instead of doing another resize |
| 620 // (http://crbug.com/321402). |
| 621 controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH); |
| 622 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
| 623 content::RunAllPendingInMessageLoop(); |
| 624 EXPECT_TRUE(resized_image.BackedBySameObjectAs(controller_->GetWallpaper())); |
| 625 } |
| 626 |
592 TEST_F(DesktopBackgroundControllerTest, GetMaxDisplaySize) { | 627 TEST_F(DesktopBackgroundControllerTest, GetMaxDisplaySize) { |
593 // Device scale factor shouldn't affect the native size. | 628 // Device scale factor shouldn't affect the native size. |
594 UpdateDisplay("1000x300*2"); | 629 UpdateDisplay("1000x300*2"); |
595 EXPECT_EQ( | 630 EXPECT_EQ( |
596 "1000x300", | 631 "1000x300", |
597 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); | 632 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); |
598 | 633 |
599 // Rotated display should return the rotated size. | 634 // Rotated display should return the rotated size. |
600 UpdateDisplay("1000x300*2/r"); | 635 UpdateDisplay("1000x300*2/r"); |
601 EXPECT_EQ( | 636 EXPECT_EQ( |
(...skipping 22 matching lines...) Expand all Loading... |
624 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); | 659 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); |
625 | 660 |
626 // Maximum width and height belongs to different displays. | 661 // Maximum width and height belongs to different displays. |
627 UpdateDisplay("400x300,100x500"); | 662 UpdateDisplay("400x300,100x500"); |
628 EXPECT_EQ( | 663 EXPECT_EQ( |
629 "400x500", | 664 "400x500", |
630 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); | 665 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); |
631 } | 666 } |
632 | 667 |
633 } // namespace ash | 668 } // namespace ash |
OLD | NEW |