| 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/common/wallpaper/wallpaper_controller.h" | 5 #include "ash/common/wallpaper/wallpaper_controller.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <cstdlib> | 8 #include <cstdlib> |
| 9 | 9 |
| 10 #include "ash/common/wallpaper/wallpaper_view.h" | 10 #include "ash/common/wallpaper/wallpaper_view.h" |
| 11 #include "ash/common/wallpaper/wallpaper_widget_controller.h" | 11 #include "ash/common/wallpaper/wallpaper_widget_controller.h" |
| 12 #include "ash/common/wm_shell.h" | 12 #include "ash/common/wm_shell.h" |
| 13 #include "ash/common/wm_window.h" | 13 #include "ash/common/wm_window.h" |
| 14 #include "ash/public/cpp/shell_window_ids.h" | 14 #include "ash/public/cpp/shell_window_ids.h" |
| 15 #include "ash/root_window_controller.h" | 15 #include "ash/root_window_controller.h" |
| 16 #include "ash/shell.h" |
| 16 #include "ash/test/ash_test_base.h" | 17 #include "ash/test/ash_test_base.h" |
| 17 #include "ash/test/test_wallpaper_delegate.h" | 18 #include "ash/test/test_wallpaper_delegate.h" |
| 18 #include "base/message_loop/message_loop.h" | 19 #include "base/message_loop/message_loop.h" |
| 19 #include "base/run_loop.h" | 20 #include "base/run_loop.h" |
| 20 #include "base/strings/stringprintf.h" | 21 #include "base/strings/stringprintf.h" |
| 21 #include "base/threading/sequenced_worker_pool.h" | 22 #include "base/threading/sequenced_worker_pool.h" |
| 22 #include "third_party/skia/include/core/SkBitmap.h" | 23 #include "third_party/skia/include/core/SkBitmap.h" |
| 23 #include "third_party/skia/include/core/SkColor.h" | 24 #include "third_party/skia/include/core/SkColor.h" |
| 24 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 25 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
| 25 #include "ui/compositor/test/layer_animator_test_controller.h" | 26 #include "ui/compositor/test/layer_animator_test_controller.h" |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 ~WallpaperControllerTest() override {} | 109 ~WallpaperControllerTest() override {} |
| 109 | 110 |
| 110 void SetUp() override { | 111 void SetUp() override { |
| 111 test::AshTestBase::SetUp(); | 112 test::AshTestBase::SetUp(); |
| 112 // Ash shell initialization creates wallpaper. Reset it so we can manually | 113 // Ash shell initialization creates wallpaper. Reset it so we can manually |
| 113 // control wallpaper creation and animation in our tests. | 114 // control wallpaper creation and animation in our tests. |
| 114 RootWindowController* root_window_controller = | 115 RootWindowController* root_window_controller = |
| 115 WmShell::Get()->GetPrimaryRootWindow()->GetRootWindowController(); | 116 WmShell::Get()->GetPrimaryRootWindow()->GetRootWindowController(); |
| 116 root_window_controller->SetWallpaperWidgetController(nullptr); | 117 root_window_controller->SetWallpaperWidgetController(nullptr); |
| 117 root_window_controller->SetAnimatingWallpaperWidgetController(nullptr); | 118 root_window_controller->SetAnimatingWallpaperWidgetController(nullptr); |
| 118 controller_ = WmShell::Get()->wallpaper_controller(); | 119 controller_ = Shell::GetInstance()->wallpaper_controller(); |
| 119 wallpaper_delegate_ = static_cast<test::TestWallpaperDelegate*>( | 120 wallpaper_delegate_ = static_cast<test::TestWallpaperDelegate*>( |
| 120 WmShell::Get()->wallpaper_delegate()); | 121 WmShell::Get()->wallpaper_delegate()); |
| 121 controller_->set_wallpaper_reload_delay_for_test(0); | 122 controller_->set_wallpaper_reload_delay_for_test(0); |
| 122 } | 123 } |
| 123 | 124 |
| 124 WallpaperView* wallpaper_view() { | 125 WallpaperView* wallpaper_view() { |
| 125 WallpaperWidgetController* controller = | 126 WallpaperWidgetController* controller = |
| 126 WmShell::Get() | 127 WmShell::Get() |
| 127 ->GetPrimaryRootWindow() | 128 ->GetPrimaryRootWindow() |
| 128 ->GetRootWindowController() | 129 ->GetRootWindowController() |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 194 |
| 194 WallpaperController* controller_; // Not owned. | 195 WallpaperController* controller_; // Not owned. |
| 195 | 196 |
| 196 test::TestWallpaperDelegate* wallpaper_delegate_; | 197 test::TestWallpaperDelegate* wallpaper_delegate_; |
| 197 | 198 |
| 198 private: | 199 private: |
| 199 DISALLOW_COPY_AND_ASSIGN(WallpaperControllerTest); | 200 DISALLOW_COPY_AND_ASSIGN(WallpaperControllerTest); |
| 200 }; | 201 }; |
| 201 | 202 |
| 202 TEST_F(WallpaperControllerTest, BasicReparenting) { | 203 TEST_F(WallpaperControllerTest, BasicReparenting) { |
| 203 WallpaperController* controller = WmShell::Get()->wallpaper_controller(); | 204 WallpaperController* controller = |
| 205 Shell::GetInstance()->wallpaper_controller(); |
| 204 controller->CreateEmptyWallpaper(); | 206 controller->CreateEmptyWallpaper(); |
| 205 | 207 |
| 206 // Wallpaper view/window exists in the wallpaper container and nothing is in | 208 // Wallpaper view/window exists in the wallpaper container and nothing is in |
| 207 // the lock screen wallpaper container. | 209 // the lock screen wallpaper container. |
| 208 EXPECT_EQ(1, ChildCountForContainer(kWallpaperId)); | 210 EXPECT_EQ(1, ChildCountForContainer(kWallpaperId)); |
| 209 EXPECT_EQ(0, ChildCountForContainer(kLockScreenWallpaperId)); | 211 EXPECT_EQ(0, ChildCountForContainer(kLockScreenWallpaperId)); |
| 210 | 212 |
| 211 // Moving wallpaper to lock container should succeed the first time but | 213 // Moving wallpaper to lock container should succeed the first time but |
| 212 // subsequent calls should do nothing. | 214 // subsequent calls should do nothing. |
| 213 EXPECT_TRUE(controller->MoveToLockedContainer()); | 215 EXPECT_TRUE(controller->MoveToLockedContainer()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 225 EXPECT_EQ(1, ChildCountForContainer(kWallpaperId)); | 227 EXPECT_EQ(1, ChildCountForContainer(kWallpaperId)); |
| 226 EXPECT_EQ(0, ChildCountForContainer(kLockScreenWallpaperId)); | 228 EXPECT_EQ(0, ChildCountForContainer(kLockScreenWallpaperId)); |
| 227 } | 229 } |
| 228 | 230 |
| 229 TEST_F(WallpaperControllerTest, ControllerOwnership) { | 231 TEST_F(WallpaperControllerTest, ControllerOwnership) { |
| 230 // We cannot short-circuit animations for this test. | 232 // We cannot short-circuit animations for this test. |
| 231 ui::ScopedAnimationDurationScaleMode test_duration_mode( | 233 ui::ScopedAnimationDurationScaleMode test_duration_mode( |
| 232 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | 234 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); |
| 233 | 235 |
| 234 // Create the wallpaper and its view. | 236 // Create the wallpaper and its view. |
| 235 WallpaperController* controller = WmShell::Get()->wallpaper_controller(); | 237 WallpaperController* controller = |
| 238 Shell::GetInstance()->wallpaper_controller(); |
| 236 controller->CreateEmptyWallpaper(); | 239 controller->CreateEmptyWallpaper(); |
| 237 | 240 |
| 238 // The new wallpaper is ready to animate. | 241 // The new wallpaper is ready to animate. |
| 239 RootWindowController* root_window_controller = | 242 RootWindowController* root_window_controller = |
| 240 WmShell::Get()->GetPrimaryRootWindow()->GetRootWindowController(); | 243 WmShell::Get()->GetPrimaryRootWindow()->GetRootWindowController(); |
| 241 EXPECT_TRUE(root_window_controller->animating_wallpaper_widget_controller() | 244 EXPECT_TRUE(root_window_controller->animating_wallpaper_widget_controller() |
| 242 ->GetController(false)); | 245 ->GetController(false)); |
| 243 EXPECT_FALSE(root_window_controller->wallpaper_widget_controller()); | 246 EXPECT_FALSE(root_window_controller->wallpaper_widget_controller()); |
| 244 | 247 |
| 245 // Force the animation to play to completion. | 248 // Force the animation to play to completion. |
| 246 RunDesktopControllerAnimation(); | 249 RunDesktopControllerAnimation(); |
| 247 EXPECT_FALSE(root_window_controller->animating_wallpaper_widget_controller() | 250 EXPECT_FALSE(root_window_controller->animating_wallpaper_widget_controller() |
| 248 ->GetController(false)); | 251 ->GetController(false)); |
| 249 EXPECT_TRUE(root_window_controller->wallpaper_widget_controller()); | 252 EXPECT_TRUE(root_window_controller->wallpaper_widget_controller()); |
| 250 } | 253 } |
| 251 | 254 |
| 252 // Test for crbug.com/149043 "Unlock screen, no launcher appears". Ensure we | 255 // Test for crbug.com/149043 "Unlock screen, no launcher appears". Ensure we |
| 253 // move all wallpaper views if there are more than one. | 256 // move all wallpaper views if there are more than one. |
| 254 TEST_F(WallpaperControllerTest, WallpaperMovementDuringUnlock) { | 257 TEST_F(WallpaperControllerTest, WallpaperMovementDuringUnlock) { |
| 255 // We cannot short-circuit animations for this test. | 258 // We cannot short-circuit animations for this test. |
| 256 ui::ScopedAnimationDurationScaleMode test_duration_mode( | 259 ui::ScopedAnimationDurationScaleMode test_duration_mode( |
| 257 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | 260 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); |
| 258 | 261 |
| 259 // Reset wallpaper state, see ControllerOwnership above. | 262 // Reset wallpaper state, see ControllerOwnership above. |
| 260 WallpaperController* controller = WmShell::Get()->wallpaper_controller(); | 263 WallpaperController* controller = |
| 264 Shell::GetInstance()->wallpaper_controller(); |
| 261 controller->CreateEmptyWallpaper(); | 265 controller->CreateEmptyWallpaper(); |
| 262 | 266 |
| 263 // Run wallpaper show animation to completion. | 267 // Run wallpaper show animation to completion. |
| 264 RunDesktopControllerAnimation(); | 268 RunDesktopControllerAnimation(); |
| 265 | 269 |
| 266 // User locks the screen, which moves the wallpaper forward. | 270 // User locks the screen, which moves the wallpaper forward. |
| 267 controller->MoveToLockedContainer(); | 271 controller->MoveToLockedContainer(); |
| 268 | 272 |
| 269 // Suspend/resume cycle causes wallpaper to refresh, loading a new wallpaper | 273 // Suspend/resume cycle causes wallpaper to refresh, loading a new wallpaper |
| 270 // that will animate in on top of the old one. | 274 // that will animate in on top of the old one. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 297 } | 301 } |
| 298 | 302 |
| 299 // Test for crbug.com/156542. Animating wallpaper should immediately finish | 303 // Test for crbug.com/156542. Animating wallpaper should immediately finish |
| 300 // animation and replace current wallpaper before next animation starts. | 304 // animation and replace current wallpaper before next animation starts. |
| 301 TEST_F(WallpaperControllerTest, ChangeWallpaperQuick) { | 305 TEST_F(WallpaperControllerTest, ChangeWallpaperQuick) { |
| 302 // We cannot short-circuit animations for this test. | 306 // We cannot short-circuit animations for this test. |
| 303 ui::ScopedAnimationDurationScaleMode test_duration_mode( | 307 ui::ScopedAnimationDurationScaleMode test_duration_mode( |
| 304 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); | 308 ui::ScopedAnimationDurationScaleMode::NON_ZERO_DURATION); |
| 305 | 309 |
| 306 // Reset wallpaper state, see ControllerOwnership above. | 310 // Reset wallpaper state, see ControllerOwnership above. |
| 307 WallpaperController* controller = WmShell::Get()->wallpaper_controller(); | 311 WallpaperController* controller = |
| 312 Shell::GetInstance()->wallpaper_controller(); |
| 308 controller->CreateEmptyWallpaper(); | 313 controller->CreateEmptyWallpaper(); |
| 309 | 314 |
| 310 // Run wallpaper show animation to completion. | 315 // Run wallpaper show animation to completion. |
| 311 RunDesktopControllerAnimation(); | 316 RunDesktopControllerAnimation(); |
| 312 | 317 |
| 313 // Change to a new wallpaper. | 318 // Change to a new wallpaper. |
| 314 controller->CreateEmptyWallpaper(); | 319 controller->CreateEmptyWallpaper(); |
| 315 | 320 |
| 316 RootWindowController* root_window_controller = | 321 RootWindowController* root_window_controller = |
| 317 WmShell::Get()->GetPrimaryRootWindow()->GetRootWindowController(); | 322 WmShell::Get()->GetPrimaryRootWindow()->GetRootWindowController(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 | 354 |
| 350 TEST_F(WallpaperControllerTest, ResizeCustomWallpaper) { | 355 TEST_F(WallpaperControllerTest, ResizeCustomWallpaper) { |
| 351 UpdateDisplay("320x200"); | 356 UpdateDisplay("320x200"); |
| 352 | 357 |
| 353 gfx::ImageSkia image = CreateImage(640, 480, kCustomWallpaperColor); | 358 gfx::ImageSkia image = CreateImage(640, 480, kCustomWallpaperColor); |
| 354 | 359 |
| 355 // Set the image as custom wallpaper, wait for the resize to finish, and check | 360 // Set the image as custom wallpaper, wait for the resize to finish, and check |
| 356 // that the resized image is the expected size. | 361 // that the resized image is the expected size. |
| 357 controller_->SetWallpaperImage(image, WALLPAPER_LAYOUT_STRETCH); | 362 controller_->SetWallpaperImage(image, WALLPAPER_LAYOUT_STRETCH); |
| 358 EXPECT_TRUE(image.BackedBySameObjectAs(controller_->GetWallpaper())); | 363 EXPECT_TRUE(image.BackedBySameObjectAs(controller_->GetWallpaper())); |
| 359 RunAllBlockingPoolTasksUntilIdle(WmShell::Get()->blocking_pool().get()); | 364 RunAllBlockingPoolTasksUntilIdle(Shell::GetInstance()->blocking_pool().get()); |
| 360 gfx::ImageSkia resized_image = controller_->GetWallpaper(); | 365 gfx::ImageSkia resized_image = controller_->GetWallpaper(); |
| 361 EXPECT_FALSE(image.BackedBySameObjectAs(resized_image)); | 366 EXPECT_FALSE(image.BackedBySameObjectAs(resized_image)); |
| 362 EXPECT_EQ(gfx::Size(320, 200).ToString(), resized_image.size().ToString()); | 367 EXPECT_EQ(gfx::Size(320, 200).ToString(), resized_image.size().ToString()); |
| 363 | 368 |
| 364 // Load the original wallpaper again and check that we're still using the | 369 // Load the original wallpaper again and check that we're still using the |
| 365 // previously-resized image instead of doing another resize | 370 // previously-resized image instead of doing another resize |
| 366 // (http://crbug.com/321402). | 371 // (http://crbug.com/321402). |
| 367 controller_->SetWallpaperImage(image, WALLPAPER_LAYOUT_STRETCH); | 372 controller_->SetWallpaperImage(image, WALLPAPER_LAYOUT_STRETCH); |
| 368 RunAllBlockingPoolTasksUntilIdle(WmShell::Get()->blocking_pool().get()); | 373 RunAllBlockingPoolTasksUntilIdle(Shell::GetInstance()->blocking_pool().get()); |
| 369 EXPECT_TRUE(resized_image.BackedBySameObjectAs(controller_->GetWallpaper())); | 374 EXPECT_TRUE(resized_image.BackedBySameObjectAs(controller_->GetWallpaper())); |
| 370 } | 375 } |
| 371 | 376 |
| 372 TEST_F(WallpaperControllerTest, GetMaxDisplaySize) { | 377 TEST_F(WallpaperControllerTest, GetMaxDisplaySize) { |
| 373 // Device scale factor shouldn't affect the native size. | 378 // Device scale factor shouldn't affect the native size. |
| 374 UpdateDisplay("1000x300*2"); | 379 UpdateDisplay("1000x300*2"); |
| 375 EXPECT_EQ("1000x300", | 380 EXPECT_EQ("1000x300", |
| 376 WallpaperController::GetMaxDisplaySizeInNative().ToString()); | 381 WallpaperController::GetMaxDisplaySizeInNative().ToString()); |
| 377 | 382 |
| 378 // TODO: mash doesn't support rotation yet, http://crbug.com/695556. | 383 // TODO: mash doesn't support rotation yet, http://crbug.com/695556. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 { | 469 { |
| 465 SCOPED_TRACE(base::StringPrintf("1200x600/u@1.5 low resolution")); | 470 SCOPED_TRACE(base::StringPrintf("1200x600/u@1.5 low resolution")); |
| 466 controller_->SetWallpaperImage(image_low_res, WALLPAPER_LAYOUT_CENTER); | 471 controller_->SetWallpaperImage(image_low_res, WALLPAPER_LAYOUT_CENTER); |
| 467 WallpaperFitToNativeResolution( | 472 WallpaperFitToNativeResolution( |
| 468 wallpaper_view(), low_dsf, low_resolution.width(), | 473 wallpaper_view(), low_dsf, low_resolution.width(), |
| 469 low_resolution.height(), kCustomWallpaperColor); | 474 low_resolution.height(), kCustomWallpaperColor); |
| 470 } | 475 } |
| 471 } | 476 } |
| 472 | 477 |
| 473 } // namespace ash | 478 } // namespace ash |
| OLD | NEW |