OLD | NEW |
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_wallpaper_resources.h" |
7 #include "ash/desktop_background/desktop_background_controller.h" | 8 #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_observer.h" |
9 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
10 #include "ash/shell.h" | 11 #include "ash/shell.h" |
11 #include "ash/test/display_manager_test_api.h" | 12 #include "ash/test/display_manager_test_api.h" |
12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
13 #include "base/file_util.h" | 14 #include "base/file_util.h" |
14 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
16 #include "base/time.h" | 17 #include "base/time.h" |
17 #include "base/values.h" | 18 #include "base/values.h" |
18 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" | 19 #include "chrome/browser/chromeos/cros/cros_in_process_browser_test.h" |
19 #include "chrome/browser/chromeos/login/user.h" | 20 #include "chrome/browser/chromeos/login/user.h" |
20 #include "chrome/browser/chromeos/login/user_manager.h" | 21 #include "chrome/browser/chromeos/login/user_manager.h" |
21 #include "chrome/browser/prefs/scoped_user_pref_update.h" | 22 #include "chrome/browser/prefs/scoped_user_pref_update.h" |
22 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
23 #include "chrome/test/base/testing_browser_process.h" | 24 #include "chrome/test/base/testing_browser_process.h" |
24 #include "chromeos/chromeos_switches.h" | 25 #include "chromeos/chromeos_switches.h" |
25 #include "ui/aura/env.h" | 26 #include "ui/aura/env.h" |
26 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
27 | 28 |
28 using namespace ash; | 29 using namespace ash; |
29 | 30 |
30 namespace chromeos { | 31 namespace chromeos { |
31 | 32 |
32 namespace { | 33 namespace { |
33 | 34 |
34 #if defined(GOOGLE_CHROME_BUILD) | 35 const int kLargeWallpaperResourceId = IDR_AURA_WALLPAPERS_5_GRADIENT5_LARGE; |
35 int kExpectedSmallWallpaperWidth = ash::kSmallWallpaperMaxWidth; | 36 const int kSmallWallpaperResourceId = IDR_AURA_WALLPAPERS_5_GRADIENT5_SMALL; |
36 int kExpectedSmallWallpaperHeight = ash::kSmallWallpaperMaxHeight; | 37 |
37 int kExpectedLargeWallpaperWidth = ash::kLargeWallpaperMaxWidth; | 38 int kLargeWallpaperWidth = 256; |
38 int kExpectedLargeWallpaperHeight = ash::kLargeWallpaperMaxHeight; | 39 int kLargeWallpaperHeight = ash::kLargeWallpaperMaxHeight; |
39 #else | 40 int kSmallWallpaperWidth = 256; |
40 // The defualt wallpaper for non official build is a gradient wallpaper which | 41 int kSmallWallpaperHeight = ash::kSmallWallpaperMaxHeight; |
41 // stretches to fit screen. | |
42 int kExpectedSmallWallpaperWidth = 256; | |
43 int kExpectedSmallWallpaperHeight = ash::kSmallWallpaperMaxHeight; | |
44 int kExpectedLargeWallpaperWidth = 256; | |
45 int kExpectedLargeWallpaperHeight = ash::kLargeWallpaperMaxHeight; | |
46 #endif | |
47 | 42 |
48 const char kTestUser1[] = "test@domain.com"; | 43 const char kTestUser1[] = "test@domain.com"; |
49 | 44 |
50 } // namespace | 45 } // namespace |
51 | 46 |
52 class WallpaperManagerBrowserTest : public CrosInProcessBrowserTest, | 47 class WallpaperManagerBrowserTest : public CrosInProcessBrowserTest, |
53 public DesktopBackgroundControllerObserver { | 48 public DesktopBackgroundControllerObserver { |
54 public: | 49 public: |
55 WallpaperManagerBrowserTest () : controller_(NULL), | 50 WallpaperManagerBrowserTest () : controller_(NULL), |
56 local_state_(NULL) { | 51 local_state_(NULL) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 base::MessageLoop::current()->Run(); | 83 base::MessageLoop::current()->Run(); |
89 } | 84 } |
90 | 85 |
91 virtual void OnWallpaperDataChanged() OVERRIDE { | 86 virtual void OnWallpaperDataChanged() OVERRIDE { |
92 base::MessageLoop::current()->Quit(); | 87 base::MessageLoop::current()->Quit(); |
93 } | 88 } |
94 | 89 |
95 protected: | 90 protected: |
96 // Return custom wallpaper path. Create directory if not exist. | 91 // Return custom wallpaper path. Create directory if not exist. |
97 base::FilePath GetCustomWallpaperPath(const char* sub_dir, | 92 base::FilePath GetCustomWallpaperPath(const char* sub_dir, |
98 const std::string& email, | 93 const std::string& email, |
99 const std::string& id) { | 94 const std::string& id) { |
100 base::FilePath wallpaper_path = | 95 base::FilePath wallpaper_path = |
101 WallpaperManager::Get()->GetCustomWallpaperPath(sub_dir, email, id); | 96 WallpaperManager::Get()->GetCustomWallpaperPath(sub_dir, email, id); |
102 if (!file_util::DirectoryExists(wallpaper_path.DirName())) | 97 if (!file_util::DirectoryExists(wallpaper_path.DirName())) |
103 file_util::CreateDirectory(wallpaper_path.DirName()); | 98 file_util::CreateDirectory(wallpaper_path.DirName()); |
104 | 99 |
105 return wallpaper_path; | 100 return wallpaper_path; |
106 } | 101 } |
107 | 102 |
108 // Logs in |username|. | 103 // Logs in |username|. |
109 void LogIn(const std::string& username) { | 104 void LogIn(const std::string& username) { |
(...skipping 18 matching lines...) Expand all Loading... |
128 return WallpaperManager::Get()->loaded_wallpapers(); | 123 return WallpaperManager::Get()->loaded_wallpapers(); |
129 } | 124 } |
130 | 125 |
131 DesktopBackgroundController* controller_; | 126 DesktopBackgroundController* controller_; |
132 PrefService* local_state_; | 127 PrefService* local_state_; |
133 | 128 |
134 private: | 129 private: |
135 DISALLOW_COPY_AND_ASSIGN(WallpaperManagerBrowserTest); | 130 DISALLOW_COPY_AND_ASSIGN(WallpaperManagerBrowserTest); |
136 }; | 131 }; |
137 | 132 |
138 // The large resolution wallpaper should be loaded when a large external screen | 133 // Tests that the appropriate custom wallpaper (large vs. small) is loaded |
139 // is hooked up. If the external screen is smaller than small wallpaper | 134 // depending on the desktop resolution. |
140 // resolution, do not load large resolution wallpaper. | |
141 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, | |
142 LoadLargeWallpaperForLargeExternalScreen) { | |
143 LogIn(kTestUser1); | |
144 WaitAsyncWallpaperLoad(); | |
145 gfx::ImageSkia wallpaper = controller_->GetWallpaper(); | |
146 | |
147 // Display is initialized to 800x600. The small resolution default wallpaper | |
148 // is expected. | |
149 EXPECT_EQ(kExpectedSmallWallpaperWidth, wallpaper.width()); | |
150 EXPECT_EQ(kExpectedSmallWallpaperHeight, wallpaper.height()); | |
151 | |
152 // Hook up another 800x600 display. | |
153 UpdateDisplay("800x600,800x600"); | |
154 #if !defined(GOOGLE_CHROME_BUILD) | |
155 // wallpaper.width() < 800, expect to reload wallpaper. | |
156 WaitAsyncWallpaperLoad(); | |
157 #endif | |
158 // The small resolution wallpaper is expected. | |
159 EXPECT_EQ(kExpectedSmallWallpaperWidth, wallpaper.width()); | |
160 EXPECT_EQ(kExpectedSmallWallpaperHeight, wallpaper.height()); | |
161 | |
162 // Detach the secondary display. | |
163 UpdateDisplay("800x600"); | |
164 // Hook up a 2000x2000 display. The large resolution default wallpaper should | |
165 // be loaded. | |
166 UpdateDisplay("800x600,2000x2000"); | |
167 WaitAsyncWallpaperLoad(); | |
168 wallpaper = controller_->GetWallpaper(); | |
169 | |
170 // The large resolution default wallpaper is expected. | |
171 EXPECT_EQ(kExpectedLargeWallpaperWidth, wallpaper.width()); | |
172 EXPECT_EQ(kExpectedLargeWallpaperHeight, wallpaper.height()); | |
173 | |
174 // Detach the secondary display. | |
175 UpdateDisplay("800x600"); | |
176 // Hook up the 2000x2000 display again. The large resolution default wallpaper | |
177 // should persist. Test for crbug/165788. | |
178 UpdateDisplay("800x600,2000x2000"); | |
179 WaitAsyncWallpaperLoad(); | |
180 wallpaper = controller_->GetWallpaper(); | |
181 | |
182 // The large resolution default wallpaper is expected. | |
183 EXPECT_EQ(kExpectedLargeWallpaperWidth, wallpaper.width()); | |
184 EXPECT_EQ(kExpectedLargeWallpaperHeight, wallpaper.height()); | |
185 } | |
186 | |
187 // This test is similar to LoadLargeWallpaperForExternalScreen test. Instead of | |
188 // testing default wallpaper, it tests custom wallpaper. | |
189 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, | 135 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, |
190 LoadCustomLargeWallpaperForLargeExternalScreen) { | 136 LoadCustomLargeWallpaperForLargeExternalScreen) { |
191 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); | 137 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); |
192 LogIn(kTestUser1); | 138 LogIn(kTestUser1); |
193 // Wait for default wallpaper loaded. | 139 // Wait for default wallpaper loaded. |
194 WaitAsyncWallpaperLoad(); | 140 WaitAsyncWallpaperLoad(); |
195 std::string id = base::Int64ToString(base::Time::Now().ToInternalValue()); | 141 std::string id = base::Int64ToString(base::Time::Now().ToInternalValue()); |
196 base::FilePath small_wallpaper_path = GetCustomWallpaperPath( | 142 base::FilePath small_wallpaper_path = GetCustomWallpaperPath( |
197 kSmallWallpaperSubDir, | 143 kSmallWallpaperSubDir, |
198 kTestUser1, | 144 kTestUser1, |
199 id); | 145 id); |
200 base::FilePath large_wallpaper_path = GetCustomWallpaperPath( | 146 base::FilePath large_wallpaper_path = GetCustomWallpaperPath( |
201 kLargeWallpaperSubDir, | 147 kLargeWallpaperSubDir, |
202 kTestUser1, | 148 kTestUser1, |
203 id); | 149 id); |
204 | 150 |
205 // Saves the small/large resolution wallpapers to small/large custom | 151 // Saves the small/large resolution wallpapers to small/large custom |
206 // wallpaper paths. | 152 // wallpaper paths. |
207 SaveUserWallpaperData(kTestUser1, | 153 SaveUserWallpaperData(kTestUser1, |
208 small_wallpaper_path, | 154 small_wallpaper_path, |
209 ash::kDefaultSmallWallpaper.idr); | 155 kSmallWallpaperResourceId); |
210 SaveUserWallpaperData(kTestUser1, | 156 SaveUserWallpaperData(kTestUser1, |
211 large_wallpaper_path, | 157 large_wallpaper_path, |
212 ash::kDefaultLargeWallpaper.idr); | 158 kLargeWallpaperResourceId); |
213 | 159 |
214 // Saves wallpaper info to local state for user |kTestUser1|. | 160 // Saves wallpaper info to local state for user |kTestUser1|. |
215 WallpaperInfo info = { | 161 WallpaperInfo info = { |
216 id, | 162 id, |
217 WALLPAPER_LAYOUT_CENTER_CROPPED, | 163 WALLPAPER_LAYOUT_CENTER_CROPPED, |
218 User::CUSTOMIZED, | 164 User::CUSTOMIZED, |
219 base::Time::Now().LocalMidnight() | 165 base::Time::Now().LocalMidnight() |
220 }; | 166 }; |
221 wallpaper_manager->SetUserWallpaperInfo(kTestUser1, info, true); | 167 wallpaper_manager->SetUserWallpaperInfo(kTestUser1, info, true); |
222 | 168 |
223 // Set the wallpaper for |kTestUser1|. | 169 // Set the wallpaper for |kTestUser1|. |
224 wallpaper_manager->SetUserWallpaper(kTestUser1); | 170 wallpaper_manager->SetUserWallpaper(kTestUser1); |
225 WaitAsyncWallpaperLoad(); | 171 WaitAsyncWallpaperLoad(); |
226 gfx::ImageSkia wallpaper = controller_->GetWallpaper(); | 172 gfx::ImageSkia wallpaper = controller_->GetWallpaper(); |
227 | 173 |
228 // Display is initialized to 800x600. The small resolution custom wallpaper is | 174 // Display is initialized to 800x600. The small resolution custom wallpaper is |
229 // expected. | 175 // expected. |
230 EXPECT_EQ(kExpectedSmallWallpaperWidth, wallpaper.width()); | 176 EXPECT_EQ(kSmallWallpaperWidth, wallpaper.width()); |
231 EXPECT_EQ(kExpectedSmallWallpaperHeight, wallpaper.height()); | 177 EXPECT_EQ(kSmallWallpaperHeight, wallpaper.height()); |
232 | 178 |
233 // Hook up another 800x600 display. | 179 // Hook up another 800x600 display. |
234 UpdateDisplay("800x600,800x600"); | 180 UpdateDisplay("800x600,800x600"); |
235 #if !defined(GOOGLE_CHROME_BUILD) | |
236 // wallpaper.width() < 800, expect to reload wallpaper. | |
237 WaitAsyncWallpaperLoad(); | 181 WaitAsyncWallpaperLoad(); |
238 #endif | |
239 // The small resolution custom wallpaper is expected. | 182 // The small resolution custom wallpaper is expected. |
240 EXPECT_EQ(kExpectedSmallWallpaperWidth, wallpaper.width()); | 183 EXPECT_EQ(kSmallWallpaperWidth, wallpaper.width()); |
241 EXPECT_EQ(kExpectedSmallWallpaperHeight, wallpaper.height()); | 184 EXPECT_EQ(kSmallWallpaperHeight, wallpaper.height()); |
242 | 185 |
243 // Detach the secondary display. | 186 // Detach the secondary display. |
244 UpdateDisplay("800x600"); | 187 UpdateDisplay("800x600"); |
245 // Hook up a 2000x2000 display. The large resolution custom wallpaper should | 188 // Hook up a 2000x2000 display. The large resolution custom wallpaper should |
246 // be loaded. | 189 // be loaded. |
247 UpdateDisplay("800x600,2000x2000"); | 190 UpdateDisplay("800x600,2000x2000"); |
248 WaitAsyncWallpaperLoad(); | 191 WaitAsyncWallpaperLoad(); |
249 wallpaper = controller_->GetWallpaper(); | 192 wallpaper = controller_->GetWallpaper(); |
250 | 193 |
251 // The large resolution custom wallpaper is expected. | 194 // The large resolution custom wallpaper is expected. |
252 EXPECT_EQ(kExpectedLargeWallpaperWidth, wallpaper.width()); | 195 EXPECT_EQ(kLargeWallpaperWidth, wallpaper.width()); |
253 EXPECT_EQ(kExpectedLargeWallpaperHeight, wallpaper.height()); | 196 EXPECT_EQ(kLargeWallpaperHeight, wallpaper.height()); |
254 | 197 |
255 // Detach the secondary display. | 198 // Detach the secondary display. |
256 UpdateDisplay("800x600"); | 199 UpdateDisplay("800x600"); |
257 // Hook up the 2000x2000 display again. The large resolution default wallpaper | 200 // Hook up the 2000x2000 display again. The large resolution default wallpaper |
258 // should persist. Test for crbug/165788. | 201 // should persist. Test for crbug/165788. |
259 UpdateDisplay("800x600,2000x2000"); | 202 UpdateDisplay("800x600,2000x2000"); |
260 WaitAsyncWallpaperLoad(); | 203 WaitAsyncWallpaperLoad(); |
261 wallpaper = controller_->GetWallpaper(); | 204 wallpaper = controller_->GetWallpaper(); |
262 | 205 |
263 // The large resolution custom wallpaper is expected. | 206 // The large resolution custom wallpaper is expected. |
264 EXPECT_EQ(kExpectedLargeWallpaperWidth, wallpaper.width()); | 207 EXPECT_EQ(kLargeWallpaperWidth, wallpaper.width()); |
265 EXPECT_EQ(kExpectedLargeWallpaperHeight, wallpaper.height()); | 208 EXPECT_EQ(kLargeWallpaperHeight, wallpaper.height()); |
266 } | 209 } |
267 | 210 |
268 // 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 |
269 // be prevented. Otherwise, there are some strange animation issues as | 212 // be prevented. Otherwise, there are some strange animation issues as |
270 // described in crbug.com/158383. | 213 // described in crbug.com/158383. |
271 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, | 214 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, |
272 PreventReloadingSameWallpaper) { | 215 PreventReloadingSameWallpaper) { |
273 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); | 216 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); |
274 // New user log in, a default wallpaper is loaded. | 217 // New user log in, a default wallpaper is loaded. |
275 LogIn(kTestUser1); | 218 LogIn(kTestUser1); |
(...skipping 10 matching lines...) Expand all Loading... |
286 wallpaper_manager->ClearWallpaperCache(); | 229 wallpaper_manager->ClearWallpaperCache(); |
287 | 230 |
288 // Change wallpaper to a custom wallpaper. | 231 // Change wallpaper to a custom wallpaper. |
289 std::string id = base::Int64ToString(base::Time::Now().ToInternalValue()); | 232 std::string id = base::Int64ToString(base::Time::Now().ToInternalValue()); |
290 base::FilePath small_wallpaper_path = GetCustomWallpaperPath( | 233 base::FilePath small_wallpaper_path = GetCustomWallpaperPath( |
291 kSmallWallpaperSubDir, | 234 kSmallWallpaperSubDir, |
292 kTestUser1, | 235 kTestUser1, |
293 id); | 236 id); |
294 SaveUserWallpaperData(kTestUser1, | 237 SaveUserWallpaperData(kTestUser1, |
295 small_wallpaper_path, | 238 small_wallpaper_path, |
296 ash::kDefaultSmallWallpaper.idr); | 239 kSmallWallpaperResourceId); |
297 | 240 |
298 // Saves wallpaper info to local state for user |kTestUser1|. | 241 // Saves wallpaper info to local state for user |kTestUser1|. |
299 WallpaperInfo info = { | 242 WallpaperInfo info = { |
300 id, | 243 id, |
301 WALLPAPER_LAYOUT_CENTER_CROPPED, | 244 WALLPAPER_LAYOUT_CENTER_CROPPED, |
302 User::CUSTOMIZED, | 245 User::CUSTOMIZED, |
303 base::Time::Now().LocalMidnight() | 246 base::Time::Now().LocalMidnight() |
304 }; | 247 }; |
305 wallpaper_manager->SetUserWallpaperInfo(kTestUser1, info, true); | 248 wallpaper_manager->SetUserWallpaperInfo(kTestUser1, info, true); |
306 | 249 |
(...skipping 14 matching lines...) Expand all Loading... |
321 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, | 264 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTest, |
322 MoveCustomWallpaper) { | 265 MoveCustomWallpaper) { |
323 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); | 266 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); |
324 LogIn(kTestUser1); | 267 LogIn(kTestUser1); |
325 WaitAsyncWallpaperLoad(); | 268 WaitAsyncWallpaperLoad(); |
326 | 269 |
327 base::FilePath old_wallpaper_path = wallpaper_manager-> | 270 base::FilePath old_wallpaper_path = wallpaper_manager-> |
328 GetOriginalWallpaperPathForUser(kTestUser1); | 271 GetOriginalWallpaperPathForUser(kTestUser1); |
329 SaveUserWallpaperData(kTestUser1, | 272 SaveUserWallpaperData(kTestUser1, |
330 old_wallpaper_path, | 273 old_wallpaper_path, |
331 ash::kDefaultSmallWallpaper.idr); | 274 kSmallWallpaperResourceId); |
332 // Saves wallpaper info to local state for user |kTestUser1|. | 275 // Saves wallpaper info to local state for user |kTestUser1|. |
333 WallpaperInfo info = { | 276 WallpaperInfo info = { |
334 "DUMMY", | 277 "DUMMY", |
335 WALLPAPER_LAYOUT_CENTER_CROPPED, | 278 WALLPAPER_LAYOUT_CENTER_CROPPED, |
336 User::CUSTOMIZED, | 279 User::CUSTOMIZED, |
337 base::Time::Now().LocalMidnight() | 280 base::Time::Now().LocalMidnight() |
338 }; | 281 }; |
339 wallpaper_manager->SetUserWallpaperInfo(kTestUser1, info, true); | 282 wallpaper_manager->SetUserWallpaperInfo(kTestUser1, info, true); |
340 wallpaper_manager->SetUserWallpaper(kTestUser1); | 283 wallpaper_manager->SetUserWallpaper(kTestUser1); |
341 WaitAsyncWallpaperLoad(); | 284 WaitAsyncWallpaperLoad(); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 } | 399 } |
457 | 400 |
458 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestNoAnimation, | 401 IN_PROC_BROWSER_TEST_F(WallpaperManagerBrowserTestNoAnimation, |
459 UsePreMigrationWallpaperInfo) { | 402 UsePreMigrationWallpaperInfo) { |
460 LogIn(kTestUser1); | 403 LogIn(kTestUser1); |
461 WaitAsyncWallpaperLoad(); | 404 WaitAsyncWallpaperLoad(); |
462 // This test should finish normally. If timeout, it is probably because chrome | 405 // This test should finish normally. If timeout, it is probably because chrome |
463 // can not handle pre migrated user profile (M21 profile or older). | 406 // can not handle pre migrated user profile (M21 profile or older). |
464 } | 407 } |
465 | 408 |
466 } // namepace chromeos | 409 } // namespace chromeos |
OLD | NEW |