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

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

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

Powered by Google App Engine
This is Rietveld 408576698