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

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

Issue 69863006: Address races in UserImageManagerImpl (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix WallpaperManager browser tests now that UserImageLoader contains a DCHECK(success). Created 7 years, 1 month 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
« no previous file with comments | « chrome/browser/chromeos/login/user_manager_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/ash_resources/grit/ash_resources.h" 7 #include "ash/ash_resources/grit/ash_resources.h"
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/display/display_manager.h" 10 #include "ash/display/display_manager.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "ash/test/display_manager_test_api.h" 12 #include "ash/test/display_manager_test_api.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/file_util.h" 14 #include "base/file_util.h"
15 #include "base/files/file_path.h"
15 #include "base/message_loop/message_loop.h" 16 #include "base/message_loop/message_loop.h"
17 #include "base/path_service.h"
16 #include "base/prefs/scoped_user_pref_update.h" 18 #include "base/prefs/scoped_user_pref_update.h"
17 #include "base/strings/string_number_conversions.h" 19 #include "base/strings/string_number_conversions.h"
18 #include "base/time/time.h" 20 #include "base/time/time.h"
19 #include "base/values.h" 21 #include "base/values.h"
20 #include "chrome/browser/chromeos/login/user.h" 22 #include "chrome/browser/chromeos/login/user.h"
21 #include "chrome/browser/chromeos/login/user_manager.h" 23 #include "chrome/browser/chromeos/login/user_manager.h"
24 #include "chrome/common/chrome_paths.h"
22 #include "chrome/common/chrome_switches.h" 25 #include "chrome/common/chrome_switches.h"
23 #include "chrome/test/base/in_process_browser_test.h" 26 #include "chrome/test/base/in_process_browser_test.h"
24 #include "chrome/test/base/testing_browser_process.h" 27 #include "chrome/test/base/testing_browser_process.h"
25 #include "chromeos/chromeos_switches.h" 28 #include "chromeos/chromeos_switches.h"
26 #include "chromeos/dbus/cryptohome_client.h" 29 #include "chromeos/dbus/cryptohome_client.h"
27 #include "ui/aura/env.h" 30 #include "ui/aura/env.h"
28 #include "ui/base/resource/resource_bundle.h" 31 #include "ui/base/resource/resource_bundle.h"
29 32
30 using namespace ash; 33 using namespace ash;
31 34
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 106
104 return wallpaper_path; 107 return wallpaper_path;
105 } 108 }
106 109
107 // Logs in |username|. 110 // Logs in |username|.
108 void LogIn(const std::string& username, const std::string& username_hash) { 111 void LogIn(const std::string& username, const std::string& username_hash) {
109 UserManager::Get()->UserLoggedIn(username, username_hash, false); 112 UserManager::Get()->UserLoggedIn(username, username_hash, false);
110 } 113 }
111 114
112 // Saves bitmap |resource_id| to disk. 115 // Saves bitmap |resource_id| to disk.
113 void SaveUserWallpaperData(const std::string& username, 116 void SaveUserWallpaperData(const base::FilePath& wallpaper_path,
114 const base::FilePath& wallpaper_path,
115 int resource_id) { 117 int resource_id) {
116 scoped_refptr<base::RefCountedStaticMemory> image_data( 118 scoped_refptr<base::RefCountedStaticMemory> image_data(
117 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale( 119 ResourceBundle::GetSharedInstance().LoadDataResourceBytesForScale(
118 resource_id, ui::SCALE_FACTOR_100P)); 120 resource_id, ui::SCALE_FACTOR_100P));
119 int written = file_util::WriteFile( 121 int written = file_util::WriteFile(
120 wallpaper_path, 122 wallpaper_path,
121 reinterpret_cast<const char*>(image_data->front()), 123 reinterpret_cast<const char*>(image_data->front()),
122 image_data->size()); 124 image_data->size());
123 EXPECT_EQ(static_cast<int>(image_data->size()), written); 125 EXPECT_EQ(static_cast<int>(image_data->size()), written);
124 } 126 }
(...skipping 22 matching lines...) Expand all
147 kSmallWallpaperSubDir, 149 kSmallWallpaperSubDir,
148 kTestUser1Hash, 150 kTestUser1Hash,
149 id); 151 id);
150 base::FilePath large_wallpaper_path = GetCustomWallpaperPath( 152 base::FilePath large_wallpaper_path = GetCustomWallpaperPath(
151 kLargeWallpaperSubDir, 153 kLargeWallpaperSubDir,
152 kTestUser1Hash, 154 kTestUser1Hash,
153 id); 155 id);
154 156
155 // Saves the small/large resolution wallpapers to small/large custom 157 // Saves the small/large resolution wallpapers to small/large custom
156 // wallpaper paths. 158 // wallpaper paths.
157 SaveUserWallpaperData(kTestUser1, 159 SaveUserWallpaperData(small_wallpaper_path,
158 small_wallpaper_path,
159 kSmallWallpaperResourceId); 160 kSmallWallpaperResourceId);
160 SaveUserWallpaperData(kTestUser1, 161 SaveUserWallpaperData(large_wallpaper_path,
161 large_wallpaper_path,
162 kLargeWallpaperResourceId); 162 kLargeWallpaperResourceId);
163 163
164 std::string relative_path = base::FilePath(kTestUser1Hash).Append(id).value(); 164 std::string relative_path = base::FilePath(kTestUser1Hash).Append(id).value();
165 // Saves wallpaper info to local state for user |kTestUser1|. 165 // Saves wallpaper info to local state for user |kTestUser1|.
166 WallpaperInfo info = { 166 WallpaperInfo info = {
167 relative_path, 167 relative_path,
168 WALLPAPER_LAYOUT_CENTER_CROPPED, 168 WALLPAPER_LAYOUT_CENTER_CROPPED,
169 User::CUSTOMIZED, 169 User::CUSTOMIZED,
170 base::Time::Now().LocalMidnight() 170 base::Time::Now().LocalMidnight()
171 }; 171 };
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 wallpaper_manager->SetUserWallpaper(kTestUser1); 232 wallpaper_manager->SetUserWallpaper(kTestUser1);
233 EXPECT_EQ(1, LoadedWallpapers()); 233 EXPECT_EQ(1, LoadedWallpapers());
234 wallpaper_manager->ClearWallpaperCache(); 234 wallpaper_manager->ClearWallpaperCache();
235 235
236 // Change wallpaper to a custom wallpaper. 236 // Change wallpaper to a custom wallpaper.
237 std::string id = base::Int64ToString(base::Time::Now().ToInternalValue()); 237 std::string id = base::Int64ToString(base::Time::Now().ToInternalValue());
238 base::FilePath small_wallpaper_path = GetCustomWallpaperPath( 238 base::FilePath small_wallpaper_path = GetCustomWallpaperPath(
239 kSmallWallpaperSubDir, 239 kSmallWallpaperSubDir,
240 kTestUser1Hash, 240 kTestUser1Hash,
241 id); 241 id);
242 SaveUserWallpaperData(kTestUser1, 242 SaveUserWallpaperData(small_wallpaper_path,
243 small_wallpaper_path,
244 kSmallWallpaperResourceId); 243 kSmallWallpaperResourceId);
245 244
246 std::string relative_path = base::FilePath(kTestUser1Hash).Append(id).value(); 245 std::string relative_path = base::FilePath(kTestUser1Hash).Append(id).value();
247 // Saves wallpaper info to local state for user |kTestUser1|. 246 // Saves wallpaper info to local state for user |kTestUser1|.
248 WallpaperInfo info = { 247 WallpaperInfo info = {
249 relative_path, 248 relative_path,
250 WALLPAPER_LAYOUT_CENTER_CROPPED, 249 WALLPAPER_LAYOUT_CENTER_CROPPED,
251 User::CUSTOMIZED, 250 User::CUSTOMIZED,
252 base::Time::Now().LocalMidnight() 251 base::Time::Now().LocalMidnight()
253 }; 252 };
(...skipping 21 matching lines...) Expand all
275 WaitAsyncWallpaperLoad(); 274 WaitAsyncWallpaperLoad();
276 // Old wallpaper migration code doesn't exist in codebase anymore. Modify user 275 // Old wallpaper migration code doesn't exist in codebase anymore. Modify user
277 // wallpaper info directly to simulate the wallpaper migration. See 276 // wallpaper info directly to simulate the wallpaper migration. See
278 // crosbug.com/38429 for details about why we modify wallpaper info this way. 277 // crosbug.com/38429 for details about why we modify wallpaper info this way.
279 WallpaperInfo info = { 278 WallpaperInfo info = {
280 "123", 279 "123",
281 WALLPAPER_LAYOUT_CENTER_CROPPED, 280 WALLPAPER_LAYOUT_CENTER_CROPPED,
282 User::DEFAULT, 281 User::DEFAULT,
283 base::Time::Now().LocalMidnight() 282 base::Time::Now().LocalMidnight()
284 }; 283 };
284 base::FilePath user_data_dir;
285 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir));
286 SaveUserWallpaperData(user_data_dir.Append("123"),
287 kLargeWallpaperResourceId);
285 WallpaperManager::Get()->SetUserWallpaperInfo(kTestUser1, info, true); 288 WallpaperManager::Get()->SetUserWallpaperInfo(kTestUser1, info, true);
286 } 289 }
287 290
288 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, 291 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest,
289 UseMigratedWallpaperInfo) { 292 UseMigratedWallpaperInfo) {
290 LogIn(kTestUser1, kTestUser1Hash); 293 LogIn(kTestUser1, kTestUser1Hash);
291 WaitAsyncWallpaperLoad(); 294 WaitAsyncWallpaperLoad();
292 // This test should finish normally. If timeout, it is probably because 295 // This test should finish normally. If timeout, it is probably because
293 // migrated wallpaper is somehow not loaded. Bad things can happen if 296 // migrated wallpaper is somehow not loaded. Bad things can happen if
294 // wallpaper is not loaded at login screen. One example is: crosbug.com/38429. 297 // wallpaper is not loaded at login screen. One example is: crosbug.com/38429.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 WaitAsyncWallpaperLoad(); 353 WaitAsyncWallpaperLoad();
351 // Old wallpaper migration code doesn't exist in codebase anymore. Modify user 354 // Old wallpaper migration code doesn't exist in codebase anymore. Modify user
352 // wallpaper info directly to simulate the wallpaper migration. See 355 // wallpaper info directly to simulate the wallpaper migration. See
353 // crosbug.com/38429 for details about why we modify wallpaper info this way. 356 // crosbug.com/38429 for details about why we modify wallpaper info this way.
354 WallpaperInfo info = { 357 WallpaperInfo info = {
355 "123", 358 "123",
356 WALLPAPER_LAYOUT_CENTER_CROPPED, 359 WALLPAPER_LAYOUT_CENTER_CROPPED,
357 User::DEFAULT, 360 User::DEFAULT,
358 base::Time::Now().LocalMidnight() 361 base::Time::Now().LocalMidnight()
359 }; 362 };
363 base::FilePath user_data_dir;
364 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir));
365 SaveUserWallpaperData(user_data_dir.Append("123"),
366 kLargeWallpaperResourceId);
360 WallpaperManager::Get()->SetUserWallpaperInfo(kTestUser1, info, true); 367 WallpaperManager::Get()->SetUserWallpaperInfo(kTestUser1, info, true);
361 } 368 }
362 369
363 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestNoAnimation, 370 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestNoAnimation,
364 UseMigratedWallpaperInfo) { 371 UseMigratedWallpaperInfo) {
365 LogIn(kTestUser1, kTestUser1Hash); 372 LogIn(kTestUser1, kTestUser1Hash);
366 WaitAsyncWallpaperLoad(); 373 WaitAsyncWallpaperLoad();
367 // This test should finish normally. If timeout, it is probably because 374 // This test should finish normally. If timeout, it is probably because
368 // migrated wallpaper is somehow not loaded. Bad things can happen if 375 // migrated wallpaper is somehow not loaded. Bad things can happen if
369 // wallpaper is not loaded at login screen. One example is: crosbug.com/38429. 376 // wallpaper is not loaded at login screen. One example is: crosbug.com/38429.
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 } 416 }
410 417
411 // Test for crbug.com/270278. It simulates a browser crash and verifies if user 418 // Test for crbug.com/270278. It simulates a browser crash and verifies if user
412 // wallpaper is loaded. 419 // wallpaper is loaded.
413 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCrashRestore, 420 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestCrashRestore,
414 RestoreWallpaper) { 421 RestoreWallpaper) {
415 EXPECT_EQ(1, LoadedWallpapers()); 422 EXPECT_EQ(1, LoadedWallpapers());
416 } 423 }
417 424
418 } // namespace chromeos 425 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/user_manager_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698