| 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 "base/command_line.h" | 19 #include "base/command_line.h" |
| 19 #include "base/file_util.h" | 20 #include "base/file_util.h" |
| 20 #include "base/files/file_path.h" | 21 #include "base/files/file_path.h" |
| 21 #include "base/files/scoped_temp_dir.h" | 22 #include "base/files/scoped_temp_dir.h" |
| 22 #include "base/message_loop/message_loop.h" | 23 #include "base/message_loop/message_loop.h" |
| 23 #include "content/public/test/test_browser_thread.h" | 24 #include "content/public/test/test_browser_thread.h" |
| 24 #include "third_party/skia/include/core/SkBitmap.h" | 25 #include "third_party/skia/include/core/SkBitmap.h" |
| 25 #include "third_party/skia/include/core/SkColor.h" | 26 #include "third_party/skia/include/core/SkColor.h" |
| 26 #include "ui/aura/root_window.h" | 27 #include "ui/aura/root_window.h" |
| 27 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 28 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 106 |
| 106 virtual void SetUp() OVERRIDE { | 107 virtual void SetUp() OVERRIDE { |
| 107 test::AshTestBase::SetUp(); | 108 test::AshTestBase::SetUp(); |
| 108 // Ash shell initialization creates wallpaper. Reset it so we can manually | 109 // Ash shell initialization creates wallpaper. Reset it so we can manually |
| 109 // control wallpaper creation and animation in our tests. | 110 // control wallpaper creation and animation in our tests. |
| 110 internal::RootWindowController* root_window_controller = | 111 internal::RootWindowController* root_window_controller = |
| 111 Shell::GetPrimaryRootWindowController(); | 112 Shell::GetPrimaryRootWindowController(); |
| 112 root_window_controller->SetWallpaperController(NULL); | 113 root_window_controller->SetWallpaperController(NULL); |
| 113 root_window_controller->SetAnimatingWallpaperController(NULL); | 114 root_window_controller->SetAnimatingWallpaperController(NULL); |
| 114 controller_ = Shell::GetInstance()->desktop_background_controller(); | 115 controller_ = Shell::GetInstance()->desktop_background_controller(); |
| 116 wallpaper_delegate_ = static_cast<test::TestUserWallpaperDelegate*>( |
| 117 Shell::GetInstance()->user_wallpaper_delegate()); |
| 118 controller_->set_wallpaper_reload_delay_for_test(0); |
| 115 } | 119 } |
| 116 | 120 |
| 117 protected: | 121 protected: |
| 118 // Colors used for different default wallpapers by | 122 // Colors used for different default wallpapers by |
| 119 // WriteWallpapersAndSetFlags(). | 123 // WriteWallpapersAndSetFlags(). |
| 120 static const SkColor kLargeWallpaperColor = SK_ColorRED; | 124 static const SkColor kLargeWallpaperColor = SK_ColorRED; |
| 121 static const SkColor kSmallWallpaperColor = SK_ColorGREEN; | 125 static const SkColor kSmallWallpaperColor = SK_ColorGREEN; |
| 122 static const SkColor kLargeGuestWallpaperColor = SK_ColorBLUE; | 126 static const SkColor kLargeGuestWallpaperColor = SK_ColorBLUE; |
| 123 static const SkColor kSmallGuestWallpaperColor = SK_ColorYELLOW; | 127 static const SkColor kSmallGuestWallpaperColor = SK_ColorYELLOW; |
| 124 | 128 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 // Custom command line passed to DesktopBackgroundController by | 251 // Custom command line passed to DesktopBackgroundController by |
| 248 // WriteWallpapersAndSetFlags(). | 252 // WriteWallpapersAndSetFlags(). |
| 249 CommandLine command_line_; | 253 CommandLine command_line_; |
| 250 | 254 |
| 251 // Directory created by WriteWallpapersAndSetFlags() to store default | 255 // Directory created by WriteWallpapersAndSetFlags() to store default |
| 252 // wallpaper images. | 256 // wallpaper images. |
| 253 scoped_ptr<base::ScopedTempDir> wallpaper_dir_; | 257 scoped_ptr<base::ScopedTempDir> wallpaper_dir_; |
| 254 | 258 |
| 255 DesktopBackgroundController* controller_; // Not owned. | 259 DesktopBackgroundController* controller_; // Not owned. |
| 256 | 260 |
| 261 test::TestUserWallpaperDelegate* wallpaper_delegate_; |
| 262 |
| 257 private: | 263 private: |
| 258 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundControllerTest); | 264 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundControllerTest); |
| 259 }; | 265 }; |
| 260 | 266 |
| 261 TEST_F(DesktopBackgroundControllerTest, BasicReparenting) { | 267 TEST_F(DesktopBackgroundControllerTest, BasicReparenting) { |
| 262 DesktopBackgroundController* controller = | 268 DesktopBackgroundController* controller = |
| 263 Shell::GetInstance()->desktop_background_controller(); | 269 Shell::GetInstance()->desktop_background_controller(); |
| 264 controller->CreateEmptyWallpaper(); | 270 controller->CreateEmptyWallpaper(); |
| 265 | 271 |
| 266 // Wallpaper view/window exists in the desktop background container and | 272 // Wallpaper view/window exists in the desktop background container and |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 GetController(false)->widget())); | 414 GetController(false)->widget())); |
| 409 | 415 |
| 410 EXPECT_TRUE(root_window_controller->wallpaper_controller()); | 416 EXPECT_TRUE(root_window_controller->wallpaper_controller()); |
| 411 EXPECT_FALSE(root_window_controller->animating_wallpaper_controller()-> | 417 EXPECT_FALSE(root_window_controller->animating_wallpaper_controller()-> |
| 412 GetController(false)); | 418 GetController(false)); |
| 413 // The desktop controller should be the last created animating controller. | 419 // The desktop controller should be the last created animating controller. |
| 414 EXPECT_EQ(animating_controller, | 420 EXPECT_EQ(animating_controller, |
| 415 root_window_controller->wallpaper_controller()); | 421 root_window_controller->wallpaper_controller()); |
| 416 } | 422 } |
| 417 | 423 |
| 418 TEST_F(DesktopBackgroundControllerTest, GetAppropriateResolution) { | 424 TEST_F(DesktopBackgroundControllerTest, DisplayChange) { |
| 419 // TODO(derat|oshima|bshe): Configuring desktops seems busted on Win8, | 425 // TODO(derat|oshima|bshe): Host windows can't be resized on Win8. |
| 420 // even when just a single display is being used -- the small wallpaper | 426 if (!SupportsHostWindowResize()) |
| 421 // is used instead of the large one. Track down the cause of the problem | |
| 422 // and only use a SupportsMultipleDisplays() clause for the dual-display | |
| 423 // code below. | |
| 424 if (!SupportsMultipleDisplays()) | |
| 425 return; | 427 return; |
| 426 | 428 |
| 427 test::DisplayManagerTestApi display_manager_test_api( | 429 test::DisplayManagerTestApi display_manager_test_api( |
| 428 Shell::GetInstance()->display_manager()); | 430 Shell::GetInstance()->display_manager()); |
| 429 | 431 |
| 430 // Small wallpaper images should be used for configurations less than or | 432 // Small wallpaper images should be used for configurations less than or |
| 431 // equal to kSmallWallpaperMaxWidth by kSmallWallpaperMaxHeight, even if | 433 // equal to kSmallWallpaperMaxWidth by kSmallWallpaperMaxHeight, even if |
| 432 // multiple displays are connected. | 434 // multiple displays are connected. |
| 433 display_manager_test_api.UpdateDisplay("800x600"); | 435 display_manager_test_api.UpdateDisplay("800x600"); |
| 436 RunAllPendingInMessageLoop(); |
| 434 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, | 437 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, |
| 435 controller_->GetAppropriateResolution()); | 438 controller_->GetAppropriateResolution()); |
| 439 EXPECT_EQ(0, |
| 440 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
| 441 |
| 436 display_manager_test_api.UpdateDisplay("800x600,800x600"); | 442 display_manager_test_api.UpdateDisplay("800x600,800x600"); |
| 443 RunAllPendingInMessageLoop(); |
| 437 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, | 444 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, |
| 438 controller_->GetAppropriateResolution()); | 445 controller_->GetAppropriateResolution()); |
| 446 EXPECT_EQ(0, |
| 447 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
| 448 |
| 439 display_manager_test_api.UpdateDisplay("1366x800"); | 449 display_manager_test_api.UpdateDisplay("1366x800"); |
| 450 RunAllPendingInMessageLoop(); |
| 440 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, | 451 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, |
| 441 controller_->GetAppropriateResolution()); | 452 controller_->GetAppropriateResolution()); |
| 453 EXPECT_EQ(1, |
| 454 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
| 442 | 455 |
| 443 // At larger sizes, large wallpapers should be used. | 456 // At larger sizes, large wallpapers should be used. |
| 444 display_manager_test_api.UpdateDisplay("1367x800"); | 457 display_manager_test_api.UpdateDisplay("1367x800"); |
| 458 RunAllPendingInMessageLoop(); |
| 445 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, | 459 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, |
| 446 controller_->GetAppropriateResolution()); | 460 controller_->GetAppropriateResolution()); |
| 461 EXPECT_EQ(1, |
| 462 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
| 463 |
| 447 display_manager_test_api.UpdateDisplay("1367x801"); | 464 display_manager_test_api.UpdateDisplay("1367x801"); |
| 465 RunAllPendingInMessageLoop(); |
| 448 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, | 466 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, |
| 449 controller_->GetAppropriateResolution()); | 467 controller_->GetAppropriateResolution()); |
| 468 EXPECT_EQ(1, |
| 469 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
| 470 |
| 450 display_manager_test_api.UpdateDisplay("2560x1700"); | 471 display_manager_test_api.UpdateDisplay("2560x1700"); |
| 472 RunAllPendingInMessageLoop(); |
| 451 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, | 473 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, |
| 452 controller_->GetAppropriateResolution()); | 474 controller_->GetAppropriateResolution()); |
| 475 EXPECT_EQ(1, |
| 476 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
| 453 | 477 |
| 454 // Rotated smaller screen may use larger image. | 478 // Rotated smaller screen may use larger image. |
| 455 display_manager_test_api.UpdateDisplay("800x600/r"); | 479 display_manager_test_api.UpdateDisplay("800x600/r"); |
| 480 RunAllPendingInMessageLoop(); |
| 456 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, | 481 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, |
| 457 controller_->GetAppropriateResolution()); | 482 controller_->GetAppropriateResolution()); |
| 483 EXPECT_EQ(1, |
| 484 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
| 485 |
| 458 display_manager_test_api.UpdateDisplay("800x600/r,800x600"); | 486 display_manager_test_api.UpdateDisplay("800x600/r,800x600"); |
| 487 RunAllPendingInMessageLoop(); |
| 459 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, | 488 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, |
| 460 controller_->GetAppropriateResolution()); | 489 controller_->GetAppropriateResolution()); |
| 490 EXPECT_EQ(1, |
| 491 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
| 461 display_manager_test_api.UpdateDisplay("1366x800/r"); | 492 display_manager_test_api.UpdateDisplay("1366x800/r"); |
| 493 RunAllPendingInMessageLoop(); |
| 462 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, | 494 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, |
| 463 controller_->GetAppropriateResolution()); | 495 controller_->GetAppropriateResolution()); |
| 496 EXPECT_EQ(1, |
| 497 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
| 498 |
| 499 // Max display size didn't chagne. |
| 500 display_manager_test_api.UpdateDisplay("900x800/r,400x1366"); |
| 501 RunAllPendingInMessageLoop(); |
| 502 EXPECT_EQ(0, |
| 503 wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); |
| 504 |
| 464 } | 505 } |
| 465 | 506 |
| 466 // Test that DesktopBackgroundController loads the appropriate wallpaper | 507 // Test that DesktopBackgroundController loads the appropriate wallpaper |
| 467 // images as specified via command-line flags in various situations. | 508 // images as specified via command-line flags in various situations. |
| 468 // Splitting these into separate tests avoids needing to run animations. | 509 // Splitting these into separate tests avoids needing to run animations. |
| 469 // TODO(derat): Combine these into a single test -- see | 510 // TODO(derat): Combine these into a single test -- see |
| 470 // RunDesktopControllerAnimation()'s TODO. | 511 // RunDesktopControllerAnimation()'s TODO. |
| 471 TEST_F(DesktopBackgroundControllerTest, SmallDefaultWallpaper) { | 512 TEST_F(DesktopBackgroundControllerTest, SmallDefaultWallpaper) { |
| 472 if (!SupportsMultipleDisplays()) | 513 if (!SupportsMultipleDisplays()) |
| 473 return; | 514 return; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); | 624 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); |
| 584 | 625 |
| 585 // Maximum width and height belongs to different displays. | 626 // Maximum width and height belongs to different displays. |
| 586 UpdateDisplay("400x300,100x500"); | 627 UpdateDisplay("400x300,100x500"); |
| 587 EXPECT_EQ( | 628 EXPECT_EQ( |
| 588 "400x500", | 629 "400x500", |
| 589 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); | 630 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); |
| 590 } | 631 } |
| 591 | 632 |
| 592 } // namespace ash | 633 } // namespace ash |
| OLD | NEW |