| 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/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/wallpaper/wallpaper_controller.h" | 10 #include "ash/wallpaper/wallpaper_controller.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/files/file_util.h" | 14 #include "base/files/file_util.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/message_loop/message_loop.h" | 16 #include "base/message_loop/message_loop.h" |
| 17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
| 19 #include "base/threading/thread_restrictions.h" |
| 19 #include "base/time/time.h" | 20 #include "base/time/time.h" |
| 20 #include "base/values.h" | 21 #include "base/values.h" |
| 21 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager_test_u
tils.h" | 22 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager_test_u
tils.h" |
| 22 #include "chrome/browser/ui/ash/session_controller_client.h" | 23 #include "chrome/browser/ui/ash/session_controller_client.h" |
| 23 #include "chrome/common/chrome_paths.h" | 24 #include "chrome/common/chrome_paths.h" |
| 24 #include "chrome/test/base/in_process_browser_test.h" | 25 #include "chrome/test/base/in_process_browser_test.h" |
| 25 #include "chrome/test/base/testing_browser_process.h" | 26 #include "chrome/test/base/testing_browser_process.h" |
| 26 #include "chromeos/chromeos_switches.h" | 27 #include "chromeos/chromeos_switches.h" |
| 27 #include "components/prefs/scoped_user_pref_update.h" | 28 #include "components/prefs/scoped_user_pref_update.h" |
| 28 #include "components/session_manager/core/session_manager.h" | 29 #include "components/session_manager/core/session_manager.h" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 base::RunLoop().RunUntilIdle(); | 96 base::RunLoop().RunUntilIdle(); |
| 96 } | 97 } |
| 97 | 98 |
| 98 protected: | 99 protected: |
| 99 | 100 |
| 100 // Return custom wallpaper path. Create directory if not exist. | 101 // Return custom wallpaper path. Create directory if not exist. |
| 101 base::FilePath GetCustomWallpaperPath( | 102 base::FilePath GetCustomWallpaperPath( |
| 102 const char* sub_dir, | 103 const char* sub_dir, |
| 103 const wallpaper::WallpaperFilesId& wallpaper_files_id, | 104 const wallpaper::WallpaperFilesId& wallpaper_files_id, |
| 104 const std::string& id) { | 105 const std::string& id) { |
| 106 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 105 base::FilePath wallpaper_path = | 107 base::FilePath wallpaper_path = |
| 106 WallpaperManager::Get()->GetCustomWallpaperPath(sub_dir, | 108 WallpaperManager::Get()->GetCustomWallpaperPath(sub_dir, |
| 107 wallpaper_files_id, id); | 109 wallpaper_files_id, id); |
| 108 if (!base::DirectoryExists(wallpaper_path.DirName())) | 110 if (!base::DirectoryExists(wallpaper_path.DirName())) |
| 109 base::CreateDirectory(wallpaper_path.DirName()); | 111 base::CreateDirectory(wallpaper_path.DirName()); |
| 110 | 112 |
| 111 return wallpaper_path; | 113 return wallpaper_path; |
| 112 } | 114 } |
| 113 | 115 |
| 114 // Logs in |account_id|. | 116 // Logs in |account_id|. |
| 115 void LogIn(const AccountId& account_id, const std::string& user_id_hash) { | 117 void LogIn(const AccountId& account_id, const std::string& user_id_hash) { |
| 118 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 116 SessionManager::Get()->CreateSession(account_id, user_id_hash); | 119 SessionManager::Get()->CreateSession(account_id, user_id_hash); |
| 117 SessionManager::Get()->SessionStarted(); | 120 SessionManager::Get()->SessionStarted(); |
| 118 // Flush to ensure the created session and ACTIVE state reaches ash. | 121 // Flush to ensure the created session and ACTIVE state reaches ash. |
| 119 SessionControllerClient::FlushForTesting(); | 122 SessionControllerClient::FlushForTesting(); |
| 120 WaitAsyncWallpaperLoadStarted(); | 123 WaitAsyncWallpaperLoadStarted(); |
| 121 } | 124 } |
| 122 | 125 |
| 123 // Logs in |account_id| and sets it as child account. | 126 // Logs in |account_id| and sets it as child account. |
| 124 void LogInAsChild(const AccountId& account_id, | 127 void LogInAsChild(const AccountId& account_id, |
| 125 const std::string& user_id_hash) { | 128 const std::string& user_id_hash) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 145 | 148 |
| 146 void ClearDisposableWallpaperCache() { | 149 void ClearDisposableWallpaperCache() { |
| 147 WallpaperManager::Get()->ClearDisposableWallpaperCache(); | 150 WallpaperManager::Get()->ClearDisposableWallpaperCache(); |
| 148 } | 151 } |
| 149 | 152 |
| 150 // Initializes default wallpaper paths "*default_*file" and writes JPEG | 153 // Initializes default wallpaper paths "*default_*file" and writes JPEG |
| 151 // wallpaper images to them. | 154 // wallpaper images to them. |
| 152 // Only needs to be called (once) by tests that want to test loading of | 155 // Only needs to be called (once) by tests that want to test loading of |
| 153 // default wallpapers. | 156 // default wallpapers. |
| 154 void CreateCmdlineWallpapers() { | 157 void CreateCmdlineWallpapers() { |
| 158 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 155 wallpaper_dir_.reset(new base::ScopedTempDir); | 159 wallpaper_dir_.reset(new base::ScopedTempDir); |
| 156 ASSERT_TRUE(wallpaper_dir_->CreateUniqueTempDir()); | 160 ASSERT_TRUE(wallpaper_dir_->CreateUniqueTempDir()); |
| 157 wallpaper_manager_test_utils::CreateCmdlineWallpapers( | 161 wallpaper_manager_test_utils::CreateCmdlineWallpapers( |
| 158 *wallpaper_dir_, &wallpaper_manager_command_line_); | 162 *wallpaper_dir_, &wallpaper_manager_command_line_); |
| 159 } | 163 } |
| 160 | 164 |
| 161 ash::WallpaperController* controller_; | 165 ash::WallpaperController* controller_; |
| 162 PrefService* local_state_; | 166 PrefService* local_state_; |
| 163 std::unique_ptr<base::CommandLine> wallpaper_manager_command_line_; | 167 std::unique_ptr<base::CommandLine> wallpaper_manager_command_line_; |
| 164 | 168 |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 | 828 |
| 825 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId()); | 829 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId()); |
| 826 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | 830 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); |
| 827 | 831 |
| 828 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( | 832 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( |
| 829 controller_->GetWallpaper(), | 833 controller_->GetWallpaper(), |
| 830 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor)); | 834 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor)); |
| 831 } | 835 } |
| 832 | 836 |
| 833 } // namespace chromeos | 837 } // namespace chromeos |
| OLD | NEW |