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 "ash/desktop_background/desktop_background_controller.h" | 5 #include "ash/desktop_background/desktop_background_controller.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 #include <cstdlib> | 8 #include <cstdlib> |
9 | 9 |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
11 #include "ash/desktop_background/desktop_background_controller_observer.h" | |
12 #include "ash/desktop_background/desktop_background_widget_controller.h" | 11 #include "ash/desktop_background/desktop_background_widget_controller.h" |
13 #include "ash/root_window_controller.h" | 12 #include "ash/root_window_controller.h" |
14 #include "ash/shell.h" | 13 #include "ash/shell.h" |
15 #include "ash/shell_window_ids.h" | 14 #include "ash/shell_window_ids.h" |
16 #include "ash/test/ash_test_base.h" | 15 #include "ash/test/ash_test_base.h" |
17 #include "ash/test/display_manager_test_api.h" | 16 #include "ash/test/display_manager_test_api.h" |
18 #include "ash/test/test_user_wallpaper_delegate.h" | 17 #include "ash/test/test_user_wallpaper_delegate.h" |
19 #include "base/command_line.h" | |
20 #include "base/file_util.h" | |
21 #include "base/files/file_path.h" | |
22 #include "base/files/scoped_temp_dir.h" | |
23 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
24 #include "base/threading/sequenced_worker_pool.h" | 19 #include "base/threading/sequenced_worker_pool.h" |
25 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
26 #include "content/public/test/test_browser_thread.h" | 21 #include "content/public/test/test_browser_thread.h" |
27 #include "content/public/test/test_utils.h" | 22 #include "content/public/test/test_utils.h" |
28 #include "third_party/skia/include/core/SkBitmap.h" | 23 #include "third_party/skia/include/core/SkBitmap.h" |
29 #include "third_party/skia/include/core/SkColor.h" | 24 #include "third_party/skia/include/core/SkColor.h" |
30 #include "ui/aura/window_event_dispatcher.h" | 25 #include "ui/aura/window_event_dispatcher.h" |
31 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 26 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
32 #include "ui/compositor/test/layer_animator_test_controller.h" | 27 #include "ui/compositor/test/layer_animator_test_controller.h" |
33 #include "ui/gfx/codec/jpeg_codec.h" | |
34 #include "ui/gfx/point.h" | |
35 #include "ui/gfx/rect.h" | |
36 | 28 |
37 using aura::RootWindow; | 29 using aura::RootWindow; |
38 using aura::Window; | 30 using aura::Window; |
39 | 31 |
40 namespace ash { | 32 namespace ash { |
41 namespace { | 33 namespace { |
42 | 34 |
43 // Containers IDs used for tests. | 35 // Containers IDs used for tests. |
44 const int kDesktopBackgroundId = ash::kShellWindowId_DesktopBackgroundContainer; | 36 const int kDesktopBackgroundId = ash::kShellWindowId_DesktopBackgroundContainer; |
45 const int kLockScreenBackgroundId = | 37 const int kLockScreenBackgroundId = |
46 ash::kShellWindowId_LockScreenBackgroundContainer; | 38 ash::kShellWindowId_LockScreenBackgroundContainer; |
47 | 39 |
48 // Returns number of child windows in a shell window container. | 40 // Returns number of child windows in a shell window container. |
49 int ChildCountForContainer(int container_id) { | 41 int ChildCountForContainer(int container_id) { |
50 Window* root = ash::Shell::GetPrimaryRootWindow(); | 42 Window* root = ash::Shell::GetPrimaryRootWindow(); |
51 Window* container = root->GetChildById(container_id); | 43 Window* container = root->GetChildById(container_id); |
52 return static_cast<int>(container->children().size()); | 44 return static_cast<int>(container->children().size()); |
53 } | 45 } |
54 | 46 |
55 class TestObserver : public DesktopBackgroundControllerObserver { | |
56 public: | |
57 explicit TestObserver(DesktopBackgroundController* controller) | |
58 : controller_(controller) { | |
59 DCHECK(controller_); | |
60 controller_->AddObserver(this); | |
61 } | |
62 | |
63 virtual ~TestObserver() { | |
64 controller_->RemoveObserver(this); | |
65 } | |
66 | |
67 void WaitForWallpaperDataChanged() { | |
68 base::MessageLoop::current()->Run(); | |
69 } | |
70 | |
71 // DesktopBackgroundControllerObserver overrides: | |
72 virtual void OnWallpaperDataChanged() OVERRIDE { | |
73 base::MessageLoop::current()->Quit(); | |
74 } | |
75 | |
76 private: | |
77 DesktopBackgroundController* controller_; | |
78 }; | |
79 | |
80 // Steps a widget's layer animation until it is completed. Animations must be | 47 // Steps a widget's layer animation until it is completed. Animations must be |
81 // enabled. | 48 // enabled. |
82 void RunAnimationForWidget(views::Widget* widget) { | 49 void RunAnimationForWidget(views::Widget* widget) { |
83 // Animations must be enabled for stepping to work. | 50 // Animations must be enabled for stepping to work. |
84 ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(), | 51 ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(), |
85 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); | 52 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); |
86 | 53 |
87 ui::Layer* layer = widget->GetNativeView()->layer(); | 54 ui::Layer* layer = widget->GetNativeView()->layer(); |
88 ui::LayerAnimatorTestController controller(layer->GetAnimator()); | 55 ui::LayerAnimatorTestController controller(layer->GetAnimator()); |
89 gfx::AnimationContainerElement* element = layer->GetAnimator(); | 56 gfx::AnimationContainerElement* element = layer->GetAnimator(); |
90 // Multiple steps are required to complete complex animations. | 57 // Multiple steps are required to complete complex animations. |
91 // TODO(vollick): This should not be necessary. crbug.com/154017 | 58 // TODO(vollick): This should not be necessary. crbug.com/154017 |
92 while (controller.animator()->is_animating()) { | 59 while (controller.animator()->is_animating()) { |
93 controller.StartThreadedAnimationsIfNeeded(); | 60 controller.StartThreadedAnimationsIfNeeded(); |
94 base::TimeTicks step_time = controller.animator()->last_step_time(); | 61 base::TimeTicks step_time = controller.animator()->last_step_time(); |
95 element->Step(step_time + base::TimeDelta::FromMilliseconds(1000)); | 62 element->Step(step_time + base::TimeDelta::FromMilliseconds(1000)); |
96 } | 63 } |
97 } | 64 } |
98 | 65 |
99 } // namespace | 66 } // namespace |
100 | 67 |
101 class DesktopBackgroundControllerTest : public test::AshTestBase { | 68 class DesktopBackgroundControllerTest : public test::AshTestBase { |
102 public: | 69 public: |
103 DesktopBackgroundControllerTest() | 70 DesktopBackgroundControllerTest() |
104 : command_line_(CommandLine::NO_PROGRAM), | 71 : controller_(NULL) { |
105 controller_(NULL) { | |
106 } | 72 } |
107 virtual ~DesktopBackgroundControllerTest() {} | 73 virtual ~DesktopBackgroundControllerTest() {} |
108 | 74 |
109 virtual void SetUp() OVERRIDE { | 75 virtual void SetUp() OVERRIDE { |
110 test::AshTestBase::SetUp(); | 76 test::AshTestBase::SetUp(); |
111 // Ash shell initialization creates wallpaper. Reset it so we can manually | 77 // Ash shell initialization creates wallpaper. Reset it so we can manually |
112 // control wallpaper creation and animation in our tests. | 78 // control wallpaper creation and animation in our tests. |
113 RootWindowController* root_window_controller = | 79 RootWindowController* root_window_controller = |
114 Shell::GetPrimaryRootWindowController(); | 80 Shell::GetPrimaryRootWindowController(); |
115 root_window_controller->SetWallpaperController(NULL); | 81 root_window_controller->SetWallpaperController(NULL); |
116 root_window_controller->SetAnimatingWallpaperController(NULL); | 82 root_window_controller->SetAnimatingWallpaperController(NULL); |
117 controller_ = Shell::GetInstance()->desktop_background_controller(); | 83 controller_ = Shell::GetInstance()->desktop_background_controller(); |
118 wallpaper_delegate_ = static_cast<test::TestUserWallpaperDelegate*>( | 84 wallpaper_delegate_ = static_cast<test::TestUserWallpaperDelegate*>( |
119 Shell::GetInstance()->user_wallpaper_delegate()); | 85 Shell::GetInstance()->user_wallpaper_delegate()); |
120 controller_->set_wallpaper_reload_delay_for_test(0); | 86 controller_->set_wallpaper_reload_delay_for_test(0); |
121 } | 87 } |
122 | 88 |
123 protected: | 89 protected: |
124 // Colors used for different default wallpapers by | |
125 // WriteWallpapersAndSetFlags(). | |
126 static const SkColor kLargeWallpaperColor = SK_ColorRED; | |
127 static const SkColor kSmallWallpaperColor = SK_ColorGREEN; | |
128 static const SkColor kLargeGuestWallpaperColor = SK_ColorBLUE; | |
129 static const SkColor kSmallGuestWallpaperColor = SK_ColorYELLOW; | |
130 | |
131 // A color that can be passed to CreateImage(). Specifically chosen to not | 90 // A color that can be passed to CreateImage(). Specifically chosen to not |
132 // conflict with any of the default wallpaper colors. | 91 // conflict with any of the default wallpaper colors. |
133 static const SkColor kCustomWallpaperColor = SK_ColorMAGENTA; | 92 static const SkColor kCustomWallpaperColor = SK_ColorMAGENTA; |
134 | 93 |
135 // Dimension used for width and height of default wallpaper images. A | |
136 // small value is used to minimize the amount of time spent compressing | |
137 // and writing images. | |
138 static const int kWallpaperSize = 2; | |
139 | |
140 // Creates an image of size |size|. | 94 // Creates an image of size |size|. |
141 gfx::ImageSkia CreateImage(int width, int height, SkColor color) { | 95 gfx::ImageSkia CreateImage(int width, int height, SkColor color) { |
142 SkBitmap bitmap; | 96 SkBitmap bitmap; |
143 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 97 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
144 bitmap.allocPixels(); | 98 bitmap.allocPixels(); |
145 bitmap.eraseColor(color); | 99 bitmap.eraseColor(color); |
146 gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | 100 gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
147 return image; | 101 return image; |
148 } | 102 } |
149 | 103 |
150 // Runs kAnimatingDesktopController's animation to completion. | 104 // Runs kAnimatingDesktopController's animation to completion. |
151 // TODO(bshe): Don't require tests to run animations; it's slow. | 105 // TODO(bshe): Don't require tests to run animations; it's slow. |
152 void RunDesktopControllerAnimation() { | 106 void RunDesktopControllerAnimation() { |
153 DesktopBackgroundWidgetController* controller = | 107 DesktopBackgroundWidgetController* controller = |
154 Shell::GetPrimaryRootWindowController() | 108 Shell::GetPrimaryRootWindowController() |
155 ->animating_wallpaper_controller() | 109 ->animating_wallpaper_controller() |
156 ->GetController(false); | 110 ->GetController(false); |
157 ASSERT_NO_FATAL_FAILURE(RunAnimationForWidget(controller->widget())); | 111 ASSERT_NO_FATAL_FAILURE(RunAnimationForWidget(controller->widget())); |
158 } | 112 } |
159 | 113 |
160 // Returns true if the color at the center of |image| is close to | |
161 // |expected_color|. (The center is used so small wallpaper images can be | |
162 // used.) | |
163 bool ImageIsNearColor(gfx::ImageSkia image, SkColor expected_color) { | |
164 if (image.size().IsEmpty()) { | |
165 LOG(ERROR) << "Image is empty"; | |
166 return false; | |
167 } | |
168 | |
169 const SkBitmap* bitmap = image.bitmap(); | |
170 if (!bitmap) { | |
171 LOG(ERROR) << "Unable to get bitmap from image"; | |
172 return false; | |
173 } | |
174 | |
175 bitmap->lockPixels(); | |
176 gfx::Point center = gfx::Rect(image.size()).CenterPoint(); | |
177 SkColor image_color = bitmap->getColor(center.x(), center.y()); | |
178 bitmap->unlockPixels(); | |
179 | |
180 const int kDiff = 3; | |
181 if (std::abs(static_cast<int>(SkColorGetA(image_color)) - | |
182 static_cast<int>(SkColorGetA(expected_color))) > kDiff || | |
183 std::abs(static_cast<int>(SkColorGetR(image_color)) - | |
184 static_cast<int>(SkColorGetR(expected_color))) > kDiff || | |
185 std::abs(static_cast<int>(SkColorGetG(image_color)) - | |
186 static_cast<int>(SkColorGetG(expected_color))) > kDiff || | |
187 std::abs(static_cast<int>(SkColorGetB(image_color)) - | |
188 static_cast<int>(SkColorGetB(expected_color))) > kDiff) { | |
189 LOG(ERROR) << "Expected color near 0x" << std::hex << expected_color | |
190 << " but got 0x" << image_color; | |
191 return false; | |
192 } | |
193 | |
194 return true; | |
195 } | |
196 | |
197 // Writes a JPEG image of the specified size and color to |path|. Returns | |
198 // true on success. | |
199 bool WriteJPEGFile(const base::FilePath& path, | |
200 int width, | |
201 int height, | |
202 SkColor color) { | |
203 SkBitmap bitmap; | |
204 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, 0); | |
205 bitmap.allocPixels(); | |
206 bitmap.eraseColor(color); | |
207 | |
208 const int kQuality = 80; | |
209 std::vector<unsigned char> output; | |
210 if (!gfx::JPEGCodec::Encode( | |
211 static_cast<const unsigned char*>(bitmap.getPixels()), | |
212 gfx::JPEGCodec::FORMAT_SkBitmap, width, height, bitmap.rowBytes(), | |
213 kQuality, &output)) { | |
214 LOG(ERROR) << "Unable to encode " << width << "x" << height << " bitmap"; | |
215 return false; | |
216 } | |
217 | |
218 size_t bytes_written = base::WriteFile( | |
219 path, reinterpret_cast<const char*>(&output[0]), output.size()); | |
220 if (bytes_written != output.size()) { | |
221 LOG(ERROR) << "Wrote " << bytes_written << " byte(s) instead of " | |
222 << output.size() << " to " << path.value(); | |
223 return false; | |
224 } | |
225 | |
226 return true; | |
227 } | |
228 | |
229 // Initializes |wallpaper_dir_|, writes JPEG wallpaper images to it, and | |
230 // passes |controller_| a command line instructing it to use the images. | |
231 // Only needs to be called (once) by tests that want to test loading of | |
232 // default wallpapers. | |
233 void WriteWallpapersAndSetFlags() { | |
234 wallpaper_dir_.reset(new base::ScopedTempDir); | |
235 ASSERT_TRUE(wallpaper_dir_->CreateUniqueTempDir()); | |
236 | |
237 const base::FilePath kLargePath = | |
238 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("large.jpg")); | |
239 ASSERT_TRUE(WriteJPEGFile(kLargePath, kWallpaperSize, kWallpaperSize, | |
240 kLargeWallpaperColor)); | |
241 command_line_.AppendSwitchPath( | |
242 switches::kAshDefaultWallpaperLarge, kLargePath); | |
243 | |
244 const base::FilePath kSmallPath = | |
245 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("small.jpg")); | |
246 ASSERT_TRUE(WriteJPEGFile(kSmallPath, kWallpaperSize, kWallpaperSize, | |
247 kSmallWallpaperColor)); | |
248 command_line_.AppendSwitchPath( | |
249 switches::kAshDefaultWallpaperSmall, kSmallPath); | |
250 | |
251 const base::FilePath kLargeGuestPath = | |
252 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("guest_large.jpg")); | |
253 ASSERT_TRUE(WriteJPEGFile(kLargeGuestPath, kWallpaperSize, kWallpaperSize, | |
254 kLargeGuestWallpaperColor)); | |
255 command_line_.AppendSwitchPath( | |
256 switches::kAshGuestWallpaperLarge, kLargeGuestPath); | |
257 | |
258 const base::FilePath kSmallGuestPath = | |
259 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("guest_small.jpg")); | |
260 ASSERT_TRUE(WriteJPEGFile(kSmallGuestPath, kWallpaperSize, kWallpaperSize, | |
261 kSmallGuestWallpaperColor)); | |
262 command_line_.AppendSwitchPath( | |
263 switches::kAshGuestWallpaperSmall, kSmallGuestPath); | |
264 | |
265 controller_->set_command_line_for_testing(&command_line_); | |
266 } | |
267 | |
268 // Custom command line passed to DesktopBackgroundController by | |
269 // WriteWallpapersAndSetFlags(). | |
270 CommandLine command_line_; | |
271 | |
272 // Directory created by WriteWallpapersAndSetFlags() to store default | |
273 // wallpaper images. | |
274 scoped_ptr<base::ScopedTempDir> wallpaper_dir_; | |
275 | |
276 DesktopBackgroundController* controller_; // Not owned. | 114 DesktopBackgroundController* controller_; // Not owned. |
277 | 115 |
278 test::TestUserWallpaperDelegate* wallpaper_delegate_; | 116 test::TestUserWallpaperDelegate* wallpaper_delegate_; |
279 | 117 |
280 private: | 118 private: |
281 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundControllerTest); | 119 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundControllerTest); |
282 }; | 120 }; |
283 | 121 |
284 TEST_F(DesktopBackgroundControllerTest, BasicReparenting) { | 122 TEST_F(DesktopBackgroundControllerTest, BasicReparenting) { |
285 DesktopBackgroundController* controller = | 123 DesktopBackgroundController* controller = |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 GetController(false)->widget())); | 269 GetController(false)->widget())); |
432 | 270 |
433 EXPECT_TRUE(root_window_controller->wallpaper_controller()); | 271 EXPECT_TRUE(root_window_controller->wallpaper_controller()); |
434 EXPECT_FALSE(root_window_controller->animating_wallpaper_controller()-> | 272 EXPECT_FALSE(root_window_controller->animating_wallpaper_controller()-> |
435 GetController(false)); | 273 GetController(false)); |
436 // The desktop controller should be the last created animating controller. | 274 // The desktop controller should be the last created animating controller. |
437 EXPECT_EQ(animating_controller, | 275 EXPECT_EQ(animating_controller, |
438 root_window_controller->wallpaper_controller()); | 276 root_window_controller->wallpaper_controller()); |
439 } | 277 } |
440 | 278 |
441 TEST_F(DesktopBackgroundControllerTest, DisplayChange) { | |
442 // TODO(derat|oshima|bshe): Host windows can't be resized on Win8. | |
443 if (!SupportsHostWindowResize()) | |
444 return; | |
445 | |
446 // Set the wallpaper to ensure that UpdateWallpaper() will be called when the | |
447 // display configuration changes. | |
448 gfx::ImageSkia image = CreateImage(640, 480, kCustomWallpaperColor); | |
449 wallpaper_delegate_->set_custom_wallpaper(image); | |
450 controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH); | |
451 | |
452 // Small wallpaper images should be used for configurations less than or | |
453 // equal to kSmallWallpaperMaxWidth by kSmallWallpaperMaxHeight, even if | |
454 // multiple displays are connected. | |
455 test::DisplayManagerTestApi display_manager_test_api( | |
456 Shell::GetInstance()->display_manager()); | |
457 display_manager_test_api.UpdateDisplay("800x600"); | |
458 RunAllPendingInMessageLoop(); | |
459 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, | |
460 controller_->GetAppropriateResolution()); | |
461 EXPECT_EQ(0, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
462 | |
463 display_manager_test_api.UpdateDisplay("800x600,800x600"); | |
464 RunAllPendingInMessageLoop(); | |
465 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, | |
466 controller_->GetAppropriateResolution()); | |
467 EXPECT_EQ(0, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
468 | |
469 display_manager_test_api.UpdateDisplay("1366x800"); | |
470 RunAllPendingInMessageLoop(); | |
471 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, | |
472 controller_->GetAppropriateResolution()); | |
473 EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
474 | |
475 // At larger sizes, large wallpapers should be used. | |
476 display_manager_test_api.UpdateDisplay("1367x800"); | |
477 RunAllPendingInMessageLoop(); | |
478 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, | |
479 controller_->GetAppropriateResolution()); | |
480 EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
481 | |
482 display_manager_test_api.UpdateDisplay("1367x801"); | |
483 RunAllPendingInMessageLoop(); | |
484 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, | |
485 controller_->GetAppropriateResolution()); | |
486 EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
487 | |
488 display_manager_test_api.UpdateDisplay("2560x1700"); | |
489 RunAllPendingInMessageLoop(); | |
490 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, | |
491 controller_->GetAppropriateResolution()); | |
492 EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
493 | |
494 // Rotated smaller screen may use larger image. | |
495 display_manager_test_api.UpdateDisplay("800x600/r"); | |
496 RunAllPendingInMessageLoop(); | |
497 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, | |
498 controller_->GetAppropriateResolution()); | |
499 EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
500 | |
501 display_manager_test_api.UpdateDisplay("800x600/r,800x600"); | |
502 RunAllPendingInMessageLoop(); | |
503 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, | |
504 controller_->GetAppropriateResolution()); | |
505 EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
506 display_manager_test_api.UpdateDisplay("1366x800/r"); | |
507 RunAllPendingInMessageLoop(); | |
508 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, | |
509 controller_->GetAppropriateResolution()); | |
510 EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
511 | |
512 // Max display size didn't chagne. | |
513 display_manager_test_api.UpdateDisplay("900x800/r,400x1366"); | |
514 RunAllPendingInMessageLoop(); | |
515 EXPECT_EQ(0, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); | |
516 } | |
517 | |
518 // Test that DesktopBackgroundController loads the appropriate wallpaper | |
519 // images as specified via command-line flags in various situations. | |
520 // Splitting these into separate tests avoids needing to run animations. | |
521 // TODO(derat): Combine these into a single test -- see | |
522 // RunDesktopControllerAnimation()'s TODO. | |
523 TEST_F(DesktopBackgroundControllerTest, SmallDefaultWallpaper) { | |
524 if (!SupportsMultipleDisplays()) | |
525 return; | |
526 | |
527 WriteWallpapersAndSetFlags(); | |
528 TestObserver observer(controller_); | |
529 | |
530 // At 800x600, the small wallpaper should be loaded. | |
531 test::DisplayManagerTestApi display_manager_test_api( | |
532 Shell::GetInstance()->display_manager()); | |
533 display_manager_test_api.UpdateDisplay("800x600"); | |
534 ASSERT_TRUE(controller_->SetDefaultWallpaper(false)); | |
535 observer.WaitForWallpaperDataChanged(); | |
536 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), | |
537 kSmallWallpaperColor)); | |
538 | |
539 // Requesting the same wallpaper again should be a no-op. | |
540 ASSERT_FALSE(controller_->SetDefaultWallpaper(false)); | |
541 } | |
542 | |
543 TEST_F(DesktopBackgroundControllerTest, LargeDefaultWallpaper) { | |
544 if (!SupportsMultipleDisplays()) | |
545 return; | |
546 | |
547 WriteWallpapersAndSetFlags(); | |
548 TestObserver observer(controller_); | |
549 test::DisplayManagerTestApi display_manager_test_api( | |
550 Shell::GetInstance()->display_manager()); | |
551 display_manager_test_api.UpdateDisplay("1600x1200"); | |
552 ASSERT_TRUE(controller_->SetDefaultWallpaper(false)); | |
553 observer.WaitForWallpaperDataChanged(); | |
554 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), | |
555 kLargeWallpaperColor)); | |
556 } | |
557 | |
558 TEST_F(DesktopBackgroundControllerTest, LargeDefaultWallpaperWhenRotated) { | |
559 if (!SupportsMultipleDisplays()) | |
560 return; | |
561 WriteWallpapersAndSetFlags(); | |
562 TestObserver observer(controller_); | |
563 test::DisplayManagerTestApi display_manager_test_api( | |
564 Shell::GetInstance()->display_manager()); | |
565 | |
566 display_manager_test_api.UpdateDisplay("1200x800/r"); | |
567 ASSERT_TRUE(controller_->SetDefaultWallpaper(false)); | |
568 observer.WaitForWallpaperDataChanged(); | |
569 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), | |
570 kLargeWallpaperColor)); | |
571 } | |
572 | |
573 TEST_F(DesktopBackgroundControllerTest, SmallGuestWallpaper) { | |
574 if (!SupportsMultipleDisplays()) | |
575 return; | |
576 | |
577 WriteWallpapersAndSetFlags(); | |
578 TestObserver observer(controller_); | |
579 test::DisplayManagerTestApi display_manager_test_api( | |
580 Shell::GetInstance()->display_manager()); | |
581 display_manager_test_api.UpdateDisplay("800x600"); | |
582 ASSERT_TRUE(controller_->SetDefaultWallpaper(true)); | |
583 observer.WaitForWallpaperDataChanged(); | |
584 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), | |
585 kSmallGuestWallpaperColor)); | |
586 } | |
587 | |
588 TEST_F(DesktopBackgroundControllerTest, LargeGuestWallpaper) { | |
589 if (!SupportsMultipleDisplays()) | |
590 return; | |
591 | |
592 WriteWallpapersAndSetFlags(); | |
593 TestObserver observer(controller_); | |
594 test::DisplayManagerTestApi display_manager_test_api( | |
595 Shell::GetInstance()->display_manager()); | |
596 display_manager_test_api.UpdateDisplay("1600x1200"); | |
597 ASSERT_TRUE(controller_->SetDefaultWallpaper(true)); | |
598 observer.WaitForWallpaperDataChanged(); | |
599 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), | |
600 kLargeGuestWallpaperColor)); | |
601 } | |
602 | |
603 TEST_F(DesktopBackgroundControllerTest, ResizeCustomWallpaper) { | 279 TEST_F(DesktopBackgroundControllerTest, ResizeCustomWallpaper) { |
604 if (!SupportsMultipleDisplays()) | 280 if (!SupportsMultipleDisplays()) |
605 return; | 281 return; |
606 | 282 |
607 test::DisplayManagerTestApi display_manager_test_api( | 283 test::DisplayManagerTestApi display_manager_test_api( |
608 Shell::GetInstance()->display_manager()); | 284 Shell::GetInstance()->display_manager()); |
609 display_manager_test_api.UpdateDisplay("320x200"); | 285 display_manager_test_api.UpdateDisplay("320x200"); |
610 | 286 |
611 gfx::ImageSkia image = CreateImage(640, 480, kCustomWallpaperColor); | 287 gfx::ImageSkia image = CreateImage(640, 480, kCustomWallpaperColor); |
612 | 288 |
613 // Set the image as custom wallpaper, wait for the resize to finish, and check | 289 // Set the image as custom wallpaper, wait for the resize to finish, and check |
614 // that the resized image is the expected size. | 290 // that the resized image is the expected size. |
615 controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH); | 291 controller_->SetWallpaperImage(image, WALLPAPER_LAYOUT_STRETCH); |
616 EXPECT_TRUE(image.BackedBySameObjectAs(controller_->GetWallpaper())); | 292 EXPECT_TRUE(image.BackedBySameObjectAs(controller_->GetWallpaper())); |
617 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 293 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
618 content::RunAllPendingInMessageLoop(); | 294 content::RunAllPendingInMessageLoop(); |
619 gfx::ImageSkia resized_image = controller_->GetWallpaper(); | 295 gfx::ImageSkia resized_image = controller_->GetWallpaper(); |
620 EXPECT_FALSE(image.BackedBySameObjectAs(resized_image)); | 296 EXPECT_FALSE(image.BackedBySameObjectAs(resized_image)); |
621 EXPECT_EQ(gfx::Size(320, 200).ToString(), resized_image.size().ToString()); | 297 EXPECT_EQ(gfx::Size(320, 200).ToString(), resized_image.size().ToString()); |
622 | 298 |
623 // Load the original wallpaper again and check that we're still using the | 299 // Load the original wallpaper again and check that we're still using the |
624 // previously-resized image instead of doing another resize | 300 // previously-resized image instead of doing another resize |
625 // (http://crbug.com/321402). | 301 // (http://crbug.com/321402). |
626 controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH); | 302 controller_->SetWallpaperImage(image, WALLPAPER_LAYOUT_STRETCH); |
627 content::BrowserThread::GetBlockingPool()->FlushForTesting(); | 303 content::BrowserThread::GetBlockingPool()->FlushForTesting(); |
628 content::RunAllPendingInMessageLoop(); | 304 content::RunAllPendingInMessageLoop(); |
629 EXPECT_TRUE(resized_image.BackedBySameObjectAs(controller_->GetWallpaper())); | 305 EXPECT_TRUE(resized_image.BackedBySameObjectAs(controller_->GetWallpaper())); |
630 } | 306 } |
631 | 307 |
632 TEST_F(DesktopBackgroundControllerTest, GetMaxDisplaySize) { | 308 TEST_F(DesktopBackgroundControllerTest, GetMaxDisplaySize) { |
633 // Device scale factor shouldn't affect the native size. | 309 // Device scale factor shouldn't affect the native size. |
634 UpdateDisplay("1000x300*2"); | 310 UpdateDisplay("1000x300*2"); |
635 EXPECT_EQ( | 311 EXPECT_EQ( |
636 "1000x300", | 312 "1000x300", |
(...skipping 26 matching lines...) Expand all Loading... |
663 "500x600", | 339 "500x600", |
664 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); | 340 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); |
665 | 341 |
666 // Maximum width and height belongs to different displays. | 342 // Maximum width and height belongs to different displays. |
667 UpdateDisplay("400x300,100x500"); | 343 UpdateDisplay("400x300,100x500"); |
668 EXPECT_EQ( | 344 EXPECT_EQ( |
669 "400x500", | 345 "400x500", |
670 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); | 346 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); |
671 } | 347 } |
672 | 348 |
673 TEST_F(DesktopBackgroundControllerTest, SwitchBetweenDefaultAndCustom) { | |
674 // Start loading the default wallpaper. | |
675 UpdateDisplay("640x480"); | |
676 WriteWallpapersAndSetFlags(); | |
677 ASSERT_TRUE(controller_->SetDefaultWallpaper(false)); | |
678 | |
679 // Custom wallpaper should be applied immediately, canceling the default | |
680 // wallpaper load task. | |
681 gfx::ImageSkia image = CreateImage(640, 480, kCustomWallpaperColor); | |
682 controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH); | |
683 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), | |
684 kCustomWallpaperColor)); | |
685 | |
686 // A call to SetDefaultWallpaper() should return true now, indicating that a | |
687 // new load task was started (since the previous one was interrupted by | |
688 // SetCustomWallpaper()). See http://crbug.com/327443. | |
689 TestObserver observer(controller_); | |
690 ASSERT_TRUE(controller_->SetDefaultWallpaper(false)); | |
691 observer.WaitForWallpaperDataChanged(); | |
692 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), | |
693 kSmallWallpaperColor)); | |
694 } | |
695 | 349 |
696 } // namespace ash | 350 } // namespace ash |
OLD | NEW |