| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <cstdlib> | 5 #include <cstdlib> |
| 6 #include <cstring> | 6 #include <cstring> |
| 7 | 7 |
| 8 #include "ash/desktop_background/desktop_background_controller.h" | 8 #include "ash/desktop_background/desktop_background_controller.h" |
| 9 #include "ash/desktop_background/desktop_background_controller_observer.h" | 9 #include "ash/desktop_background/desktop_background_controller_observer.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | 65 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
| 66 } | 66 } |
| 67 | 67 |
| 68 private: | 68 private: |
| 69 FakeChromeUserManager* fake_user_manager_; | 69 FakeChromeUserManager* fake_user_manager_; |
| 70 ScopedUserManagerEnabler scoped_user_manager_; | 70 ScopedUserManagerEnabler scoped_user_manager_; |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 TEST_F(WallpaperManagerCacheTest, VerifyWallpaperCache) { | 73 TEST_F(WallpaperManagerCacheTest, VerifyWallpaperCache) { |
| 74 // Add three users to known users. | 74 // Add three users to known users. |
| 75 const AccountId test_account_id_1 = | 75 std::string test_user_1 = "test1@example.com"; |
| 76 AccountId::FromUserEmail("test1@example.com"); | 76 std::string test_user_2 = "test2@example.com"; |
| 77 const AccountId test_account_id_2 = | 77 std::string test_user_3 = "test3@example.com"; |
| 78 AccountId::FromUserEmail("test2@example.com"); | |
| 79 const AccountId test_account_id_3 = | |
| 80 AccountId::FromUserEmail("test3@example.com"); | |
| 81 base::FilePath path1("path1"); | 78 base::FilePath path1("path1"); |
| 82 base::FilePath path2("path2"); | 79 base::FilePath path2("path2"); |
| 83 base::FilePath path3("path3"); | 80 base::FilePath path3("path3"); |
| 84 fake_user_manager()->AddUser(test_account_id_1); | 81 fake_user_manager()->AddUser(test_user_1); |
| 85 fake_user_manager()->AddUser(test_account_id_2); | 82 fake_user_manager()->AddUser(test_user_2); |
| 86 fake_user_manager()->AddUser(test_account_id_3); | 83 fake_user_manager()->AddUser(test_user_3); |
| 87 | 84 |
| 88 // Login two users. | 85 // Login two users. |
| 89 fake_user_manager()->LoginUser(test_account_id_1); | 86 fake_user_manager()->LoginUser(test_user_1); |
| 90 fake_user_manager()->LoginUser(test_account_id_2); | 87 fake_user_manager()->LoginUser(test_user_2); |
| 91 | 88 |
| 92 scoped_ptr<WallpaperManager::TestApi> test_api; | 89 scoped_ptr<WallpaperManager::TestApi> test_api; |
| 93 test_api.reset(new WallpaperManager::TestApi(WallpaperManager::Get())); | 90 test_api.reset(new WallpaperManager::TestApi(WallpaperManager::Get())); |
| 94 | 91 |
| 95 gfx::ImageSkia test_user_1_wallpaper = CreateTestImage(SK_ColorRED); | 92 gfx::ImageSkia test_user_1_wallpaper = CreateTestImage(SK_ColorRED); |
| 96 gfx::ImageSkia test_user_2_wallpaper = CreateTestImage(SK_ColorGREEN); | 93 gfx::ImageSkia test_user_2_wallpaper = CreateTestImage(SK_ColorGREEN); |
| 97 gfx::ImageSkia test_user_3_wallpaper = CreateTestImage(SK_ColorWHITE); | 94 gfx::ImageSkia test_user_3_wallpaper = CreateTestImage(SK_ColorWHITE); |
| 98 test_api->SetWallpaperCache(test_account_id_1.GetUserEmail(), path1, | 95 test_api->SetWallpaperCache(test_user_1, path1, test_user_1_wallpaper); |
| 99 test_user_1_wallpaper); | 96 test_api->SetWallpaperCache(test_user_2, path2, test_user_2_wallpaper); |
| 100 test_api->SetWallpaperCache(test_account_id_2.GetUserEmail(), path2, | 97 test_api->SetWallpaperCache(test_user_3, path3, test_user_3_wallpaper); |
| 101 test_user_2_wallpaper); | |
| 102 test_api->SetWallpaperCache(test_account_id_3.GetUserEmail(), path3, | |
| 103 test_user_3_wallpaper); | |
| 104 | 98 |
| 105 test_api->ClearDisposableWallpaperCache(); | 99 test_api->ClearDisposableWallpaperCache(); |
| 106 | 100 |
| 107 gfx::ImageSkia cached_wallpaper; | 101 gfx::ImageSkia cached_wallpaper; |
| 108 EXPECT_TRUE(test_api->GetWallpaperFromCache(test_account_id_1.GetUserEmail(), | 102 EXPECT_TRUE(test_api->GetWallpaperFromCache(test_user_1, &cached_wallpaper)); |
| 109 &cached_wallpaper)); | |
| 110 base::FilePath path; | 103 base::FilePath path; |
| 111 EXPECT_TRUE( | 104 EXPECT_TRUE(test_api->GetPathFromCache(test_user_1, &path)); |
| 112 test_api->GetPathFromCache(test_account_id_1.GetUserEmail(), &path)); | |
| 113 // Logged in users' wallpaper cache should be kept. | 105 // Logged in users' wallpaper cache should be kept. |
| 114 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(test_user_1_wallpaper)); | 106 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(test_user_1_wallpaper)); |
| 115 EXPECT_EQ(path, path1); | 107 EXPECT_EQ(path, path1); |
| 116 EXPECT_TRUE(test_api->GetWallpaperFromCache(test_account_id_2.GetUserEmail(), | 108 EXPECT_TRUE(test_api->GetWallpaperFromCache(test_user_2, &cached_wallpaper)); |
| 117 &cached_wallpaper)); | 109 EXPECT_TRUE(test_api->GetPathFromCache(test_user_2, &path)); |
| 118 EXPECT_TRUE( | |
| 119 test_api->GetPathFromCache(test_account_id_2.GetUserEmail(), &path)); | |
| 120 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(test_user_2_wallpaper)); | 110 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(test_user_2_wallpaper)); |
| 121 EXPECT_EQ(path, path2); | 111 EXPECT_EQ(path, path2); |
| 122 | 112 |
| 123 // Not logged in user's wallpaper cache should be cleared. | 113 // Not logged in user's wallpaper cache should be cleared. |
| 124 EXPECT_FALSE(test_api->GetWallpaperFromCache(test_account_id_3.GetUserEmail(), | 114 EXPECT_FALSE(test_api->GetWallpaperFromCache(test_user_3, &cached_wallpaper)); |
| 125 &cached_wallpaper)); | 115 EXPECT_FALSE(test_api->GetPathFromCache(test_user_3, &path)); |
| 126 EXPECT_FALSE( | |
| 127 test_api->GetPathFromCache(test_account_id_3.GetUserEmail(), &path)); | |
| 128 } | 116 } |
| 129 | 117 |
| 130 } // namespace chromeos | 118 } // namespace chromeos |
| OLD | NEW |