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