| 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/wallpaper/wallpaper_controller.h" | 5 #include "ash/wallpaper/wallpaper_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/public/cpp/shell_window_ids.h" | 11 #include "ash/public/cpp/shell_window_ids.h" |
| 12 #include "ash/root_window_controller.h" | 12 #include "ash/root_window_controller.h" |
| 13 #include "ash/session/session_controller.h" | 13 #include "ash/session/session_controller.h" |
| 14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
| 15 #include "ash/shell_port.h" |
| 15 #include "ash/test/ash_test_base.h" | 16 #include "ash/test/ash_test_base.h" |
| 16 #include "ash/test/test_session_controller_client.h" | 17 #include "ash/test/test_session_controller_client.h" |
| 17 #include "ash/test/test_wallpaper_delegate.h" | 18 #include "ash/test/test_wallpaper_delegate.h" |
| 18 #include "ash/wallpaper/wallpaper_view.h" | 19 #include "ash/wallpaper/wallpaper_view.h" |
| 19 #include "ash/wallpaper/wallpaper_widget_controller.h" | 20 #include "ash/wallpaper/wallpaper_widget_controller.h" |
| 20 #include "ash/wm_shell.h" | |
| 21 #include "ash/wm_window.h" | 21 #include "ash/wm_window.h" |
| 22 #include "base/command_line.h" | 22 #include "base/command_line.h" |
| 23 #include "base/message_loop/message_loop.h" | 23 #include "base/message_loop/message_loop.h" |
| 24 #include "base/run_loop.h" | 24 #include "base/run_loop.h" |
| 25 #include "base/strings/stringprintf.h" | 25 #include "base/strings/stringprintf.h" |
| 26 #include "base/threading/sequenced_worker_pool.h" | 26 #include "base/threading/sequenced_worker_pool.h" |
| 27 #include "third_party/skia/include/core/SkBitmap.h" | 27 #include "third_party/skia/include/core/SkBitmap.h" |
| 28 #include "third_party/skia/include/core/SkColor.h" | 28 #include "third_party/skia/include/core/SkColor.h" |
| 29 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 29 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 30 #include "ui/compositor/test/layer_animator_test_controller.h" | 30 #include "ui/compositor/test/layer_animator_test_controller.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 41 namespace ash { | 41 namespace ash { |
| 42 namespace { | 42 namespace { |
| 43 | 43 |
| 44 // Containers IDs used for tests. | 44 // Containers IDs used for tests. |
| 45 const int kWallpaperId = ash::kShellWindowId_WallpaperContainer; | 45 const int kWallpaperId = ash::kShellWindowId_WallpaperContainer; |
| 46 const int kLockScreenWallpaperId = | 46 const int kLockScreenWallpaperId = |
| 47 ash::kShellWindowId_LockScreenWallpaperContainer; | 47 ash::kShellWindowId_LockScreenWallpaperContainer; |
| 48 | 48 |
| 49 // Returns number of child windows in a shell window container. | 49 // Returns number of child windows in a shell window container. |
| 50 int ChildCountForContainer(int container_id) { | 50 int ChildCountForContainer(int container_id) { |
| 51 WmWindow* root = WmShell::Get()->GetPrimaryRootWindow(); | 51 WmWindow* root = ShellPort::Get()->GetPrimaryRootWindow(); |
| 52 WmWindow* container = root->GetChildByShellWindowId(container_id); | 52 WmWindow* container = root->GetChildByShellWindowId(container_id); |
| 53 return static_cast<int>(container->GetChildren().size()); | 53 return static_cast<int>(container->GetChildren().size()); |
| 54 } | 54 } |
| 55 | 55 |
| 56 // Steps a widget's layer animation until it is completed. Animations must be | 56 // Steps a widget's layer animation until it is completed. Animations must be |
| 57 // enabled. | 57 // enabled. |
| 58 void RunAnimationForWidget(views::Widget* widget) { | 58 void RunAnimationForWidget(views::Widget* widget) { |
| 59 // Animations must be enabled for stepping to work. | 59 // Animations must be enabled for stepping to work. |
| 60 ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(), | 60 ASSERT_NE(ui::ScopedAnimationDurationScaleMode::duration_scale_mode(), |
| 61 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); | 61 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 public: | 112 public: |
| 113 WallpaperControllerTest() | 113 WallpaperControllerTest() |
| 114 : controller_(nullptr), wallpaper_delegate_(nullptr) {} | 114 : controller_(nullptr), wallpaper_delegate_(nullptr) {} |
| 115 ~WallpaperControllerTest() override {} | 115 ~WallpaperControllerTest() override {} |
| 116 | 116 |
| 117 void SetUp() override { | 117 void SetUp() override { |
| 118 test::AshTestBase::SetUp(); | 118 test::AshTestBase::SetUp(); |
| 119 // Ash shell initialization creates wallpaper. Reset it so we can manually | 119 // Ash shell initialization creates wallpaper. Reset it so we can manually |
| 120 // control wallpaper creation and animation in our tests. | 120 // control wallpaper creation and animation in our tests. |
| 121 RootWindowController* root_window_controller = | 121 RootWindowController* root_window_controller = |
| 122 WmShell::Get()->GetPrimaryRootWindow()->GetRootWindowController(); | 122 ShellPort::Get()->GetPrimaryRootWindow()->GetRootWindowController(); |
| 123 root_window_controller->SetWallpaperWidgetController(nullptr); | 123 root_window_controller->SetWallpaperWidgetController(nullptr); |
| 124 root_window_controller->SetAnimatingWallpaperWidgetController(nullptr); | 124 root_window_controller->SetAnimatingWallpaperWidgetController(nullptr); |
| 125 controller_ = Shell::Get()->wallpaper_controller(); | 125 controller_ = Shell::Get()->wallpaper_controller(); |
| 126 wallpaper_delegate_ = static_cast<test::TestWallpaperDelegate*>( | 126 wallpaper_delegate_ = static_cast<test::TestWallpaperDelegate*>( |
| 127 Shell::Get()->wallpaper_delegate()); | 127 Shell::Get()->wallpaper_delegate()); |
| 128 controller_->set_wallpaper_reload_delay_for_test(0); | 128 controller_->set_wallpaper_reload_delay_for_test(0); |
| 129 } | 129 } |
| 130 | 130 |
| 131 WallpaperView* wallpaper_view() { | 131 WallpaperView* wallpaper_view() { |
| 132 WallpaperWidgetController* controller = | 132 WallpaperWidgetController* controller = |
| 133 WmShell::Get() | 133 ShellPort::Get() |
| 134 ->GetPrimaryRootWindow() | 134 ->GetPrimaryRootWindow() |
| 135 ->GetRootWindowController() | 135 ->GetRootWindowController() |
| 136 ->animating_wallpaper_widget_controller() | 136 ->animating_wallpaper_widget_controller() |
| 137 ->GetController(false); | 137 ->GetController(false); |
| 138 EXPECT_TRUE(controller); | 138 EXPECT_TRUE(controller); |
| 139 return static_cast<WallpaperView*>( | 139 return static_cast<WallpaperView*>( |
| 140 controller->widget()->GetContentsView()->child_at(0)); | 140 controller->widget()->GetContentsView()->child_at(0)); |
| 141 } | 141 } |
| 142 | 142 |
| 143 protected: | 143 protected: |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 EXPECT_EQ(SK_ColorBLACK, bitmap.getColor(i, j)); | 179 EXPECT_EQ(SK_ColorBLACK, bitmap.getColor(i, j)); |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 } | 183 } |
| 184 | 184 |
| 185 // Runs AnimatingWallpaperWidgetController's animation to completion. | 185 // Runs AnimatingWallpaperWidgetController's animation to completion. |
| 186 // TODO(bshe): Don't require tests to run animations; it's slow. | 186 // TODO(bshe): Don't require tests to run animations; it's slow. |
| 187 void RunDesktopControllerAnimation() { | 187 void RunDesktopControllerAnimation() { |
| 188 WallpaperWidgetController* controller = | 188 WallpaperWidgetController* controller = |
| 189 WmShell::Get() | 189 ShellPort::Get() |
| 190 ->GetPrimaryRootWindow() | 190 ->GetPrimaryRootWindow() |
| 191 ->GetRootWindowController() | 191 ->GetRootWindowController() |
| 192 ->animating_wallpaper_widget_controller() | 192 ->animating_wallpaper_widget_controller() |
| 193 ->GetController(false); | 193 ->GetController(false); |
| 194 EXPECT_TRUE(controller); | 194 EXPECT_TRUE(controller); |
| 195 ASSERT_NO_FATAL_FAILURE(RunAnimationForWidget(controller->widget())); | 195 ASSERT_NO_FATAL_FAILURE(RunAnimationForWidget(controller->widget())); |
| 196 } | 196 } |
| 197 | 197 |
| 198 // Convenience function to ensure ShouldCalculateColors() returns true. | 198 // Convenience function to ensure ShouldCalculateColors() returns true. |
| 199 void EnableShelfColoring() { | 199 void EnableShelfColoring() { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 // We cannot short-circuit animations for this test. | 258 // We cannot short-circuit animations for this test. |
| 259 ui::ScopedAnimationDurationScaleMode test_duration_mode( | 259 ui::ScopedAnimationDurationScaleMode test_duration_mode( |
| 260 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | 260 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); |
| 261 | 261 |
| 262 // Create the wallpaper and its view. | 262 // Create the wallpaper and its view. |
| 263 WallpaperController* controller = Shell::Get()->wallpaper_controller(); | 263 WallpaperController* controller = Shell::Get()->wallpaper_controller(); |
| 264 controller->CreateEmptyWallpaper(); | 264 controller->CreateEmptyWallpaper(); |
| 265 | 265 |
| 266 // The new wallpaper is ready to animate. | 266 // The new wallpaper is ready to animate. |
| 267 RootWindowController* root_window_controller = | 267 RootWindowController* root_window_controller = |
| 268 WmShell::Get()->GetPrimaryRootWindow()->GetRootWindowController(); | 268 ShellPort::Get()->GetPrimaryRootWindow()->GetRootWindowController(); |
| 269 EXPECT_TRUE(root_window_controller->animating_wallpaper_widget_controller() | 269 EXPECT_TRUE(root_window_controller->animating_wallpaper_widget_controller() |
| 270 ->GetController(false)); | 270 ->GetController(false)); |
| 271 EXPECT_FALSE(root_window_controller->wallpaper_widget_controller()); | 271 EXPECT_FALSE(root_window_controller->wallpaper_widget_controller()); |
| 272 | 272 |
| 273 // Force the animation to play to completion. | 273 // Force the animation to play to completion. |
| 274 RunDesktopControllerAnimation(); | 274 RunDesktopControllerAnimation(); |
| 275 EXPECT_FALSE(root_window_controller->animating_wallpaper_widget_controller() | 275 EXPECT_FALSE(root_window_controller->animating_wallpaper_widget_controller() |
| 276 ->GetController(false)); | 276 ->GetController(false)); |
| 277 EXPECT_TRUE(root_window_controller->wallpaper_widget_controller()); | 277 EXPECT_TRUE(root_window_controller->wallpaper_widget_controller()); |
| 278 } | 278 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 294 // User locks the screen, which moves the wallpaper forward. | 294 // User locks the screen, which moves the wallpaper forward. |
| 295 controller->MoveToLockedContainer(); | 295 controller->MoveToLockedContainer(); |
| 296 | 296 |
| 297 // Suspend/resume cycle causes wallpaper to refresh, loading a new wallpaper | 297 // Suspend/resume cycle causes wallpaper to refresh, loading a new wallpaper |
| 298 // that will animate in on top of the old one. | 298 // that will animate in on top of the old one. |
| 299 controller->CreateEmptyWallpaper(); | 299 controller->CreateEmptyWallpaper(); |
| 300 | 300 |
| 301 // In this state we have two wallpaper views stored in different properties. | 301 // In this state we have two wallpaper views stored in different properties. |
| 302 // Both are in the lock screen wallpaper container. | 302 // Both are in the lock screen wallpaper container. |
| 303 RootWindowController* root_window_controller = | 303 RootWindowController* root_window_controller = |
| 304 WmShell::Get()->GetPrimaryRootWindow()->GetRootWindowController(); | 304 ShellPort::Get()->GetPrimaryRootWindow()->GetRootWindowController(); |
| 305 EXPECT_TRUE(root_window_controller->animating_wallpaper_widget_controller() | 305 EXPECT_TRUE(root_window_controller->animating_wallpaper_widget_controller() |
| 306 ->GetController(false)); | 306 ->GetController(false)); |
| 307 EXPECT_TRUE(root_window_controller->wallpaper_widget_controller()); | 307 EXPECT_TRUE(root_window_controller->wallpaper_widget_controller()); |
| 308 EXPECT_EQ(0, ChildCountForContainer(kWallpaperId)); | 308 EXPECT_EQ(0, ChildCountForContainer(kWallpaperId)); |
| 309 EXPECT_EQ(2, ChildCountForContainer(kLockScreenWallpaperId)); | 309 EXPECT_EQ(2, ChildCountForContainer(kLockScreenWallpaperId)); |
| 310 | 310 |
| 311 // Before the wallpaper's animation completes, user unlocks the screen, which | 311 // Before the wallpaper's animation completes, user unlocks the screen, which |
| 312 // moves the wallpaper to the back. | 312 // moves the wallpaper to the back. |
| 313 controller->MoveToUnlockedContainer(); | 313 controller->MoveToUnlockedContainer(); |
| 314 | 314 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 335 WallpaperController* controller = Shell::Get()->wallpaper_controller(); | 335 WallpaperController* controller = Shell::Get()->wallpaper_controller(); |
| 336 controller->CreateEmptyWallpaper(); | 336 controller->CreateEmptyWallpaper(); |
| 337 | 337 |
| 338 // Run wallpaper show animation to completion. | 338 // Run wallpaper show animation to completion. |
| 339 RunDesktopControllerAnimation(); | 339 RunDesktopControllerAnimation(); |
| 340 | 340 |
| 341 // Change to a new wallpaper. | 341 // Change to a new wallpaper. |
| 342 controller->CreateEmptyWallpaper(); | 342 controller->CreateEmptyWallpaper(); |
| 343 | 343 |
| 344 RootWindowController* root_window_controller = | 344 RootWindowController* root_window_controller = |
| 345 WmShell::Get()->GetPrimaryRootWindow()->GetRootWindowController(); | 345 ShellPort::Get()->GetPrimaryRootWindow()->GetRootWindowController(); |
| 346 WallpaperWidgetController* animating_controller = | 346 WallpaperWidgetController* animating_controller = |
| 347 root_window_controller->animating_wallpaper_widget_controller() | 347 root_window_controller->animating_wallpaper_widget_controller() |
| 348 ->GetController(false); | 348 ->GetController(false); |
| 349 EXPECT_TRUE(animating_controller); | 349 EXPECT_TRUE(animating_controller); |
| 350 EXPECT_TRUE(root_window_controller->wallpaper_widget_controller()); | 350 EXPECT_TRUE(root_window_controller->wallpaper_widget_controller()); |
| 351 | 351 |
| 352 // Change to another wallpaper before animation finished. | 352 // Change to another wallpaper before animation finished. |
| 353 controller->CreateEmptyWallpaper(); | 353 controller->CreateEmptyWallpaper(); |
| 354 | 354 |
| 355 // The animating controller should immediately move to wallpaper controller. | 355 // The animating controller should immediately move to wallpaper controller. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 397 EXPECT_TRUE(resized_image.BackedBySameObjectAs(controller_->GetWallpaper())); | 397 EXPECT_TRUE(resized_image.BackedBySameObjectAs(controller_->GetWallpaper())); |
| 398 } | 398 } |
| 399 | 399 |
| 400 TEST_F(WallpaperControllerTest, GetMaxDisplaySize) { | 400 TEST_F(WallpaperControllerTest, GetMaxDisplaySize) { |
| 401 // Device scale factor shouldn't affect the native size. | 401 // Device scale factor shouldn't affect the native size. |
| 402 UpdateDisplay("1000x300*2"); | 402 UpdateDisplay("1000x300*2"); |
| 403 EXPECT_EQ("1000x300", | 403 EXPECT_EQ("1000x300", |
| 404 WallpaperController::GetMaxDisplaySizeInNative().ToString()); | 404 WallpaperController::GetMaxDisplaySizeInNative().ToString()); |
| 405 | 405 |
| 406 // TODO: mash doesn't support rotation yet, http://crbug.com/695556. | 406 // TODO: mash doesn't support rotation yet, http://crbug.com/695556. |
| 407 if (!WmShell::Get()->IsRunningInMash()) { | 407 if (!ShellPort::Get()->IsRunningInMash()) { |
| 408 // Rotated display should return the rotated size. | 408 // Rotated display should return the rotated size. |
| 409 UpdateDisplay("1000x300*2/r"); | 409 UpdateDisplay("1000x300*2/r"); |
| 410 EXPECT_EQ("300x1000", | 410 EXPECT_EQ("300x1000", |
| 411 WallpaperController::GetMaxDisplaySizeInNative().ToString()); | 411 WallpaperController::GetMaxDisplaySizeInNative().ToString()); |
| 412 } | 412 } |
| 413 | 413 |
| 414 // UI Scaling shouldn't affect the native size. | 414 // UI Scaling shouldn't affect the native size. |
| 415 UpdateDisplay("1000x300*2@1.5"); | 415 UpdateDisplay("1000x300*2@1.5"); |
| 416 EXPECT_EQ("1000x300", | 416 EXPECT_EQ("1000x300", |
| 417 WallpaperController::GetMaxDisplaySizeInNative().ToString()); | 417 WallpaperController::GetMaxDisplaySizeInNative().ToString()); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 525 EXPECT_TRUE(ShouldCalculateColors()); | 525 EXPECT_TRUE(ShouldCalculateColors()); |
| 526 | 526 |
| 527 SetSessionState(SessionState::LOCKED); | 527 SetSessionState(SessionState::LOCKED); |
| 528 EXPECT_FALSE(ShouldCalculateColors()); | 528 EXPECT_FALSE(ShouldCalculateColors()); |
| 529 | 529 |
| 530 SetSessionState(SessionState::LOGIN_SECONDARY); | 530 SetSessionState(SessionState::LOGIN_SECONDARY); |
| 531 EXPECT_FALSE(ShouldCalculateColors()); | 531 EXPECT_FALSE(ShouldCalculateColors()); |
| 532 } | 532 } |
| 533 | 533 |
| 534 } // namespace ash | 534 } // namespace ash |
| OLD | NEW |