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_resources.h" | 7 #include "ash/ash_resources/grit/ash_resources.h" |
8 #include "ash/ash_switches.h" | |
8 #include "ash/desktop_background/desktop_background_controller.h" | 9 #include "ash/desktop_background/desktop_background_controller.h" |
9 #include "ash/desktop_background/desktop_background_controller_observer.h" | 10 #include "ash/desktop_background/desktop_background_controller_observer.h" |
11 #include "ash/desktop_background/desktop_background_controller_test_api.h" | |
10 #include "ash/display/display_manager.h" | 12 #include "ash/display/display_manager.h" |
11 #include "ash/shell.h" | 13 #include "ash/shell.h" |
14 #include "ash/test/ash_test_base.h" | |
15 #include "ash/test/ash_test_helper.h" | |
12 #include "ash/test/display_manager_test_api.h" | 16 #include "ash/test/display_manager_test_api.h" |
17 #include "ash/test/test_user_wallpaper_delegate.h" | |
13 #include "base/command_line.h" | 18 #include "base/command_line.h" |
19 #include "base/compiler_specific.h" | |
14 #include "base/file_util.h" | 20 #include "base/file_util.h" |
15 #include "base/files/file_path.h" | 21 #include "base/files/file_path.h" |
22 #include "base/macros.h" | |
16 #include "base/message_loop/message_loop.h" | 23 #include "base/message_loop/message_loop.h" |
17 #include "base/path_service.h" | 24 #include "base/path_service.h" |
18 #include "base/prefs/scoped_user_pref_update.h" | 25 #include "base/prefs/scoped_user_pref_update.h" |
19 #include "base/strings/string_number_conversions.h" | 26 #include "base/strings/string_number_conversions.h" |
20 #include "base/time/time.h" | 27 #include "base/time/time.h" |
21 #include "base/values.h" | 28 #include "base/values.h" |
22 #include "chrome/browser/chromeos/login/user.h" | 29 #include "chrome/browser/chromeos/login/user.h" |
23 #include "chrome/browser/chromeos/login/user_manager.h" | 30 #include "chrome/browser/chromeos/login/user_manager.h" |
24 #include "chrome/common/chrome_paths.h" | 31 #include "chrome/common/chrome_paths.h" |
25 #include "chrome/common/chrome_switches.h" | 32 #include "chrome/common/chrome_switches.h" |
26 #include "chrome/test/base/in_process_browser_test.h" | 33 #include "chrome/test/base/in_process_browser_test.h" |
27 #include "chrome/test/base/testing_browser_process.h" | 34 #include "chrome/test/base/testing_browser_process.h" |
28 #include "chromeos/chromeos_switches.h" | 35 #include "chromeos/chromeos_switches.h" |
29 #include "chromeos/dbus/cryptohome_client.h" | 36 #include "chromeos/dbus/cryptohome_client.h" |
30 #include "content/public/test/test_utils.h" | 37 #include "content/public/test/test_utils.h" |
31 #include "ui/aura/env.h" | 38 #include "ui/aura/env.h" |
32 #include "ui/base/resource/resource_bundle.h" | 39 #include "ui/base/resource/resource_bundle.h" |
40 #include "ui/gfx/codec/jpeg_codec.h" | |
41 #include "ui/gfx/point.h" | |
42 #include "ui/gfx/rect.h" | |
33 | 43 |
34 using namespace ash; | 44 using namespace ash; |
35 | 45 |
36 namespace chromeos { | 46 namespace chromeos { |
37 | 47 |
38 namespace { | 48 namespace { |
39 | 49 |
40 const int kLargeWallpaperResourceId = IDR_AURA_WALLPAPER_DEFAULT_LARGE; | 50 const int kLargeWallpaperResourceId = IDR_AURA_WALLPAPER_DEFAULT_LARGE; |
41 const int kSmallWallpaperResourceId = IDR_AURA_WALLPAPER_DEFAULT_SMALL; | 51 const int kSmallWallpaperResourceId = IDR_AURA_WALLPAPER_DEFAULT_SMALL; |
42 | 52 |
43 int kLargeWallpaperWidth = 256; | 53 int kLargeWallpaperWidth = 256; |
44 int kLargeWallpaperHeight = ash::kLargeWallpaperMaxHeight; | 54 int kLargeWallpaperHeight = chromeos::kLargeWallpaperMaxHeight; |
45 int kSmallWallpaperWidth = 256; | 55 int kSmallWallpaperWidth = 256; |
46 int kSmallWallpaperHeight = ash::kSmallWallpaperMaxHeight; | 56 int kSmallWallpaperHeight = chromeos::kSmallWallpaperMaxHeight; |
47 | 57 |
48 const char kTestUser1[] = "test1@domain.com"; | 58 const char kTestUser1[] = "test1@domain.com"; |
49 const char kTestUser1Hash[] = "test1@domain.com-hash"; | 59 const char kTestUser1Hash[] = "test1@domain.com-hash"; |
50 const char kTestUser2[] = "test2@domain.com"; | 60 const char kTestUser2[] = "test2@domain.com"; |
51 const char kTestUser2Hash[] = "test2@domain.com-hash"; | 61 const char kTestUser2Hash[] = "test2@domain.com-hash"; |
52 | 62 |
53 } // namespace | 63 } // namespace |
54 | 64 |
55 class WallpaperManagerBrowserTest : public InProcessBrowserTest, | 65 class WallpaperManagerBrowserTest : public InProcessBrowserTest, |
56 public DesktopBackgroundControllerObserver, | |
57 public testing::WithParamInterface<bool> { | 66 public testing::WithParamInterface<bool> { |
58 public: | 67 public: |
59 WallpaperManagerBrowserTest () : controller_(NULL), | 68 WallpaperManagerBrowserTest () : controller_(NULL), |
60 local_state_(NULL) { | 69 local_state_(NULL) { |
61 } | 70 } |
62 | 71 |
63 virtual ~WallpaperManagerBrowserTest () {} | 72 virtual ~WallpaperManagerBrowserTest () {} |
64 | 73 |
65 virtual void SetUpOnMainThread() OVERRIDE { | 74 virtual void SetUpOnMainThread() OVERRIDE { |
66 controller_ = ash::Shell::GetInstance()->desktop_background_controller(); | 75 controller_ = ash::Shell::GetInstance()->desktop_background_controller(); |
67 controller_->AddObserver(this); | |
68 local_state_ = g_browser_process->local_state(); | 76 local_state_ = g_browser_process->local_state(); |
77 DesktopBackgroundController::TestAPI(controller_) | |
78 .set_wallpaper_reload_delay_for_test(0); | |
69 UpdateDisplay("800x600"); | 79 UpdateDisplay("800x600"); |
70 } | 80 } |
71 | 81 |
72 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 82 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
73 command_line->AppendSwitch(switches::kLoginManager); | 83 command_line->AppendSwitch(switches::kLoginManager); |
74 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); | 84 command_line->AppendSwitchASCII(switches::kLoginProfile, "user"); |
75 if (GetParam()) | 85 if (GetParam()) |
76 command_line->AppendSwitch(::switches::kMultiProfiles); | 86 command_line->AppendSwitch(::switches::kMultiProfiles); |
77 } | 87 } |
78 | 88 |
79 virtual void CleanUpOnMainThread() OVERRIDE { | 89 virtual void CleanUpOnMainThread() OVERRIDE { |
80 controller_->RemoveObserver(this); | |
81 controller_ = NULL; | 90 controller_ = NULL; |
82 } | 91 } |
83 | 92 |
84 // Update the display configuration as given in |display_specs|. See | 93 // Update the display configuration as given in |display_specs|. See |
85 // ash::test::DisplayManagerTestApi::UpdateDisplay for more details. | 94 // ash::test::DisplayManagerTestApi::UpdateDisplay for more details. |
86 void UpdateDisplay(const std::string& display_specs) { | 95 void UpdateDisplay(const std::string& display_specs) { |
87 ash::test::DisplayManagerTestApi display_manager_test_api( | 96 ash::test::DisplayManagerTestApi display_manager_test_api( |
88 ash::Shell::GetInstance()->display_manager()); | 97 ash::Shell::GetInstance()->display_manager()); |
89 display_manager_test_api.UpdateDisplay(display_specs); | 98 display_manager_test_api.UpdateDisplay(display_specs); |
90 } | 99 } |
91 | 100 |
92 void WaitAsyncWallpaperLoadStarted() { | 101 void WaitAsyncWallpaperLoadStarted() { |
93 base::MessageLoop::current()->RunUntilIdle(); | 102 base::RunLoop().RunUntilIdle(); |
94 } | 103 } |
95 | 104 |
96 void WaitAsyncWallpaperLoadFinished() { | 105 void WaitAsyncWallpaperLoadFinished() { |
97 base::MessageLoop::current()->RunUntilIdle(); | 106 base::RunLoop current_loop; |
107 current_loop.RunUntilIdle(); | |
98 while (WallpaperManager::Get()->loading_.size()) { | 108 while (WallpaperManager::Get()->loading_.size()) { |
oshima
2014/04/08 21:49:38
You need the RunLoop here (you can't reuse the ins
Alexander Alekseev
2014/04/08 22:22:12
Done.
| |
99 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); | 109 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100)); |
100 base::MessageLoop::current()->RunUntilIdle(); | 110 current_loop.RunUntilIdle(); |
101 } | 111 } |
102 } | 112 } |
103 | 113 |
104 virtual void OnWallpaperDataChanged() OVERRIDE { | 114 protected: |
105 base::MessageLoop::current()->Quit(); | 115 // Colors used for different default wallpapers by |
106 } | 116 // WriteWallpapers(). |
117 static const SkColor kLargeWallpaperColor = SK_ColorRED; | |
118 static const SkColor kSmallWallpaperColor = SK_ColorGREEN; | |
119 static const SkColor kLargeGuestWallpaperColor = SK_ColorBLUE; | |
120 static const SkColor kSmallGuestWallpaperColor = SK_ColorYELLOW; | |
107 | 121 |
108 protected: | 122 // A color that can be passed to CreateImage(). Specifically chosen to not |
123 // conflict with any of the default wallpaper colors. | |
124 static const SkColor kCustomWallpaperColor = SK_ColorMAGENTA; | |
125 | |
126 // Dimension used for width and height of default wallpaper images. A | |
127 // small value is used to minimize the amount of time spent compressing | |
128 // and writing images. | |
129 static const int kWallpaperSize = 2; | |
130 | |
109 // Return custom wallpaper path. Create directory if not exist. | 131 // Return custom wallpaper path. Create directory if not exist. |
110 base::FilePath GetCustomWallpaperPath(const char* sub_dir, | 132 base::FilePath GetCustomWallpaperPath(const char* sub_dir, |
111 const std::string& username_hash, | 133 const std::string& username_hash, |
112 const std::string& id) { | 134 const std::string& id) { |
113 base::FilePath wallpaper_path = | 135 base::FilePath wallpaper_path = |
114 WallpaperManager::Get()->GetCustomWallpaperPath(sub_dir, | 136 WallpaperManager::Get()->GetCustomWallpaperPath(sub_dir, |
115 username_hash, | 137 username_hash, |
116 id); | 138 id); |
117 if (!base::DirectoryExists(wallpaper_path.DirName())) | 139 if (!base::DirectoryExists(wallpaper_path.DirName())) |
118 base::CreateDirectory(wallpaper_path.DirName()); | 140 base::CreateDirectory(wallpaper_path.DirName()); |
(...skipping 17 matching lines...) Expand all Loading... | |
136 wallpaper_path, | 158 wallpaper_path, |
137 reinterpret_cast<const char*>(image_data->front()), | 159 reinterpret_cast<const char*>(image_data->front()), |
138 image_data->size()); | 160 image_data->size()); |
139 EXPECT_EQ(static_cast<int>(image_data->size()), written); | 161 EXPECT_EQ(static_cast<int>(image_data->size()), written); |
140 } | 162 } |
141 | 163 |
142 int LoadedWallpapers() { | 164 int LoadedWallpapers() { |
143 return WallpaperManager::Get()->loaded_wallpapers(); | 165 return WallpaperManager::Get()->loaded_wallpapers(); |
144 } | 166 } |
145 | 167 |
168 // Creates a test image of size 1x1. | |
169 gfx::ImageSkia CreateTestImage(int width, int height, SkColor color) { | |
170 SkBitmap bitmap; | |
171 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | |
172 bitmap.allocPixels(); | |
173 bitmap.eraseColor(color); | |
174 return gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | |
175 } | |
176 | |
177 // Writes a JPEG image of the specified size and color to |path|. Returns | |
178 // true on success. | |
179 bool WriteJPEGFile(const base::FilePath& path, | |
180 int width, | |
181 int height, | |
182 SkColor color) { | |
183 SkBitmap bitmap; | |
184 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, 0); | |
185 bitmap.allocPixels(); | |
186 bitmap.eraseColor(color); | |
187 | |
188 const int kQuality = 80; | |
189 std::vector<unsigned char> output; | |
190 if (!gfx::JPEGCodec::Encode( | |
191 static_cast<const unsigned char*>(bitmap.getPixels()), | |
192 gfx::JPEGCodec::FORMAT_SkBitmap, | |
193 width, | |
194 height, | |
195 bitmap.rowBytes(), | |
196 kQuality, | |
197 &output)) { | |
198 LOG(ERROR) << "Unable to encode " << width << "x" << height << " bitmap"; | |
199 return false; | |
200 } | |
201 | |
202 size_t bytes_written = base::WriteFile( | |
203 path, reinterpret_cast<const char*>(&output[0]), output.size()); | |
204 if (bytes_written != output.size()) { | |
205 LOG(ERROR) << "Wrote " << bytes_written << " byte(s) instead of " | |
206 << output.size() << " to " << path.value(); | |
207 return false; | |
208 } | |
209 | |
210 return true; | |
211 } | |
212 | |
213 // Initializes default wallpaper paths "*default_*file" and writes JPEG | |
214 // wallpaper images to them. | |
215 // Only needs to be called (once) by tests that want to test loading of | |
216 // default wallpapers. | |
217 void WriteWallpapers() { | |
218 wallpaper_dir_.reset(new base::ScopedTempDir); | |
219 ASSERT_TRUE(wallpaper_dir_->CreateUniqueTempDir()); | |
220 | |
221 std::vector<std::string> options; | |
222 options.push_back(std::string("WM_Test_cmdline")); | |
223 const base::FilePath small_file = | |
224 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("small.jpg")); | |
225 options.push_back(std::string("--") + | |
226 ash::switches::kAshDefaultWallpaperSmall + "=" + | |
227 small_file.value()); | |
228 const base::FilePath large_file = | |
229 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("large.jpg")); | |
230 options.push_back(std::string("--") + | |
231 ash::switches::kAshDefaultWallpaperLarge + "=" + | |
232 large_file.value()); | |
233 const base::FilePath guest_small_file = | |
234 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("guest_small.jpg")); | |
235 options.push_back(std::string("--") + | |
236 ash::switches::kAshGuestWallpaperSmall + "=" + | |
237 guest_small_file.value()); | |
238 const base::FilePath guest_large_file = | |
239 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("guest_large.jpg")); | |
240 options.push_back(std::string("--") + | |
241 ash::switches::kAshGuestWallpaperLarge + "=" + | |
242 guest_large_file.value()); | |
243 | |
244 ASSERT_TRUE(WriteJPEGFile(small_file, | |
245 kWallpaperSize, | |
246 kWallpaperSize, | |
247 kSmallWallpaperColor)); | |
248 ASSERT_TRUE(WriteJPEGFile(large_file, | |
249 kWallpaperSize, | |
250 kWallpaperSize, | |
251 kLargeWallpaperColor)); | |
252 ASSERT_TRUE(WriteJPEGFile(guest_small_file, | |
253 kWallpaperSize, | |
254 kWallpaperSize, | |
255 kSmallGuestWallpaperColor)); | |
256 ASSERT_TRUE(WriteJPEGFile(guest_large_file, | |
257 kWallpaperSize, | |
258 kWallpaperSize, | |
259 kLargeGuestWallpaperColor)); | |
260 | |
261 wallpaper_manager_command_line_.reset(new base::CommandLine(options)); | |
262 WallpaperManager::Get()->SetCommandLineForTesting( | |
263 wallpaper_manager_command_line_.get()); | |
264 } | |
265 | |
266 // Returns true if the color at the center of |image| is close to | |
267 // |expected_color|. (The center is used so small wallpaper images can be | |
268 // used.) | |
269 bool ImageIsNearColor(gfx::ImageSkia image, SkColor expected_color) { | |
270 if (image.size().IsEmpty()) { | |
271 LOG(ERROR) << "Image is empty"; | |
272 return false; | |
273 } | |
274 | |
275 const SkBitmap* bitmap = image.bitmap(); | |
276 if (!bitmap) { | |
277 LOG(ERROR) << "Unable to get bitmap from image"; | |
278 return false; | |
279 } | |
280 | |
281 bitmap->lockPixels(); | |
282 gfx::Point center = gfx::Rect(image.size()).CenterPoint(); | |
283 SkColor image_color = bitmap->getColor(center.x(), center.y()); | |
284 bitmap->unlockPixels(); | |
285 | |
286 const int kDiff = 3; | |
287 if (std::abs(static_cast<int>(SkColorGetA(image_color)) - | |
288 static_cast<int>(SkColorGetA(expected_color))) > kDiff || | |
289 std::abs(static_cast<int>(SkColorGetR(image_color)) - | |
290 static_cast<int>(SkColorGetR(expected_color))) > kDiff || | |
291 std::abs(static_cast<int>(SkColorGetG(image_color)) - | |
292 static_cast<int>(SkColorGetG(expected_color))) > kDiff || | |
293 std::abs(static_cast<int>(SkColorGetB(image_color)) - | |
294 static_cast<int>(SkColorGetB(expected_color))) > kDiff) { | |
295 LOG(ERROR) << "Expected color near 0x" << std::hex << expected_color | |
296 << " but got 0x" << image_color; | |
297 return false; | |
298 } | |
299 | |
300 return true; | |
301 } | |
302 | |
146 DesktopBackgroundController* controller_; | 303 DesktopBackgroundController* controller_; |
147 PrefService* local_state_; | 304 PrefService* local_state_; |
305 scoped_ptr<base::CommandLine> wallpaper_manager_command_line_; | |
306 | |
307 // Directory created by WriteWallpapersAndSetFlags() to store default | |
308 // wallpaper images. | |
309 scoped_ptr<base::ScopedTempDir> wallpaper_dir_; | |
148 | 310 |
149 private: | 311 private: |
150 DISALLOW_COPY_AND_ASSIGN(WallpaperManagerBrowserTest); | 312 DISALLOW_COPY_AND_ASSIGN(WallpaperManagerBrowserTest); |
151 }; | 313 }; |
152 | 314 |
153 // Tests that the appropriate custom wallpaper (large vs. small) is loaded | 315 // Tests that the appropriate custom wallpaper (large vs. small) is loaded |
154 // depending on the desktop resolution. | 316 // depending on the desktop resolution. |
155 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, | 317 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, |
156 LoadCustomLargeWallpaperForLargeExternalScreen) { | 318 LoadCustomLargeWallpaperForLargeExternalScreen) { |
157 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); | 319 WallpaperManager* wallpaper_manager = WallpaperManager::Get(); |
(...skipping 30 matching lines...) Expand all Loading... | |
188 WaitAsyncWallpaperLoadFinished(); | 350 WaitAsyncWallpaperLoadFinished(); |
189 gfx::ImageSkia wallpaper = controller_->GetWallpaper(); | 351 gfx::ImageSkia wallpaper = controller_->GetWallpaper(); |
190 | 352 |
191 // Display is initialized to 800x600. The small resolution custom wallpaper is | 353 // Display is initialized to 800x600. The small resolution custom wallpaper is |
192 // expected. | 354 // expected. |
193 EXPECT_EQ(kSmallWallpaperWidth, wallpaper.width()); | 355 EXPECT_EQ(kSmallWallpaperWidth, wallpaper.width()); |
194 EXPECT_EQ(kSmallWallpaperHeight, wallpaper.height()); | 356 EXPECT_EQ(kSmallWallpaperHeight, wallpaper.height()); |
195 | 357 |
196 // Hook up another 800x600 display. This shouldn't trigger a reload. | 358 // Hook up another 800x600 display. This shouldn't trigger a reload. |
197 UpdateDisplay("800x600,800x600"); | 359 UpdateDisplay("800x600,800x600"); |
198 content::RunAllPendingInMessageLoop(); | 360 WaitAsyncWallpaperLoadFinished(); |
199 // The small resolution custom wallpaper is expected. | 361 // The small resolution custom wallpaper is expected. |
200 EXPECT_EQ(kSmallWallpaperWidth, wallpaper.width()); | 362 EXPECT_EQ(kSmallWallpaperWidth, wallpaper.width()); |
201 EXPECT_EQ(kSmallWallpaperHeight, wallpaper.height()); | 363 EXPECT_EQ(kSmallWallpaperHeight, wallpaper.height()); |
202 | 364 |
203 // Detach the secondary display. | 365 // Detach the secondary display. |
204 UpdateDisplay("800x600"); | 366 UpdateDisplay("800x600"); |
205 // Hook up a 2000x2000 display. The large resolution custom wallpaper should | 367 // Hook up a 2000x2000 display. The large resolution custom wallpaper should |
206 // be loaded. | 368 // be loaded. |
207 UpdateDisplay("800x600,2000x2000"); | 369 UpdateDisplay("800x600,2000x2000"); |
208 WaitAsyncWallpaperLoadFinished(); | 370 WaitAsyncWallpaperLoadFinished(); |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
563 testing::Bool()); | 725 testing::Bool()); |
564 | 726 |
565 INSTANTIATE_TEST_CASE_P(WallpaperManagerBrowserTestCrashRestoreInstantiation, | 727 INSTANTIATE_TEST_CASE_P(WallpaperManagerBrowserTestCrashRestoreInstantiation, |
566 WallpaperManagerBrowserTestCrashRestore, | 728 WallpaperManagerBrowserTestCrashRestore, |
567 testing::Bool()); | 729 testing::Bool()); |
568 | 730 |
569 INSTANTIATE_TEST_CASE_P(WallpaperManagerBrowserTestCacheUpdateInstantiation, | 731 INSTANTIATE_TEST_CASE_P(WallpaperManagerBrowserTestCacheUpdateInstantiation, |
570 WallpaperManagerBrowserTestCacheUpdate, | 732 WallpaperManagerBrowserTestCacheUpdate, |
571 testing::Bool()); | 733 testing::Bool()); |
572 | 734 |
735 // ---------------------------------------------------------------------- | |
736 // Test default wallpapers. | |
737 | |
738 class TestObserver : public WallpaperManager::Observer { | |
739 public: | |
740 explicit TestObserver(WallpaperManager* wallpaper_manager) | |
741 : update_wallpaper_count_(0), wallpaper_manager_(wallpaper_manager) { | |
742 DCHECK(wallpaper_manager_); | |
743 wallpaper_manager_->AddObserver(this); | |
744 } | |
745 | |
746 virtual ~TestObserver() { | |
747 wallpaper_manager_->RemoveObserver(this); | |
748 } | |
749 | |
750 virtual void OnWallpaperAnimationFinished(const std::string&) OVERRIDE { | |
751 } | |
752 | |
753 virtual void OnUpdateWallpaperForTesting() OVERRIDE { | |
754 ++update_wallpaper_count_; | |
755 } | |
756 | |
757 int GetUpdateWallpaperCountAndReset() { | |
758 const size_t old = update_wallpaper_count_; | |
759 update_wallpaper_count_ = 0; | |
760 return old; | |
761 } | |
762 | |
763 private: | |
764 int update_wallpaper_count_; | |
765 WallpaperManager* wallpaper_manager_; | |
766 | |
767 DISALLOW_COPY_AND_ASSIGN(TestObserver); | |
768 }; | |
769 | |
770 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, DisplayChange) { | |
771 // TODO(derat|oshima|bshe): Host windows can't be resized on Win8. | |
772 if (!ash::test::AshTestHelper::SupportsHostWindowResize()) | |
773 return; | |
774 | |
775 TestObserver observer(WallpaperManager::Get()); | |
776 | |
777 // Set the wallpaper to ensure that UpdateWallpaper() will be called when the | |
778 // display configuration changes. | |
779 gfx::ImageSkia image = CreateTestImage(640, 480, kCustomWallpaperColor); | |
780 controller_->SetWallpaperImage(image, WALLPAPER_LAYOUT_STRETCH); | |
781 | |
782 // Small wallpaper images should be used for configurations less than or | |
783 // equal to kSmallWallpaperMaxWidth by kSmallWallpaperMaxHeight, even if | |
784 // multiple displays are connected. | |
785 UpdateDisplay("800x600"); | |
786 WaitAsyncWallpaperLoadFinished(); | |
787 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, | |
788 WallpaperManager::Get()->GetAppropriateResolution()); | |
789 EXPECT_EQ(0, observer.GetUpdateWallpaperCountAndReset()); | |
790 | |
791 UpdateDisplay("800x600,800x600"); | |
792 WaitAsyncWallpaperLoadFinished(); | |
793 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, | |
794 WallpaperManager::Get()->GetAppropriateResolution()); | |
795 EXPECT_EQ(0, observer.GetUpdateWallpaperCountAndReset()); | |
796 | |
797 UpdateDisplay("1366x800"); | |
798 WaitAsyncWallpaperLoadFinished(); | |
799 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, | |
800 WallpaperManager::Get()->GetAppropriateResolution()); | |
801 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | |
802 | |
803 // At larger sizes, large wallpapers should be used. | |
804 UpdateDisplay("1367x800"); | |
805 WaitAsyncWallpaperLoadFinished(); | |
806 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_LARGE, | |
807 WallpaperManager::Get()->GetAppropriateResolution()); | |
808 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | |
809 | |
810 UpdateDisplay("1367x801"); | |
811 WaitAsyncWallpaperLoadFinished(); | |
812 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_LARGE, | |
813 WallpaperManager::Get()->GetAppropriateResolution()); | |
814 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | |
815 | |
816 UpdateDisplay("2560x1700"); | |
817 WaitAsyncWallpaperLoadFinished(); | |
818 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_LARGE, | |
819 WallpaperManager::Get()->GetAppropriateResolution()); | |
820 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | |
821 | |
822 // Rotated smaller screen may use larger image. | |
823 UpdateDisplay("800x600/r"); | |
824 WaitAsyncWallpaperLoadFinished(); | |
825 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, | |
826 WallpaperManager::Get()->GetAppropriateResolution()); | |
827 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | |
828 | |
829 DesktopBackgroundController::TestAPI(controller_) | |
830 .set_wallpaper_reload_delay_for_test(0); | |
831 UpdateDisplay("800x600/r,800x600"); | |
832 DesktopBackgroundController::TestAPI(controller_) | |
833 .set_wallpaper_reload_delay_for_test(0); | |
834 WaitAsyncWallpaperLoadFinished(); | |
835 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_SMALL, | |
836 WallpaperManager::Get()->GetAppropriateResolution()); | |
837 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | |
838 UpdateDisplay("1366x800/r"); | |
839 WaitAsyncWallpaperLoadFinished(); | |
840 EXPECT_EQ(WallpaperManager::WALLPAPER_RESOLUTION_LARGE, | |
841 WallpaperManager::Get()->GetAppropriateResolution()); | |
842 EXPECT_EQ(1, observer.GetUpdateWallpaperCountAndReset()); | |
843 | |
844 // Max display size didn't chagne. | |
845 UpdateDisplay("900x800/r,400x1366"); | |
846 WaitAsyncWallpaperLoadFinished(); | |
847 EXPECT_EQ(0, observer.GetUpdateWallpaperCountAndReset()); | |
848 } | |
849 | |
850 // Test that WallpaperManager loads the appropriate wallpaper | |
851 // images as specified via command-line flags in various situations. | |
852 // Splitting these into separate tests avoids needing to run animations. | |
853 // TODO(derat): Combine these into a single test | |
854 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, SmallDefaultWallpaper) { | |
855 if (!ash::test::AshTestHelper::SupportsMultipleDisplays()) | |
856 return; | |
857 | |
858 WriteWallpapers(); | |
859 | |
860 // At 800x600, the small wallpaper should be loaded. | |
861 UpdateDisplay("800x600"); | |
862 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); | |
863 WaitAsyncWallpaperLoadFinished(); | |
864 EXPECT_TRUE( | |
865 ImageIsNearColor(controller_->GetWallpaper(), kSmallWallpaperColor)); | |
866 } | |
867 | |
868 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, LargeDefaultWallpaper) { | |
869 if (!ash::test::AshTestHelper::SupportsMultipleDisplays()) | |
870 return; | |
871 | |
872 WriteWallpapers(); | |
873 UpdateDisplay("1600x1200"); | |
874 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); | |
875 WaitAsyncWallpaperLoadFinished(); | |
876 EXPECT_TRUE( | |
877 ImageIsNearColor(controller_->GetWallpaper(), kLargeWallpaperColor)); | |
878 } | |
879 | |
880 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, | |
881 LargeDefaultWallpaperWhenRotated) { | |
882 if (!ash::test::AshTestHelper::SupportsMultipleDisplays()) | |
883 return; | |
884 WriteWallpapers(); | |
885 | |
886 UpdateDisplay("1200x800/r"); | |
887 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); | |
888 WaitAsyncWallpaperLoadFinished(); | |
889 EXPECT_TRUE( | |
890 ImageIsNearColor(controller_->GetWallpaper(), kLargeWallpaperColor)); | |
891 } | |
892 | |
893 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, SmallGuestWallpaper) { | |
894 if (!ash::test::AshTestHelper::SupportsMultipleDisplays()) | |
895 return; | |
896 WriteWallpapers(); | |
897 UserManager::Get()->UserLoggedIn( | |
898 UserManager::kGuestUserName, UserManager::kGuestUserName, false); | |
899 UpdateDisplay("800x600"); | |
900 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); | |
901 WaitAsyncWallpaperLoadFinished(); | |
902 EXPECT_TRUE( | |
903 ImageIsNearColor(controller_->GetWallpaper(), kSmallGuestWallpaperColor)); | |
904 } | |
905 | |
906 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, LargeGuestWallpaper) { | |
907 if (!ash::test::AshTestHelper::SupportsMultipleDisplays()) | |
908 return; | |
909 | |
910 WriteWallpapers(); | |
911 UserManager::Get()->UserLoggedIn( | |
912 UserManager::kGuestUserName, UserManager::kGuestUserName, false); | |
913 UpdateDisplay("1600x1200"); | |
914 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); | |
915 WaitAsyncWallpaperLoadFinished(); | |
916 EXPECT_TRUE( | |
917 ImageIsNearColor(controller_->GetWallpaper(), kLargeGuestWallpaperColor)); | |
918 } | |
919 | |
920 IN_PROC_BROWSER_TEST_P(WallpaperManagerBrowserTest, | |
921 SwitchBetweenDefaultAndCustom) { | |
922 // Start loading the default wallpaper. | |
923 UpdateDisplay("640x480"); | |
924 WriteWallpapers(); | |
925 UserManager::Get()->UserLoggedIn(UserManager::kStubUser, "test_hash", false); | |
926 | |
927 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); | |
928 | |
929 // Custom wallpaper should be applied immediately, canceling the default | |
930 // wallpaper load task. | |
931 gfx::ImageSkia image = CreateTestImage(640, 480, kCustomWallpaperColor); | |
932 UserImage wallpaper(image); | |
933 WallpaperManager::Get()->SetCustomWallpaper(UserManager::kStubUser, | |
934 "test_hash", | |
935 "test-nofile.jpeg", | |
936 WALLPAPER_LAYOUT_STRETCH, | |
937 User::CUSTOMIZED, | |
938 wallpaper, | |
939 true); | |
940 WaitAsyncWallpaperLoadFinished(); | |
941 | |
942 EXPECT_TRUE( | |
943 ImageIsNearColor(controller_->GetWallpaper(), kCustomWallpaperColor)); | |
944 | |
945 WallpaperManager::Get()->SetDefaultWallpaperNow(std::string()); | |
946 WaitAsyncWallpaperLoadFinished(); | |
947 | |
948 EXPECT_TRUE( | |
949 ImageIsNearColor(controller_->GetWallpaper(), kSmallWallpaperColor)); | |
950 } | |
951 | |
573 } // namespace chromeos | 952 } // namespace chromeos |
OLD | NEW |