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" |
(...skipping 23 matching lines...) Expand all Loading... |
34 #include "ui/gfx/point.h" | 34 #include "ui/gfx/point.h" |
35 #include "ui/gfx/rect.h" | 35 #include "ui/gfx/rect.h" |
36 | 36 |
37 using aura::RootWindow; | 37 using aura::RootWindow; |
38 using aura::Window; | 38 using aura::Window; |
39 | 39 |
40 namespace ash { | 40 namespace ash { |
41 namespace { | 41 namespace { |
42 | 42 |
43 // Containers IDs used for tests. | 43 // Containers IDs used for tests. |
44 const int kDesktopBackgroundId = | 44 const int kDesktopBackgroundId = ash::kShellWindowId_DesktopBackgroundContainer; |
45 ash::internal::kShellWindowId_DesktopBackgroundContainer; | |
46 const int kLockScreenBackgroundId = | 45 const int kLockScreenBackgroundId = |
47 ash::internal::kShellWindowId_LockScreenBackgroundContainer; | 46 ash::kShellWindowId_LockScreenBackgroundContainer; |
48 | 47 |
49 // Returns number of child windows in a shell window container. | 48 // Returns number of child windows in a shell window container. |
50 int ChildCountForContainer(int container_id) { | 49 int ChildCountForContainer(int container_id) { |
51 Window* root = ash::Shell::GetPrimaryRootWindow(); | 50 Window* root = ash::Shell::GetPrimaryRootWindow(); |
52 Window* container = root->GetChildById(container_id); | 51 Window* container = root->GetChildById(container_id); |
53 return static_cast<int>(container->children().size()); | 52 return static_cast<int>(container->children().size()); |
54 } | 53 } |
55 | 54 |
56 class TestObserver : public DesktopBackgroundControllerObserver { | 55 class TestObserver : public DesktopBackgroundControllerObserver { |
57 public: | 56 public: |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
104 DesktopBackgroundControllerTest() | 103 DesktopBackgroundControllerTest() |
105 : command_line_(CommandLine::NO_PROGRAM), | 104 : command_line_(CommandLine::NO_PROGRAM), |
106 controller_(NULL) { | 105 controller_(NULL) { |
107 } | 106 } |
108 virtual ~DesktopBackgroundControllerTest() {} | 107 virtual ~DesktopBackgroundControllerTest() {} |
109 | 108 |
110 virtual void SetUp() OVERRIDE { | 109 virtual void SetUp() OVERRIDE { |
111 test::AshTestBase::SetUp(); | 110 test::AshTestBase::SetUp(); |
112 // Ash shell initialization creates wallpaper. Reset it so we can manually | 111 // Ash shell initialization creates wallpaper. Reset it so we can manually |
113 // control wallpaper creation and animation in our tests. | 112 // control wallpaper creation and animation in our tests. |
114 internal::RootWindowController* root_window_controller = | 113 RootWindowController* root_window_controller = |
115 Shell::GetPrimaryRootWindowController(); | 114 Shell::GetPrimaryRootWindowController(); |
116 root_window_controller->SetWallpaperController(NULL); | 115 root_window_controller->SetWallpaperController(NULL); |
117 root_window_controller->SetAnimatingWallpaperController(NULL); | 116 root_window_controller->SetAnimatingWallpaperController(NULL); |
118 controller_ = Shell::GetInstance()->desktop_background_controller(); | 117 controller_ = Shell::GetInstance()->desktop_background_controller(); |
119 wallpaper_delegate_ = static_cast<test::TestUserWallpaperDelegate*>( | 118 wallpaper_delegate_ = static_cast<test::TestUserWallpaperDelegate*>( |
120 Shell::GetInstance()->user_wallpaper_delegate()); | 119 Shell::GetInstance()->user_wallpaper_delegate()); |
121 controller_->set_wallpaper_reload_delay_for_test(0); | 120 controller_->set_wallpaper_reload_delay_for_test(0); |
122 } | 121 } |
123 | 122 |
124 protected: | 123 protected: |
(...skipping 19 matching lines...) Expand all Loading... |
144 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); | 143 bitmap.setConfig(SkBitmap::kARGB_8888_Config, width, height); |
145 bitmap.allocPixels(); | 144 bitmap.allocPixels(); |
146 bitmap.eraseColor(color); | 145 bitmap.eraseColor(color); |
147 gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); | 146 gfx::ImageSkia image = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); |
148 return image; | 147 return image; |
149 } | 148 } |
150 | 149 |
151 // Runs kAnimatingDesktopController's animation to completion. | 150 // Runs kAnimatingDesktopController's animation to completion. |
152 // TODO(bshe): Don't require tests to run animations; it's slow. | 151 // TODO(bshe): Don't require tests to run animations; it's slow. |
153 void RunDesktopControllerAnimation() { | 152 void RunDesktopControllerAnimation() { |
154 internal::DesktopBackgroundWidgetController* controller = | 153 DesktopBackgroundWidgetController* controller = |
155 Shell::GetPrimaryRootWindowController()-> | 154 Shell::GetPrimaryRootWindowController() |
156 animating_wallpaper_controller()->GetController(false); | 155 ->animating_wallpaper_controller() |
| 156 ->GetController(false); |
157 ASSERT_NO_FATAL_FAILURE(RunAnimationForWidget(controller->widget())); | 157 ASSERT_NO_FATAL_FAILURE(RunAnimationForWidget(controller->widget())); |
158 } | 158 } |
159 | 159 |
160 // Returns true if the color at the center of |image| is close to | 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 | 161 // |expected_color|. (The center is used so small wallpaper images can be |
162 // used.) | 162 // used.) |
163 bool ImageIsNearColor(gfx::ImageSkia image, SkColor expected_color) { | 163 bool ImageIsNearColor(gfx::ImageSkia image, SkColor expected_color) { |
164 if (image.size().IsEmpty()) { | 164 if (image.size().IsEmpty()) { |
165 LOG(ERROR) << "Image is empty"; | 165 LOG(ERROR) << "Image is empty"; |
166 return false; | 166 return false; |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 ui::ScopedAnimationDurationScaleMode normal_duration_mode( | 314 ui::ScopedAnimationDurationScaleMode normal_duration_mode( |
315 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); | 315 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); |
316 | 316 |
317 // Create wallpaper and background view. | 317 // Create wallpaper and background view. |
318 DesktopBackgroundController* controller = | 318 DesktopBackgroundController* controller = |
319 Shell::GetInstance()->desktop_background_controller(); | 319 Shell::GetInstance()->desktop_background_controller(); |
320 controller->CreateEmptyWallpaper(); | 320 controller->CreateEmptyWallpaper(); |
321 | 321 |
322 // The new wallpaper is ready to start animating. kAnimatingDesktopController | 322 // The new wallpaper is ready to start animating. kAnimatingDesktopController |
323 // holds the widget controller instance. kDesktopController will get it later. | 323 // holds the widget controller instance. kDesktopController will get it later. |
324 internal::RootWindowController* root_window_controller = | 324 RootWindowController* root_window_controller = |
325 Shell::GetPrimaryRootWindowController(); | 325 Shell::GetPrimaryRootWindowController(); |
326 EXPECT_TRUE(root_window_controller->animating_wallpaper_controller()-> | 326 EXPECT_TRUE(root_window_controller->animating_wallpaper_controller()-> |
327 GetController(false)); | 327 GetController(false)); |
328 | 328 |
329 // kDesktopController will receive the widget controller when the animation | 329 // kDesktopController will receive the widget controller when the animation |
330 // is done. | 330 // is done. |
331 EXPECT_FALSE(root_window_controller->wallpaper_controller()); | 331 EXPECT_FALSE(root_window_controller->wallpaper_controller()); |
332 | 332 |
333 // Force the widget's layer animation to play to completion. | 333 // Force the widget's layer animation to play to completion. |
334 RunDesktopControllerAnimation(); | 334 RunDesktopControllerAnimation(); |
(...skipping 21 matching lines...) Expand all Loading... |
356 | 356 |
357 // User locks the screen, which moves the background forward. | 357 // User locks the screen, which moves the background forward. |
358 controller->MoveDesktopToLockedContainer(); | 358 controller->MoveDesktopToLockedContainer(); |
359 | 359 |
360 // Suspend/resume cycle causes wallpaper to refresh, loading a new desktop | 360 // Suspend/resume cycle causes wallpaper to refresh, loading a new desktop |
361 // background that will animate in on top of the old one. | 361 // background that will animate in on top of the old one. |
362 controller->CreateEmptyWallpaper(); | 362 controller->CreateEmptyWallpaper(); |
363 | 363 |
364 // In this state we have two desktop background views stored in different | 364 // In this state we have two desktop background views stored in different |
365 // properties. Both are in the lock screen background container. | 365 // properties. Both are in the lock screen background container. |
366 internal::RootWindowController* root_window_controller = | 366 RootWindowController* root_window_controller = |
367 Shell::GetPrimaryRootWindowController(); | 367 Shell::GetPrimaryRootWindowController(); |
368 EXPECT_TRUE(root_window_controller->animating_wallpaper_controller()-> | 368 EXPECT_TRUE(root_window_controller->animating_wallpaper_controller()-> |
369 GetController(false)); | 369 GetController(false)); |
370 EXPECT_TRUE(root_window_controller->wallpaper_controller()); | 370 EXPECT_TRUE(root_window_controller->wallpaper_controller()); |
371 EXPECT_EQ(0, ChildCountForContainer(kDesktopBackgroundId)); | 371 EXPECT_EQ(0, ChildCountForContainer(kDesktopBackgroundId)); |
372 EXPECT_EQ(2, ChildCountForContainer(kLockScreenBackgroundId)); | 372 EXPECT_EQ(2, ChildCountForContainer(kLockScreenBackgroundId)); |
373 | 373 |
374 // Before the wallpaper's animation completes, user unlocks the screen, which | 374 // Before the wallpaper's animation completes, user unlocks the screen, which |
375 // moves the desktop to the back. | 375 // moves the desktop to the back. |
376 controller->MoveDesktopToUnlockedContainer(); | 376 controller->MoveDesktopToUnlockedContainer(); |
(...skipping 21 matching lines...) Expand all Loading... |
398 DesktopBackgroundController* controller = | 398 DesktopBackgroundController* controller = |
399 Shell::GetInstance()->desktop_background_controller(); | 399 Shell::GetInstance()->desktop_background_controller(); |
400 controller->CreateEmptyWallpaper(); | 400 controller->CreateEmptyWallpaper(); |
401 | 401 |
402 // Run wallpaper show animation to completion. | 402 // Run wallpaper show animation to completion. |
403 RunDesktopControllerAnimation(); | 403 RunDesktopControllerAnimation(); |
404 | 404 |
405 // Change to a new wallpaper. | 405 // Change to a new wallpaper. |
406 controller->CreateEmptyWallpaper(); | 406 controller->CreateEmptyWallpaper(); |
407 | 407 |
408 internal::RootWindowController* root_window_controller = | 408 RootWindowController* root_window_controller = |
409 Shell::GetPrimaryRootWindowController(); | 409 Shell::GetPrimaryRootWindowController(); |
410 internal::DesktopBackgroundWidgetController* animating_controller = | 410 DesktopBackgroundWidgetController* animating_controller = |
411 root_window_controller->animating_wallpaper_controller()-> | 411 root_window_controller->animating_wallpaper_controller()->GetController( |
412 GetController(false); | 412 false); |
413 EXPECT_TRUE(animating_controller); | 413 EXPECT_TRUE(animating_controller); |
414 EXPECT_TRUE(root_window_controller->wallpaper_controller()); | 414 EXPECT_TRUE(root_window_controller->wallpaper_controller()); |
415 | 415 |
416 // Change to another wallpaper before animation finished. | 416 // Change to another wallpaper before animation finished. |
417 controller->CreateEmptyWallpaper(); | 417 controller->CreateEmptyWallpaper(); |
418 | 418 |
419 // The animating controller should immediately move to desktop controller. | 419 // The animating controller should immediately move to desktop controller. |
420 EXPECT_EQ(animating_controller, | 420 EXPECT_EQ(animating_controller, |
421 root_window_controller->wallpaper_controller()); | 421 root_window_controller->wallpaper_controller()); |
422 | 422 |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 // new load task was started (since the previous one was interrupted by | 687 // new load task was started (since the previous one was interrupted by |
688 // SetCustomWallpaper()). See http://crbug.com/327443. | 688 // SetCustomWallpaper()). See http://crbug.com/327443. |
689 TestObserver observer(controller_); | 689 TestObserver observer(controller_); |
690 ASSERT_TRUE(controller_->SetDefaultWallpaper(false)); | 690 ASSERT_TRUE(controller_->SetDefaultWallpaper(false)); |
691 observer.WaitForWallpaperDataChanged(); | 691 observer.WaitForWallpaperDataChanged(); |
692 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), | 692 EXPECT_TRUE(ImageIsNearColor(controller_->GetWallpaper(), |
693 kSmallWallpaperColor)); | 693 kSmallWallpaperColor)); |
694 } | 694 } |
695 | 695 |
696 } // namespace ash | 696 } // namespace ash |
OLD | NEW |