Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager_browsertest.cc

Issue 1497973002: This CL replaces e-mail with AccountId in wallpaper manager code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after review. Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "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/desktop_background/desktop_background_controller_test_api.h" 9 #include "ash/desktop_background/desktop_background_controller_test_api.h"
10 #include "ash/display/display_manager.h" 10 #include "ash/display/display_manager.h"
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 const char kTestUser1[] = "test1@domain.com"; 58 const char kTestUser1[] = "test1@domain.com";
59 const char kTestUser1Hash[] = "test1@domain.com-hash"; 59 const char kTestUser1Hash[] = "test1@domain.com-hash";
60 const char kTestUser2[] = "test2@domain.com"; 60 const char kTestUser2[] = "test2@domain.com";
61 const char kTestUser2Hash[] = "test2@domain.com-hash"; 61 const char kTestUser2Hash[] = "test2@domain.com-hash";
62 62
63 } // namespace 63 } // namespace
64 64
65 class WallpaperManagerBrowserTest : public InProcessBrowserTest { 65 class WallpaperManagerBrowserTest : public InProcessBrowserTest {
66 public: 66 public:
67 WallpaperManagerBrowserTest () : controller_(NULL), 67 WallpaperManagerBrowserTest() : controller_(NULL),
68 local_state_(NULL) { 68 local_state_(NULL) {
69 } 69 }
70 70
71 ~WallpaperManagerBrowserTest() override {} 71 ~WallpaperManagerBrowserTest() override {}
72 72
73 void SetUpOnMainThread() override { 73 void SetUpOnMainThread() override {
74 controller_ = ash::Shell::GetInstance()->desktop_background_controller(); 74 controller_ = ash::Shell::GetInstance()->desktop_background_controller();
75 local_state_ = g_browser_process->local_state(); 75 local_state_ = g_browser_process->local_state();
76 ash::DesktopBackgroundController::TestAPI(controller_) 76 ash::DesktopBackgroundController::TestAPI(controller_)
77 .set_wallpaper_reload_delay_for_test(0); 77 .set_wallpaper_reload_delay_for_test(0);
78 UpdateDisplay("800x600"); 78 UpdateDisplay("800x600");
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 user_manager::User* user = 126 user_manager::User* user =
127 user_manager::UserManager::Get()->FindUserAndModify(account_id); 127 user_manager::UserManager::Get()->FindUserAndModify(account_id);
128 user_manager::UserManager::Get()->ChangeUserChildStatus( 128 user_manager::UserManager::Get()->ChangeUserChildStatus(
129 user, true /* is_child */); 129 user, true /* is_child */);
130 } 130 }
131 131
132 int LoadedWallpapers() { 132 int LoadedWallpapers() {
133 return WallpaperManager::Get()->loaded_wallpapers_for_test(); 133 return WallpaperManager::Get()->loaded_wallpapers_for_test();
134 } 134 }
135 135
136 void CacheUserWallpaper(const std::string& user) { 136 void CacheUserWallpaper(const AccountId& account_id) {
137 WallpaperManager::Get()->CacheUserWallpaper(user); 137 WallpaperManager::Get()->CacheUserWallpaper(account_id);
138 } 138 }
139 139
140 void ClearDisposableWallpaperCache() { 140 void ClearDisposableWallpaperCache() {
141 WallpaperManager::Get()->ClearDisposableWallpaperCache(); 141 WallpaperManager::Get()->ClearDisposableWallpaperCache();
142 } 142 }
143 143
144 // Initializes default wallpaper paths "*default_*file" and writes JPEG 144 // Initializes default wallpaper paths "*default_*file" and writes JPEG
145 // wallpaper images to them. 145 // wallpaper images to them.
146 // Only needs to be called (once) by tests that want to test loading of 146 // Only needs to be called (once) by tests that want to test loading of
147 // default wallpapers. 147 // default wallpapers.
148 void CreateCmdlineWallpapers() { 148 void CreateCmdlineWallpapers() {
149 wallpaper_dir_.reset(new base::ScopedTempDir); 149 wallpaper_dir_.reset(new base::ScopedTempDir);
150 ASSERT_TRUE(wallpaper_dir_->CreateUniqueTempDir()); 150 ASSERT_TRUE(wallpaper_dir_->CreateUniqueTempDir());
151 wallpaper_manager_test_utils::CreateCmdlineWallpapers( 151 wallpaper_manager_test_utils::CreateCmdlineWallpapers(
152 *wallpaper_dir_, &wallpaper_manager_command_line_); 152 *wallpaper_dir_, &wallpaper_manager_command_line_);
153 } 153 }
154 154
155 ash::DesktopBackgroundController* controller_; 155 ash::DesktopBackgroundController* controller_;
156 PrefService* local_state_; 156 PrefService* local_state_;
157 scoped_ptr<base::CommandLine> wallpaper_manager_command_line_; 157 scoped_ptr<base::CommandLine> wallpaper_manager_command_line_;
158 158
159 // Directory created by CreateCmdlineWallpapers () to store default 159 // Directory created by CreateCmdlineWallpapers () to store default
160 // wallpaper images. 160 // wallpaper images.
161 scoped_ptr<base::ScopedTempDir> wallpaper_dir_; 161 scoped_ptr<base::ScopedTempDir> wallpaper_dir_;
162 162
163 const AccountId test_account_id1_ = AccountId::FromUserEmail(kTestUser1);
164 const AccountId test_account_id2_ = AccountId::FromUserEmail(kTestUser2);
165
163 private: 166 private:
164 DISALLOW_COPY_AND_ASSIGN(WallpaperManagerBrowserTest); 167 DISALLOW_COPY_AND_ASSIGN(WallpaperManagerBrowserTest);
165 }; 168 };
166 169
167 // Tests that the appropriate custom wallpaper (large vs. small) is loaded 170 // Tests that the appropriate custom wallpaper (large vs. small) is loaded
168 // depending on the desktop resolution. 171 // depending on the desktop resolution.
169 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, 172 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest,
170 LoadCustomLargeWallpaperForLargeExternalScreen) { 173 LoadCustomLargeWallpaperForLargeExternalScreen) {
171 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); 174 WallpaperManager* wallpaper_manager = WallpaperManager::Get();
172 LogIn(AccountId::FromUserEmail(kTestUser1), kTestUser1Hash); 175 LogIn(test_account_id1_, kTestUser1Hash);
173 std::string id = base::Int64ToString(base::Time::Now().ToInternalValue()); 176 std::string id = base::Int64ToString(base::Time::Now().ToInternalValue());
174 base::FilePath small_wallpaper_path = GetCustomWallpaperPath( 177 base::FilePath small_wallpaper_path = GetCustomWallpaperPath(
175 wallpaper::kSmallWallpaperSubDir, kTestUser1Hash, id); 178 wallpaper::kSmallWallpaperSubDir, kTestUser1Hash, id);
176 base::FilePath large_wallpaper_path = GetCustomWallpaperPath( 179 base::FilePath large_wallpaper_path = GetCustomWallpaperPath(
177 wallpaper::kLargeWallpaperSubDir, kTestUser1Hash, id); 180 wallpaper::kLargeWallpaperSubDir, kTestUser1Hash, id);
178 181
179 // Saves the small/large resolution wallpapers to small/large custom 182 // Saves the small/large resolution wallpapers to small/large custom
180 // wallpaper paths. 183 // wallpaper paths.
181 ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile( 184 ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile(
182 small_wallpaper_path, 185 small_wallpaper_path,
183 kSmallWallpaperWidth, 186 kSmallWallpaperWidth,
184 kSmallWallpaperHeight, 187 kSmallWallpaperHeight,
185 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor)); 188 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor));
186 ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile( 189 ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile(
187 large_wallpaper_path, 190 large_wallpaper_path,
188 kLargeWallpaperWidth, 191 kLargeWallpaperWidth,
189 kLargeWallpaperHeight, 192 kLargeWallpaperHeight,
190 wallpaper_manager_test_utils::kLargeDefaultWallpaperColor)); 193 wallpaper_manager_test_utils::kLargeDefaultWallpaperColor));
191 194
192 std::string relative_path = base::FilePath(kTestUser1Hash).Append(id).value(); 195 std::string relative_path = base::FilePath(kTestUser1Hash).Append(id).value();
193 // Saves wallpaper info to local state for user |kTestUser1|. 196 // Saves wallpaper info to local state for user |test_account_id1_|.
194 WallpaperInfo info = {relative_path, WALLPAPER_LAYOUT_CENTER_CROPPED, 197 WallpaperInfo info = {relative_path, WALLPAPER_LAYOUT_CENTER_CROPPED,
195 user_manager::User::CUSTOMIZED, 198 user_manager::User::CUSTOMIZED,
196 base::Time::Now().LocalMidnight()}; 199 base::Time::Now().LocalMidnight()};
197 wallpaper_manager->SetUserWallpaperInfo(kTestUser1, info, true); 200 wallpaper_manager->SetUserWallpaperInfo(test_account_id1_, info, true);
198 201
199 // Set the wallpaper for |kTestUser1|. 202 // Set the wallpaper for |test_account_id1_|.
200 wallpaper_manager->SetUserWallpaperNow(kTestUser1); 203 wallpaper_manager->SetUserWallpaperNow(test_account_id1_);
201 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 204 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
202 gfx::ImageSkia wallpaper = controller_->GetWallpaper(); 205 gfx::ImageSkia wallpaper = controller_->GetWallpaper();
203 206
204 // Display is initialized to 800x600. The small resolution custom wallpaper is 207 // Display is initialized to 800x600. The small resolution custom wallpaper is
205 // expected. 208 // expected.
206 EXPECT_EQ(kSmallWallpaperWidth, wallpaper.width()); 209 EXPECT_EQ(kSmallWallpaperWidth, wallpaper.width());
207 EXPECT_EQ(kSmallWallpaperHeight, wallpaper.height()); 210 EXPECT_EQ(kSmallWallpaperHeight, wallpaper.height());
208 211
209 // Hook up another 800x600 display. This shouldn't trigger a reload. 212 // Hook up another 800x600 display. This shouldn't trigger a reload.
210 UpdateDisplay("800x600,800x600"); 213 UpdateDisplay("800x600,800x600");
(...skipping 27 matching lines...) Expand all
238 EXPECT_EQ(kLargeWallpaperHeight, wallpaper.height()); 241 EXPECT_EQ(kLargeWallpaperHeight, wallpaper.height());
239 } 242 }
240 243
241 // If chrome tries to reload the same wallpaper twice, the latter request should 244 // If chrome tries to reload the same wallpaper twice, the latter request should
242 // be prevented. Otherwise, there are some strange animation issues as 245 // be prevented. Otherwise, there are some strange animation issues as
243 // described in crbug.com/158383. 246 // described in crbug.com/158383.
244 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, 247 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest,
245 PreventReloadingSameWallpaper) { 248 PreventReloadingSameWallpaper) {
246 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); 249 WallpaperManager* wallpaper_manager = WallpaperManager::Get();
247 // New user log in, a default wallpaper is loaded. 250 // New user log in, a default wallpaper is loaded.
248 LogIn(AccountId::FromUserEmail(kTestUser1), kTestUser1Hash); 251 LogIn(test_account_id1_, kTestUser1Hash);
249 EXPECT_EQ(1, LoadedWallpapers()); 252 EXPECT_EQ(1, LoadedWallpapers());
250 // Loads the same wallpaper before the initial one finished. It should be 253 // Loads the same wallpaper before the initial one finished. It should be
251 // prevented. 254 // prevented.
252 wallpaper_manager->SetUserWallpaperNow(kTestUser1); 255 wallpaper_manager->SetUserWallpaperNow(test_account_id1_);
253 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 256 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
254 EXPECT_EQ(1, LoadedWallpapers()); 257 EXPECT_EQ(1, LoadedWallpapers());
255 // Loads the same wallpaper after the initial one finished. It should be 258 // Loads the same wallpaper after the initial one finished. It should be
256 // prevented. 259 // prevented.
257 wallpaper_manager->SetUserWallpaperNow(kTestUser1); 260 wallpaper_manager->SetUserWallpaperNow(test_account_id1_);
258 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 261 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
259 EXPECT_EQ(1, LoadedWallpapers()); 262 EXPECT_EQ(1, LoadedWallpapers());
260 ClearDisposableWallpaperCache(); 263 ClearDisposableWallpaperCache();
261 264
262 // Change wallpaper to a custom wallpaper. 265 // Change wallpaper to a custom wallpaper.
263 std::string id = base::Int64ToString(base::Time::Now().ToInternalValue()); 266 std::string id = base::Int64ToString(base::Time::Now().ToInternalValue());
264 base::FilePath small_wallpaper_path = GetCustomWallpaperPath( 267 base::FilePath small_wallpaper_path = GetCustomWallpaperPath(
265 wallpaper::kSmallWallpaperSubDir, kTestUser1Hash, id); 268 wallpaper::kSmallWallpaperSubDir, kTestUser1Hash, id);
266 ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile( 269 ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile(
267 small_wallpaper_path, 270 small_wallpaper_path,
268 kSmallWallpaperWidth, 271 kSmallWallpaperWidth,
269 kSmallWallpaperHeight, 272 kSmallWallpaperHeight,
270 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor)); 273 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor));
271 274
272 std::string relative_path = base::FilePath(kTestUser1Hash).Append(id).value(); 275 std::string relative_path = base::FilePath(kTestUser1Hash).Append(id).value();
273 // Saves wallpaper info to local state for user |kTestUser1|. 276 // Saves wallpaper info to local state for user |test_account_id1_|.
274 WallpaperInfo info = {relative_path, WALLPAPER_LAYOUT_CENTER_CROPPED, 277 WallpaperInfo info = {relative_path, WALLPAPER_LAYOUT_CENTER_CROPPED,
275 user_manager::User::CUSTOMIZED, 278 user_manager::User::CUSTOMIZED,
276 base::Time::Now().LocalMidnight()}; 279 base::Time::Now().LocalMidnight()};
277 wallpaper_manager->SetUserWallpaperInfo(kTestUser1, info, true); 280 wallpaper_manager->SetUserWallpaperInfo(test_account_id1_, info, true);
278 281
279 wallpaper_manager->SetUserWallpaperNow(kTestUser1); 282 wallpaper_manager->SetUserWallpaperNow(test_account_id1_);
280 WaitAsyncWallpaperLoadStarted(); 283 WaitAsyncWallpaperLoadStarted();
281 EXPECT_EQ(2, LoadedWallpapers()); 284 EXPECT_EQ(2, LoadedWallpapers());
282 // Loads the same wallpaper before the initial one finished. It should be 285 // Loads the same wallpaper before the initial one finished. It should be
283 // prevented. 286 // prevented.
284 wallpaper_manager->SetUserWallpaperNow(kTestUser1); 287 wallpaper_manager->SetUserWallpaperNow(test_account_id1_);
285 WaitAsyncWallpaperLoadStarted(); 288 WaitAsyncWallpaperLoadStarted();
286 EXPECT_EQ(2, LoadedWallpapers()); 289 EXPECT_EQ(2, LoadedWallpapers());
287 wallpaper_manager->SetUserWallpaperNow(kTestUser1); 290 wallpaper_manager->SetUserWallpaperNow(test_account_id1_);
288 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 291 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
289 EXPECT_EQ(2, LoadedWallpapers()); 292 EXPECT_EQ(2, LoadedWallpapers());
290 } 293 }
291 294
292 // Some users have old user profiles which may have legacy wallpapers. And these 295 // Some users have old user profiles which may have legacy wallpapers. And these
293 // lagacy wallpapers should migrate to new wallpaper picker version seamlessly. 296 // lagacy wallpapers should migrate to new wallpaper picker version seamlessly.
294 // This tests make sure we compatible with migrated old wallpapers. 297 // This tests make sure we compatible with migrated old wallpapers.
295 // crosbug.com/38429 298 // crosbug.com/38429
296 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, 299 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest,
297 PRE_UseMigratedWallpaperInfo) { 300 PRE_UseMigratedWallpaperInfo) {
298 // New user log in, a default wallpaper is loaded. 301 // New user log in, a default wallpaper is loaded.
299 LogIn(AccountId::FromUserEmail(kTestUser1), kTestUser1Hash); 302 LogIn(test_account_id1_, kTestUser1Hash);
300 // Old wallpaper migration code doesn't exist in codebase anymore. Modify user 303 // Old wallpaper migration code doesn't exist in codebase anymore. Modify user
301 // wallpaper info directly to simulate the wallpaper migration. See 304 // wallpaper info directly to simulate the wallpaper migration. See
302 // crosbug.com/38429 for details about why we modify wallpaper info this way. 305 // crosbug.com/38429 for details about why we modify wallpaper info this way.
303 WallpaperInfo info = {"123", WALLPAPER_LAYOUT_CENTER_CROPPED, 306 WallpaperInfo info = {"123", WALLPAPER_LAYOUT_CENTER_CROPPED,
304 user_manager::User::DEFAULT, 307 user_manager::User::DEFAULT,
305 base::Time::Now().LocalMidnight()}; 308 base::Time::Now().LocalMidnight()};
306 base::FilePath user_data_dir; 309 base::FilePath user_data_dir;
307 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); 310 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir));
308 ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile( 311 ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile(
309 user_data_dir.Append("123"), 312 user_data_dir.Append("123"),
310 wallpaper_manager_test_utils::kWallpaperSize, 313 wallpaper_manager_test_utils::kWallpaperSize,
311 wallpaper_manager_test_utils::kWallpaperSize, 314 wallpaper_manager_test_utils::kWallpaperSize,
312 wallpaper_manager_test_utils::kLargeDefaultWallpaperColor)); 315 wallpaper_manager_test_utils::kLargeDefaultWallpaperColor));
313 WallpaperManager::Get()->SetUserWallpaperInfo(kTestUser1, info, true); 316 WallpaperManager::Get()->SetUserWallpaperInfo(test_account_id1_, info, true);
314 } 317 }
315 318
316 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, 319 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest,
317 UseMigratedWallpaperInfo) { 320 UseMigratedWallpaperInfo) {
318 LogIn(AccountId::FromUserEmail(kTestUser1), kTestUser1Hash); 321 LogIn(test_account_id1_, kTestUser1Hash);
319 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 322 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
320 // This test should finish normally. If timeout, it is probably because 323 // This test should finish normally. If timeout, it is probably because
321 // migrated wallpaper is somehow not loaded. Bad things can happen if 324 // migrated wallpaper is somehow not loaded. Bad things can happen if
322 // wallpaper is not loaded at login screen. One example is: crosbug.com/38429. 325 // wallpaper is not loaded at login screen. One example is: crosbug.com/38429.
323 } 326 }
324 327
325 // Some users have old user profiles which may never get a chance to migrate. 328 // Some users have old user profiles which may never get a chance to migrate.
326 // This tests make sure we compatible with these profiles. 329 // This tests make sure we compatible with these profiles.
327 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, 330 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest,
328 PRE_UsePreMigrationWallpaperInfo) { 331 PRE_UsePreMigrationWallpaperInfo) {
329 // New user log in, a default wallpaper is loaded. 332 // New user log in, a default wallpaper is loaded.
330 LogIn(AccountId::FromUserEmail(kTestUser1), kTestUser1Hash); 333 LogIn(test_account_id1_, kTestUser1Hash);
331 // Old wallpaper migration code doesn't exist in codebase anymore. So if 334 // Old wallpaper migration code doesn't exist in codebase anymore. So if
332 // user's profile is not migrated, it is the same as no wallpaper info. To 335 // user's profile is not migrated, it is the same as no wallpaper info. To
333 // simulate this, we remove user's wallpaper info here. 336 // simulate this, we remove user's wallpaper info here.
334 WallpaperManager::Get()->RemoveUserWallpaperInfo(kTestUser1); 337 WallpaperManager::Get()->RemoveUserWallpaperInfo(test_account_id1_);
335 } 338 }
336 339
337 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, 340 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest,
338 UsePreMigrationWallpaperInfo) { 341 UsePreMigrationWallpaperInfo) {
339 LogIn(AccountId::FromUserEmail(kTestUser1), kTestUser1Hash); 342 LogIn(test_account_id1_, kTestUser1Hash);
340 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 343 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
341 // This test should finish normally. If timeout, it is probably because chrome 344 // This test should finish normally. If timeout, it is probably because chrome
342 // can not handle pre migrated user profile (M21 profile or older). 345 // can not handle pre migrated user profile (M21 profile or older).
343 } 346 }
344 347
345 // Test for http://crbug.com/265689. When hooked up a large external monitor, 348 // Test for http://crbug.com/265689. When hooked up a large external monitor,
346 // the default large resolution wallpaper should load. 349 // the default large resolution wallpaper should load.
347 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, 350 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest,
348 HotPlugInScreenAtGAIALoginScreen) { 351 HotPlugInScreenAtGAIALoginScreen) {
349 UpdateDisplay("800x600"); 352 UpdateDisplay("800x600");
350 // Set initial wallpaper to the default wallpaper. 353 // Set initial wallpaper to the default wallpaper.
351 WallpaperManager::Get()->SetDefaultWallpaperNow( 354 WallpaperManager::Get()->SetDefaultWallpaperNow(login::StubAccountId());
352 login::StubAccountId().GetUserEmail());
353 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 355 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
354 356
355 // Hook up a 2000x2000 display. The large resolution custom wallpaper should 357 // Hook up a 2000x2000 display. The large resolution custom wallpaper should
356 // be loaded. 358 // be loaded.
357 UpdateDisplay("800x600,2000x2000"); 359 UpdateDisplay("800x600,2000x2000");
358 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 360 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
359 } 361 }
360 362
361 class WallpaperManagerBrowserTestNoAnimation 363 class WallpaperManagerBrowserTestNoAnimation
362 : public WallpaperManagerBrowserTest { 364 : public WallpaperManagerBrowserTest {
363 public: 365 public:
364 void SetUpCommandLine(base::CommandLine* command_line) override { 366 void SetUpCommandLine(base::CommandLine* command_line) override {
365 command_line->AppendSwitch(switches::kLoginManager); 367 command_line->AppendSwitch(switches::kLoginManager);
366 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); 368 command_line->AppendSwitchASCII(switches::kLoginProfile, "user");
367 command_line->AppendSwitch(chromeos::switches::kDisableLoginAnimations); 369 command_line->AppendSwitch(chromeos::switches::kDisableLoginAnimations);
368 command_line->AppendSwitch(chromeos::switches::kDisableBootAnimation); 370 command_line->AppendSwitch(chromeos::switches::kDisableBootAnimation);
369 } 371 }
370 }; 372 };
371 373
372 // Same test as WallpaperManagerBrowserTest.UseMigratedWallpaperInfo. But 374 // Same test as WallpaperManagerBrowserTest.UseMigratedWallpaperInfo. But
373 // disabled boot and login animation. 375 // disabled boot and login animation.
374 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestNoAnimation, 376 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestNoAnimation,
375 PRE_UseMigratedWallpaperInfo) { 377 PRE_UseMigratedWallpaperInfo) {
376 // New user log in, a default wallpaper is loaded. 378 // New user log in, a default wallpaper is loaded.
377 LogIn(AccountId::FromUserEmail(kTestUser1), kTestUser1Hash); 379 LogIn(test_account_id1_, kTestUser1Hash);
378 // Old wallpaper migration code doesn't exist in codebase anymore. Modify user 380 // Old wallpaper migration code doesn't exist in codebase anymore. Modify user
379 // wallpaper info directly to simulate the wallpaper migration. See 381 // wallpaper info directly to simulate the wallpaper migration. See
380 // crosbug.com/38429 for details about why we modify wallpaper info this way. 382 // crosbug.com/38429 for details about why we modify wallpaper info this way.
381 WallpaperInfo info = {"123", WALLPAPER_LAYOUT_CENTER_CROPPED, 383 WallpaperInfo info = {"123", WALLPAPER_LAYOUT_CENTER_CROPPED,
382 user_manager::User::DEFAULT, 384 user_manager::User::DEFAULT,
383 base::Time::Now().LocalMidnight()}; 385 base::Time::Now().LocalMidnight()};
384 base::FilePath user_data_dir; 386 base::FilePath user_data_dir;
385 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); 387 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir));
386 ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile( 388 ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile(
387 user_data_dir.Append("123"), 389 user_data_dir.Append("123"),
388 wallpaper_manager_test_utils::kWallpaperSize, 390 wallpaper_manager_test_utils::kWallpaperSize,
389 wallpaper_manager_test_utils::kWallpaperSize, 391 wallpaper_manager_test_utils::kWallpaperSize,
390 wallpaper_manager_test_utils::kLargeDefaultWallpaperColor)); 392 wallpaper_manager_test_utils::kLargeDefaultWallpaperColor));
391 WallpaperManager::Get()->SetUserWallpaperInfo(kTestUser1, info, true); 393 WallpaperManager::Get()->SetUserWallpaperInfo(test_account_id1_, info, true);
392 } 394 }
393 395
394 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestNoAnimation, 396 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestNoAnimation,
395 UseMigratedWallpaperInfo) { 397 UseMigratedWallpaperInfo) {
396 LogIn(AccountId::FromUserEmail(kTestUser1), kTestUser1Hash); 398 LogIn(test_account_id1_, kTestUser1Hash);
397 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 399 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
398 // This test should finish normally. If timeout, it is probably because 400 // This test should finish normally. If timeout, it is probably because
399 // migrated wallpaper is somehow not loaded. Bad things can happen if 401 // migrated wallpaper is somehow not loaded. Bad things can happen if
400 // wallpaper is not loaded at login screen. One example is: crosbug.com/38429. 402 // wallpaper is not loaded at login screen. One example is: crosbug.com/38429.
401 } 403 }
402 404
403 // Same test as WallpaperManagerBrowserTest.UsePreMigrationWallpaperInfo. But 405 // Same test as WallpaperManagerBrowserTest.UsePreMigrationWallpaperInfo. But
404 // disabled boot and login animation. 406 // disabled boot and login animation.
405 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestNoAnimation, 407 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestNoAnimation,
406 PRE_UsePreMigrationWallpaperInfo) { 408 PRE_UsePreMigrationWallpaperInfo) {
407 // New user log in, a default wallpaper is loaded. 409 // New user log in, a default wallpaper is loaded.
408 LogIn(AccountId::FromUserEmail(kTestUser1), kTestUser1Hash); 410 LogIn(test_account_id1_, kTestUser1Hash);
409 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 411 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
410 // Old wallpaper migration code doesn't exist in codebase anymore. So if 412 // Old wallpaper migration code doesn't exist in codebase anymore. So if
411 // user's profile is not migrated, it is the same as no wallpaper info. To 413 // user's profile is not migrated, it is the same as no wallpaper info. To
412 // simulate this, we remove user's wallpaper info here. 414 // simulate this, we remove user's wallpaper info here.
413 WallpaperManager::Get()->RemoveUserWallpaperInfo(kTestUser1); 415 WallpaperManager::Get()->RemoveUserWallpaperInfo(test_account_id1_);
414 } 416 }
415 417
416 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestNoAnimation, 418 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestNoAnimation,
417 UsePreMigrationWallpaperInfo) { 419 UsePreMigrationWallpaperInfo) {
418 LogIn(AccountId::FromUserEmail(kTestUser1), kTestUser1Hash); 420 LogIn(test_account_id1_, kTestUser1Hash);
419 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 421 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
420 // This test should finish normally. If timeout, it is probably because chrome 422 // This test should finish normally. If timeout, it is probably because chrome
421 // can not handle pre migrated user profile (M21 profile or older). 423 // can not handle pre migrated user profile (M21 profile or older).
422 } 424 }
423 425
424 class WallpaperManagerBrowserTestCrashRestore 426 class WallpaperManagerBrowserTestCrashRestore
425 : public WallpaperManagerBrowserTest { 427 : public WallpaperManagerBrowserTest {
426 public: 428 public:
427 void SetUpCommandLine(base::CommandLine* command_line) override { 429 void SetUpCommandLine(base::CommandLine* command_line) override {
428 command_line->AppendSwitch(chromeos::switches::kDisableLoginAnimations); 430 command_line->AppendSwitch(chromeos::switches::kDisableLoginAnimations);
429 command_line->AppendSwitch(chromeos::switches::kDisableBootAnimation); 431 command_line->AppendSwitch(chromeos::switches::kDisableBootAnimation);
430 command_line->AppendSwitchASCII(switches::kLoginUser, kTestUser1); 432 command_line->AppendSwitchASCII(switches::kLoginUser,
433 test_account_id1_.GetUserEmail());
431 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); 434 command_line->AppendSwitchASCII(switches::kLoginProfile, "user");
432 } 435 }
433 }; 436 };
434 437
435 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCrashRestore, 438 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCrashRestore,
436 PRE_RestoreWallpaper) { 439 PRE_RestoreWallpaper) {
437 LogIn(AccountId::FromUserEmail(kTestUser1), kTestUser1Hash); 440 LogIn(test_account_id1_, kTestUser1Hash);
438 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 441 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
439 } 442 }
440 443
441 // Test for crbug.com/270278. It simulates a browser crash and verifies if user 444 // Test for crbug.com/270278. It simulates a browser crash and verifies if user
442 // wallpaper is loaded. 445 // wallpaper is loaded.
443 // Fails on the MSAN bots. See http://crbug.com/444477 446 // Fails on the MSAN bots. See http://crbug.com/444477
444 #if defined(MEMORY_SANITIZER) 447 #if defined(MEMORY_SANITIZER)
445 #define MAYBE_RestoreWallpaper DISABLED_RestoreWallpaper 448 #define MAYBE_RestoreWallpaper DISABLED_RestoreWallpaper
446 #else 449 #else
447 #define MAYBE_RestoreWallpaper RestoreWallpaper 450 #define MAYBE_RestoreWallpaper RestoreWallpaper
448 #endif 451 #endif
449 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCrashRestore, 452 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCrashRestore,
450 MAYBE_RestoreWallpaper) { 453 MAYBE_RestoreWallpaper) {
451 EXPECT_EQ(1, LoadedWallpapers()); 454 EXPECT_EQ(1, LoadedWallpapers());
452 } 455 }
453 456
454 class WallpaperManagerBrowserTestCacheUpdate 457 class WallpaperManagerBrowserTestCacheUpdate
455 : public WallpaperManagerBrowserTest { 458 : public WallpaperManagerBrowserTest {
456 public: 459 public:
457 void SetUpCommandLine(base::CommandLine* command_line) override { 460 void SetUpCommandLine(base::CommandLine* command_line) override {
458 command_line->AppendSwitchASCII(switches::kLoginUser, kTestUser1); 461 command_line->AppendSwitchASCII(switches::kLoginUser,
462 test_account_id1_.GetUserEmail());
459 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); 463 command_line->AppendSwitchASCII(switches::kLoginProfile, "user");
460 } 464 }
461 protected: 465 protected:
462 // Creates a test image of size 1x1. 466 // Creates a test image of size 1x1.
463 gfx::ImageSkia CreateTestImage(SkColor color) { 467 gfx::ImageSkia CreateTestImage(SkColor color) {
464 return wallpaper_manager_test_utils::CreateTestImage(1, 1, color); 468 return wallpaper_manager_test_utils::CreateTestImage(1, 1, color);
465 } 469 }
466 }; 470 };
467 471
468 // Sets kTestUser1's wallpaper to a custom wallpaper. 472 // Sets test_account_id1_'s wallpaper to a custom wallpaper.
469 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCacheUpdate, 473 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCacheUpdate,
470 PRE_VerifyWallpaperCache) { 474 PRE_VerifyWallpaperCache) {
471 // Add kTestUser1 to user list. kTestUser1 is the default login profile. 475 // Add test_account_id1_ to user list.
472 LogIn(AccountId::FromUserEmail(kTestUser1), kTestUser1Hash); 476 // test_account_id1_ is the default login profile.
477 LogIn(test_account_id1_, kTestUser1Hash);
473 478
474 std::string id = base::Int64ToString(base::Time::Now().ToInternalValue()); 479 std::string id = base::Int64ToString(base::Time::Now().ToInternalValue());
475 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); 480 WallpaperManager* wallpaper_manager = WallpaperManager::Get();
476 base::FilePath small_wallpaper_path = GetCustomWallpaperPath( 481 base::FilePath small_wallpaper_path = GetCustomWallpaperPath(
477 wallpaper::kSmallWallpaperSubDir, kTestUser1Hash, id); 482 wallpaper::kSmallWallpaperSubDir, kTestUser1Hash, id);
478 base::FilePath large_wallpaper_path = GetCustomWallpaperPath( 483 base::FilePath large_wallpaper_path = GetCustomWallpaperPath(
479 wallpaper::kLargeWallpaperSubDir, kTestUser1Hash, id); 484 wallpaper::kLargeWallpaperSubDir, kTestUser1Hash, id);
480 485
481 // Saves the small/large resolution wallpapers to small/large custom 486 // Saves the small/large resolution wallpapers to small/large custom
482 // wallpaper paths. 487 // wallpaper paths.
483 ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile( 488 ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile(
484 small_wallpaper_path, 489 small_wallpaper_path,
485 kSmallWallpaperWidth, 490 kSmallWallpaperWidth,
486 kSmallWallpaperHeight, 491 kSmallWallpaperHeight,
487 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor)); 492 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor));
488 ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile( 493 ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile(
489 large_wallpaper_path, 494 large_wallpaper_path,
490 kLargeWallpaperWidth, 495 kLargeWallpaperWidth,
491 kLargeWallpaperHeight, 496 kLargeWallpaperHeight,
492 wallpaper_manager_test_utils::kLargeDefaultWallpaperColor)); 497 wallpaper_manager_test_utils::kLargeDefaultWallpaperColor));
493 498
494 std::string relative_path = base::FilePath(kTestUser1Hash).Append(id).value(); 499 std::string relative_path = base::FilePath(kTestUser1Hash).Append(id).value();
495 // Saves wallpaper info to local state for user |kTestUser1|. 500 // Saves wallpaper info to local state for user |test_account_id1_|.
496 WallpaperInfo info = {relative_path, WALLPAPER_LAYOUT_CENTER_CROPPED, 501 WallpaperInfo info = {relative_path, WALLPAPER_LAYOUT_CENTER_CROPPED,
497 user_manager::User::CUSTOMIZED, 502 user_manager::User::CUSTOMIZED,
498 base::Time::Now().LocalMidnight()}; 503 base::Time::Now().LocalMidnight()};
499 wallpaper_manager->SetUserWallpaperInfo(kTestUser1, info, true); 504 wallpaper_manager->SetUserWallpaperInfo(test_account_id1_, info, true);
500 wallpaper_manager->SetUserWallpaperNow(kTestUser1); 505 wallpaper_manager->SetUserWallpaperNow(test_account_id1_);
501 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 506 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
502 scoped_ptr<WallpaperManager::TestApi> test_api; 507 scoped_ptr<WallpaperManager::TestApi> test_api;
503 test_api.reset(new WallpaperManager::TestApi(wallpaper_manager)); 508 test_api.reset(new WallpaperManager::TestApi(wallpaper_manager));
504 // Verify SetUserWallpaperNow updates wallpaper cache. 509 // Verify SetUserWallpaperNow updates wallpaper cache.
505 gfx::ImageSkia cached_wallpaper; 510 gfx::ImageSkia cached_wallpaper;
506 EXPECT_TRUE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper)); 511 EXPECT_TRUE(
512 test_api->GetWallpaperFromCache(test_account_id1_, &cached_wallpaper));
507 base::FilePath path; 513 base::FilePath path;
508 EXPECT_TRUE(test_api->GetPathFromCache(kTestUser1, &path)); 514 EXPECT_TRUE(test_api->GetPathFromCache(test_account_id1_, &path));
509 EXPECT_FALSE(path.empty()); 515 EXPECT_FALSE(path.empty());
510 } 516 }
511 517
512 // Tests for crbug.com/339576. Wallpaper cache should be updated in 518 // Tests for crbug.com/339576. Wallpaper cache should be updated in
513 // multi-profile mode when user: 519 // multi-profile mode when user:
514 // 1. chooses an online wallpaper from wallpaper 520 // 1. chooses an online wallpaper from wallpaper
515 // picker (calls SetWallpaperFromImageSkia); 521 // picker (calls SetWallpaperFromImageSkia);
516 // 2. chooses a custom wallpaper from wallpaper 522 // 2. chooses a custom wallpaper from wallpaper
517 // picker (calls SetCustomWallpaper); 523 // picker (calls SetCustomWallpaper);
518 // 3. reverts to a default wallpaper. 524 // 3. reverts to a default wallpaper.
519 // Also, when user login at multi-profile mode, previous logged in users' 525 // Also, when user login at multi-profile mode, previous logged in users'
520 // wallpaper cache should not be deleted. 526 // wallpaper cache should not be deleted.
521 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCacheUpdate, 527 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCacheUpdate,
522 VerifyWallpaperCache) { 528 VerifyWallpaperCache) {
523 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); 529 WallpaperManager* wallpaper_manager = WallpaperManager::Get();
524 530
525 // Force load initial wallpaper 531 // Force load initial wallpaper
526 // (simulate DesktopBackgroundController::UpdateDisplay()). 532 // (simulate DesktopBackgroundController::UpdateDisplay()).
527 wallpaper_manager->UpdateWallpaper(true); 533 wallpaper_manager->UpdateWallpaper(true);
528 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 534 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
529 scoped_ptr<WallpaperManager::TestApi> test_api; 535 scoped_ptr<WallpaperManager::TestApi> test_api;
530 test_api.reset(new WallpaperManager::TestApi(wallpaper_manager)); 536 test_api.reset(new WallpaperManager::TestApi(wallpaper_manager));
531 gfx::ImageSkia cached_wallpaper; 537 gfx::ImageSkia cached_wallpaper;
532 // Previous custom wallpaper should be cached after user login. 538 // Previous custom wallpaper should be cached after user login.
533 EXPECT_TRUE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper)); 539 EXPECT_TRUE(
540 test_api->GetWallpaperFromCache(test_account_id1_, &cached_wallpaper));
534 base::FilePath original_path; 541 base::FilePath original_path;
535 EXPECT_TRUE(test_api->GetPathFromCache(kTestUser1, &original_path)); 542 EXPECT_TRUE(test_api->GetPathFromCache(test_account_id1_, &original_path));
536 EXPECT_FALSE(original_path.empty()); 543 EXPECT_FALSE(original_path.empty());
537 544
538 LogIn(AccountId::FromUserEmail(kTestUser2), kTestUser2Hash); 545 LogIn(test_account_id2_, kTestUser2Hash);
539 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 546 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
540 // Login another user should not delete logged in user's wallpaper cache. 547 // Login another user should not delete logged in user's wallpaper cache.
541 // Note active user is still kTestUser1. 548 // Note active user is still test_account_id1_.
542 EXPECT_TRUE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper)); 549 EXPECT_TRUE(
550 test_api->GetWallpaperFromCache(test_account_id1_, &cached_wallpaper));
543 base::FilePath path; 551 base::FilePath path;
544 EXPECT_TRUE(test_api->GetPathFromCache(kTestUser1, &path)); 552 EXPECT_TRUE(test_api->GetPathFromCache(test_account_id1_, &path));
545 EXPECT_EQ(original_path, path); 553 EXPECT_EQ(original_path, path);
546 554
547 gfx::ImageSkia red_wallpaper = CreateTestImage(SK_ColorRED); 555 gfx::ImageSkia red_wallpaper = CreateTestImage(SK_ColorRED);
548 wallpaper_manager->SetWallpaperFromImageSkia(kTestUser1, 556 wallpaper_manager->SetWallpaperFromImageSkia(test_account_id1_, red_wallpaper,
549 red_wallpaper, 557 WALLPAPER_LAYOUT_CENTER, true);
550 WALLPAPER_LAYOUT_CENTER,
551 true);
552 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 558 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
553 // SetWallpaperFromImageSkia should update wallpaper cache when multi-profile 559 // SetWallpaperFromImageSkia should update wallpaper cache when multi-profile
554 // is turned on. 560 // is turned on.
555 EXPECT_TRUE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper)); 561 EXPECT_TRUE(
556 EXPECT_TRUE(test_api->GetPathFromCache(kTestUser1, &path)); 562 test_api->GetWallpaperFromCache(test_account_id1_, &cached_wallpaper));
563 EXPECT_TRUE(test_api->GetPathFromCache(test_account_id1_, &path));
557 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(red_wallpaper)); 564 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(red_wallpaper));
558 565
559 gfx::ImageSkia green_wallpaper = CreateTestImage(SK_ColorGREEN); 566 gfx::ImageSkia green_wallpaper = CreateTestImage(SK_ColorGREEN);
560 wallpaper_manager->SetCustomWallpaper(kTestUser1, 567 wallpaper_manager->SetCustomWallpaper(test_account_id1_, kTestUser1Hash,
561 kTestUser1Hash,
562 "dummy", // dummy file name 568 "dummy", // dummy file name
563 WALLPAPER_LAYOUT_CENTER, 569 WALLPAPER_LAYOUT_CENTER,
564 user_manager::User::CUSTOMIZED, 570 user_manager::User::CUSTOMIZED,
565 green_wallpaper, 571 green_wallpaper, true);
566 true);
567 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 572 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
568 // SetCustomWallpaper should also update wallpaper cache when multi-profile is 573 // SetCustomWallpaper should also update wallpaper cache when multi-profile is
569 // turned on. 574 // turned on.
570 EXPECT_TRUE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper)); 575 EXPECT_TRUE(
576 test_api->GetWallpaperFromCache(test_account_id1_, &cached_wallpaper));
571 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(green_wallpaper)); 577 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(green_wallpaper));
572 EXPECT_TRUE(test_api->GetPathFromCache(kTestUser1, &path)); 578 EXPECT_TRUE(test_api->GetPathFromCache(test_account_id1_, &path));
573 EXPECT_NE(original_path, path); 579 EXPECT_NE(original_path, path);
574 580
575 wallpaper_manager->SetDefaultWallpaperNow(kTestUser1); 581 wallpaper_manager->SetDefaultWallpaperNow(test_account_id1_);
576 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 582 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
577 // SetDefaultWallpaper should invalidate the user's wallpaper cache. 583 // SetDefaultWallpaper should invalidate the user's wallpaper cache.
578 EXPECT_FALSE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper)); 584 EXPECT_FALSE(
585 test_api->GetWallpaperFromCache(test_account_id1_, &cached_wallpaper));
579 } 586 }
580 587
581 // ---------------------------------------------------------------------- 588 // ----------------------------------------------------------------------
582 // Test default wallpapers. 589 // Test default wallpapers.
583 590
584 class TestObserver : public WallpaperManager::Observer { 591 class TestObserver : public WallpaperManager::Observer {
585 public: 592 public:
586 explicit TestObserver(WallpaperManager* wallpaper_manager) 593 explicit TestObserver(WallpaperManager* wallpaper_manager)
587 : update_wallpaper_count_(0), wallpaper_manager_(wallpaper_manager) { 594 : update_wallpaper_count_(0), wallpaper_manager_(wallpaper_manager) {
588 DCHECK(wallpaper_manager_); 595 DCHECK(wallpaper_manager_);
589 wallpaper_manager_->AddObserver(this); 596 wallpaper_manager_->AddObserver(this);
590 } 597 }
591 598
592 ~TestObserver() override { wallpaper_manager_->RemoveObserver(this); } 599 ~TestObserver() override { wallpaper_manager_->RemoveObserver(this); }
593 600
594 void OnWallpaperAnimationFinished(const std::string&) override {} 601 void OnWallpaperAnimationFinished(const AccountId& account_id) override {}
595 602
596 void OnUpdateWallpaperForTesting() override { ++update_wallpaper_count_; } 603 void OnUpdateWallpaperForTesting() override { ++update_wallpaper_count_; }
597 604
598 int GetUpdateWallpaperCountAndReset() { 605 int GetUpdateWallpaperCountAndReset() {
599 const size_t old = update_wallpaper_count_; 606 const size_t old = update_wallpaper_count_;
600 update_wallpaper_count_ = 0; 607 update_wallpaper_count_ = 0;
601 return old; 608 return old;
602 } 609 }
603 610
604 private: 611 private:
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
710 // Splitting these into separate tests avoids needing to run animations. 717 // Splitting these into separate tests avoids needing to run animations.
711 // TODO(derat): Combine these into a single test 718 // TODO(derat): Combine these into a single test
712 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, SmallDefaultWallpaper) { 719 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, SmallDefaultWallpaper) {
713 if (!ash::test::AshTestHelper::SupportsMultipleDisplays()) 720 if (!ash::test::AshTestHelper::SupportsMultipleDisplays())
714 return; 721 return;
715 722
716 CreateCmdlineWallpapers(); 723 CreateCmdlineWallpapers();
717 724
718 // At 800x600, the small wallpaper should be loaded. 725 // At 800x600, the small wallpaper should be loaded.
719 UpdateDisplay("800x600"); 726 UpdateDisplay("800x600");
720 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); 727 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId());
721 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 728 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
722 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( 729 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
723 controller_->GetWallpaper(), 730 controller_->GetWallpaper(),
724 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor)); 731 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor));
725 } 732 }
726 733
727 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, LargeDefaultWallpaper) { 734 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, LargeDefaultWallpaper) {
728 if (!ash::test::AshTestHelper::SupportsMultipleDisplays()) 735 if (!ash::test::AshTestHelper::SupportsMultipleDisplays())
729 return; 736 return;
730 737
731 CreateCmdlineWallpapers(); 738 CreateCmdlineWallpapers();
732 UpdateDisplay("1600x1200"); 739 UpdateDisplay("1600x1200");
733 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); 740 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId());
734 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 741 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
735 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( 742 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
736 controller_->GetWallpaper(), 743 controller_->GetWallpaper(),
737 wallpaper_manager_test_utils::kLargeDefaultWallpaperColor)); 744 wallpaper_manager_test_utils::kLargeDefaultWallpaperColor));
738 } 745 }
739 746
740 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, 747 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest,
741 LargeDefaultWallpaperWhenRotated) { 748 LargeDefaultWallpaperWhenRotated) {
742 if (!ash::test::AshTestHelper::SupportsMultipleDisplays()) 749 if (!ash::test::AshTestHelper::SupportsMultipleDisplays())
743 return; 750 return;
744 CreateCmdlineWallpapers(); 751 CreateCmdlineWallpapers();
745 752
746 UpdateDisplay("1200x800/r"); 753 UpdateDisplay("1200x800/r");
747 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); 754 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId());
748 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 755 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
749 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( 756 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
750 controller_->GetWallpaper(), 757 controller_->GetWallpaper(),
751 wallpaper_manager_test_utils::kLargeDefaultWallpaperColor)); 758 wallpaper_manager_test_utils::kLargeDefaultWallpaperColor));
752 } 759 }
753 760
754 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, SmallGuestWallpaper) { 761 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, SmallGuestWallpaper) {
755 if (!ash::test::AshTestHelper::SupportsMultipleDisplays()) 762 if (!ash::test::AshTestHelper::SupportsMultipleDisplays())
756 return; 763 return;
757 CreateCmdlineWallpapers(); 764 CreateCmdlineWallpapers();
758 user_manager::UserManager::Get()->UserLoggedIn( 765 user_manager::UserManager::Get()->UserLoggedIn(
759 chromeos::login::GuestAccountId(), chromeos::login::kGuestUserName, 766 chromeos::login::GuestAccountId(), chromeos::login::kGuestUserName,
760 false); 767 false);
761 UpdateDisplay("800x600"); 768 UpdateDisplay("800x600");
762 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); 769 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId());
763 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 770 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
764 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( 771 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
765 controller_->GetWallpaper(), 772 controller_->GetWallpaper(),
766 wallpaper_manager_test_utils::kSmallGuestWallpaperColor)); 773 wallpaper_manager_test_utils::kSmallGuestWallpaperColor));
767 } 774 }
768 775
769 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, LargeGuestWallpaper) { 776 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, LargeGuestWallpaper) {
770 if (!ash::test::AshTestHelper::SupportsMultipleDisplays()) 777 if (!ash::test::AshTestHelper::SupportsMultipleDisplays())
771 return; 778 return;
772 779
773 CreateCmdlineWallpapers(); 780 CreateCmdlineWallpapers();
774 user_manager::UserManager::Get()->UserLoggedIn( 781 user_manager::UserManager::Get()->UserLoggedIn(
775 chromeos::login::GuestAccountId(), chromeos::login::kGuestUserName, 782 chromeos::login::GuestAccountId(), chromeos::login::kGuestUserName,
776 false); 783 false);
777 UpdateDisplay("1600x1200"); 784 UpdateDisplay("1600x1200");
778 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); 785 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId());
779 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 786 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
780 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( 787 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
781 controller_->GetWallpaper(), 788 controller_->GetWallpaper(),
782 wallpaper_manager_test_utils::kLargeGuestWallpaperColor)); 789 wallpaper_manager_test_utils::kLargeGuestWallpaperColor));
783 } 790 }
784 791
785 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, SmallChildWallpaper) { 792 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, SmallChildWallpaper) {
786 if (!ash::test::AshTestHelper::SupportsMultipleDisplays()) 793 if (!ash::test::AshTestHelper::SupportsMultipleDisplays())
787 return; 794 return;
788 CreateCmdlineWallpapers(); 795 CreateCmdlineWallpapers();
789 LogInAsChild(AccountId::FromUserEmail(kTestUser1), kTestUser1Hash); 796 LogInAsChild(test_account_id1_, kTestUser1Hash);
790 UpdateDisplay("800x600"); 797 UpdateDisplay("800x600");
791 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); 798 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId());
792 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 799 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
793 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( 800 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
794 controller_->GetWallpaper(), 801 controller_->GetWallpaper(),
795 wallpaper_manager_test_utils::kSmallChildWallpaperColor)); 802 wallpaper_manager_test_utils::kSmallChildWallpaperColor));
796 } 803 }
797 804
798 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, LargeChildWallpaper) { 805 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, LargeChildWallpaper) {
799 if (!ash::test::AshTestHelper::SupportsMultipleDisplays()) 806 if (!ash::test::AshTestHelper::SupportsMultipleDisplays())
800 return; 807 return;
801 808
802 CreateCmdlineWallpapers(); 809 CreateCmdlineWallpapers();
803 LogInAsChild(AccountId::FromUserEmail(kTestUser1), kTestUser1Hash); 810 LogInAsChild(test_account_id1_, kTestUser1Hash);
804 UpdateDisplay("1600x1200"); 811 UpdateDisplay("1600x1200");
805 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); 812 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId());
806 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 813 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
807 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( 814 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
808 controller_->GetWallpaper(), 815 controller_->GetWallpaper(),
809 wallpaper_manager_test_utils::kLargeChildWallpaperColor)); 816 wallpaper_manager_test_utils::kLargeChildWallpaperColor));
810 } 817 }
811 818
812 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, 819 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest,
813 SwitchBetweenDefaultAndCustom) { 820 SwitchBetweenDefaultAndCustom) {
814 // Start loading the default wallpaper. 821 // Start loading the default wallpaper.
815 UpdateDisplay("640x480"); 822 UpdateDisplay("640x480");
816 CreateCmdlineWallpapers(); 823 CreateCmdlineWallpapers();
817 user_manager::UserManager::Get()->UserLoggedIn( 824 user_manager::UserManager::Get()->UserLoggedIn(
818 chromeos::login::StubAccountId(), "test_hash", false); 825 chromeos::login::StubAccountId(), "test_hash", false);
819 826
820 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); 827 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId());
821 828
822 // Custom wallpaper should be applied immediately, canceling the default 829 // Custom wallpaper should be applied immediately, canceling the default
823 // wallpaper load task. 830 // wallpaper load task.
824 gfx::ImageSkia image = wallpaper_manager_test_utils::CreateTestImage( 831 gfx::ImageSkia image = wallpaper_manager_test_utils::CreateTestImage(
825 640, 480, wallpaper_manager_test_utils::kCustomWallpaperColor); 832 640, 480, wallpaper_manager_test_utils::kCustomWallpaperColor);
826 WallpaperManager::Get()->SetCustomWallpaper(chromeos::login::kStubUser, 833 WallpaperManager::Get()->SetCustomWallpaper(
827 "test_hash", 834 chromeos::login::StubAccountId(), "test_hash", "test-nofile.jpeg",
828 "test-nofile.jpeg", 835 WALLPAPER_LAYOUT_STRETCH, user_manager::User::CUSTOMIZED, image, true);
829 WALLPAPER_LAYOUT_STRETCH,
830 user_manager::User::CUSTOMIZED,
831 image,
832 true);
833 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 836 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
834 837
835 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( 838 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
836 controller_->GetWallpaper(), 839 controller_->GetWallpaper(),
837 wallpaper_manager_test_utils::kCustomWallpaperColor)); 840 wallpaper_manager_test_utils::kCustomWallpaperColor));
838 841
839 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); 842 WallpaperManager::Get()->SetDefaultWallpaperNow(EmptyAccountId());
840 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); 843 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished();
841 844
842 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( 845 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor(
843 controller_->GetWallpaper(), 846 controller_->GetWallpaper(),
844 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor)); 847 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor));
845 } 848 }
846 849
847 } // namespace chromeos 850 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698