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

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

Issue 17502005: Revert r207560 and r207566 to reland r207511. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add more SupportsMultipleDisplays checks Created 7 years, 6 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 | Annotate | Revision Log
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>
8 #include <cstdlib>
9
10 #include "ash/ash_switches.h"
11 #include "ash/desktop_background/desktop_background_controller_observer.h"
7 #include "ash/desktop_background/desktop_background_widget_controller.h" 12 #include "ash/desktop_background/desktop_background_widget_controller.h"
8 #include "ash/shell.h" 13 #include "ash/shell.h"
9 #include "ash/shell_window_ids.h" 14 #include "ash/shell_window_ids.h"
10 #include "ash/test/ash_test_base.h" 15 #include "ash/test/ash_test_base.h"
16 #include "ash/test/display_manager_test_api.h"
17 #include "base/command_line.h"
18 #include "base/file_util.h"
19 #include "base/files/file_path.h"
20 #include "base/files/scoped_temp_dir.h"
21 #include "base/message_loop/message_loop.h"
22 #include "content/public/test/test_browser_thread.h"
23 #include "third_party/skia/include/core/SkBitmap.h"
24 #include "third_party/skia/include/core/SkColor.h"
11 #include "ui/aura/root_window.h" 25 #include "ui/aura/root_window.h"
12 #include "ui/compositor/scoped_animation_duration_scale_mode.h" 26 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
13 #include "ui/compositor/test/layer_animator_test_controller.h" 27 #include "ui/compositor/test/layer_animator_test_controller.h"
28 #include "ui/gfx/codec/jpeg_codec.h"
29 #include "ui/gfx/point.h"
30 #include "ui/gfx/rect.h"
14 31
15 using aura::RootWindow; 32 using aura::RootWindow;
16 using aura::Window; 33 using aura::Window;
17 34
35 namespace ash {
36 namespace internal {
37
18 namespace { 38 namespace {
19 39
20 // Containers IDs used for tests. 40 // Containers IDs used for tests.
21 const int kDesktopBackgroundId = 41 const int kDesktopBackgroundId =
22 ash::internal::kShellWindowId_DesktopBackgroundContainer; 42 ash::internal::kShellWindowId_DesktopBackgroundContainer;
23 const int kLockScreenBackgroundId = 43 const int kLockScreenBackgroundId =
24 ash::internal::kShellWindowId_LockScreenBackgroundContainer; 44 ash::internal::kShellWindowId_LockScreenBackgroundContainer;
25 45
26 // Returns number of child windows in a shell window container. 46 // Returns number of child windows in a shell window container.
27 int ChildCountForContainer(int container_id) { 47 int ChildCountForContainer(int container_id) {
28 RootWindow* root = ash::Shell::GetPrimaryRootWindow(); 48 RootWindow* root = ash::Shell::GetPrimaryRootWindow();
29 Window* container = root->GetChildById(container_id); 49 Window* container = root->GetChildById(container_id);
30 return static_cast<int>(container->children().size()); 50 return static_cast<int>(container->children().size());
31 } 51 }
32 52
53 class TestObserver : public DesktopBackgroundControllerObserver {
54 public:
55 explicit TestObserver(DesktopBackgroundController* controller)
56 : controller_(controller) {
57 DCHECK(controller_);
58 controller_->AddObserver(this);
59 }
60
61 virtual ~TestObserver() {
62 controller_->RemoveObserver(this);
63 }
64
65 void WaitForWallpaperDataChanged() {
66 base::MessageLoop::current()->Run();
67 }
68
69 // DesktopBackgroundControllerObserver overrides:
70 virtual void OnWallpaperDataChanged() OVERRIDE {
71 base::MessageLoop::current()->Quit();
72 }
73
74 private:
75 DesktopBackgroundController* controller_;
76 };
77
33 // Steps a widget's layer animation until it is completed. Animations must be 78 // Steps a widget's layer animation until it is completed. Animations must be
34 // enabled. 79 // enabled.
35 void RunAnimationForWidget(views::Widget* widget) { 80 void RunAnimationForWidget(views::Widget* widget) {
36 // Animations must be enabled for stepping to work. 81 // Animations must be enabled for stepping to work.
37 ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(), 82 ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(),
38 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); 83 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION);
39 84
40 ui::Layer* layer = widget->GetNativeView()->layer(); 85 ui::Layer* layer = widget->GetNativeView()->layer();
41 ui::LayerAnimatorTestController controller(layer->GetAnimator()); 86 ui::LayerAnimatorTestController controller(layer->GetAnimator());
42 ui::AnimationContainerElement* element = layer->GetAnimator(); 87 ui::AnimationContainerElement* element = layer->GetAnimator();
43 // Multiple steps are required to complete complex animations. 88 // Multiple steps are required to complete complex animations.
44 // TODO(vollick): This should not be necessary. crbug.com/154017 89 // TODO(vollick): This should not be necessary. crbug.com/154017
45 while (controller.animator()->is_animating()) { 90 while (controller.animator()->is_animating()) {
46 controller.StartThreadedAnimationsIfNeeded(); 91 controller.StartThreadedAnimationsIfNeeded();
47 base::TimeTicks step_time = controller.animator()->last_step_time(); 92 base::TimeTicks step_time = controller.animator()->last_step_time();
48 element->Step(step_time + base::TimeDelta::FromMilliseconds(1000)); 93 element->Step(step_time + base::TimeDelta::FromMilliseconds(1000));
49 } 94 }
50 } 95 }
51 96
52 } // namespace 97 } // namespace
53 98
54 namespace ash {
55 namespace internal {
56
57 class DesktopBackgroundControllerTest : public test::AshTestBase { 99 class DesktopBackgroundControllerTest : public test::AshTestBase {
58 public: 100 public:
59 DesktopBackgroundControllerTest() {} 101 DesktopBackgroundControllerTest()
102 : ui_thread_(content::BrowserThread::UI, base::MessageLoop::current()),
103 command_line_(CommandLine::NO_PROGRAM),
104 controller_(NULL) {
105 }
60 virtual ~DesktopBackgroundControllerTest() {} 106 virtual ~DesktopBackgroundControllerTest() {}
61 107
62 virtual void SetUp() OVERRIDE { 108 virtual void SetUp() OVERRIDE {
63 test::AshTestBase::SetUp(); 109 test::AshTestBase::SetUp();
64 // Ash shell initialization creates wallpaper. Reset it so we can manually 110 // Ash shell initialization creates wallpaper. Reset it so we can manually
65 // control wallpaper creation and animation in our tests. 111 // control wallpaper creation and animation in our tests.
66 RootWindow* root = Shell::GetPrimaryRootWindow(); 112 RootWindow* root = Shell::GetPrimaryRootWindow();
67 root->SetProperty(kDesktopController, 113 root->SetProperty(kDesktopController,
68 static_cast<DesktopBackgroundWidgetController*>(NULL)); 114 static_cast<DesktopBackgroundWidgetController*>(NULL));
69 root->SetProperty(kAnimatingDesktopController, 115 root->SetProperty(kAnimatingDesktopController,
70 static_cast<AnimatingDesktopController*>(NULL)); 116 static_cast<AnimatingDesktopController*>(NULL));
117
118 controller_ = Shell::GetInstance()->desktop_background_controller();
71 } 119 }
72 120
121 protected:
122 // Colors used for different default wallpapers by
123 // WriteWallpapersAndSetFlags().
124 static const SkColor kLargeWallpaperColor = SK_ColorRED;
125 static const SkColor kSmallWallpaperColor = SK_ColorGREEN;
126 static const SkColor kLargeGuestWallpaperColor = SK_ColorBLUE;
127 static const SkColor kSmallGuestWallpaperColor = SK_ColorYELLOW;
128
129 // Dimension used for width and height of default wallpaper images. A
130 // small value is used to minimize the amount of time spent compressing
131 // and writing images.
132 static const int kWallpaperSize = 2;
133
134 // Runs kAnimatingDesktopController's animation to completion.
135 // TODO(bshe): Don't require tests to run animations; it's slow.
136 void RunDesktopControllerAnimation() {
137 RootWindow* root = Shell::GetPrimaryRootWindow();
138 DesktopBackgroundWidgetController* controller =
139 root->GetProperty(kAnimatingDesktopController)->GetController(false);
140 ASSERT_NO_FATAL_FAILURE(RunAnimationForWidget(controller->widget()));
141 }
142
143 // Returns true if the color at the center of |image| is close to
144 // |expected_color|. (The center is used so small wallpaper images can be
145 // used.)
146 bool ImageIsNearColor(gfx::ImageSkia image, SkColor expected_color) {
147 if (image.size().IsEmpty()) {
148 LOG(ERROR) << "Image is empty";
149 return false;
150 }
151
152 const SkBitmap* bitmap = image.bitmap();
153 if (!bitmap) {
154 LOG(ERROR) << "Unable to get bitmap from image";
155 return false;
156 }
157
158 bitmap->lockPixels();
159 gfx::Point center = gfx::Rect(image.size()).CenterPoint();
160 SkColor image_color = bitmap->getColor(center.x(), center.y());
161 bitmap->unlockPixels();
162
163 const int kDiff = 3;
164 if (std::abs(static_cast<int>(SkColorGetA(image_color)) -
165 static_cast<int>(SkColorGetA(expected_color))) > kDiff ||
166 std::abs(static_cast<int>(SkColorGetR(image_color)) -
167 static_cast<int>(SkColorGetR(expected_color))) > kDiff ||
168 std::abs(static_cast<int>(SkColorGetG(image_color)) -
169 static_cast<int>(SkColorGetG(expected_color))) > kDiff ||
170 std::abs(static_cast<int>(SkColorGetB(image_color)) -
171 static_cast<int>(SkColorGetB(expected_color))) > kDiff) {
172 LOG(ERROR) << "Expected color near 0x" << std::hex << expected_color
173 << " but got 0x" << image_color;
174 return false;
175 }
176
177 return true;
178 }
179
180 // Writes a JPEG image of the specified size and color to |path|. Returns
181 // true on success.
182 bool WriteJPEGFile(const base::FilePath& path,
183 int width,
184 int height,
185 SkColor color) {
186 SkBitmap bitmap;
187 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height, 0);
188 bitmap.allocPixels();
189 bitmap.eraseColor(color);
190
191 const int kQuality = 80;
192 std::vector<unsigned char> output;
193 if (!gfx::JPEGCodec::Encode(
194 static_cast<const unsigned char*>(bitmap.getPixels()),
195 gfx::JPEGCodec::FORMAT_SkBitmap, width, height, bitmap.rowBytes(),
196 kQuality, &output)) {
197 LOG(ERROR) << "Unable to encode " << width << "x" << height << " bitmap";
198 return false;
199 }
200
201 size_t bytes_written = file_util::WriteFile(
202 path, reinterpret_cast<const char*>(&output[0]), output.size());
203 if (bytes_written != output.size()) {
204 LOG(ERROR) << "Wrote " << bytes_written << " byte(s) instead of "
205 << output.size() << " to " << path.value();
206 return false;
207 }
208
209 return true;
210 }
211
212 // Initializes |wallpaper_dir_|, writes JPEG wallpaper images to it, and
213 // passes |controller_| a command line instructing it to use the images.
214 // Only needs to be called (once) by tests that want to test loading of
215 // default wallpapers.
216 void WriteWallpapersAndSetFlags() {
217 wallpaper_dir_.reset(new base::ScopedTempDir);
218 ASSERT_TRUE(wallpaper_dir_->CreateUniqueTempDir());
219
220 const base::FilePath kLargePath =
221 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("large.jpg"));
222 ASSERT_TRUE(WriteJPEGFile(kLargePath, kWallpaperSize, kWallpaperSize,
223 kLargeWallpaperColor));
224 command_line_.AppendSwitchPath(
225 switches::kAshDefaultWallpaperLarge, kLargePath);
226
227 const base::FilePath kSmallPath =
228 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("small.jpg"));
229 ASSERT_TRUE(WriteJPEGFile(kSmallPath, kWallpaperSize, kWallpaperSize,
230 kSmallWallpaperColor));
231 command_line_.AppendSwitchPath(
232 switches::kAshDefaultWallpaperSmall, kSmallPath);
233
234 const base::FilePath kLargeGuestPath =
235 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("guest_large.jpg"));
236 ASSERT_TRUE(WriteJPEGFile(kLargeGuestPath, kWallpaperSize, kWallpaperSize,
237 kLargeGuestWallpaperColor));
238 command_line_.AppendSwitchPath(
239 switches::kAshDefaultGuestWallpaperLarge, kLargeGuestPath);
240
241 const base::FilePath kSmallGuestPath =
242 wallpaper_dir_->path().Append(FILE_PATH_LITERAL("guest_small.jpg"));
243 ASSERT_TRUE(WriteJPEGFile(kSmallGuestPath, kWallpaperSize, kWallpaperSize,
244 kSmallGuestWallpaperColor));
245 command_line_.AppendSwitchPath(
246 switches::kAshDefaultGuestWallpaperSmall, kSmallGuestPath);
247
248 controller_->set_command_line_for_testing(&command_line_);
249 }
250
251 content::TestBrowserThread ui_thread_;
252
253 // Custom command line passed to DesktopBackgroundController by
254 // WriteWallpapersAndSetFlags().
255 CommandLine command_line_;
256
257 // Directory created by WriteWallpapersAndSetFlags() to store default
258 // wallpaper images.
259 scoped_ptr<base::ScopedTempDir> wallpaper_dir_;
260
261 DesktopBackgroundController* controller_; // Not owned.
262
73 private: 263 private:
74 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundControllerTest); 264 DISALLOW_COPY_AND_ASSIGN(DesktopBackgroundControllerTest);
75 }; 265 };
76 266
77 TEST_F(DesktopBackgroundControllerTest, BasicReparenting) { 267 TEST_F(DesktopBackgroundControllerTest, BasicReparenting) {
78 DesktopBackgroundController* controller = 268 DesktopBackgroundController* controller =
79 Shell::GetInstance()->desktop_background_controller(); 269 Shell::GetInstance()->desktop_background_controller();
80 controller->CreateEmptyWallpaper(); 270 controller->CreateEmptyWallpaper();
81 271
82 // Wallpaper view/window exists in the desktop background container and 272 // Wallpaper view/window exists in the desktop background container and
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 // holds the widget controller instance. kDesktopController will get it later. 306 // holds the widget controller instance. kDesktopController will get it later.
117 RootWindow* root = Shell::GetPrimaryRootWindow(); 307 RootWindow* root = Shell::GetPrimaryRootWindow();
118 EXPECT_TRUE( 308 EXPECT_TRUE(
119 root->GetProperty(kAnimatingDesktopController)->GetController(false)); 309 root->GetProperty(kAnimatingDesktopController)->GetController(false));
120 310
121 // kDesktopController will receive the widget controller when the animation 311 // kDesktopController will receive the widget controller when the animation
122 // is done. 312 // is done.
123 EXPECT_FALSE(root->GetProperty(kDesktopController)); 313 EXPECT_FALSE(root->GetProperty(kDesktopController));
124 314
125 // Force the widget's layer animation to play to completion. 315 // Force the widget's layer animation to play to completion.
126 ASSERT_NO_FATAL_FAILURE( 316 RunDesktopControllerAnimation();
127 RunAnimationForWidget(
128 root->GetProperty(kAnimatingDesktopController)->GetController(false)->
129 widget()));
130 317
131 // Ownership has moved from kAnimatingDesktopController to kDesktopController. 318 // Ownership has moved from kAnimatingDesktopController to kDesktopController.
132 EXPECT_FALSE( 319 EXPECT_FALSE(
133 root->GetProperty(kAnimatingDesktopController)->GetController(false)); 320 root->GetProperty(kAnimatingDesktopController)->GetController(false));
134 EXPECT_TRUE(root->GetProperty(kDesktopController)); 321 EXPECT_TRUE(root->GetProperty(kDesktopController));
135 } 322 }
136 323
137 // Test for crbug.com/149043 "Unlock screen, no launcher appears". Ensure we 324 // Test for crbug.com/149043 "Unlock screen, no launcher appears". Ensure we
138 // move all desktop views if there are more than one. 325 // move all desktop views if there are more than one.
139 TEST_F(DesktopBackgroundControllerTest, BackgroundMovementDuringUnlock) { 326 TEST_F(DesktopBackgroundControllerTest, BackgroundMovementDuringUnlock) {
140 // We cannot short-circuit animations for this test. 327 // We cannot short-circuit animations for this test.
141 ui::ScopedAnimationDurationScaleMode normal_duration_mode( 328 ui::ScopedAnimationDurationScaleMode normal_duration_mode(
142 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); 329 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
143 330
144 // Reset wallpaper state, see ControllerOwnership above. 331 // Reset wallpaper state, see ControllerOwnership above.
145 DesktopBackgroundController* controller = 332 DesktopBackgroundController* controller =
146 Shell::GetInstance()->desktop_background_controller(); 333 Shell::GetInstance()->desktop_background_controller();
147 controller->CreateEmptyWallpaper(); 334 controller->CreateEmptyWallpaper();
148 335
149 // Run wallpaper show animation to completion. 336 // Run wallpaper show animation to completion.
150 RootWindow* root = Shell::GetPrimaryRootWindow(); 337 RunDesktopControllerAnimation();
151 ASSERT_NO_FATAL_FAILURE(
152 RunAnimationForWidget(
153 root->GetProperty(kAnimatingDesktopController)->GetController(false)->
154 widget()));
155 338
156 // User locks the screen, which moves the background forward. 339 // User locks the screen, which moves the background forward.
157 controller->MoveDesktopToLockedContainer(); 340 controller->MoveDesktopToLockedContainer();
158 341
159 // Suspend/resume cycle causes wallpaper to refresh, loading a new desktop 342 // Suspend/resume cycle causes wallpaper to refresh, loading a new desktop
160 // background that will animate in on top of the old one. 343 // background that will animate in on top of the old one.
161 controller->CreateEmptyWallpaper(); 344 controller->CreateEmptyWallpaper();
162 345
163 // In this state we have two desktop background views stored in different 346 // In this state we have two desktop background views stored in different
164 // properties. Both are in the lock screen background container. 347 // properties. Both are in the lock screen background container.
348 RootWindow* root = Shell::GetPrimaryRootWindow();
165 EXPECT_TRUE( 349 EXPECT_TRUE(
166 root->GetProperty(kAnimatingDesktopController)->GetController(false)); 350 root->GetProperty(kAnimatingDesktopController)->GetController(false));
167 EXPECT_TRUE(root->GetProperty(kDesktopController)); 351 EXPECT_TRUE(root->GetProperty(kDesktopController));
168 EXPECT_EQ(0, ChildCountForContainer(kDesktopBackgroundId)); 352 EXPECT_EQ(0, ChildCountForContainer(kDesktopBackgroundId));
169 EXPECT_EQ(2, ChildCountForContainer(kLockScreenBackgroundId)); 353 EXPECT_EQ(2, ChildCountForContainer(kLockScreenBackgroundId));
170 354
171 // Before the wallpaper's animation completes, user unlocks the screen, which 355 // Before the wallpaper's animation completes, user unlocks the screen, which
172 // moves the desktop to the back. 356 // moves the desktop to the back.
173 controller->MoveDesktopToUnlockedContainer(); 357 controller->MoveDesktopToUnlockedContainer();
174 358
175 // Ensure both desktop backgrounds have moved. 359 // Ensure both desktop backgrounds have moved.
176 EXPECT_EQ(2, ChildCountForContainer(kDesktopBackgroundId)); 360 EXPECT_EQ(2, ChildCountForContainer(kDesktopBackgroundId));
177 EXPECT_EQ(0, ChildCountForContainer(kLockScreenBackgroundId)); 361 EXPECT_EQ(0, ChildCountForContainer(kLockScreenBackgroundId));
178 362
179 // Finish the new desktop background animation. 363 // Finish the new desktop background animation.
180 ASSERT_NO_FATAL_FAILURE( 364 RunDesktopControllerAnimation();
181 RunAnimationForWidget(
182 root->GetProperty(kAnimatingDesktopController)->GetController(false)->
183 widget()));
184 365
185 // Now there is one desktop background, in the back. 366 // Now there is one desktop background, in the back.
186 EXPECT_EQ(1, ChildCountForContainer(kDesktopBackgroundId)); 367 EXPECT_EQ(1, ChildCountForContainer(kDesktopBackgroundId));
187 EXPECT_EQ(0, ChildCountForContainer(kLockScreenBackgroundId)); 368 EXPECT_EQ(0, ChildCountForContainer(kLockScreenBackgroundId));
188 } 369 }
189 370
190 // Test for crbug.com/156542. Animating wallpaper should immediately finish 371 // Test for crbug.com/156542. Animating wallpaper should immediately finish
191 // animation and replace current wallpaper before next animation starts. 372 // animation and replace current wallpaper before next animation starts.
192 TEST_F(DesktopBackgroundControllerTest, ChangeWallpaperQuick) { 373 TEST_F(DesktopBackgroundControllerTest, ChangeWallpaperQuick) {
193 // We cannot short-circuit animations for this test. 374 // We cannot short-circuit animations for this test.
194 ui::ScopedAnimationDurationScaleMode normal_duration_mode( 375 ui::ScopedAnimationDurationScaleMode normal_duration_mode(
195 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); 376 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
196 377
197 // Reset wallpaper state, see ControllerOwnership above. 378 // Reset wallpaper state, see ControllerOwnership above.
198 DesktopBackgroundController* controller = 379 DesktopBackgroundController* controller =
199 Shell::GetInstance()->desktop_background_controller(); 380 Shell::GetInstance()->desktop_background_controller();
200 controller->CreateEmptyWallpaper(); 381 controller->CreateEmptyWallpaper();
201 382
202 // Run wallpaper show animation to completion. 383 // Run wallpaper show animation to completion.
203 RootWindow* root = Shell::GetPrimaryRootWindow(); 384 RunDesktopControllerAnimation();
204 ASSERT_NO_FATAL_FAILURE(
205 RunAnimationForWidget(
206 root->GetProperty(kAnimatingDesktopController)->GetController(false)->
207 widget()));
208 385
209 // Change to a new wallpaper. 386 // Change to a new wallpaper.
210 controller->CreateEmptyWallpaper(); 387 controller->CreateEmptyWallpaper();
211 388
212 DesktopBackgroundWidgetController* animatingController = 389 RootWindow* root = Shell::GetPrimaryRootWindow();
390 DesktopBackgroundWidgetController* animating_controller =
213 root->GetProperty(kAnimatingDesktopController)->GetController(false); 391 root->GetProperty(kAnimatingDesktopController)->GetController(false);
214 EXPECT_TRUE(animatingController); 392 EXPECT_TRUE(animating_controller);
215 EXPECT_TRUE(root->GetProperty(kDesktopController)); 393 EXPECT_TRUE(root->GetProperty(kDesktopController));
216 394
217 // Change to another wallpaper before animation finished. 395 // Change to another wallpaper before animation finished.
218 controller->CreateEmptyWallpaper(); 396 controller->CreateEmptyWallpaper();
219 397
220 // The animating controller should immediately move to desktop controller. 398 // The animating controller should immediately move to desktop controller.
221 EXPECT_EQ(animatingController, root->GetProperty(kDesktopController)); 399 EXPECT_EQ(animating_controller, root->GetProperty(kDesktopController));
222 400
223 // Cache the new animating controller. 401 // Cache the new animating controller.
224 animatingController = 402 animating_controller =
225 root->GetProperty(kAnimatingDesktopController)->GetController(false); 403 root->GetProperty(kAnimatingDesktopController)->GetController(false);
226 404
227 // Run wallpaper show animation to completion. 405 // Run wallpaper show animation to completion.
228 ASSERT_NO_FATAL_FAILURE( 406 ASSERT_NO_FATAL_FAILURE(
229 RunAnimationForWidget( 407 RunAnimationForWidget(
230 root->GetProperty(kAnimatingDesktopController)->GetController(false)-> 408 root->GetProperty(kAnimatingDesktopController)->GetController(false)->
231 widget())); 409 widget()));
232 410
233 EXPECT_TRUE(root->GetProperty(kDesktopController)); 411 EXPECT_TRUE(root->GetProperty(kDesktopController));
234 EXPECT_FALSE( 412 EXPECT_FALSE(
235 root->GetProperty(kAnimatingDesktopController)->GetController(false)); 413 root->GetProperty(kAnimatingDesktopController)->GetController(false));
236 // The desktop controller should be the last created animating controller. 414 // The desktop controller should be the last created animating controller.
237 EXPECT_EQ(animatingController, root->GetProperty(kDesktopController)); 415 EXPECT_EQ(animating_controller, root->GetProperty(kDesktopController));
416 }
417
418 TEST_F(DesktopBackgroundControllerTest, GetAppropriateResolution) {
419 // TODO(derat|oshima|bshe): Configuring desktops seems busted on Win8,
420 // even when just a single display is being used -- the small wallpaper
421 // is used instead of the large one. Track down the cause of the problem
422 // and only use a SupportsMultipleDisplays() clause for the dual-display
423 // code below.
424 if (!SupportsMultipleDisplays())
425 return;
426
427 test::DisplayManagerTestApi display_manager_test_api(
428 Shell::GetInstance()->display_manager());
429
430 // Small wallpaper images should be used for configurations less than or
431 // equal to kSmallWallpaperMaxWidth by kSmallWallpaperMaxHeight, even if
432 // multiple displays are connected.
433 display_manager_test_api.UpdateDisplay("800x600");
434 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL,
435 controller_->GetAppropriateResolution());
436 display_manager_test_api.UpdateDisplay("800x600,800x600");
437 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL,
438 controller_->GetAppropriateResolution());
439 display_manager_test_api.UpdateDisplay("1366x800");
440 EXPECT_EQ(WALLPAPER_RESOLUTION_SMALL,
441 controller_->GetAppropriateResolution());
442
443 // At larger sizes, large wallpapers should be used.
444 display_manager_test_api.UpdateDisplay("1367x800");
445 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE,
446 controller_->GetAppropriateResolution());
447 display_manager_test_api.UpdateDisplay("1367x801");
448 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE,
449 controller_->GetAppropriateResolution());
450 display_manager_test_api.UpdateDisplay("2560x1700");
451 EXPECT_EQ(WALLPAPER_RESOLUTION_LARGE,
452 controller_->GetAppropriateResolution());
453 }
454
455 // Test that DesktopBackgroundController loads the appropriate wallpaper
456 // images as specified via command-line flags in various situations.
457 // Splitting these into separate tests avoids needing to run animations.
458 // TODO(derat): Combine these into a single test -- see
459 // RunDesktopControllerAnimation()'s TODO.
460 TEST_F(DesktopBackgroundControllerTest, SmallDefaultWallpaper) {
461 if (!SupportsMultipleDisplays())
462 return;
463
464 WriteWallpapersAndSetFlags();
465 TestObserver observer(controller_);
466
467 // At 800x600, the small wallpaper should be loaded.
468 test::DisplayManagerTestApi display_manager_test_api(
469 Shell::GetInstance()->display_manager());
470 display_manager_test_api.UpdateDisplay("800x600");
471 ASSERT_TRUE(controller_->SetDefaultWallpaper(false));
472 observer.WaitForWallpaperDataChanged();
473 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(),
474 kSmallWallpaperColor));
475
476 // Requesting the same wallpaper again should be a no-op.
477 ASSERT_FALSE(controller_->SetDefaultWallpaper(false));
478 }
479
480 TEST_F(DesktopBackgroundControllerTest, LargeDefaultWallpaper) {
481 if (!SupportsMultipleDisplays())
482 return;
483
484 WriteWallpapersAndSetFlags();
485 TestObserver observer(controller_);
486 test::DisplayManagerTestApi display_manager_test_api(
487 Shell::GetInstance()->display_manager());
488 display_manager_test_api.UpdateDisplay("1600x1200");
489 ASSERT_TRUE(controller_->SetDefaultWallpaper(false));
490 observer.WaitForWallpaperDataChanged();
491 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(),
492 kLargeWallpaperColor));
493 }
494
495 TEST_F(DesktopBackgroundControllerTest, SmallGuestWallpaper) {
496 if (!SupportsMultipleDisplays())
497 return;
498
499 WriteWallpapersAndSetFlags();
500 TestObserver observer(controller_);
501 test::DisplayManagerTestApi display_manager_test_api(
502 Shell::GetInstance()->display_manager());
503 display_manager_test_api.UpdateDisplay("800x600");
504 ASSERT_TRUE(controller_->SetDefaultWallpaper(true));
505 observer.WaitForWallpaperDataChanged();
506 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(),
507 kSmallGuestWallpaperColor));
508 }
509
510 TEST_F(DesktopBackgroundControllerTest, LargeGuestWallpaper) {
511 if (!SupportsMultipleDisplays())
512 return;
513
514 WriteWallpapersAndSetFlags();
515 TestObserver observer(controller_);
516 test::DisplayManagerTestApi display_manager_test_api(
517 Shell::GetInstance()->display_manager());
518 display_manager_test_api.UpdateDisplay("1600x1200");
519 ASSERT_TRUE(controller_->SetDefaultWallpaper(true));
520 observer.WaitForWallpaperDataChanged();
521 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(),
522 kLargeGuestWallpaperColor));
238 } 523 }
239 524
240 } // namespace internal 525 } // namespace internal
241 } // namespace ash 526 } // namespace ash
OLDNEW
« no previous file with comments | « ash/desktop_background/desktop_background_controller.cc ('k') | ash/desktop_background/wallpaper_resizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698