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

Side by Side Diff: chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager_unittest.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 <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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // Login two users. 88 // Login two users.
89 fake_user_manager()->LoginUser(test_account_id_1); 89 fake_user_manager()->LoginUser(test_account_id_1);
90 fake_user_manager()->LoginUser(test_account_id_2); 90 fake_user_manager()->LoginUser(test_account_id_2);
91 91
92 scoped_ptr<WallpaperManager::TestApi> test_api; 92 scoped_ptr<WallpaperManager::TestApi> test_api;
93 test_api.reset(new WallpaperManager::TestApi(WallpaperManager::Get())); 93 test_api.reset(new WallpaperManager::TestApi(WallpaperManager::Get()));
94 94
95 gfx::ImageSkia test_user_1_wallpaper = CreateTestImage(SK_ColorRED); 95 gfx::ImageSkia test_user_1_wallpaper = CreateTestImage(SK_ColorRED);
96 gfx::ImageSkia test_user_2_wallpaper = CreateTestImage(SK_ColorGREEN); 96 gfx::ImageSkia test_user_2_wallpaper = CreateTestImage(SK_ColorGREEN);
97 gfx::ImageSkia test_user_3_wallpaper = CreateTestImage(SK_ColorWHITE); 97 gfx::ImageSkia test_user_3_wallpaper = CreateTestImage(SK_ColorWHITE);
98 test_api->SetWallpaperCache(test_account_id_1.GetUserEmail(), path1, 98 test_api->SetWallpaperCache(test_account_id_1, path1, test_user_1_wallpaper);
99 test_user_1_wallpaper); 99 test_api->SetWallpaperCache(test_account_id_2, path2, test_user_2_wallpaper);
100 test_api->SetWallpaperCache(test_account_id_2.GetUserEmail(), path2, 100 test_api->SetWallpaperCache(test_account_id_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 101
105 test_api->ClearDisposableWallpaperCache(); 102 test_api->ClearDisposableWallpaperCache();
106 103
107 gfx::ImageSkia cached_wallpaper; 104 gfx::ImageSkia cached_wallpaper;
108 EXPECT_TRUE(test_api->GetWallpaperFromCache(test_account_id_1.GetUserEmail(), 105 EXPECT_TRUE(
109 &cached_wallpaper)); 106 test_api->GetWallpaperFromCache(test_account_id_1, &cached_wallpaper));
110 base::FilePath path; 107 base::FilePath path;
111 EXPECT_TRUE( 108 EXPECT_TRUE(test_api->GetPathFromCache(test_account_id_1, &path));
112 test_api->GetPathFromCache(test_account_id_1.GetUserEmail(), &path));
113 // Logged in users' wallpaper cache should be kept. 109 // Logged in users' wallpaper cache should be kept.
114 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(test_user_1_wallpaper)); 110 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(test_user_1_wallpaper));
115 EXPECT_EQ(path, path1); 111 EXPECT_EQ(path, path1);
116 EXPECT_TRUE(test_api->GetWallpaperFromCache(test_account_id_2.GetUserEmail(),
117 &cached_wallpaper));
118 EXPECT_TRUE( 112 EXPECT_TRUE(
119 test_api->GetPathFromCache(test_account_id_2.GetUserEmail(), &path)); 113 test_api->GetWallpaperFromCache(test_account_id_2, &cached_wallpaper));
114 EXPECT_TRUE(test_api->GetPathFromCache(test_account_id_2, &path));
120 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(test_user_2_wallpaper)); 115 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(test_user_2_wallpaper));
121 EXPECT_EQ(path, path2); 116 EXPECT_EQ(path, path2);
122 117
123 // Not logged in user's wallpaper cache should be cleared. 118 // Not logged in user's wallpaper cache should be cleared.
124 EXPECT_FALSE(test_api->GetWallpaperFromCache(test_account_id_3.GetUserEmail(),
125 &cached_wallpaper));
126 EXPECT_FALSE( 119 EXPECT_FALSE(
127 test_api->GetPathFromCache(test_account_id_3.GetUserEmail(), &path)); 120 test_api->GetWallpaperFromCache(test_account_id_3, &cached_wallpaper));
121 EXPECT_FALSE(test_api->GetPathFromCache(test_account_id_3, &path));
128 } 122 }
129 123
130 // Test that the user's wallpaper cache is cleared after the user is removed. 124 // Test that the user's wallpaper cache is cleared after the user is removed.
131 TEST_F(WallpaperManagerCacheTest, CacheClearedOnUserRemoval) { 125 TEST_F(WallpaperManagerCacheTest, CacheClearedOnUserRemoval) {
132 const AccountId test_account_id_1 = 126 const AccountId test_account_id_1 =
133 AccountId::FromUserEmail("test1@example.com"); 127 AccountId::FromUserEmail("test1@example.com");
134 const AccountId test_account_id_2 = 128 const AccountId test_account_id_2 =
135 AccountId::FromUserEmail("test2@example.com"); 129 AccountId::FromUserEmail("test2@example.com");
136 const base::FilePath path1("user1_custom_path"); 130 const base::FilePath path1("user1_custom_path");
137 const base::FilePath path2("user2_custom_path"); 131 const base::FilePath path2("user2_custom_path");
138 fake_user_manager()->AddUser(test_account_id_1); 132 fake_user_manager()->AddUser(test_account_id_1);
139 fake_user_manager()->AddUser(test_account_id_2); 133 fake_user_manager()->AddUser(test_account_id_2);
140 134
141 scoped_ptr<WallpaperManager::TestApi> test_api( 135 scoped_ptr<WallpaperManager::TestApi> test_api(
142 new WallpaperManager::TestApi(WallpaperManager::Get())); 136 new WallpaperManager::TestApi(WallpaperManager::Get()));
143 137
144 const gfx::ImageSkia test_user_1_wallpaper = CreateTestImage(SK_ColorRED); 138 const gfx::ImageSkia test_user_1_wallpaper = CreateTestImage(SK_ColorRED);
145 const gfx::ImageSkia test_user_2_wallpaper = CreateTestImage(SK_ColorGREEN); 139 const gfx::ImageSkia test_user_2_wallpaper = CreateTestImage(SK_ColorGREEN);
146 test_api->SetWallpaperCache(test_account_id_1.GetUserEmail(), path1, 140 test_api->SetWallpaperCache(test_account_id_1, path1, test_user_1_wallpaper);
147 test_user_1_wallpaper); 141 test_api->SetWallpaperCache(test_account_id_2, path2, test_user_2_wallpaper);
148 test_api->SetWallpaperCache(test_account_id_2.GetUserEmail(), path2,
149 test_user_2_wallpaper);
150 142
151 gfx::ImageSkia cached_wallpaper; 143 gfx::ImageSkia cached_wallpaper;
152 // Test that both user1 and user2's wallpaper can be found in cache. 144 // Test that both user1 and user2's wallpaper can be found in cache.
153 EXPECT_TRUE(test_api->GetWallpaperFromCache(test_account_id_1.GetUserEmail(), 145 EXPECT_TRUE(
154 &cached_wallpaper)); 146 test_api->GetWallpaperFromCache(test_account_id_1, &cached_wallpaper));
155 EXPECT_TRUE(test_api->GetWallpaperFromCache(test_account_id_2.GetUserEmail(), 147 EXPECT_TRUE(
156 &cached_wallpaper)); 148 test_api->GetWallpaperFromCache(test_account_id_2, &cached_wallpaper));
157 149
158 // Remove user2. 150 // Remove user2.
159 fake_user_manager()->RemoveUserFromList(test_account_id_2); 151 fake_user_manager()->RemoveUserFromList(test_account_id_2);
160 152
161 // Test that only user1's wallpaper can be found in cache. 153 // Test that only user1's wallpaper can be found in cache.
162 EXPECT_TRUE(test_api->GetWallpaperFromCache(test_account_id_1.GetUserEmail(), 154 EXPECT_TRUE(
163 &cached_wallpaper)); 155 test_api->GetWallpaperFromCache(test_account_id_1, &cached_wallpaper));
164 EXPECT_FALSE(test_api->GetWallpaperFromCache(test_account_id_2.GetUserEmail(), 156 EXPECT_FALSE(
165 &cached_wallpaper)); 157 test_api->GetWallpaperFromCache(test_account_id_2, &cached_wallpaper));
166 } 158 }
167 159
168 } // namespace chromeos 160 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698