ae17295deaa9e243c086d574630f1f5a915b69df
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / login / wallpaper_manager_browsertest.cc
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/chromeos/login/wallpaper_manager.h"
6
7 #include "ash/ash_resources/grit/ash_resources.h"
8 #include "ash/desktop_background/desktop_background_controller.h"
9 #include "ash/desktop_background/desktop_background_controller_observer.h"
10 #include "ash/display/display_manager.h"
11 #include "ash/shell.h"
12 #include "ash/test/display_manager_test_api.h"
13 #include "base/command_line.h"
14 #include "base/file_util.h"
15 #include "base/files/file_path.h"
16 #include "base/message_loop/message_loop.h"
17 #include "base/path_service.h"
18 #include "base/prefs/scoped_user_pref_update.h"
19 #include "base/strings/string_number_conversions.h"
20 #include "base/time/time.h"
21 #include "base/values.h"
22 #include "chrome/browser/chromeos/login/user.h"
23 #include "chrome/browser/chromeos/login/user_manager.h"
24 #include "chrome/common/chrome_paths.h"
25 #include "chrome/common/chrome_switches.h"
26 #include "chrome/test/base/in_process_browser_test.h"
27 #include "chrome/test/base/testing_browser_process.h"
28 #include "chromeos/chromeos_switches.h"
29 #include "chromeos/dbus/cryptohome_client.h"
30 #include "content/public/test/test_utils.h"
31 #include "ui/aura/env.h"
32 #include "ui/base/resource/resource_bundle.h"
33
34 using namespace ash;
35
36 namespace chromeos {
37
38 namespace {
39
40 const int kLargeWallpaperResourceId = IDR_AURA_WALLPAPER_DEFAULT_LARGE;
41 const int kSmallWallpaperResourceId = IDR_AURA_WALLPAPER_DEFAULT_SMALL;
42
43 int kLargeWallpaperWidth = 256;
44 int kLargeWallpaperHeight = ash::kLargeWallpaperMaxHeight;
45 int kSmallWallpaperWidth = 256;
46 int kSmallWallpaperHeight = ash::kSmallWallpaperMaxHeight;
47
48 const char kTestUser1[] = "test1@domain.com";
49 const char kTestUser1Hash[] = "test1@domain.com-hash";
50 const char kTestUser2[] = "test2@domain.com";
51 const char kTestUser2Hash[] = "test2@domain.com-hash";
52
53 }  // namespace
54
55 class WallpaperManagerBrowserTest : public InProcessBrowserTest,
56                                     public DesktopBackgroundControllerObserver {
57  public:
58   WallpaperManagerBrowserTest () : controller_(NULL),
59                                    local_state_(NULL) {
60   }
61
62   virtual ~WallpaperManagerBrowserTest () {}
63
64   virtual void SetUpOnMainThread() OVERRIDE {
65     controller_ = ash::Shell::GetInstance()->desktop_background_controller();
66     controller_->AddObserver(this);
67     local_state_ = g_browser_process->local_state();
68     UpdateDisplay("800x600");
69   }
70
71   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
72     command_line->AppendSwitch(switches::kLoginManager);
73     command_line->AppendSwitchASCII(switches::kLoginProfile, "user");
74   }
75
76   virtual void CleanUpOnMainThread() OVERRIDE {
77     controller_->RemoveObserver(this);
78     controller_ = NULL;
79   }
80
81   // Update the display configuration as given in |display_specs|.
82   // See ash::test::DisplayManagerTestApi::UpdateDisplay for more
83   // details.
84   void UpdateDisplay(const std::string& display_specs) {
85     ash::test::DisplayManagerTestApi display_manager_test_api(
86         ash::Shell::GetInstance()->display_manager());
87     display_manager_test_api.UpdateDisplay(display_specs);
88   }
89
90   void WaitAsyncWallpaperLoadStarted() {
91     base::MessageLoop::current()->RunUntilIdle();
92   }
93
94   void WaitAsyncWallpaperLoadFinished() {
95     base::MessageLoop::current()->RunUntilIdle();
96     while (WallpaperManager::Get()->loading_.size()) {
97       base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
98       base::MessageLoop::current()->RunUntilIdle();
99     }
100   }
101
102   virtual void OnWallpaperDataChanged() OVERRIDE {
103     base::MessageLoop::current()->Quit();
104   }
105
106  protected:
107   // Return custom wallpaper path. Create directory if not exist.
108   base::FilePath GetCustomWallpaperPath(const char* sub_dir,
109                                         const std::string& username_hash,
110                                         const std::string& id) {
111     base::FilePath wallpaper_path =
112         WallpaperManager::Get()->GetCustomWallpaperPath(sub_dir,
113                                                         username_hash,
114                                                         id);
115     if (!base::DirectoryExists(wallpaper_path.DirName()))
116       base::CreateDirectory(wallpaper_path.DirName());
117
118     return wallpaper_path;
119   }
120
121   // Logs in |username|.
122   void LogIn(const std::string& username, const std::string& username_hash) {
123     UserManager::Get()->UserLoggedIn(username, username_hash, false);
124     WaitAsyncWallpaperLoadStarted();
125   }
126
127   // Saves bitmap |resource_id| to disk.
128   void SaveUserWallpaperData(const base::FilePath& wallpaper_path,
129                              int resource_id) {
130     scoped_refptr<base::RefCountedStaticMemory> image_data(
131         ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
132             resource_id, ui::SCALE_FACTOR_100P));
133     int written = file_util::WriteFile(
134         wallpaper_path,
135         reinterpret_cast<const char*>(image_data->front()),
136         image_data->size());
137     EXPECT_EQ(static_cast<int>(image_data->size()), written);
138   }
139
140   int LoadedWallpapers() {
141     return WallpaperManager::Get()->loaded_wallpapers();
142   }
143
144   DesktopBackgroundController* controller_;
145   PrefService* local_state_;
146
147  private:
148   DISALLOW_COPY_AND_ASSIGN(WallpaperManagerBrowserTest);
149 };
150
151 // Tests that the appropriate custom wallpaper (large vs. small) is loaded
152 // depending on the desktop resolution.
153 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest,
154                        LoadCustomLargeWallpaperForLargeExternalScreen) {
155   WallpaperManager* wallpaper_manager = WallpaperManager::Get();
156   LogIn(kTestUser1, kTestUser1Hash);
157   std::string id = base::Int64ToString(base::Time::Now().ToInternalValue());
158   base::FilePath small_wallpaper_path = GetCustomWallpaperPath(
159       kSmallWallpaperSubDir,
160       kTestUser1Hash,
161       id);
162   base::FilePath large_wallpaper_path = GetCustomWallpaperPath(
163       kLargeWallpaperSubDir,
164       kTestUser1Hash,
165       id);
166
167   // Saves the small/large resolution wallpapers to small/large custom
168   // wallpaper paths.
169   SaveUserWallpaperData(small_wallpaper_path,
170                         kSmallWallpaperResourceId);
171   SaveUserWallpaperData(large_wallpaper_path,
172                         kLargeWallpaperResourceId);
173
174   std::string relative_path = base::FilePath(kTestUser1Hash).Append(id).value();
175   // Saves wallpaper info to local state for user |kTestUser1|.
176   WallpaperInfo info = {
177       relative_path,
178       WALLPAPER_LAYOUT_CENTER_CROPPED,
179       User::CUSTOMIZED,
180       base::Time::Now().LocalMidnight()
181   };
182   wallpaper_manager->SetUserWallpaperInfo(kTestUser1, info, true);
183
184   // Set the wallpaper for |kTestUser1|.
185   wallpaper_manager->SetUserWallpaperNow(kTestUser1);
186   WaitAsyncWallpaperLoadFinished();
187   gfx::ImageSkia wallpaper = controller_->GetWallpaper();
188
189   // Display is initialized to 800x600. The small resolution custom wallpaper is
190   // expected.
191   EXPECT_EQ(kSmallWallpaperWidth, wallpaper.width());
192   EXPECT_EQ(kSmallWallpaperHeight, wallpaper.height());
193
194   // Hook up another 800x600 display. This shouldn't trigger a reload.
195   UpdateDisplay("800x600,800x600");
196   content::RunAllPendingInMessageLoop();
197   // The small resolution custom wallpaper is expected.
198   EXPECT_EQ(kSmallWallpaperWidth, wallpaper.width());
199   EXPECT_EQ(kSmallWallpaperHeight, wallpaper.height());
200
201   // Detach the secondary display.
202   UpdateDisplay("800x600");
203   // Hook up a 2000x2000 display. The large resolution custom wallpaper should
204   // be loaded.
205   UpdateDisplay("800x600,2000x2000");
206   WaitAsyncWallpaperLoadFinished();
207   wallpaper = controller_->GetWallpaper();
208
209   // The large resolution custom wallpaper is expected.
210   EXPECT_EQ(kLargeWallpaperWidth, wallpaper.width());
211   EXPECT_EQ(kLargeWallpaperHeight, wallpaper.height());
212
213   // Detach the secondary display.
214   UpdateDisplay("800x600");
215   // Hook up the 2000x2000 display again. The large resolution default wallpaper
216   // should persist. Test for crbug/165788.
217   UpdateDisplay("800x600,2000x2000");
218   WaitAsyncWallpaperLoadFinished();
219   wallpaper = controller_->GetWallpaper();
220
221   // The large resolution custom wallpaper is expected.
222   EXPECT_EQ(kLargeWallpaperWidth, wallpaper.width());
223   EXPECT_EQ(kLargeWallpaperHeight, wallpaper.height());
224 }
225
226 // If chrome tries to reload the same wallpaper twice, the latter request should
227 // be prevented. Otherwise, there are some strange animation issues as
228 // described in crbug.com/158383.
229 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest,
230                        PreventReloadingSameWallpaper) {
231   WallpaperManager* wallpaper_manager = WallpaperManager::Get();
232   // New user log in, a default wallpaper is loaded.
233   LogIn(kTestUser1, kTestUser1Hash);
234   EXPECT_EQ(1, LoadedWallpapers());
235   // Loads the same wallpaper before the initial one finished. It should be
236   // prevented.
237   wallpaper_manager->SetUserWallpaperNow(kTestUser1);
238   WaitAsyncWallpaperLoadFinished();
239   EXPECT_EQ(1, LoadedWallpapers());
240   // Loads the same wallpaper after the initial one finished. It should be
241   // prevented.
242   wallpaper_manager->SetUserWallpaperNow(kTestUser1);
243   WaitAsyncWallpaperLoadFinished();
244   EXPECT_EQ(1, LoadedWallpapers());
245   wallpaper_manager->ClearWallpaperCache();
246
247   // Change wallpaper to a custom wallpaper.
248   std::string id = base::Int64ToString(base::Time::Now().ToInternalValue());
249   base::FilePath small_wallpaper_path = GetCustomWallpaperPath(
250       kSmallWallpaperSubDir,
251       kTestUser1Hash,
252       id);
253   SaveUserWallpaperData(small_wallpaper_path,
254                         kSmallWallpaperResourceId);
255
256   std::string relative_path = base::FilePath(kTestUser1Hash).Append(id).value();
257   // Saves wallpaper info to local state for user |kTestUser1|.
258   WallpaperInfo info = {
259       relative_path,
260       WALLPAPER_LAYOUT_CENTER_CROPPED,
261       User::CUSTOMIZED,
262       base::Time::Now().LocalMidnight()
263   };
264   wallpaper_manager->SetUserWallpaperInfo(kTestUser1, info, true);
265
266   wallpaper_manager->SetUserWallpaperNow(kTestUser1);
267   WaitAsyncWallpaperLoadStarted();
268   EXPECT_EQ(2, LoadedWallpapers());
269   // Loads the same wallpaper before the initial one finished. It should be
270   // prevented.
271   wallpaper_manager->SetUserWallpaperNow(kTestUser1);
272   WaitAsyncWallpaperLoadStarted();
273   EXPECT_EQ(2, LoadedWallpapers());
274   wallpaper_manager->SetUserWallpaperNow(kTestUser1);
275   WaitAsyncWallpaperLoadFinished();
276   EXPECT_EQ(2, LoadedWallpapers());
277 }
278
279 // Some users have old user profiles which may have legacy wallpapers. And these
280 // lagacy wallpapers should migrate to new wallpaper picker version seamlessly.
281 // This tests make sure we compatible with migrated old wallpapers.
282 // crosbug.com/38429
283 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest,
284                        PRE_UseMigratedWallpaperInfo) {
285   // New user log in, a default wallpaper is loaded.
286   LogIn(kTestUser1, kTestUser1Hash);
287   // Old wallpaper migration code doesn't exist in codebase anymore. Modify user
288   // wallpaper info directly to simulate the wallpaper migration. See
289   // crosbug.com/38429 for details about why we modify wallpaper info this way.
290   WallpaperInfo info = {
291       "123",
292       WALLPAPER_LAYOUT_CENTER_CROPPED,
293       User::DEFAULT,
294       base::Time::Now().LocalMidnight()
295   };
296   base::FilePath user_data_dir;
297   ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir));
298   SaveUserWallpaperData(user_data_dir.Append("123"),
299                         kLargeWallpaperResourceId);
300   WallpaperManager::Get()->SetUserWallpaperInfo(kTestUser1, info, true);
301 }
302
303 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest,
304                        UseMigratedWallpaperInfo) {
305   LogIn(kTestUser1, kTestUser1Hash);
306   WaitAsyncWallpaperLoadFinished();
307   // This test should finish normally. If timeout, it is probably because
308   // migrated wallpaper is somehow not loaded. Bad things can happen if
309   // wallpaper is not loaded at login screen. One example is: crosbug.com/38429.
310 }
311
312 // Some users have old user profiles which may never get a chance to migrate.
313 // This tests make sure we compatible with these profiles.
314 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest,
315                        PRE_UsePreMigrationWallpaperInfo) {
316   // New user log in, a default wallpaper is loaded.
317   LogIn(kTestUser1, kTestUser1Hash);
318   // Old wallpaper migration code doesn't exist in codebase anymore. So if
319   // user's profile is not migrated, it is the same as no wallpaper info. To
320   // simulate this, we remove user's wallpaper info here.
321   WallpaperManager::Get()->RemoveUserWallpaperInfo(kTestUser1);
322 }
323
324 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest,
325                        UsePreMigrationWallpaperInfo) {
326   LogIn(kTestUser1, kTestUser1Hash);
327   WaitAsyncWallpaperLoadFinished();
328   // This test should finish normally. If timeout, it is probably because chrome
329   // can not handle pre migrated user profile (M21 profile or older).
330 }
331
332 // Test for http://crbug.com/265689. When hooked up a large external monitor,
333 // the default large resolution wallpaper should load.
334 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest,
335                        HotPlugInScreenAtGAIALoginScreen) {
336   UpdateDisplay("800x600");
337   // Set initial wallpaper to the default wallpaper.
338   WallpaperManager::Get()->SetDefaultWallpaperNow(UserManager::kStubUser);
339   WaitAsyncWallpaperLoadFinished();
340
341   // Hook up a 2000x2000 display. The large resolution custom wallpaper should
342   // be loaded.
343   UpdateDisplay("800x600,2000x2000");
344   WaitAsyncWallpaperLoadFinished();
345 }
346
347 class WallpaperManagerBrowserTestNoAnimation
348     : public WallpaperManagerBrowserTest {
349  public:
350   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
351     command_line->AppendSwitch(switches::kLoginManager);
352     command_line->AppendSwitchASCII(switches::kLoginProfile, "user");
353     command_line->AppendSwitch(chromeos::switches::kDisableLoginAnimations);
354     command_line->AppendSwitch(chromeos::switches::kDisableBootAnimation);
355   }
356 };
357
358 // Same test as WallpaperManagerBrowserTest.UseMigratedWallpaperInfo. But
359 // disabled boot and login animation.
360 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestNoAnimation,
361                        PRE_UseMigratedWallpaperInfo) {
362   // New user log in, a default wallpaper is loaded.
363   LogIn(kTestUser1, kTestUser1Hash);
364   // Old wallpaper migration code doesn't exist in codebase anymore. Modify user
365   // wallpaper info directly to simulate the wallpaper migration. See
366   // crosbug.com/38429 for details about why we modify wallpaper info this way.
367   WallpaperInfo info = {
368       "123",
369       WALLPAPER_LAYOUT_CENTER_CROPPED,
370       User::DEFAULT,
371       base::Time::Now().LocalMidnight()
372   };
373   base::FilePath user_data_dir;
374   ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir));
375   SaveUserWallpaperData(user_data_dir.Append("123"),
376                         kLargeWallpaperResourceId);
377   WallpaperManager::Get()->SetUserWallpaperInfo(kTestUser1, info, true);
378 }
379
380 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestNoAnimation,
381                        UseMigratedWallpaperInfo) {
382   LogIn(kTestUser1, kTestUser1Hash);
383   WaitAsyncWallpaperLoadFinished();
384   // This test should finish normally. If timeout, it is probably because
385   // migrated wallpaper is somehow not loaded. Bad things can happen if
386   // wallpaper is not loaded at login screen. One example is: crosbug.com/38429.
387 }
388
389 // Same test as WallpaperManagerBrowserTest.UsePreMigrationWallpaperInfo. But
390 // disabled boot and login animation.
391 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestNoAnimation,
392                        PRE_UsePreMigrationWallpaperInfo) {
393   // New user log in, a default wallpaper is loaded.
394   LogIn(kTestUser1, kTestUser1Hash);
395   WaitAsyncWallpaperLoadFinished();
396   // Old wallpaper migration code doesn't exist in codebase anymore. So if
397   // user's profile is not migrated, it is the same as no wallpaper info. To
398   // simulate this, we remove user's wallpaper info here.
399   WallpaperManager::Get()->RemoveUserWallpaperInfo(kTestUser1);
400 }
401
402 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestNoAnimation,
403                        UsePreMigrationWallpaperInfo) {
404   LogIn(kTestUser1, kTestUser1Hash);
405   WaitAsyncWallpaperLoadFinished();
406   // This test should finish normally. If timeout, it is probably because chrome
407   // can not handle pre migrated user profile (M21 profile or older).
408 }
409
410 class WallpaperManagerBrowserTestCrashRestore
411     : public WallpaperManagerBrowserTest {
412  public:
413   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
414     command_line->AppendSwitch(chromeos::switches::kDisableLoginAnimations);
415     command_line->AppendSwitch(chromeos::switches::kDisableBootAnimation);
416     command_line->AppendSwitch(::switches::kMultiProfiles);
417     command_line->AppendSwitchASCII(switches::kLoginUser, kTestUser1);
418     command_line->AppendSwitchASCII(switches::kLoginProfile,
419         CryptohomeClient::GetStubSanitizedUsername(kTestUser1));
420   }
421 };
422
423 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCrashRestore,
424                        PRE_RestoreWallpaper) {
425   LogIn(kTestUser1, kTestUser1Hash);
426   WaitAsyncWallpaperLoadFinished();
427 }
428
429 // Test for crbug.com/270278. It simulates a browser crash and verifies if user
430 // wallpaper is loaded.
431 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCrashRestore,
432                        RestoreWallpaper) {
433   EXPECT_EQ(1, LoadedWallpapers());
434 }
435
436 class WallpaperManagerBrowserTestCacheUpdate
437     : public WallpaperManagerBrowserTest {
438  public:
439   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
440     command_line->AppendSwitch(::switches::kMultiProfiles);
441     command_line->AppendSwitchASCII(switches::kLoginUser, kTestUser1);
442     command_line->AppendSwitchASCII(switches::kLoginProfile,
443         CryptohomeClient::GetStubSanitizedUsername(kTestUser1));
444   }
445  protected:
446   // Creates a test image of size 1x1.
447   gfx::ImageSkia CreateTestImage(SkColor color) {
448     SkBitmap bitmap;
449     bitmap.setConfig(SkBitmap::kARGB_8888_Config, 1, 1);
450     bitmap.allocPixels();
451     bitmap.eraseColor(color);
452     return gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
453   }
454 };
455
456 // Sets kTestUser1's wallpaper to a custom wallpaper.
457 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCacheUpdate,
458                        PRE_VerifyWallpaperCache) {
459   // Add kTestUser1 to user list. kTestUser1 is the default login profile.
460   LogIn(kTestUser1, kTestUser1Hash);
461
462   std::string id = base::Int64ToString(base::Time::Now().ToInternalValue());
463   WallpaperManager* wallpaper_manager = WallpaperManager::Get();
464   base::FilePath small_wallpaper_path = GetCustomWallpaperPath(
465       kSmallWallpaperSubDir,
466       kTestUser1Hash,
467       id);
468   base::FilePath large_wallpaper_path = GetCustomWallpaperPath(
469       kLargeWallpaperSubDir,
470       kTestUser1Hash,
471       id);
472
473   // Saves the small/large resolution wallpapers to small/large custom
474   // wallpaper paths.
475   SaveUserWallpaperData(small_wallpaper_path,
476                         kSmallWallpaperResourceId);
477   SaveUserWallpaperData(large_wallpaper_path,
478                         kLargeWallpaperResourceId);
479
480   std::string relative_path = base::FilePath(kTestUser1Hash).Append(id).value();
481   // Saves wallpaper info to local state for user |kTestUser1|.
482   WallpaperInfo info = {
483       relative_path,
484       WALLPAPER_LAYOUT_CENTER_CROPPED,
485       User::CUSTOMIZED,
486       base::Time::Now().LocalMidnight()
487   };
488   wallpaper_manager->SetUserWallpaperInfo(kTestUser1, info, true);
489   wallpaper_manager->SetUserWallpaperNow(kTestUser1);
490   WaitAsyncWallpaperLoadFinished();
491   scoped_ptr<WallpaperManager::TestApi> test_api;
492   test_api.reset(new WallpaperManager::TestApi(wallpaper_manager));
493   // Verify SetUserWallpaperNow updates wallpaper cache.
494   gfx::ImageSkia cached_wallpaper;
495   EXPECT_TRUE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper));
496 }
497
498 // Tests for crbug.com/339576. Wallpaper cache should be updated in
499 // multi-profile mode when user:
500 // 1. chooses an online wallpaper from wallpaper
501 //    picker(calls SetWallpaperFromImageSkia);
502 // 2. chooses a custom wallpaper from wallpaper
503 //    picker(calls SetCustomWallpaper);
504 // 3. reverts to a default wallpaper.
505 // Also, when user login at multi-profile mode, previous logged in users'
506 // wallpaper cache should not be deleted.
507 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCacheUpdate,
508                        VerifyWallpaperCache) {
509   WaitAsyncWallpaperLoadFinished();
510   WallpaperManager* wallpaper_manager = WallpaperManager::Get();
511   scoped_ptr<WallpaperManager::TestApi> test_api;
512   test_api.reset(new WallpaperManager::TestApi(wallpaper_manager));
513   gfx::ImageSkia cached_wallpaper;
514   // Previous custom wallpaper should be cached after user login.
515   EXPECT_TRUE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper));
516
517   LogIn(kTestUser2, kTestUser2Hash);
518   WaitAsyncWallpaperLoadFinished();
519   // Login another user should not delete logged in user's wallpaper cache.
520   // Note active user is still kTestUser1.
521   EXPECT_TRUE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper));
522
523   gfx::ImageSkia red_wallpaper = CreateTestImage(SK_ColorRED);
524   wallpaper_manager->SetWallpaperFromImageSkia(kTestUser1,
525                                                red_wallpaper,
526                                                WALLPAPER_LAYOUT_CENTER,
527                                                true);
528   WaitAsyncWallpaperLoadFinished();
529   // SetWallpaperFromImageSkia should update wallpaper cache when multi-profile
530   // is turned on.
531   EXPECT_TRUE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper));
532   EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(red_wallpaper));
533
534   gfx::ImageSkia green_wallpaper = CreateTestImage(SK_ColorGREEN);
535   chromeos::UserImage image(green_wallpaper);
536   wallpaper_manager->SetCustomWallpaper(kTestUser1,
537                                         kTestUser1Hash,
538                                         "dummy",  // dummy file name
539                                         WALLPAPER_LAYOUT_CENTER,
540                                         User::CUSTOMIZED,
541                                         image,
542                                         true);
543   WaitAsyncWallpaperLoadFinished();
544   // SetCustomWallpaper should also update wallpaper cache when multi-profile is
545   // turned on.
546   EXPECT_TRUE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper));
547   EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(green_wallpaper));
548
549   wallpaper_manager->SetDefaultWallpaperNow(kTestUser1);
550   WaitAsyncWallpaperLoadFinished();
551   // SetDefaultWallpaper should invalidate the user's wallpaper cache.
552   EXPECT_FALSE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper));
553 }
554
555 }  // namespace chromeos