| 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/wm/power_button_controller.h" | 5 #include "ash/wm/power_button_controller.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/time.h" | 10 #include "base/time.h" |
| 11 #include "ui/aura/root_window.h" | 11 #include "ui/aura/root_window.h" |
| 12 #include "ui/aura/window.h" | |
| 13 | 12 |
| 14 namespace ash { | 13 namespace ash { |
| 15 namespace test { | 14 namespace test { |
| 16 | 15 |
| 17 // Fake implementation of PowerButtonControllerDelegate that just logs requests | 16 // Fake implementation of PowerButtonControllerDelegate that just logs requests |
| 18 // to lock the screen and shut down the device. | 17 // to lock the screen and shut down the device. |
| 19 class TestPowerButtonControllerDelegate : public PowerButtonControllerDelegate { | 18 class TestPowerButtonControllerDelegate : public PowerButtonControllerDelegate { |
| 20 public: | 19 public: |
| 21 TestPowerButtonControllerDelegate() | 20 TestPowerButtonControllerDelegate() |
| 22 : num_lock_requests_(0), | 21 : num_lock_requests_(0), |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 // Notify that the screen has been unlocked. We should show the | 270 // Notify that the screen has been unlocked. We should show the |
| 272 // non-screen-locker windows and hide the background layer. | 271 // non-screen-locker windows and hide the background layer. |
| 273 controller_->OnLockStateChange(false); | 272 controller_->OnLockStateChange(false); |
| 274 EXPECT_TRUE( | 273 EXPECT_TRUE( |
| 275 test_api_->ContainerGroupIsAnimated( | 274 test_api_->ContainerGroupIsAnimated( |
| 276 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | 275 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, |
| 277 PowerButtonController::ANIMATION_RESTORE)); | 276 PowerButtonController::ANIMATION_RESTORE)); |
| 278 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); | 277 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); |
| 279 } | 278 } |
| 280 | 279 |
| 281 // Test that we restore transformations that are non empty. | |
| 282 TEST_F(PowerButtonControllerTest, LockAndUnlockTransformed) { | |
| 283 controller_->set_has_legacy_power_button_for_test(false); | |
| 284 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); | |
| 285 controller_->OnLockStateChange(false); | |
| 286 | |
| 287 // Get current transformation on the containers. | |
| 288 aura::Window::Windows windows; | |
| 289 controller_->GetContainers( | |
| 290 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | |
| 291 &windows); | |
| 292 | |
| 293 // Set a random transform to each container layer. | |
| 294 ui::Transform expected_transform; | |
| 295 expected_transform.ConcatTranslate(180, 180); | |
| 296 for (aura::Window::Windows::iterator it = windows.begin(); | |
| 297 it != windows.end(); | |
| 298 ++it) { | |
| 299 (*it)->layer()->SetTransform(expected_transform); | |
| 300 } | |
| 301 | |
| 302 // Press the power button and check that the lock timer is started and that we | |
| 303 // start scaling the non-screen-locker containers. | |
| 304 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | |
| 305 EXPECT_TRUE(test_api_->lock_timer_is_running()); | |
| 306 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | |
| 307 EXPECT_TRUE( | |
| 308 test_api_->ContainerGroupIsAnimated( | |
| 309 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | |
| 310 PowerButtonController::ANIMATION_SLOW_CLOSE)); | |
| 311 | |
| 312 // Check current transformation is different than before. | |
| 313 windows.clear(); | |
| 314 controller_->GetContainers( | |
| 315 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | |
| 316 &windows); | |
| 317 for (aura::Window::Windows::iterator it = windows.begin(); | |
| 318 it != windows.end(); | |
| 319 ++it) { | |
| 320 EXPECT_NE(expected_transform, (*it)->layer()->GetTargetTransform()); | |
| 321 } | |
| 322 | |
| 323 // Release the button before the lock timer fires. | |
| 324 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | |
| 325 EXPECT_FALSE(test_api_->lock_timer_is_running()); | |
| 326 EXPECT_TRUE( | |
| 327 test_api_->ContainerGroupIsAnimated( | |
| 328 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | |
| 329 PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE)); | |
| 330 | |
| 331 // Get current transformation on the containers to compare, | |
| 332 // it shouldn't have changed. | |
| 333 windows.clear(); | |
| 334 controller_->GetContainers( | |
| 335 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, | |
| 336 &windows); | |
| 337 for (aura::Window::Windows::iterator it = windows.begin(); | |
| 338 it != windows.end(); | |
| 339 ++it) { | |
| 340 EXPECT_EQ(expected_transform, (*it)->layer()->GetTargetTransform()); | |
| 341 } | |
| 342 } | |
| 343 | |
| 344 // Hold the power button down from the unlocked state to eventual shutdown. | 280 // Hold the power button down from the unlocked state to eventual shutdown. |
| 345 TEST_F(PowerButtonControllerTest, LockToShutdown) { | 281 TEST_F(PowerButtonControllerTest, LockToShutdown) { |
| 346 controller_->set_has_legacy_power_button_for_test(false); | 282 controller_->set_has_legacy_power_button_for_test(false); |
| 347 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); | 283 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); |
| 348 controller_->OnLockStateChange(false); | 284 controller_->OnLockStateChange(false); |
| 349 | 285 |
| 350 // Hold the power button and lock the screen. | 286 // Hold the power button and lock the screen. |
| 351 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 287 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 352 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 288 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| 353 test_api_->trigger_lock_timeout(); | 289 test_api_->trigger_lock_timeout(); |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 581 EXPECT_FALSE(aura::RootWindow::GetInstance()->cursor_shown()); | 517 EXPECT_FALSE(aura::RootWindow::GetInstance()->cursor_shown()); |
| 582 | 518 |
| 583 EXPECT_EQ(0, delegate_->num_shutdown_requests()); | 519 EXPECT_EQ(0, delegate_->num_shutdown_requests()); |
| 584 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 520 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 585 test_api_->trigger_real_shutdown_timeout(); | 521 test_api_->trigger_real_shutdown_timeout(); |
| 586 EXPECT_EQ(1, delegate_->num_shutdown_requests()); | 522 EXPECT_EQ(1, delegate_->num_shutdown_requests()); |
| 587 } | 523 } |
| 588 | 524 |
| 589 } // namespace test | 525 } // namespace test |
| 590 } // namespace ash | 526 } // namespace ash |
| OLD | NEW |