| 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 "chrome/browser/chromeos/login/wallpaper_manager.h" | 5 #include "chrome/browser/chromeos/login/wallpaper_manager.h" |
| 6 | 6 |
| 7 #include "ash/desktop_background/desktop_background_controller.h" | 7 #include "ash/desktop_background/desktop_background_controller.h" |
| 8 #include "ash/desktop_background/desktop_background_controller_observer.h" | 8 #include "ash/desktop_background/desktop_background_controller_observer.h" |
| 9 #include "ash/display/display_manager.h" | 9 #include "ash/display/display_manager.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "ash/test/display_manager_test_api.h" | 11 #include "ash/test/display_manager_test_api.h" |
| 12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
| 15 #include "base/time.h" | 15 #include "base/time.h" |
| 16 #include "base/values.h" | 16 #include "base/values.h" |
| 17 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" | 17 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" |
| 18 #include "chrome/browser/chromeos/login/user.h" | 18 #include "chrome/browser/chromeos/login/user.h" |
| 19 #include "chrome/browser/chromeos/login/user_manager.h" | |
| 20 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 19 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
| 21 #include "chrome/test/base/testing_browser_process.h" | 20 #include "chrome/test/base/testing_browser_process.h" |
| 22 #include "ui/aura/env.h" | 21 #include "ui/aura/env.h" |
| 23 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
| 24 | 23 |
| 25 using namespace ash; | 24 using namespace ash; |
| 26 | 25 |
| 27 namespace chromeos { | 26 namespace chromeos { |
| 28 | 27 |
| 29 namespace { | 28 namespace { |
| 30 | 29 |
| 30 const char kTestUser1[] = "test-user@example.com"; |
| 31 |
| 31 #if defined(GOOGLE_CHROME_BUILD) | 32 #if defined(GOOGLE_CHROME_BUILD) |
| 32 int kExpectedSmallWallpaperWidth = ash::kSmallWallpaperMaxWidth; | 33 int kExpectedSmallWallpaperWidth = ash::kSmallWallpaperMaxWidth; |
| 33 int kExpectedSmallWallpaperHeight = ash::kSmallWallpaperMaxHeight; | 34 int kExpectedSmallWallpaperHeight = ash::kSmallWallpaperMaxHeight; |
| 34 int kExpectedLargeWallpaperWidth = ash::kLargeWallpaperMaxWidth; | 35 int kExpectedLargeWallpaperWidth = ash::kLargeWallpaperMaxWidth; |
| 35 int kExpectedLargeWallpaperHeight = ash::kLargeWallpaperMaxHeight; | 36 int kExpectedLargeWallpaperHeight = ash::kLargeWallpaperMaxHeight; |
| 36 #else | 37 #else |
| 37 // The defualt wallpaper for non official build is a gradient wallpaper which | 38 // The defualt wallpaper for non official build is a gradient wallpaper which |
| 38 // stretches to fit screen. | 39 // stretches to fit screen. |
| 39 int kExpectedSmallWallpaperWidth = 256; | 40 int kExpectedSmallWallpaperWidth = 256; |
| 40 int kExpectedSmallWallpaperHeight = ash::kSmallWallpaperMaxHeight; | 41 int kExpectedSmallWallpaperHeight = ash::kSmallWallpaperMaxHeight; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 } | 76 } |
| 76 | 77 |
| 77 void WaitAsyncWallpaperLoad() { | 78 void WaitAsyncWallpaperLoad() { |
| 78 MessageLoop::current()->Run(); | 79 MessageLoop::current()->Run(); |
| 79 } | 80 } |
| 80 | 81 |
| 81 virtual void OnWallpaperDataChanged() OVERRIDE { | 82 virtual void OnWallpaperDataChanged() OVERRIDE { |
| 82 MessageLoop::current()->Quit(); | 83 MessageLoop::current()->Quit(); |
| 83 } | 84 } |
| 84 | 85 |
| 86 // Sets |username| wallpaper. |
| 87 void SetUserWallpaper(const std::string& username) { |
| 88 ListPrefUpdate users_pref(local_state_, "LoggedInUsers"); |
| 89 users_pref->AppendIfNotPresent(new base::StringValue(username)); |
| 90 WallpaperManager::Get()->SetUserWallpaper(username); |
| 91 } |
| 92 |
| 85 protected: | 93 protected: |
| 86 // Saves bitmap |resource_id| to disk. | 94 // Saves bitmap |resource_id| to disk. |
| 87 void SaveUserWallpaperData(const std::string& username, | 95 void SaveUserWallpaperData(const std::string& username, |
| 88 const FilePath& wallpaper_path, | 96 const FilePath& wallpaper_path, |
| 89 int resource_id) { | 97 int resource_id) { |
| 90 scoped_refptr<base::RefCountedStaticMemory> image_data( | 98 scoped_refptr<base::RefCountedStaticMemory> image_data( |
| 91 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( | 99 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( |
| 92 resource_id, ui::SCALE_FACTOR_100P)); | 100 resource_id, ui::SCALE_FACTOR_100P)); |
| 93 int written = file_util::WriteFile( | 101 int written = file_util::WriteFile( |
| 94 wallpaper_path, | 102 wallpaper_path, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 114 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, | 122 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, |
| 115 LoadLargeWallpaperForLargeExternalScreen) { | 123 LoadLargeWallpaperForLargeExternalScreen) { |
| 116 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); | 124 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); |
| 117 | 125 |
| 118 WallpaperInfo info = { | 126 WallpaperInfo info = { |
| 119 "", | 127 "", |
| 120 WALLPAPER_LAYOUT_CENTER_CROPPED, | 128 WALLPAPER_LAYOUT_CENTER_CROPPED, |
| 121 User::DEFAULT, | 129 User::DEFAULT, |
| 122 base::Time::Now().LocalMidnight() | 130 base::Time::Now().LocalMidnight() |
| 123 }; | 131 }; |
| 124 wallpaper_manager->SetUserWallpaperInfo(UserManager::kStubUser, info, true); | 132 wallpaper_manager->SetUserWallpaperInfo(kTestUser1, info, true); |
| 125 | 133 |
| 126 wallpaper_manager->SetUserWallpaper(UserManager::kStubUser); | 134 SetUserWallpaper(kTestUser1); |
| 127 WaitAsyncWallpaperLoad(); | 135 WaitAsyncWallpaperLoad(); |
| 128 gfx::ImageSkia wallpaper = controller_->GetWallpaper(); | 136 gfx::ImageSkia wallpaper = controller_->GetWallpaper(); |
| 129 | 137 |
| 130 // Display is initialized to 800x600. The small resolution default wallpaper | 138 // Display is initialized to 800x600. The small resolution default wallpaper |
| 131 // is expected. | 139 // is expected. |
| 132 EXPECT_EQ(kExpectedSmallWallpaperWidth, wallpaper.width()); | 140 EXPECT_EQ(kExpectedSmallWallpaperWidth, wallpaper.width()); |
| 133 EXPECT_EQ(kExpectedSmallWallpaperHeight, wallpaper.height()); | 141 EXPECT_EQ(kExpectedSmallWallpaperHeight, wallpaper.height()); |
| 134 | 142 |
| 135 // Hook up another 800x600 display. | 143 // Hook up another 800x600 display. |
| 136 UpdateDisplay("800x600,800x600"); | 144 UpdateDisplay("800x600,800x600"); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 150 EXPECT_EQ(kExpectedLargeWallpaperWidth, wallpaper.width()); | 158 EXPECT_EQ(kExpectedLargeWallpaperWidth, wallpaper.width()); |
| 151 EXPECT_EQ(kExpectedLargeWallpaperHeight, wallpaper.height()); | 159 EXPECT_EQ(kExpectedLargeWallpaperHeight, wallpaper.height()); |
| 152 } | 160 } |
| 153 | 161 |
| 154 // This test is similar to LoadLargeWallpaperForExternalScreen test. Instead of | 162 // This test is similar to LoadLargeWallpaperForExternalScreen test. Instead of |
| 155 // testing default wallpaper, it tests custom wallpaper. | 163 // testing default wallpaper, it tests custom wallpaper. |
| 156 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, | 164 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, |
| 157 LoadCustomLargeWallpaperForLargeExternalScreen) { | 165 LoadCustomLargeWallpaperForLargeExternalScreen) { |
| 158 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); | 166 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); |
| 159 FilePath small_wallpaper_path = | 167 FilePath small_wallpaper_path = |
| 160 wallpaper_manager->GetWallpaperPathForUser(UserManager::kStubUser, true); | 168 wallpaper_manager->GetWallpaperPathForUser(kTestUser1, true); |
| 161 FilePath large_wallpaper_path = | 169 FilePath large_wallpaper_path = |
| 162 wallpaper_manager->GetWallpaperPathForUser(UserManager::kStubUser, false); | 170 wallpaper_manager->GetWallpaperPathForUser(kTestUser1, false); |
| 163 | 171 |
| 164 // Saves the small/large resolution wallpapers to small/large custom | 172 // Saves the small/large resolution wallpapers to small/large custom |
| 165 // wallpaper paths. | 173 // wallpaper paths. |
| 166 SaveUserWallpaperData(UserManager::kStubUser, | 174 SaveUserWallpaperData(kTestUser1, |
| 167 small_wallpaper_path, | 175 small_wallpaper_path, |
| 168 ash::kDefaultSmallWallpaper.idr); | 176 ash::kDefaultSmallWallpaper.idr); |
| 169 SaveUserWallpaperData(UserManager::kStubUser, | 177 SaveUserWallpaperData(kTestUser1, |
| 170 large_wallpaper_path, | 178 large_wallpaper_path, |
| 171 ash::kDefaultLargeWallpaper.idr); | 179 ash::kDefaultLargeWallpaper.idr); |
| 172 | 180 |
| 173 // Saves wallpaper info to local state for user |UserManager::kStubUser|. | 181 // Saves wallpaper info to local state for user |kTestUser1|. |
| 174 WallpaperInfo info = { | 182 WallpaperInfo info = { |
| 175 "DUMMY", | 183 "DUMMY", |
| 176 WALLPAPER_LAYOUT_CENTER_CROPPED, | 184 WALLPAPER_LAYOUT_CENTER_CROPPED, |
| 177 User::CUSTOMIZED, | 185 User::CUSTOMIZED, |
| 178 base::Time::Now().LocalMidnight() | 186 base::Time::Now().LocalMidnight() |
| 179 }; | 187 }; |
| 180 wallpaper_manager->SetUserWallpaperInfo(UserManager::kStubUser, info, true); | 188 wallpaper_manager->SetUserWallpaperInfo(kTestUser1, info, true); |
| 181 | 189 |
| 182 // Set the wallpaper for |UserManager::kStubUser|. | 190 // Add user |kTestUser1|. |
| 183 wallpaper_manager->SetUserWallpaper(UserManager::kStubUser); | 191 |
| 192 SetUserWallpaper(kTestUser1); |
| 184 WaitAsyncWallpaperLoad(); | 193 WaitAsyncWallpaperLoad(); |
| 185 gfx::ImageSkia wallpaper = controller_->GetWallpaper(); | 194 gfx::ImageSkia wallpaper = controller_->GetWallpaper(); |
| 186 | 195 |
| 187 // Display is initialized to 800x600. The small resolution custom wallpaper is | 196 // Display is initialized to 800x600. The small resolution custom wallpaper is |
| 188 // expected. | 197 // expected. |
| 189 EXPECT_EQ(kExpectedSmallWallpaperWidth, wallpaper.width()); | 198 EXPECT_EQ(kExpectedSmallWallpaperWidth, wallpaper.width()); |
| 190 EXPECT_EQ(kExpectedSmallWallpaperHeight, wallpaper.height()); | 199 EXPECT_EQ(kExpectedSmallWallpaperHeight, wallpaper.height()); |
| 191 | 200 |
| 192 // Hook up another 800x600 display. | 201 // Hook up another 800x600 display. |
| 193 UpdateDisplay("800x600,800x600"); | 202 UpdateDisplay("800x600,800x600"); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 208 EXPECT_EQ(kExpectedLargeWallpaperHeight, wallpaper.height()); | 217 EXPECT_EQ(kExpectedLargeWallpaperHeight, wallpaper.height()); |
| 209 } | 218 } |
| 210 | 219 |
| 211 // If chrome tries to reload the same wallpaper twice, the latter request should | 220 // If chrome tries to reload the same wallpaper twice, the latter request should |
| 212 // be prevented. Otherwise, there are some strange animation issues as | 221 // be prevented. Otherwise, there are some strange animation issues as |
| 213 // described in crbug.com/158383. | 222 // described in crbug.com/158383. |
| 214 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, | 223 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, |
| 215 PreventReloadingSameWallpaper) { | 224 PreventReloadingSameWallpaper) { |
| 216 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); | 225 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); |
| 217 FilePath small_wallpaper_path = | 226 FilePath small_wallpaper_path = |
| 218 wallpaper_manager->GetWallpaperPathForUser(UserManager::kStubUser, true); | 227 wallpaper_manager->GetWallpaperPathForUser(kTestUser1, true); |
| 219 | 228 |
| 220 SaveUserWallpaperData(UserManager::kStubUser, | 229 SaveUserWallpaperData(kTestUser1, |
| 221 small_wallpaper_path, | 230 small_wallpaper_path, |
| 222 ash::kDefaultSmallWallpaper.idr); | 231 ash::kDefaultSmallWallpaper.idr); |
| 223 | 232 |
| 224 // Saves wallpaper info to local state for user |UserManager::kStubUser|. | 233 // Saves wallpaper info to local state for user |kTestUser1|. |
| 225 WallpaperInfo info = { | 234 WallpaperInfo info = { |
| 226 "DUMMY", | 235 "DUMMY", |
| 227 WALLPAPER_LAYOUT_CENTER_CROPPED, | 236 WALLPAPER_LAYOUT_CENTER_CROPPED, |
| 228 User::CUSTOMIZED, | 237 User::CUSTOMIZED, |
| 229 base::Time::Now().LocalMidnight() | 238 base::Time::Now().LocalMidnight() |
| 230 }; | 239 }; |
| 231 wallpaper_manager->SetUserWallpaperInfo(UserManager::kStubUser, info, true); | 240 wallpaper_manager->SetUserWallpaperInfo(kTestUser1, info, true); |
| 232 | 241 |
| 233 wallpaper_manager->SetUserWallpaper(UserManager::kStubUser); | 242 SetUserWallpaper(kTestUser1); |
| 234 EXPECT_EQ(1, LoadedWallpapers()); | 243 EXPECT_EQ(1, LoadedWallpapers()); |
| 235 // Loads the same wallpaper before the initial one finished. It should be | 244 // Loads the same wallpaper before the initial one finished. It should be |
| 236 // prevented. | 245 // prevented. |
| 237 wallpaper_manager->SetUserWallpaper(UserManager::kStubUser); | 246 SetUserWallpaper(kTestUser1); |
| 238 EXPECT_EQ(1, LoadedWallpapers()); | 247 EXPECT_EQ(1, LoadedWallpapers()); |
| 239 WaitAsyncWallpaperLoad(); | 248 WaitAsyncWallpaperLoad(); |
| 240 // Loads the same wallpaper after the initial one finished. It should be | 249 // Loads the same wallpaper after the initial one finished. It should be |
| 241 // prevented. | 250 // prevented. |
| 242 wallpaper_manager->SetUserWallpaper(UserManager::kStubUser); | 251 SetUserWallpaper(kTestUser1); |
| 243 EXPECT_EQ(1, LoadedWallpapers()); | 252 EXPECT_EQ(1, LoadedWallpapers()); |
| 244 wallpaper_manager->ClearWallpaperCache(); | 253 wallpaper_manager->ClearWallpaperCache(); |
| 245 | 254 |
| 246 // Tests default wallpaper for user |UserManager::kStubUser|. | 255 // Tests default wallpaper for user |kTestUser1|. |
| 247 info.file = ""; | 256 info.file = ""; |
| 248 info.type = User::DEFAULT; | 257 info.type = User::DEFAULT; |
| 249 wallpaper_manager->SetUserWallpaperInfo(UserManager::kStubUser, info, true); | 258 wallpaper_manager->SetUserWallpaperInfo(kTestUser1, info, true); |
| 250 wallpaper_manager->SetUserWallpaper(UserManager::kStubUser); | 259 SetUserWallpaper(kTestUser1); |
| 251 EXPECT_EQ(2, LoadedWallpapers()); | 260 EXPECT_EQ(2, LoadedWallpapers()); |
| 252 // Loads the same wallpaper before the initial one finished. It should be | 261 // Loads the same wallpaper before the initial one finished. It should be |
| 253 // prevented. | 262 // prevented. |
| 254 wallpaper_manager->SetUserWallpaper(UserManager::kStubUser); | 263 SetUserWallpaper(kTestUser1); |
| 255 EXPECT_EQ(2, LoadedWallpapers()); | 264 EXPECT_EQ(2, LoadedWallpapers()); |
| 256 WaitAsyncWallpaperLoad(); | 265 WaitAsyncWallpaperLoad(); |
| 257 wallpaper_manager->SetUserWallpaper(UserManager::kStubUser); | 266 SetUserWallpaper(kTestUser1); |
| 258 EXPECT_EQ(2, LoadedWallpapers()); | 267 EXPECT_EQ(2, LoadedWallpapers()); |
| 259 } | 268 } |
| 260 | 269 |
| 261 } // namepace chromeos | 270 } // namepace chromeos |
| OLD | NEW |