OLD | NEW |
| (Empty) |
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/desktop_background/desktop_background_controller.h" | |
8 #include "ash/desktop_background/desktop_background_controller_observer.h" | |
9 #include "ash/desktop_background/desktop_background_controller_test_api.h" | |
10 #include "ash/display/display_manager.h" | |
11 #include "ash/shell.h" | |
12 #include "ash/test/ash_test_base.h" | |
13 #include "ash/test/ash_test_helper.h" | |
14 #include "ash/test/display_manager_test_api.h" | |
15 #include "ash/test/test_user_wallpaper_delegate.h" | |
16 #include "base/command_line.h" | |
17 #include "base/compiler_specific.h" | |
18 #include "base/file_util.h" | |
19 #include "base/files/file_path.h" | |
20 #include "base/macros.h" | |
21 #include "base/message_loop/message_loop.h" | |
22 #include "base/path_service.h" | |
23 #include "base/prefs/scoped_user_pref_update.h" | |
24 #include "base/strings/string_number_conversions.h" | |
25 #include "base/time/time.h" | |
26 #include "base/values.h" | |
27 #include "chrome/browser/chromeos/login/user.h" | |
28 #include "chrome/browser/chromeos/login/user_manager.h" | |
29 #include "chrome/browser/chromeos/login/wallpaper_manager_test_utils.h" | |
30 #include "chrome/common/chrome_paths.h" | |
31 #include "chrome/common/chrome_switches.h" | |
32 #include "chrome/test/base/in_process_browser_test.h" | |
33 #include "chrome/test/base/testing_browser_process.h" | |
34 #include "chromeos/chromeos_switches.h" | |
35 #include "content/public/test/test_utils.h" | |
36 #include "ui/aura/env.h" | |
37 #include "ui/gfx/image/image_skia.h" | |
38 #include "ui/gfx/point.h" | |
39 #include "ui/gfx/rect.h" | |
40 | |
41 using namespace ash; | |
42 | |
43 namespace chromeos { | |
44 | |
45 namespace { | |
46 | |
47 int kLargeWallpaperWidth = 256; | |
48 int kLargeWallpaperHeight = chromeos::kLargeWallpaperMaxHeight; | |
49 int kSmallWallpaperWidth = 256; | |
50 int kSmallWallpaperHeight = chromeos::kSmallWallpaperMaxHeight; | |
51 | |
52 const char kTestUser1[] = "test1@domain.com"; | |
53 const char kTestUser1Hash[] = "test1@domain.com-hash"; | |
54 const char kTestUser2[] = "test2@domain.com"; | |
55 const char kTestUser2Hash[] = "test2@domain.com-hash"; | |
56 | |
57 } // namespace | |
58 | |
59 class WallpaperManagerBrowserTest : public InProcessBrowserTest, | |
60 public testing::WithParamInterface<bool> { | |
61 public: | |
62 WallpaperManagerBrowserTest () : controller_(NULL), | |
63 local_state_(NULL) { | |
64 } | |
65 | |
66 virtual ~WallpaperManagerBrowserTest () {} | |
67 | |
68 virtual void SetUpOnMainThread() OVERRIDE { | |
69 controller_ = ash::Shell::GetInstance()->desktop_background_controller(); | |
70 local_state_ = g_browser_process->local_state(); | |
71 DesktopBackgroundController::TestAPI(controller_) | |
72 .set_wallpaper_reload_delay_for_test(0); | |
73 UpdateDisplay("800x600"); | |
74 } | |
75 | |
76 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
77 command_line->AppendSwitch(switches::kLoginManager); | |
78 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); | |
79 if (GetParam()) | |
80 command_line->AppendSwitch(::switches::kMultiProfiles); | |
81 } | |
82 | |
83 virtual void CleanUpOnMainThread() OVERRIDE { | |
84 controller_ = NULL; | |
85 } | |
86 | |
87 // Update the display configuration as given in |display_specs|. See | |
88 // ash::test::DisplayManagerTestApi::UpdateDisplay for more details. | |
89 void UpdateDisplay(const std::string& display_specs) { | |
90 ash::test::DisplayManagerTestApi display_manager_test_api( | |
91 ash::Shell::GetInstance()->display_manager()); | |
92 display_manager_test_api.UpdateDisplay(display_specs); | |
93 } | |
94 | |
95 void WaitAsyncWallpaperLoadStarted() { | |
96 base::RunLoop().RunUntilIdle(); | |
97 } | |
98 | |
99 protected: | |
100 | |
101 // Return custom wallpaper path. Create directory if not exist. | |
102 base::FilePath GetCustomWallpaperPath(const char* sub_dir, | |
103 const std::string& username_hash, | |
104 const std::string& id) { | |
105 base::FilePath wallpaper_path = | |
106 WallpaperManager::Get()->GetCustomWallpaperPath(sub_dir, | |
107 username_hash, | |
108 id); | |
109 if (!base::DirectoryExists(wallpaper_path.DirName())) | |
110 base::CreateDirectory(wallpaper_path.DirName()); | |
111 | |
112 return wallpaper_path; | |
113 } | |
114 | |
115 // Logs in |username|. | |
116 void LogIn(const std::string& username, const std::string& username_hash) { | |
117 UserManager::Get()->UserLoggedIn(username, username_hash, false); | |
118 WaitAsyncWallpaperLoadStarted(); | |
119 } | |
120 | |
121 int LoadedWallpapers() { | |
122 return WallpaperManager::Get()->loaded_wallpapers(); | |
123 } | |
124 | |
125 void ClearDisposableWallpaperCache() { | |
126 WallpaperManager::Get()->ClearDisposableWallpaperCache(); | |
127 } | |
128 | |
129 // Initializes default wallpaper paths "*default_*file" and writes JPEG | |
130 // wallpaper images to them. | |
131 // Only needs to be called (once) by tests that want to test loading of | |
132 // default wallpapers. | |
133 void CreateCmdlineWallpapers() { | |
134 wallpaper_dir_.reset(new base::ScopedTempDir); | |
135 ASSERT_TRUE(wallpaper_dir_->CreateUniqueTempDir()); | |
136 wallpaper_manager_test_utils::CreateCmdlineWallpapers( | |
137 *wallpaper_dir_, &wallpaper_manager_command_line_); | |
138 } | |
139 | |
140 DesktopBackgroundController* controller_; | |
141 PrefService* local_state_; | |
142 scoped_ptr<base::CommandLine> wallpaper_manager_command_line_; | |
143 | |
144 // Directory created by CreateCmdlineWallpapers () to store default | |
145 // wallpaper images. | |
146 scoped_ptr<base::ScopedTempDir> wallpaper_dir_; | |
147 | |
148 private: | |
149 DISALLOW_COPY_AND_ASSIGN(WallpaperManagerBrowserTest); | |
150 }; | |
151 | |
152 // Tests that the appropriate custom wallpaper (large vs. small) is loaded | |
153 // depending on the desktop resolution. | |
154 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, | |
155 LoadCustomLargeWallpaperForLargeExternalScreen) { | |
156 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); | |
157 LogIn(kTestUser1, kTestUser1Hash); | |
158 std::string id = base::Int64ToString(base::Time::Now().ToInternalValue()); | |
159 base::FilePath small_wallpaper_path = GetCustomWallpaperPath( | |
160 kSmallWallpaperSubDir, | |
161 kTestUser1Hash, | |
162 id); | |
163 base::FilePath large_wallpaper_path = GetCustomWallpaperPath( | |
164 kLargeWallpaperSubDir, | |
165 kTestUser1Hash, | |
166 id); | |
167 | |
168 // Saves the small/large resolution wallpapers to small/large custom | |
169 // wallpaper paths. | |
170 ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile( | |
171 small_wallpaper_path, | |
172 kSmallWallpaperWidth, | |
173 kSmallWallpaperHeight, | |
174 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor)); | |
175 ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile( | |
176 large_wallpaper_path, | |
177 kLargeWallpaperWidth, | |
178 kLargeWallpaperHeight, | |
179 wallpaper_manager_test_utils::kLargeDefaultWallpaperColor)); | |
180 | |
181 std::string relative_path = base::FilePath(kTestUser1Hash).Append(id).value(); | |
182 // Saves wallpaper info to local state for user |kTestUser1|. | |
183 WallpaperInfo info = { | |
184 relative_path, | |
185 WALLPAPER_LAYOUT_CENTER_CROPPED, | |
186 User::CUSTOMIZED, | |
187 base::Time::Now().LocalMidnight() | |
188 }; | |
189 wallpaper_manager->SetUserWallpaperInfo(kTestUser1, info, true); | |
190 | |
191 // Set the wallpaper for |kTestUser1|. | |
192 wallpaper_manager->SetUserWallpaperNow(kTestUser1); | |
193 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
194 gfx::ImageSkia wallpaper = controller_->GetWallpaper(); | |
195 | |
196 // Display is initialized to 800x600. The small resolution custom wallpaper is | |
197 // expected. | |
198 EXPECT_EQ(kSmallWallpaperWidth, wallpaper.width()); | |
199 EXPECT_EQ(kSmallWallpaperHeight, wallpaper.height()); | |
200 | |
201 // Hook up another 800x600 display. This shouldn't trigger a reload. | |
202 UpdateDisplay("800x600,800x600"); | |
203 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
204 // The small resolution custom wallpaper is expected. | |
205 EXPECT_EQ(kSmallWallpaperWidth, wallpaper.width()); | |
206 EXPECT_EQ(kSmallWallpaperHeight, wallpaper.height()); | |
207 | |
208 // Detach the secondary display. | |
209 UpdateDisplay("800x600"); | |
210 // Hook up a 2000x2000 display. The large resolution custom wallpaper should | |
211 // be loaded. | |
212 UpdateDisplay("800x600,2000x2000"); | |
213 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
214 wallpaper = controller_->GetWallpaper(); | |
215 | |
216 // The large resolution custom wallpaper is expected. | |
217 EXPECT_EQ(kLargeWallpaperWidth, wallpaper.width()); | |
218 EXPECT_EQ(kLargeWallpaperHeight, wallpaper.height()); | |
219 | |
220 // Detach the secondary display. | |
221 UpdateDisplay("800x600"); | |
222 // Hook up the 2000x2000 display again. The large resolution default wallpaper | |
223 // should persist. Test for crbug/165788. | |
224 UpdateDisplay("800x600,2000x2000"); | |
225 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
226 wallpaper = controller_->GetWallpaper(); | |
227 | |
228 // The large resolution custom wallpaper is expected. | |
229 EXPECT_EQ(kLargeWallpaperWidth, wallpaper.width()); | |
230 EXPECT_EQ(kLargeWallpaperHeight, wallpaper.height()); | |
231 } | |
232 | |
233 // If chrome tries to reload the same wallpaper twice, the latter request should | |
234 // be prevented. Otherwise, there are some strange animation issues as | |
235 // described in crbug.com/158383. | |
236 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, | |
237 PreventReloadingSameWallpaper) { | |
238 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); | |
239 // New user log in, a default wallpaper is loaded. | |
240 LogIn(kTestUser1, kTestUser1Hash); | |
241 EXPECT_EQ(1, LoadedWallpapers()); | |
242 // Loads the same wallpaper before the initial one finished. It should be | |
243 // prevented. | |
244 wallpaper_manager->SetUserWallpaperNow(kTestUser1); | |
245 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
246 EXPECT_EQ(1, LoadedWallpapers()); | |
247 // Loads the same wallpaper after the initial one finished. It should be | |
248 // prevented. | |
249 wallpaper_manager->SetUserWallpaperNow(kTestUser1); | |
250 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
251 EXPECT_EQ(1, LoadedWallpapers()); | |
252 ClearDisposableWallpaperCache(); | |
253 | |
254 // Change wallpaper to a custom wallpaper. | |
255 std::string id = base::Int64ToString(base::Time::Now().ToInternalValue()); | |
256 base::FilePath small_wallpaper_path = GetCustomWallpaperPath( | |
257 kSmallWallpaperSubDir, | |
258 kTestUser1Hash, | |
259 id); | |
260 ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile( | |
261 small_wallpaper_path, | |
262 kSmallWallpaperWidth, | |
263 kSmallWallpaperHeight, | |
264 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor)); | |
265 | |
266 std::string relative_path = base::FilePath(kTestUser1Hash).Append(id).value(); | |
267 // Saves wallpaper info to local state for user |kTestUser1|. | |
268 WallpaperInfo info = { | |
269 relative_path, | |
270 WALLPAPER_LAYOUT_CENTER_CROPPED, | |
271 User::CUSTOMIZED, | |
272 base::Time::Now().LocalMidnight() | |
273 }; | |
274 wallpaper_manager->SetUserWallpaperInfo(kTestUser1, info, true); | |
275 | |
276 wallpaper_manager->SetUserWallpaperNow(kTestUser1); | |
277 WaitAsyncWallpaperLoadStarted(); | |
278 EXPECT_EQ(2, LoadedWallpapers()); | |
279 // Loads the same wallpaper before the initial one finished. It should be | |
280 // prevented. | |
281 wallpaper_manager->SetUserWallpaperNow(kTestUser1); | |
282 WaitAsyncWallpaperLoadStarted(); | |
283 EXPECT_EQ(2, LoadedWallpapers()); | |
284 wallpaper_manager->SetUserWallpaperNow(kTestUser1); | |
285 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
286 EXPECT_EQ(2, LoadedWallpapers()); | |
287 } | |
288 | |
289 // Some users have old user profiles which may have legacy wallpapers. And these | |
290 // lagacy wallpapers should migrate to new wallpaper picker version seamlessly. | |
291 // This tests make sure we compatible with migrated old wallpapers. | |
292 // crosbug.com/38429 | |
293 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, | |
294 PRE_UseMigratedWallpaperInfo) { | |
295 // New user log in, a default wallpaper is loaded. | |
296 LogIn(kTestUser1, kTestUser1Hash); | |
297 // Old wallpaper migration code doesn't exist in codebase anymore. Modify user | |
298 // wallpaper info directly to simulate the wallpaper migration. See | |
299 // crosbug.com/38429 for details about why we modify wallpaper info this way. | |
300 WallpaperInfo info = { | |
301 "123", | |
302 WALLPAPER_LAYOUT_CENTER_CROPPED, | |
303 User::DEFAULT, | |
304 base::Time::Now().LocalMidnight() | |
305 }; | |
306 base::FilePath user_data_dir; | |
307 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); | |
308 ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile( | |
309 user_data_dir.Append("123"), | |
310 wallpaper_manager_test_utils::kWallpaperSize, | |
311 wallpaper_manager_test_utils::kWallpaperSize, | |
312 wallpaper_manager_test_utils::kLargeDefaultWallpaperColor)); | |
313 WallpaperManager::Get()->SetUserWallpaperInfo(kTestUser1, info, true); | |
314 } | |
315 | |
316 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, | |
317 UseMigratedWallpaperInfo) { | |
318 LogIn(kTestUser1, kTestUser1Hash); | |
319 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
320 // This test should finish normally. If timeout, it is probably because | |
321 // migrated wallpaper is somehow not loaded. Bad things can happen if | |
322 // wallpaper is not loaded at login screen. One example is: crosbug.com/38429. | |
323 } | |
324 | |
325 // Some users have old user profiles which may never get a chance to migrate. | |
326 // This tests make sure we compatible with these profiles. | |
327 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, | |
328 PRE_UsePreMigrationWallpaperInfo) { | |
329 // New user log in, a default wallpaper is loaded. | |
330 LogIn(kTestUser1, kTestUser1Hash); | |
331 // Old wallpaper migration code doesn't exist in codebase anymore. So if | |
332 // user's profile is not migrated, it is the same as no wallpaper info. To | |
333 // simulate this, we remove user's wallpaper info here. | |
334 WallpaperManager::Get()->RemoveUserWallpaperInfo(kTestUser1); | |
335 } | |
336 | |
337 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, | |
338 UsePreMigrationWallpaperInfo) { | |
339 LogIn(kTestUser1, kTestUser1Hash); | |
340 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
341 // This test should finish normally. If timeout, it is probably because chrome | |
342 // can not handle pre migrated user profile (M21 profile or older). | |
343 } | |
344 | |
345 // Test for http://crbug.com/265689. When hooked up a large external monitor, | |
346 // the default large resolution wallpaper should load. | |
347 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, | |
348 HotPlugInScreenAtGAIALoginScreen) { | |
349 UpdateDisplay("800x600"); | |
350 // Set initial wallpaper to the default wallpaper. | |
351 WallpaperManager::Get()->SetDefaultWallpaperNow(UserManager::kStubUser); | |
352 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
353 | |
354 // Hook up a 2000x2000 display. The large resolution custom wallpaper should | |
355 // be loaded. | |
356 UpdateDisplay("800x600,2000x2000"); | |
357 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
358 } | |
359 | |
360 class WallpaperManagerBrowserTestNoAnimation | |
361 : public WallpaperManagerBrowserTest { | |
362 public: | |
363 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
364 command_line->AppendSwitch(switches::kLoginManager); | |
365 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); | |
366 command_line->AppendSwitch(chromeos::switches::kDisableLoginAnimations); | |
367 command_line->AppendSwitch(chromeos::switches::kDisableBootAnimation); | |
368 } | |
369 }; | |
370 | |
371 // Same test as WallpaperManagerBrowserTest.UseMigratedWallpaperInfo. But | |
372 // disabled boot and login animation. | |
373 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTestNoAnimation, | |
374 PRE_UseMigratedWallpaperInfo) { | |
375 // New user log in, a default wallpaper is loaded. | |
376 LogIn(kTestUser1, kTestUser1Hash); | |
377 // Old wallpaper migration code doesn't exist in codebase anymore. Modify user | |
378 // wallpaper info directly to simulate the wallpaper migration. See | |
379 // crosbug.com/38429 for details about why we modify wallpaper info this way. | |
380 WallpaperInfo info = { | |
381 "123", | |
382 WALLPAPER_LAYOUT_CENTER_CROPPED, | |
383 User::DEFAULT, | |
384 base::Time::Now().LocalMidnight() | |
385 }; | |
386 base::FilePath user_data_dir; | |
387 ASSERT_TRUE(PathService::Get(chrome::DIR_USER_DATA, &user_data_dir)); | |
388 ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile( | |
389 user_data_dir.Append("123"), | |
390 wallpaper_manager_test_utils::kWallpaperSize, | |
391 wallpaper_manager_test_utils::kWallpaperSize, | |
392 wallpaper_manager_test_utils::kLargeDefaultWallpaperColor)); | |
393 WallpaperManager::Get()->SetUserWallpaperInfo(kTestUser1, info, true); | |
394 } | |
395 | |
396 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTestNoAnimation, | |
397 UseMigratedWallpaperInfo) { | |
398 LogIn(kTestUser1, kTestUser1Hash); | |
399 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
400 // This test should finish normally. If timeout, it is probably because | |
401 // migrated wallpaper is somehow not loaded. Bad things can happen if | |
402 // wallpaper is not loaded at login screen. One example is: crosbug.com/38429. | |
403 } | |
404 | |
405 // Same test as WallpaperManagerBrowserTest.UsePreMigrationWallpaperInfo. But | |
406 // disabled boot and login animation. | |
407 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTestNoAnimation, | |
408 PRE_UsePreMigrationWallpaperInfo) { | |
409 // New user log in, a default wallpaper is loaded. | |
410 LogIn(kTestUser1, kTestUser1Hash); | |
411 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
412 // Old wallpaper migration code doesn't exist in codebase anymore. So if | |
413 // user's profile is not migrated, it is the same as no wallpaper info. To | |
414 // simulate this, we remove user's wallpaper info here. | |
415 WallpaperManager::Get()->RemoveUserWallpaperInfo(kTestUser1); | |
416 } | |
417 | |
418 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTestNoAnimation, | |
419 UsePreMigrationWallpaperInfo) { | |
420 LogIn(kTestUser1, kTestUser1Hash); | |
421 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
422 // This test should finish normally. If timeout, it is probably because chrome | |
423 // can not handle pre migrated user profile (M21 profile or older). | |
424 } | |
425 | |
426 class WallpaperManagerBrowserTestCrashRestore | |
427 : public WallpaperManagerBrowserTest { | |
428 public: | |
429 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
430 command_line->AppendSwitch(chromeos::switches::kDisableLoginAnimations); | |
431 command_line->AppendSwitch(chromeos::switches::kDisableBootAnimation); | |
432 command_line->AppendSwitch(::switches::kMultiProfiles); | |
433 command_line->AppendSwitchASCII(switches::kLoginUser, kTestUser1); | |
434 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); | |
435 } | |
436 }; | |
437 | |
438 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTestCrashRestore, | |
439 PRE_RestoreWallpaper) { | |
440 LogIn(kTestUser1, kTestUser1Hash); | |
441 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
442 } | |
443 | |
444 // Test for crbug.com/270278. It simulates a browser crash and verifies if user | |
445 // wallpaper is loaded. | |
446 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTestCrashRestore, | |
447 RestoreWallpaper) { | |
448 EXPECT_EQ(1, LoadedWallpapers()); | |
449 } | |
450 | |
451 class WallpaperManagerBrowserTestCacheUpdate | |
452 : public WallpaperManagerBrowserTest { | |
453 public: | |
454 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | |
455 command_line->AppendSwitch(::switches::kMultiProfiles); | |
456 command_line->AppendSwitchASCII(switches::kLoginUser, kTestUser1); | |
457 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); | |
458 } | |
459 protected: | |
460 // Creates a test image of size 1x1. | |
461 gfx::ImageSkia CreateTestImage(SkColor color) { | |
462 return wallpaper_manager_test_utils::CreateTestImage(1, 1, color); | |
463 } | |
464 }; | |
465 | |
466 // Sets kTestUser1's wallpaper to a custom wallpaper. | |
467 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTestCacheUpdate, | |
468 PRE_VerifyWallpaperCache) { | |
469 // Add kTestUser1 to user list. kTestUser1 is the default login profile. | |
470 LogIn(kTestUser1, kTestUser1Hash); | |
471 | |
472 std::string id = base::Int64ToString(base::Time::Now().ToInternalValue()); | |
473 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); | |
474 base::FilePath small_wallpaper_path = GetCustomWallpaperPath( | |
475 kSmallWallpaperSubDir, | |
476 kTestUser1Hash, | |
477 id); | |
478 base::FilePath large_wallpaper_path = GetCustomWallpaperPath( | |
479 kLargeWallpaperSubDir, | |
480 kTestUser1Hash, | |
481 id); | |
482 | |
483 // Saves the small/large resolution wallpapers to small/large custom | |
484 // wallpaper paths. | |
485 ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile( | |
486 small_wallpaper_path, | |
487 kSmallWallpaperWidth, | |
488 kSmallWallpaperHeight, | |
489 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor)); | |
490 ASSERT_TRUE(wallpaper_manager_test_utils::WriteJPEGFile( | |
491 large_wallpaper_path, | |
492 kLargeWallpaperWidth, | |
493 kLargeWallpaperHeight, | |
494 wallpaper_manager_test_utils::kLargeDefaultWallpaperColor)); | |
495 | |
496 std::string relative_path = base::FilePath(kTestUser1Hash).Append(id).value(); | |
497 // Saves wallpaper info to local state for user |kTestUser1|. | |
498 WallpaperInfo info = { | |
499 relative_path, | |
500 WALLPAPER_LAYOUT_CENTER_CROPPED, | |
501 User::CUSTOMIZED, | |
502 base::Time::Now().LocalMidnight() | |
503 }; | |
504 wallpaper_manager->SetUserWallpaperInfo(kTestUser1, info, true); | |
505 wallpaper_manager->SetUserWallpaperNow(kTestUser1); | |
506 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
507 scoped_ptr<WallpaperManager::TestApi> test_api; | |
508 test_api.reset(new WallpaperManager::TestApi(wallpaper_manager)); | |
509 // Verify SetUserWallpaperNow updates wallpaper cache. | |
510 gfx::ImageSkia cached_wallpaper; | |
511 EXPECT_TRUE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper)); | |
512 } | |
513 | |
514 // Tests for crbug.com/339576. Wallpaper cache should be updated in | |
515 // multi-profile mode when user: | |
516 // 1. chooses an online wallpaper from wallpaper | |
517 // picker (calls SetWallpaperFromImageSkia); | |
518 // 2. chooses a custom wallpaper from wallpaper | |
519 // picker (calls SetCustomWallpaper); | |
520 // 3. reverts to a default wallpaper. | |
521 // Also, when user login at multi-profile mode, previous logged in users' | |
522 // wallpaper cache should not be deleted. | |
523 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTestCacheUpdate, | |
524 VerifyWallpaperCache) { | |
525 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); | |
526 | |
527 // Force load initial wallpaper | |
528 // (simulate DesktopBackgroundController::UpdateDisplay()). | |
529 wallpaper_manager->UpdateWallpaper(true); | |
530 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
531 scoped_ptr<WallpaperManager::TestApi> test_api; | |
532 test_api.reset(new WallpaperManager::TestApi(wallpaper_manager)); | |
533 gfx::ImageSkia cached_wallpaper; | |
534 // Previous custom wallpaper should be cached after user login. | |
535 EXPECT_TRUE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper)); | |
536 | |
537 LogIn(kTestUser2, kTestUser2Hash); | |
538 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
539 // Login another user should not delete logged in user's wallpaper cache. | |
540 // Note active user is still kTestUser1. | |
541 EXPECT_TRUE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper)); | |
542 | |
543 gfx::ImageSkia red_wallpaper = CreateTestImage(SK_ColorRED); | |
544 wallpaper_manager->SetWallpaperFromImageSkia(kTestUser1, | |
545 red_wallpaper, | |
546 WALLPAPER_LAYOUT_CENTER, | |
547 true); | |
548 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
549 // SetWallpaperFromImageSkia should update wallpaper cache when multi-profile | |
550 // is turned on. | |
551 EXPECT_TRUE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper)); | |
552 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(red_wallpaper)); | |
553 | |
554 gfx::ImageSkia green_wallpaper = CreateTestImage(SK_ColorGREEN); | |
555 wallpaper_manager->SetCustomWallpaper(kTestUser1, | |
556 kTestUser1Hash, | |
557 "dummy", // dummy file name | |
558 WALLPAPER_LAYOUT_CENTER, | |
559 User::CUSTOMIZED, | |
560 green_wallpaper, | |
561 true); | |
562 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
563 // SetCustomWallpaper should also update wallpaper cache when multi-profile is | |
564 // turned on. | |
565 EXPECT_TRUE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper)); | |
566 EXPECT_TRUE(cached_wallpaper.BackedBySameObjectAs(green_wallpaper)); | |
567 | |
568 wallpaper_manager->SetDefaultWallpaperNow(kTestUser1); | |
569 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
570 // SetDefaultWallpaper should invalidate the user's wallpaper cache. | |
571 EXPECT_FALSE(test_api->GetWallpaperFromCache(kTestUser1, &cached_wallpaper)); | |
572 } | |
573 | |
574 INSTANTIATE_TEST_CASE_P(WallpaperManagerBrowserTestInstantiation, | |
575 WallpaperManagerBrowserTest, | |
576 testing::Bool()); | |
577 | |
578 INSTANTIATE_TEST_CASE_P(WallpaperManagerBrowserTestNoAnimationInstantiation, | |
579 WallpaperManagerBrowserTestNoAnimation, | |
580 testing::Bool()); | |
581 | |
582 INSTANTIATE_TEST_CASE_P(WallpaperManagerBrowserTestCrashRestoreInstantiation, | |
583 WallpaperManagerBrowserTestCrashRestore, | |
584 testing::Bool()); | |
585 | |
586 INSTANTIATE_TEST_CASE_P(WallpaperManagerBrowserTestCacheUpdateInstantiation, | |
587 WallpaperManagerBrowserTestCacheUpdate, | |
588 testing::Bool()); | |
589 | |
590 // ---------------------------------------------------------------------- | |
591 // Test default wallpapers. | |
592 | |
593 class TestObserver : public WallpaperManager::Observer { | |
594 public: | |
595 explicit TestObserver(WallpaperManager* wallpaper_manager) | |
596 : update_wallpaper_count_(0), wallpaper_manager_(wallpaper_manager) { | |
597 DCHECK(wallpaper_manager_); | |
598 wallpaper_manager_->AddObserver(this); | |
599 } | |
600 | |
601 virtual ~TestObserver() { | |
602 wallpaper_manager_->RemoveObserver(this); | |
603 } | |
604 | |
605 virtual void OnWallpaperAnimationFinished(const std::string&) OVERRIDE { | |
606 } | |
607 | |
608 virtual void OnUpdateWallpaperForTesting() OVERRIDE { | |
609 ++update_wallpaper_count_; | |
610 } | |
611 | |
612 int GetUpdateWallpaperCountAndReset() { | |
613 const size_t old = update_wallpaper_count_; | |
614 update_wallpaper_count_ = 0; | |
615 return old; | |
616 } | |
617 | |
618 private: | |
619 int update_wallpaper_count_; | |
620 WallpaperManager* wallpaper_manager_; | |
621 | |
622 DISALLOW_COPY_AND_ASSIGN(TestObserver); | |
623 }; | |
624 | |
625 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, DisplayChange) { | |
626 // TODO(derat|oshima|bshe): Host windows can't be resized on Win8. | |
627 if (!ash::test::AshTestHelper::SupportsHostWindowResize()) | |
628 return; | |
629 | |
630 TestObserver observer(WallpaperManager::Get()); | |
631 | |
632 // Set the wallpaper to ensure that UpdateWallpaper() will be called when the | |
633 // display configuration changes. | |
634 gfx::ImageSkia image = wallpaper_manager_test_utils::CreateTestImage( | |
635 640, 480, wallpaper_manager_test_utils::kCustomWallpaperColor); | |
636 controller_->SetWallpaperImage(image, WALLPAPER_LAYOUT_STRETCH); | |
637 | |
638 // Small wallpaper images should be used for configurations less than or | |
639 // equal to kSmallWallpaperMaxWidth by kSmallWallpaperMaxHeight, even if | |
640 // multiple displays are connected. | |
641 UpdateDisplay("800x600"); | |
642 // Wait for asynchronous DisplayBackgroundController::UpdateDisplay() call. | |
643 base::RunLoop().RunUntilIdle(); | |
644 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
645 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, | |
646 WallpaperManager::Get()->GetAppropriateResolution()); | |
647 EXPECT_EQ(0, observer.GetUpdateWallpaperCountAndReset()); | |
648 | |
649 UpdateDisplay("800x600,800x600"); | |
650 // Wait for asynchronous DisplayBackgroundController::UpdateDisplay() call. | |
651 base::RunLoop().RunUntilIdle(); | |
652 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
653 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, | |
654 WallpaperManager::Get()->GetAppropriateResolution()); | |
655 EXPECT_EQ(0, observer.GetUpdateWallpaperCountAndReset()); | |
656 | |
657 UpdateDisplay("1366x800"); | |
658 // Wait for asynchronous DisplayBackgroundController::UpdateDisplay() call. | |
659 base::RunLoop().RunUntilIdle(); | |
660 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
661 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, | |
662 WallpaperManager::Get()->GetAppropriateResolution()); | |
663 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | |
664 | |
665 // At larger sizes, large wallpapers should be used. | |
666 UpdateDisplay("1367x800"); | |
667 // Wait for asynchronous DisplayBackgroundController::UpdateDisplay() call. | |
668 base::RunLoop().RunUntilIdle(); | |
669 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
670 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_LARGE, | |
671 WallpaperManager::Get()->GetAppropriateResolution()); | |
672 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | |
673 | |
674 UpdateDisplay("1367x801"); | |
675 // Wait for asynchronous DisplayBackgroundController::UpdateDisplay() call. | |
676 base::RunLoop().RunUntilIdle(); | |
677 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
678 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_LARGE, | |
679 WallpaperManager::Get()->GetAppropriateResolution()); | |
680 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | |
681 | |
682 UpdateDisplay("2560x1700"); | |
683 // Wait for asynchronous DisplayBackgroundController::UpdateDisplay() call. | |
684 base::RunLoop().RunUntilIdle(); | |
685 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
686 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_LARGE, | |
687 WallpaperManager::Get()->GetAppropriateResolution()); | |
688 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | |
689 | |
690 // Rotated smaller screen may use larger image. | |
691 UpdateDisplay("800x600/r"); | |
692 // Wait for asynchronous DisplayBackgroundController::UpdateDisplay() call. | |
693 base::RunLoop().RunUntilIdle(); | |
694 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
695 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, | |
696 WallpaperManager::Get()->GetAppropriateResolution()); | |
697 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | |
698 | |
699 UpdateDisplay("800x600/r,800x600"); | |
700 // Wait for asynchronous DisplayBackgroundController::UpdateDisplay() call. | |
701 base::RunLoop().RunUntilIdle(); | |
702 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
703 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, | |
704 WallpaperManager::Get()->GetAppropriateResolution()); | |
705 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | |
706 UpdateDisplay("1366x800/r"); | |
707 // Wait for asynchronous DisplayBackgroundController::UpdateDisplay() call. | |
708 base::RunLoop().RunUntilIdle(); | |
709 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
710 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_LARGE, | |
711 WallpaperManager::Get()->GetAppropriateResolution()); | |
712 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | |
713 | |
714 // Max display size didn't chagne. | |
715 UpdateDisplay("900x800/r,400x1366"); | |
716 // Wait for asynchronous DisplayBackgroundController::UpdateDisplay() call. | |
717 base::RunLoop().RunUntilIdle(); | |
718 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
719 EXPECT_EQ(0, observer.GetUpdateWallpaperCountAndReset()); | |
720 } | |
721 | |
722 // Test that WallpaperManager loads the appropriate wallpaper | |
723 // images as specified via command-line flags in various situations. | |
724 // Splitting these into separate tests avoids needing to run animations. | |
725 // TODO(derat): Combine these into a single test | |
726 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, SmallDefaultWallpaper) { | |
727 if (!ash::test::AshTestHelper::SupportsMultipleDisplays()) | |
728 return; | |
729 | |
730 CreateCmdlineWallpapers(); | |
731 | |
732 // At 800x600, the small wallpaper should be loaded. | |
733 UpdateDisplay("800x600"); | |
734 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); | |
735 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
736 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( | |
737 controller_->GetWallpaper(), | |
738 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor)); | |
739 } | |
740 | |
741 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, LargeDefaultWallpaper) { | |
742 if (!ash::test::AshTestHelper::SupportsMultipleDisplays()) | |
743 return; | |
744 | |
745 CreateCmdlineWallpapers(); | |
746 UpdateDisplay("1600x1200"); | |
747 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); | |
748 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
749 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( | |
750 controller_->GetWallpaper(), | |
751 wallpaper_manager_test_utils::kLargeDefaultWallpaperColor)); | |
752 } | |
753 | |
754 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, | |
755 LargeDefaultWallpaperWhenRotated) { | |
756 if (!ash::test::AshTestHelper::SupportsMultipleDisplays()) | |
757 return; | |
758 CreateCmdlineWallpapers(); | |
759 | |
760 UpdateDisplay("1200x800/r"); | |
761 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); | |
762 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
763 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( | |
764 controller_->GetWallpaper(), | |
765 wallpaper_manager_test_utils::kLargeDefaultWallpaperColor)); | |
766 } | |
767 | |
768 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, SmallGuestWallpaper) { | |
769 if (!ash::test::AshTestHelper::SupportsMultipleDisplays()) | |
770 return; | |
771 CreateCmdlineWallpapers(); | |
772 UserManager::Get()->UserLoggedIn( | |
773 UserManager::kGuestUserName, UserManager::kGuestUserName, false); | |
774 UpdateDisplay("800x600"); | |
775 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); | |
776 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
777 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( | |
778 controller_->GetWallpaper(), | |
779 wallpaper_manager_test_utils::kSmallGuestWallpaperColor)); | |
780 } | |
781 | |
782 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, LargeGuestWallpaper) { | |
783 if (!ash::test::AshTestHelper::SupportsMultipleDisplays()) | |
784 return; | |
785 | |
786 CreateCmdlineWallpapers(); | |
787 UserManager::Get()->UserLoggedIn( | |
788 UserManager::kGuestUserName, UserManager::kGuestUserName, false); | |
789 UpdateDisplay("1600x1200"); | |
790 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); | |
791 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
792 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( | |
793 controller_->GetWallpaper(), | |
794 wallpaper_manager_test_utils::kLargeGuestWallpaperColor)); | |
795 } | |
796 | |
797 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, | |
798 SwitchBetweenDefaultAndCustom) { | |
799 // Start loading the default wallpaper. | |
800 UpdateDisplay("640x480"); | |
801 CreateCmdlineWallpapers(); | |
802 UserManager::Get()->UserLoggedIn(UserManager::kStubUser, "test_hash", false); | |
803 | |
804 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); | |
805 | |
806 // Custom wallpaper should be applied immediately, canceling the default | |
807 // wallpaper load task. | |
808 gfx::ImageSkia image = wallpaper_manager_test_utils::CreateTestImage( | |
809 640, 480, wallpaper_manager_test_utils::kCustomWallpaperColor); | |
810 WallpaperManager::Get()->SetCustomWallpaper(UserManager::kStubUser, | |
811 "test_hash", | |
812 "test-nofile.jpeg", | |
813 WALLPAPER_LAYOUT_STRETCH, | |
814 User::CUSTOMIZED, | |
815 image, | |
816 true); | |
817 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
818 | |
819 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( | |
820 controller_->GetWallpaper(), | |
821 wallpaper_manager_test_utils::kCustomWallpaperColor)); | |
822 | |
823 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); | |
824 wallpaper_manager_test_utils::WaitAsyncWallpaperLoadFinished(); | |
825 | |
826 EXPECT_TRUE(wallpaper_manager_test_utils::ImageIsNearColor( | |
827 controller_->GetWallpaper(), | |
828 wallpaper_manager_test_utils::kSmallDefaultWallpaperColor)); | |
829 } | |
830 | |
831 } // namespace chromeos | |
OLD | NEW |