| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 5 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "ash/common/wm_shell.h" | 9 #include "ash/common/wm_shell.h" |
| 10 #include "ash/desktop_background/desktop_background_controller.h" | |
| 11 #include "ash/desktop_background/desktop_background_controller_observer.h" | |
| 12 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
| 13 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 14 #include "ash/test/ash_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
| 15 #include "ash/test/ash_test_helper.h" | 13 #include "ash/test/ash_test_helper.h" |
| 16 #include "ash/test/display_manager_test_api.h" | 14 #include "ash/test/display_manager_test_api.h" |
| 15 #include "ash/wallpaper/wallpaper_controller.h" |
| 16 #include "ash/wallpaper/wallpaper_controller_observer.h" |
| 17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
| 18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
| 19 #include "base/files/file_path.h" | 19 #include "base/files/file_path.h" |
| 20 #include "base/files/file_util.h" | 20 #include "base/files/file_util.h" |
| 21 #include "base/macros.h" | 21 #include "base/macros.h" |
| 22 #include "base/message_loop/message_loop.h" | 22 #include "base/message_loop/message_loop.h" |
| 23 #include "base/path_service.h" | 23 #include "base/path_service.h" |
| 24 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
| 25 #include "base/time/time.h" | 25 #include "base/time/time.h" |
| 26 #include "base/values.h" | 26 #include "base/values.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 | 65 |
| 66 class WallpaperManagerBrowserTest : public InProcessBrowserTest { | 66 class WallpaperManagerBrowserTest : public InProcessBrowserTest { |
| 67 public: | 67 public: |
| 68 WallpaperManagerBrowserTest() : controller_(NULL), | 68 WallpaperManagerBrowserTest() : controller_(NULL), |
| 69 local_state_(NULL) { | 69 local_state_(NULL) { |
| 70 } | 70 } |
| 71 | 71 |
| 72 ~WallpaperManagerBrowserTest() override {} | 72 ~WallpaperManagerBrowserTest() override {} |
| 73 | 73 |
| 74 void SetUpOnMainThread() override { | 74 void SetUpOnMainThread() override { |
| 75 controller_ = ash::Shell::GetInstance()->desktop_background_controller(); | 75 controller_ = ash::Shell::GetInstance()->wallpaper_controller(); |
| 76 controller_->set_wallpaper_reload_delay_for_test(0); | 76 controller_->set_wallpaper_reload_delay_for_test(0); |
| 77 local_state_ = g_browser_process->local_state(); | 77 local_state_ = g_browser_process->local_state(); |
| 78 UpdateDisplay("800x600"); | 78 UpdateDisplay("800x600"); |
| 79 } | 79 } |
| 80 | 80 |
| 81 void SetUpCommandLine(base::CommandLine* command_line) override { | 81 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 82 command_line->AppendSwitch(switches::kLoginManager); | 82 command_line->AppendSwitch(switches::kLoginManager); |
| 83 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); | 83 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); |
| 84 } | 84 } |
| 85 | 85 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 // wallpaper images to them. | 153 // wallpaper images to them. |
| 154 // Only needs to be called (once) by tests that want to test loading of | 154 // Only needs to be called (once) by tests that want to test loading of |
| 155 // default wallpapers. | 155 // default wallpapers. |
| 156 void CreateCmdlineWallpapers() { | 156 void CreateCmdlineWallpapers() { |
| 157 wallpaper_dir_.reset(new base::ScopedTempDir); | 157 wallpaper_dir_.reset(new base::ScopedTempDir); |
| 158 ASSERT_TRUE(wallpaper_dir_->CreateUniqueTempDir()); | 158 ASSERT_TRUE(wallpaper_dir_->CreateUniqueTempDir()); |
| 159 wallpaper_manager_test_utils::CreateCmdlineWallpapers( | 159 wallpaper_manager_test_utils::CreateCmdlineWallpapers( |
| 160 *wallpaper_dir_, &wallpaper_manager_command_line_); | 160 *wallpaper_dir_, &wallpaper_manager_command_line_); |
| 161 } | 161 } |
| 162 | 162 |
| 163 ash::DesktopBackgroundController* controller_; | 163 ash::WallpaperController* controller_; |
| 164 PrefService* local_state_; | 164 PrefService* local_state_; |
| 165 std::unique_ptr<base::CommandLine> wallpaper_manager_command_line_; | 165 std::unique_ptr<base::CommandLine> wallpaper_manager_command_line_; |
| 166 | 166 |
| 167 // Directory created by CreateCmdlineWallpapers () to store default | 167 // Directory created by CreateCmdlineWallpapers () to store default |
| 168 // wallpaper images. | 168 // wallpaper images. |
| 169 std::unique_ptr<base::ScopedTempDir> wallpaper_dir_; | 169 std::unique_ptr<base::ScopedTempDir> wallpaper_dir_; |
| 170 | 170 |
| 171 const AccountId test_account_id1_ = AccountId::FromUserEmail(kTestUser1); | 171 const AccountId test_account_id1_ = AccountId::FromUserEmail(kTestUser1); |
| 172 const AccountId test_account_id2_ = AccountId::FromUserEmail(kTestUser2); | 172 const AccountId test_account_id2_ = AccountId::FromUserEmail(kTestUser2); |
| 173 | 173 |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 // 2. chooses a custom wallpaper from wallpaper | 538 // 2. chooses a custom wallpaper from wallpaper |
| 539 // picker (calls SetCustomWallpaper); | 539 // picker (calls SetCustomWallpaper); |
| 540 // 3. reverts to a default wallpaper. | 540 // 3. reverts to a default wallpaper. |
| 541 // Also, when user login at multi-profile mode, previous logged in users' | 541 // Also, when user login at multi-profile mode, previous logged in users' |
| 542 // wallpaper cache should not be deleted. | 542 // wallpaper cache should not be deleted. |
| 543 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCacheUpdate, | 543 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCacheUpdate, |
| 544 VerifyWallpaperCache) { | 544 VerifyWallpaperCache) { |
| 545 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); | 545 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); |
| 546 | 546 |
| 547 // Force load initial wallpaper | 547 // Force load initial wallpaper |
| 548 // (simulate DesktopBackgroundController::UpdateDisplay()). | 548 // (simulate WallpaperController::UpdateDisplay()). |
| 549 wallpaper_manager->UpdateWallpaper(true); | 549 wallpaper_manager->UpdateWallpaper(true); |
| 550 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | 550 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); |
| 551 std::unique_ptr<WallpaperManager::TestApi> test_api; | 551 std::unique_ptr<WallpaperManager::TestApi> test_api; |
| 552 test_api.reset(new WallpaperManager::TestApi(wallpaper_manager)); | 552 test_api.reset(new WallpaperManager::TestApi(wallpaper_manager)); |
| 553 gfx::ImageSkia cached_wallpaper; | 553 gfx::ImageSkia cached_wallpaper; |
| 554 // Previous custom wallpaper should be cached after user login. | 554 // Previous custom wallpaper should be cached after user login. |
| 555 EXPECT_TRUE( | 555 EXPECT_TRUE( |
| 556 test_api->GetWallpaperFromCache(test_account_id1_, &cached_wallpaper)); | 556 test_api->GetWallpaperFromCache(test_account_id1_, &cached_wallpaper)); |
| 557 base::FilePath original_path; | 557 base::FilePath original_path; |
| 558 EXPECT_TRUE(test_api->GetPathFromCache(test_account_id1_, &original_path)); | 558 EXPECT_TRUE(test_api->GetPathFromCache(test_account_id1_, &original_path)); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 // Set the wallpaper to ensure that UpdateWallpaper() will be called when the | 641 // Set the wallpaper to ensure that UpdateWallpaper() will be called when the |
| 642 // display configuration changes. | 642 // display configuration changes. |
| 643 gfx::ImageSkia image = wallpaper_manager_test_utils::CreateTestImage( | 643 gfx::ImageSkia image = wallpaper_manager_test_utils::CreateTestImage( |
| 644 640, 480, wallpaper_manager_test_utils::kCustomWallpaperColor); | 644 640, 480, wallpaper_manager_test_utils::kCustomWallpaperColor); |
| 645 controller_->SetWallpaperImage(image, WALLPAPER_LAYOUT_STRETCH); | 645 controller_->SetWallpaperImage(image, WALLPAPER_LAYOUT_STRETCH); |
| 646 | 646 |
| 647 // Small wallpaper images should be used for configurations less than or | 647 // Small wallpaper images should be used for configurations less than or |
| 648 // equal to kSmallWallpaperMaxWidth by kSmallWallpaperMaxHeight, even if | 648 // equal to kSmallWallpaperMaxWidth by kSmallWallpaperMaxHeight, even if |
| 649 // multiple displays are connected. | 649 // multiple displays are connected. |
| 650 UpdateDisplay("800x600"); | 650 UpdateDisplay("800x600"); |
| 651 // Wait for asynchronous DisplayBackgroundController::UpdateDisplay() call. | |
| 652 base::RunLoop().RunUntilIdle(); | 651 base::RunLoop().RunUntilIdle(); |
| 653 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | 652 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); |
| 654 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, | 653 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, |
| 655 WallpaperManager::Get()->GetAppropriateResolution()); | 654 WallpaperManager::Get()->GetAppropriateResolution()); |
| 656 EXPECT_EQ(0, observer.GetUpdateWallpaperCountAndReset()); | 655 EXPECT_EQ(0, observer.GetUpdateWallpaperCountAndReset()); |
| 657 | 656 |
| 658 UpdateDisplay("800x600,800x600"); | 657 UpdateDisplay("800x600,800x600"); |
| 659 // Wait for asynchronous DisplayBackgroundController::UpdateDisplay() call. | |
| 660 base::RunLoop().RunUntilIdle(); | 658 base::RunLoop().RunUntilIdle(); |
| 661 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | 659 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); |
| 662 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, | 660 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, |
| 663 WallpaperManager::Get()->GetAppropriateResolution()); | 661 WallpaperManager::Get()->GetAppropriateResolution()); |
| 664 EXPECT_EQ(0, observer.GetUpdateWallpaperCountAndReset()); | 662 EXPECT_EQ(0, observer.GetUpdateWallpaperCountAndReset()); |
| 665 | 663 |
| 666 UpdateDisplay("1366x800"); | 664 UpdateDisplay("1366x800"); |
| 667 // Wait for asynchronous DisplayBackgroundController::UpdateDisplay() call. | |
| 668 base::RunLoop().RunUntilIdle(); | 665 base::RunLoop().RunUntilIdle(); |
| 669 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | 666 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); |
| 670 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, | 667 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, |
| 671 WallpaperManager::Get()->GetAppropriateResolution()); | 668 WallpaperManager::Get()->GetAppropriateResolution()); |
| 672 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | 669 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); |
| 673 | 670 |
| 674 // At larger sizes, large wallpapers should be used. | 671 // At larger sizes, large wallpapers should be used. |
| 675 UpdateDisplay("1367x800"); | 672 UpdateDisplay("1367x800"); |
| 676 // Wait for asynchronous DisplayBackgroundController::UpdateDisplay() call. | |
| 677 base::RunLoop().RunUntilIdle(); | 673 base::RunLoop().RunUntilIdle(); |
| 678 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | 674 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); |
| 679 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_LARGE, | 675 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_LARGE, |
| 680 WallpaperManager::Get()->GetAppropriateResolution()); | 676 WallpaperManager::Get()->GetAppropriateResolution()); |
| 681 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | 677 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); |
| 682 | 678 |
| 683 UpdateDisplay("1367x801"); | 679 UpdateDisplay("1367x801"); |
| 684 // Wait for asynchronous DisplayBackgroundController::UpdateDisplay() call. | |
| 685 base::RunLoop().RunUntilIdle(); | 680 base::RunLoop().RunUntilIdle(); |
| 686 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | 681 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); |
| 687 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_LARGE, | 682 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_LARGE, |
| 688 WallpaperManager::Get()->GetAppropriateResolution()); | 683 WallpaperManager::Get()->GetAppropriateResolution()); |
| 689 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | 684 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); |
| 690 | 685 |
| 691 UpdateDisplay("2560x1700"); | 686 UpdateDisplay("2560x1700"); |
| 692 // Wait for asynchronous DisplayBackgroundController::UpdateDisplay() call. | |
| 693 base::RunLoop().RunUntilIdle(); | 687 base::RunLoop().RunUntilIdle(); |
| 694 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | 688 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); |
| 695 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_LARGE, | 689 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_LARGE, |
| 696 WallpaperManager::Get()->GetAppropriateResolution()); | 690 WallpaperManager::Get()->GetAppropriateResolution()); |
| 697 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | 691 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); |
| 698 | 692 |
| 699 // Rotated smaller screen may use larger image. | 693 // Rotated smaller screen may use larger image. |
| 700 UpdateDisplay("800x600/r"); | 694 UpdateDisplay("800x600/r"); |
| 701 // Wait for asynchronous DisplayBackgroundController::UpdateDisplay() call. | |
| 702 base::RunLoop().RunUntilIdle(); | 695 base::RunLoop().RunUntilIdle(); |
| 703 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | 696 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); |
| 704 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, | 697 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, |
| 705 WallpaperManager::Get()->GetAppropriateResolution()); | 698 WallpaperManager::Get()->GetAppropriateResolution()); |
| 706 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | 699 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); |
| 707 | 700 |
| 708 UpdateDisplay("800x600/r,800x600"); | 701 UpdateDisplay("800x600/r,800x600"); |
| 709 // Wait for asynchronous DisplayBackgroundController::UpdateDisplay() call. | |
| 710 base::RunLoop().RunUntilIdle(); | 702 base::RunLoop().RunUntilIdle(); |
| 711 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | 703 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); |
| 712 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, | 704 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, |
| 713 WallpaperManager::Get()->GetAppropriateResolution()); | 705 WallpaperManager::Get()->GetAppropriateResolution()); |
| 714 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | 706 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); |
| 715 UpdateDisplay("1366x800/r"); | 707 UpdateDisplay("1366x800/r"); |
| 716 // Wait for asynchronous DisplayBackgroundController::UpdateDisplay() call. | |
| 717 base::RunLoop().RunUntilIdle(); | 708 base::RunLoop().RunUntilIdle(); |
| 718 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | 709 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); |
| 719 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_LARGE, | 710 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_LARGE, |
| 720 WallpaperManager::Get()->GetAppropriateResolution()); | 711 WallpaperManager::Get()->GetAppropriateResolution()); |
| 721 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | 712 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); |
| 722 | 713 |
| 723 // Max display size didn't change. | 714 // Max display size didn't change. |
| 724 UpdateDisplay("900x800/r,400x1366"); | 715 UpdateDisplay("900x800/r,400x1366"); |
| 725 // Wait for asynchronous DisplayBackgroundController::UpdateDisplay() call. | |
| 726 base::RunLoop().RunUntilIdle(); | 716 base::RunLoop().RunUntilIdle(); |
| 727 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | 717 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); |
| 728 EXPECT_EQ(0, observer.GetUpdateWallpaperCountAndReset()); | 718 EXPECT_EQ(0, observer.GetUpdateWallpaperCountAndReset()); |
| 729 } | 719 } |
| 730 | 720 |
| 731 // Test that WallpaperManager loads the appropriate wallpaper | 721 // Test that WallpaperManager loads the appropriate wallpaper |
| 732 // images as specified via command-line flags in various situations. | 722 // images as specified via command-line flags in various situations. |
| 733 // Splitting these into separate tests avoids needing to run animations. | 723 // Splitting these into separate tests avoids needing to run animations. |
| 734 // TODO(derat): Combine these into a single test | 724 // TODO(derat): Combine these into a single test |
| 735 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, SmallDefaultWallpaper) { | 725 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, SmallDefaultWallpaper) { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 858 | 848 |
| 859 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId()); | 849 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId()); |
| 860 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | 850 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); |
| 861 | 851 |
| 862 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( | 852 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( |
| 863 controller_->GetWallpaper(), | 853 controller_->GetWallpaper(), |
| 864 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor)); | 854 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor)); |
| 865 } | 855 } |
| 866 | 856 |
| 867 } // namespace chromeos | 857 } // namespace chromeos |
| OLD | NEW |