Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(416)

Side by Side Diff: ash/desktop_background/desktop_background_controller_unittest.cc

Issue 208273005: If customization includes default wallpaper, download and apply it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Update after-review. Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 = 36 const int kDesktopBackgroundId =
45 ash::internal::kShellWindowId_DesktopBackgroundContainer; 37 ash::internal::kShellWindowId_DesktopBackgroundContainer;
46 const int kLockScreenBackgroundId = 38 const int kLockScreenBackgroundId =
47 ash::internal::kShellWindowId_LockScreenBackgroundContainer; 39 ash::internal::kShellWindowId_LockScreenBackgroundContainer;
48 40
49 // Returns number of child windows in a shell window container. 41 // Returns number of child windows in a shell window container.
50 int ChildCountForContainer(int container_id) { 42 int ChildCountForContainer(int container_id) {
51 Window* root = ash::Shell::GetPrimaryRootWindow(); 43 Window* root = ash::Shell::GetPrimaryRootWindow();
52 Window* container = root->GetChildById(container_id); 44 Window* container = root->GetChildById(container_id);
53 return static_cast<int>(container->children().size()); 45 return static_cast<int>(container->children().size());
54 } 46 }
55 47
56 class TestObserver : public DesktopBackgroundControllerObserver {
57 public:
58 explicit TestObserver(DesktopBackgroundController* controller)
59 : controller_(controller) {
60 DCHECK(controller_);
61 controller_->AddObserver(this);
62 }
63
64 virtual ~TestObserver() {
65 controller_->RemoveObserver(this);
66 }
67
68 void WaitForWallpaperDataChanged() {
69 base::MessageLoop::current()->Run();
70 }
71
72 // DesktopBackgroundControllerObserver overrides:
73 virtual void OnWallpaperDataChanged() OVERRIDE {
74 base::MessageLoop::current()->Quit();
75 }
76
77 private:
78 DesktopBackgroundController* controller_;
79 };
80
81 // Steps a widget's layer animation until it is completed. Animations must be 48 // Steps a widget's layer animation until it is completed. Animations must be
82 // enabled. 49 // enabled.
83 void RunAnimationForWidget(views::Widget* widget) { 50 void RunAnimationForWidget(views::Widget* widget) {
84 // Animations must be enabled for stepping to work. 51 // Animations must be enabled for stepping to work.
85 ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(), 52 ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(),
86 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); 53 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
87 54
88 ui::Layer* layer = widget->GetNativeView()->layer(); 55 ui::Layer* layer = widget->GetNativeView()->layer();
89 ui::LayerAnimatorTestController controller(layer->GetAnimator()); 56 ui::LayerAnimatorTestController controller(layer->GetAnimator());
90 gfx::AnimationContainerElement* element = layer->GetAnimator(); 57 gfx::AnimationContainerElement* element = layer->GetAnimator();
91 // Multiple steps are required to complete complex animations. 58 // Multiple steps are required to complete complex animations.
92 // TODO(vollick): This should not be necessary. crbug.com/154017 59 // TODO(vollick): This should not be necessary. crbug.com/154017
93 while (controller.animator()->is_animating()) { 60 while (controller.animator()->is_animating()) {
94 controller.StartThreadedAnimationsIfNeeded(); 61 controller.StartThreadedAnimationsIfNeeded();
95 base::TimeTicks step_time = controller.animator()->last_step_time(); 62 base::TimeTicks step_time = controller.animator()->last_step_time();
96 element->Step(step_time + base::TimeDelta::FromMilliseconds(1000)); 63 element->Step(step_time + base::TimeDelta::FromMilliseconds(1000));
97 } 64 }
98 } 65 }
99 66
100 } // namespace 67 } // namespace
101 68
102 class DesktopBackgroundControllerTest : public test::AshTestBase { 69 class DesktopBackgroundControllerTest : public test::AshTestBase {
103 public: 70 public:
104 DesktopBackgroundControllerTest() 71 DesktopBackgroundControllerTest()
105 : command_line_(CommandLine::NO_PROGRAM), 72 : controller_(NULL) {
106 controller_(NULL) {
107 } 73 }
108 virtual ~DesktopBackgroundControllerTest() {} 74 virtual ~DesktopBackgroundControllerTest() {}
109 75
110 virtual void SetUp() OVERRIDE { 76 virtual void SetUp() OVERRIDE {
111 test::AshTestBase::SetUp(); 77 test::AshTestBase::SetUp();
112 // Ash shell initialization creates wallpaper. Reset it so we can manually 78 // Ash shell initialization creates wallpaper. Reset it so we can manually
113 // control wallpaper creation and animation in our tests. 79 // control wallpaper creation and animation in our tests.
114 internal::RootWindowController* root_window_controller = 80 internal::RootWindowController* root_window_controller =
115 Shell::GetPrimaryRootWindowController(); 81 Shell::GetPrimaryRootWindowController();
116 root_window_controller->SetWallpaperController(NULL); 82 root_window_controller->SetWallpaperController(NULL);
117 root_window_controller->SetAnimatingWallpaperController(NULL); 83 root_window_controller->SetAnimatingWallpaperController(NULL);
118 controller_ = Shell::GetInstance()->desktop_background_controller(); 84 controller_ = Shell::GetInstance()->desktop_background_controller();
119 wallpaper_delegate_ = static_cast<test::TestUserWallpaperDelegate*>( 85 wallpaper_delegate_ = static_cast<test::TestUserWallpaperDelegate*>(
120 Shell::GetInstance()->user_wallpaper_delegate()); 86 Shell::GetInstance()->user_wallpaper_delegate());
121 controller_->set_wallpaper_reload_delay_for_test(0); 87 controller_->set_wallpaper_reload_delay_for_test(0);
122 } 88 }
123 89
124 protected: 90 protected:
125 // Colors used for different default wallpapers by
126 // WriteWallpapersAndSetFlags().
127 static const SkColor kLargeWallpaperColor = SK_ColorRED;
128 static const SkColor kSmallWallpaperColor = SK_ColorGREEN;
129 static const SkColor kLargeGuestWallpaperColor = SK_ColorBLUE;
130 static const SkColor kSmallGuestWallpaperColor = SK_ColorYELLOW;
131
132 // A color that can be passed to CreateImage(). Specifically chosen to not 91 // A color that can be passed to CreateImage(). Specifically chosen to not
133 // conflict with any of the default wallpaper colors. 92 // conflict with any of the default wallpaper colors.
134 static const SkColor kCustomWallpaperColor = SK_ColorMAGENTA; 93 static const SkColor kCustomWallpaperColor = SK_ColorMAGENTA;
135 94
136 // Dimension used for width and height of default wallpaper images. A
137 // small value is used to minimize the amount of time spent compressing
138 // and writing images.
139 static const int kWallpaperSize = 2;
140
141 // Creates an image of size |size|. 95 // Creates an image of size |size|.
142 gfx::ImageSkia CreateImage(int width, int height, SkColor color) { 96 gfx::ImageSkia CreateImage(int width, int height, SkColor color) {
143 SkBitmap bitmap; 97 SkBitmap bitmap;
144 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); 98 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height);
145 bitmap.allocPixels(); 99 bitmap.allocPixels();
146 bitmap.eraseColor(color); 100 bitmap.eraseColor(color);
147 gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); 101 gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
148 return image; 102 return image;
149 } 103 }
150 104
151 // Runs kAnimatingDesktopController's animation to completion. 105 // Runs kAnimatingDesktopController's animation to completion.
152 // TODO(bshe): Don't require tests to run animations; it's slow. 106 // TODO(bshe): Don't require tests to run animations; it's slow.
153 void RunDesktopControllerAnimation() { 107 void RunDesktopControllerAnimation() {
154 internal::DesktopBackgroundWidgetController* controller = 108 internal::DesktopBackgroundWidgetController* controller =
155 Shell::GetPrimaryRootWindowController()-> 109 Shell::GetPrimaryRootWindowController()->
156 animating_wallpaper_controller()->GetController(false); 110 animating_wallpaper_controller()->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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 278
441 TEST_F(DesktopBackgroundControllerTest, DisplayChange) { 279 TEST_F(DesktopBackgroundControllerTest, DisplayChange) {
442 // TODO(derat|oshima|bshe): Host windows can't be resized on Win8. 280 // TODO(derat|oshima|bshe): Host windows can't be resized on Win8.
443 if (!SupportsHostWindowResize()) 281 if (!SupportsHostWindowResize())
444 return; 282 return;
445 283
446 // Set the wallpaper to ensure that UpdateWallpaper() will be called when the 284 // Set the wallpaper to ensure that UpdateWallpaper() will be called when the
447 // display configuration changes. 285 // display configuration changes.
448 gfx::ImageSkia image = CreateImage(640, 480, kCustomWallpaperColor); 286 gfx::ImageSkia image = CreateImage(640, 480, kCustomWallpaperColor);
449 wallpaper_delegate_->set_custom_wallpaper(image); 287 wallpaper_delegate_->set_custom_wallpaper(image);
450 controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH); 288 controller_->SetWallpaper(image, WALLPAPER_LAYOUT_STRETCH);
451 289
452 // Small wallpaper images should be used for configurations less than or 290 // Small wallpaper images should be used for configurations less than or
453 // equal to kSmallWallpaperMaxWidth by kSmallWallpaperMaxHeight, even if 291 // equal to kSmallWallpaperMaxWidth by kSmallWallpaperMaxHeight, even if
454 // multiple displays are connected. 292 // multiple displays are connected.
455 test::DisplayManagerTestApi display_manager_test_api( 293 test::DisplayManagerTestApi display_manager_test_api(
456 Shell::GetInstance()->display_manager()); 294 Shell::GetInstance()->display_manager());
457 display_manager_test_api.UpdateDisplay("800x600"); 295 display_manager_test_api.UpdateDisplay("800x600");
458 RunAllPendingInMessageLoop(); 296 RunAllPendingInMessageLoop();
459 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL, 297 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL,
460 controller_->GetAppropriateResolution()); 298 controller_->GetAppropriateResolution());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE, 346 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE,
509 controller_->GetAppropriateResolution()); 347 controller_->GetAppropriateResolution());
510 EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); 348 EXPECT_EQ(1, wallpaper_delegate_->GetUpdateWallpaperCountAndReset());
511 349
512 // Max display size didn't chagne. 350 // Max display size didn't chagne.
513 display_manager_test_api.UpdateDisplay("900x800/r,400x1366"); 351 display_manager_test_api.UpdateDisplay("900x800/r,400x1366");
514 RunAllPendingInMessageLoop(); 352 RunAllPendingInMessageLoop();
515 EXPECT_EQ(0, wallpaper_delegate_->GetUpdateWallpaperCountAndReset()); 353 EXPECT_EQ(0, wallpaper_delegate_->GetUpdateWallpaperCountAndReset());
516 } 354 }
517 355
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 356
603 TEST_F(DesktopBackgroundControllerTest, ResizeCustomWallpaper) { 357 TEST_F(DesktopBackgroundControllerTest, ResizeCustomWallpaper) {
604 if (!SupportsMultipleDisplays()) 358 if (!SupportsMultipleDisplays())
605 return; 359 return;
606 360
607 test::DisplayManagerTestApi display_manager_test_api( 361 test::DisplayManagerTestApi display_manager_test_api(
608 Shell::GetInstance()->display_manager()); 362 Shell::GetInstance()->display_manager());
609 display_manager_test_api.UpdateDisplay("320x200"); 363 display_manager_test_api.UpdateDisplay("320x200");
610 364
611 gfx::ImageSkia image = CreateImage(640, 480, kCustomWallpaperColor); 365 gfx::ImageSkia image = CreateImage(640, 480, kCustomWallpaperColor);
612 366
613 // Set the image as custom wallpaper, wait for the resize to finish, and check 367 // Set the image as custom wallpaper, wait for the resize to finish, and check
614 // that the resized image is the expected size. 368 // that the resized image is the expected size.
615 controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH); 369 controller_->SetWallpaper(image, WALLPAPER_LAYOUT_STRETCH);
616 EXPECT_TRUE(image.BackedBySameObjectAs(controller_->GetWallpaper())); 370 EXPECT_TRUE(image.BackedBySameObjectAs(controller_->GetWallpaper()));
617 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 371 content::BrowserThread::GetBlockingPool()->FlushForTesting();
618 content::RunAllPendingInMessageLoop(); 372 content::RunAllPendingInMessageLoop();
619 gfx::ImageSkia resized_image = controller_->GetWallpaper(); 373 gfx::ImageSkia resized_image = controller_->GetWallpaper();
620 EXPECT_FALSE(image.BackedBySameObjectAs(resized_image)); 374 EXPECT_FALSE(image.BackedBySameObjectAs(resized_image));
621 EXPECT_EQ(gfx::Size(320, 200).ToString(), resized_image.size().ToString()); 375 EXPECT_EQ(gfx::Size(320, 200).ToString(), resized_image.size().ToString());
622 376
623 // Load the original wallpaper again and check that we're still using the 377 // Load the original wallpaper again and check that we're still using the
624 // previously-resized image instead of doing another resize 378 // previously-resized image instead of doing another resize
625 // (http://crbug.com/321402). 379 // (http://crbug.com/321402).
626 controller_->SetCustomWallpaper(image, WALLPAPER_LAYOUT_STRETCH); 380 controller_->SetWallpaper(image, WALLPAPER_LAYOUT_STRETCH);
627 content::BrowserThread::GetBlockingPool()->FlushForTesting(); 381 content::BrowserThread::GetBlockingPool()->FlushForTesting();
628 content::RunAllPendingInMessageLoop(); 382 content::RunAllPendingInMessageLoop();
629 EXPECT_TRUE(resized_image.BackedBySameObjectAs(controller_->GetWallpaper())); 383 EXPECT_TRUE(resized_image.BackedBySameObjectAs(controller_->GetWallpaper()));
630 } 384 }
631 385
632 TEST_F(DesktopBackgroundControllerTest, GetMaxDisplaySize) { 386 TEST_F(DesktopBackgroundControllerTest, GetMaxDisplaySize) {
633 // Device scale factor shouldn't affect the native size. 387 // Device scale factor shouldn't affect the native size.
634 UpdateDisplay("1000x300*2"); 388 UpdateDisplay("1000x300*2");
635 EXPECT_EQ( 389 EXPECT_EQ(
636 "1000x300", 390 "1000x300",
(...skipping 26 matching lines...) Expand all
663 "500x600", 417 "500x600",
664 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); 418 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString());
665 419
666 // Maximum width and height belongs to different displays. 420 // Maximum width and height belongs to different displays.
667 UpdateDisplay("400x300,100x500"); 421 UpdateDisplay("400x300,100x500");
668 EXPECT_EQ( 422 EXPECT_EQ(
669 "400x500", 423 "400x500",
670 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString()); 424 DesktopBackgroundController::GetMaxDisplaySizeInNative().ToString());
671 } 425 }
672 426
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 427
696 } // namespace ash 428 } // namespace ash
OLDNEW
« no previous file with comments | « ash/desktop_background/desktop_background_controller.cc ('k') | ash/test/test_user_wallpaper_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698