| 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 #include "ash/wm/session_state_animator.h" | 6 #include "ash/wm/session_state_animator.h" |
| 7 #include "ash/wm/session_state_controller.h" | 7 #include "ash/wm/session_state_controller.h" |
| 8 #include "ash/wm/session_state_controller_impl.h" |
| 8 | 9 |
| 9 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 10 #include "ash/test/ash_test_base.h" | 11 #include "ash/test/ash_test_base.h" |
| 11 #include "ash/test/test_shell_delegate.h" | 12 #include "ash/test/test_shell_delegate.h" |
| 12 #include "ash/wm/cursor_manager.h" | 13 #include "ash/wm/cursor_manager.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/time.h" | 15 #include "base/time.h" |
| 15 #include "ui/aura/env.h" | 16 #include "ui/aura/env.h" |
| 16 #include "ui/aura/root_window.h" | 17 #include "ui/aura/root_window.h" |
| 17 #include "ui/aura/test/event_generator.h" | 18 #include "ui/aura/test/event_generator.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 56 |
| 56 class PowerButtonControllerTest : public AshTestBase { | 57 class PowerButtonControllerTest : public AshTestBase { |
| 57 public: | 58 public: |
| 58 PowerButtonControllerTest() : controller_(NULL), delegate_(NULL) {} | 59 PowerButtonControllerTest() : controller_(NULL), delegate_(NULL) {} |
| 59 virtual ~PowerButtonControllerTest() {} | 60 virtual ~PowerButtonControllerTest() {} |
| 60 | 61 |
| 61 void SetUp() OVERRIDE { | 62 void SetUp() OVERRIDE { |
| 62 AshTestBase::SetUp(); | 63 AshTestBase::SetUp(); |
| 63 delegate_ = new TestPowerButtonControllerDelegate; | 64 delegate_ = new TestPowerButtonControllerDelegate; |
| 64 controller_ = Shell::GetInstance()->power_button_controller(); | 65 controller_ = Shell::GetInstance()->power_button_controller(); |
| 65 state_controller_ = Shell::GetInstance()->session_state_controller(); | 66 state_controller_ = reinterpret_cast<SessionStateControllerImpl*>( |
| 67 Shell::GetInstance()->session_state_controller()); |
| 66 state_controller_->SetDelegate(delegate_); // transfers ownership | 68 state_controller_->SetDelegate(delegate_); // transfers ownership |
| 67 test_api_.reset(new SessionStateController::TestApi(state_controller_)); | 69 test_api_.reset(new SessionStateControllerImpl::TestApi(state_controller_)); |
| 68 animator_api_.reset( | 70 animator_api_.reset( |
| 69 new internal::SessionStateAnimator::TestApi(state_controller_-> | 71 new internal::SessionStateAnimator::TestApi(state_controller_-> |
| 70 animator_.get())); | 72 animator_.get())); |
| 71 } | 73 } |
| 72 | 74 |
| 73 protected: | 75 protected: |
| 74 void GenerateMouseMoveEvent() { | 76 void GenerateMouseMoveEvent() { |
| 75 aura::test::EventGenerator generator( | 77 aura::test::EventGenerator generator( |
| 76 Shell::GetPrimaryRootWindow()); | 78 Shell::GetPrimaryRootWindow()); |
| 77 generator.MoveMouseTo(10, 10); | 79 generator.MoveMouseTo(10, 10); |
| 78 } | 80 } |
| 79 | 81 |
| 80 int NumShutdownRequests() { | 82 int NumShutdownRequests() { |
| 81 return delegate_->num_shutdown_requests() + | 83 return delegate_->num_shutdown_requests() + |
| 82 reinterpret_cast<TestShellDelegate*>( | 84 reinterpret_cast<TestShellDelegate*>( |
| 83 ash::Shell::GetInstance()->delegate())->num_exit_requests(); | 85 ash::Shell::GetInstance()->delegate())->num_exit_requests(); |
| 84 } | 86 } |
| 85 | 87 |
| 86 PowerButtonController* controller_; // not owned | 88 PowerButtonController* controller_; // not owned |
| 87 SessionStateController* state_controller_; // not owned | 89 SessionStateControllerImpl* state_controller_; // not owned |
| 88 TestPowerButtonControllerDelegate* delegate_; // not owned | 90 TestPowerButtonControllerDelegate* delegate_; // not owned |
| 89 | 91 |
| 90 scoped_ptr<SessionStateController::TestApi> test_api_; | 92 scoped_ptr<SessionStateControllerImpl::TestApi> test_api_; |
| 91 scoped_ptr<internal::SessionStateAnimator::TestApi> animator_api_; | 93 scoped_ptr<internal::SessionStateAnimator::TestApi> animator_api_; |
| 92 | 94 |
| 93 private: | 95 private: |
| 94 DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerTest); | 96 DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerTest); |
| 95 }; | 97 }; |
| 96 | 98 |
| 97 // Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't | 99 // Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't |
| 98 // correctly report power button releases. We should lock immediately the first | 100 // correctly report power button releases. We should lock immediately the first |
| 99 // time the button is pressed and shut down when it's pressed from the locked | 101 // time the button is pressed and shut down when it's pressed from the locked |
| 100 // state. | 102 // state. |
| 101 TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) { | 103 TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) { |
| 102 controller_->set_has_legacy_power_button_for_test(true); | 104 controller_->set_has_legacy_power_button_for_test(true); |
| 103 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 105 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 104 state_controller_->OnLockStateChanged(false); | 106 state_controller_->OnLockStateChanged(false); |
| 105 | 107 |
| 106 // We should request that the screen be locked immediately after seeing the | 108 // We should request that the screen be locked immediately after seeing the |
| 107 // power button get pressed. | 109 // power button get pressed. |
| 108 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 110 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 109 EXPECT_TRUE( | 111 EXPECT_TRUE( |
| 110 animator_api_->ContainersAreAnimated( | 112 animator_api_->ContainersAreAnimated( |
| 111 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 113 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 112 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); | 114 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); |
| 113 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 115 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); |
| 114 EXPECT_FALSE(animator_api_->hide_black_layer_timer_is_running()); | 116 EXPECT_FALSE(animator_api_->hide_black_layer_timer_is_running()); |
| 115 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 117 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| 116 EXPECT_EQ(1, delegate_->num_lock_requests()); | 118 EXPECT_EQ(1, delegate_->num_lock_requests()); |
| 117 | 119 |
| 118 // Notify that we locked successfully. | 120 // Notify that we locked successfully. |
| 119 state_controller_->OnStartingLock(); | 121 state_controller_->OnStartingLock(); |
| 120 EXPECT_TRUE( | 122 EXPECT_TRUE( |
| 121 animator_api_->ContainersAreAnimated( | 123 animator_api_->ContainersAreAnimated( |
| 122 internal::SessionStateAnimator::LAUNCHER, | 124 internal::SessionStateAnimator::LAUNCHER, |
| 123 internal::SessionStateAnimator::ANIMATION_HIDE)); | 125 internal::SessionStateAnimator::ANIMATION_HIDE)); |
| 124 EXPECT_TRUE( | 126 EXPECT_TRUE( |
| 125 animator_api_->ContainersAreAnimated( | 127 animator_api_->ContainersAreAnimated( |
| 126 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 128 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 127 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); | 129 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); |
| 128 EXPECT_TRUE( | 130 EXPECT_TRUE( |
| 129 animator_api_->ContainersAreAnimated( | 131 animator_api_->ContainersAreAnimated( |
| 130 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | 132 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 131 internal::SessionStateAnimator::ANIMATION_HIDE)); | 133 internal::SessionStateAnimator::ANIMATION_HIDE)); |
| 132 | 134 |
| 133 // Notify that the lock window is visible. We should make it fade in. | 135 // Notify that the lock window is visible. We should make it fade in. |
| 134 state_controller_->OnLockStateChanged(true); | 136 state_controller_->OnLockStateChanged(true); |
| 135 EXPECT_TRUE( | 137 EXPECT_TRUE( |
| 136 animator_api_->ContainersAreAnimated( | 138 animator_api_->ContainersAreAnimated( |
| 137 internal::SessionStateAnimator::kAllLockScreenContainersMask, | 139 internal::SessionStateAnimator::kAllLockScreenContainersMask, |
| (...skipping 13 matching lines...) Expand all Loading... |
| 151 // 1. All user session containers have transform (including wallpaper). | 153 // 1. All user session containers have transform (including wallpaper). |
| 152 // They're in this state after lock. | 154 // They're in this state after lock. |
| 153 // 2. Screen locker and related containers are in fact animating | 155 // 2. Screen locker and related containers are in fact animating |
| 154 // (as shutdown is in progress). | 156 // (as shutdown is in progress). |
| 155 // With http://crbug.com/144737 we no longer animate user session wallpaper | 157 // With http://crbug.com/144737 we no longer animate user session wallpaper |
| 156 // during lock so it makes sense only to check that screen lock and related | 158 // during lock so it makes sense only to check that screen lock and related |
| 157 // containers are animated during shutdown. | 159 // containers are animated during shutdown. |
| 158 EXPECT_TRUE( | 160 EXPECT_TRUE( |
| 159 animator_api_->ContainersAreAnimated( | 161 animator_api_->ContainersAreAnimated( |
| 160 internal::SessionStateAnimator::kAllLockScreenContainersMask, | 162 internal::SessionStateAnimator::kAllLockScreenContainersMask, |
| 161 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); | 163 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); |
| 162 // Make sure a mouse move event won't show the cursor. | 164 // Make sure a mouse move event won't show the cursor. |
| 163 GenerateMouseMoveEvent(); | 165 GenerateMouseMoveEvent(); |
| 164 EXPECT_FALSE(cursor_visible()); | 166 EXPECT_FALSE(cursor_visible()); |
| 165 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 167 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 166 test_api_->trigger_real_shutdown_timeout(); | 168 test_api_->trigger_real_shutdown_timeout(); |
| 167 EXPECT_EQ(1, NumShutdownRequests()); | 169 EXPECT_EQ(1, NumShutdownRequests()); |
| 168 } | 170 } |
| 169 | 171 |
| 170 // Test that we start shutting down immediately if the power button is pressed | 172 // Test that we start shutting down immediately if the power button is pressed |
| 171 // while we're not logged in on an unofficial system. | 173 // while we're not logged in on an unofficial system. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 195 state_controller_->OnLockStateChanged(false); | 197 state_controller_->OnLockStateChanged(false); |
| 196 EXPECT_FALSE(animator_api_->BlackLayerIsVisible()); | 198 EXPECT_FALSE(animator_api_->BlackLayerIsVisible()); |
| 197 | 199 |
| 198 // Press the power button and check that we start the shutdown timer. | 200 // Press the power button and check that we start the shutdown timer. |
| 199 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 201 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 200 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 202 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| 201 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 203 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
| 202 EXPECT_TRUE( | 204 EXPECT_TRUE( |
| 203 animator_api_->ContainersAreAnimated( | 205 animator_api_->ContainersAreAnimated( |
| 204 internal::SessionStateAnimator::kAllContainersMask, | 206 internal::SessionStateAnimator::kAllContainersMask, |
| 205 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); | 207 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); |
| 206 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 208 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); |
| 207 | 209 |
| 208 // Release the power button before the shutdown timer fires. | 210 // Release the power button before the shutdown timer fires. |
| 209 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 211 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| 210 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 212 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
| 211 EXPECT_TRUE( | 213 EXPECT_TRUE( |
| 212 animator_api_->ContainersAreAnimated( | 214 animator_api_->ContainersAreAnimated( |
| 213 internal::SessionStateAnimator::kAllContainersMask, | 215 internal::SessionStateAnimator::kAllContainersMask, |
| 214 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE)); | 216 internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE)); |
| 215 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 217 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); |
| 216 | 218 |
| 217 // We should re-hide the black layer after waiting long enough for | 219 // We should re-hide the black layer after waiting long enough for |
| 218 // the animation to finish. | 220 // the animation to finish. |
| 219 EXPECT_TRUE(animator_api_->hide_black_layer_timer_is_running()); | 221 EXPECT_TRUE(animator_api_->hide_black_layer_timer_is_running()); |
| 220 animator_api_->TriggerHideBlackLayerTimeout(); | 222 animator_api_->TriggerHideBlackLayerTimeout(); |
| 221 EXPECT_FALSE(animator_api_->BlackLayerIsVisible()); | 223 EXPECT_FALSE(animator_api_->BlackLayerIsVisible()); |
| 222 | 224 |
| 223 // Press the button again and make the shutdown timeout fire this time. | 225 // Press the button again and make the shutdown timeout fire this time. |
| 224 // Check that we start the timer for actually requesting the shutdown. | 226 // Check that we start the timer for actually requesting the shutdown. |
| 225 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 227 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 226 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 228 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
| 227 test_api_->trigger_shutdown_timeout(); | 229 test_api_->trigger_shutdown_timeout(); |
| 228 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 230 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 229 EXPECT_EQ(0, NumShutdownRequests()); | 231 EXPECT_EQ(0, NumShutdownRequests()); |
| 230 EXPECT_TRUE( | 232 EXPECT_TRUE( |
| 231 animator_api_->ContainersAreAnimated( | 233 animator_api_->ContainersAreAnimated( |
| 232 internal::SessionStateAnimator::LAUNCHER | | 234 internal::SessionStateAnimator::LAUNCHER | |
| 233 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 235 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 234 internal::SessionStateAnimator::ANIMATION_HIDE)); | 236 internal::SessionStateAnimator::ANIMATION_HIDE)); |
| 235 EXPECT_TRUE( | 237 EXPECT_TRUE( |
| 236 animator_api_->ContainersAreAnimated( | 238 animator_api_->ContainersAreAnimated( |
| 237 internal::SessionStateAnimator::kAllLockScreenContainersMask, | 239 internal::SessionStateAnimator::kAllLockScreenContainersMask, |
| 238 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); | 240 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); |
| 239 | 241 |
| 240 // When the timout fires, we should request a shutdown. | 242 // When the timout fires, we should request a shutdown. |
| 241 test_api_->trigger_real_shutdown_timeout(); | 243 test_api_->trigger_real_shutdown_timeout(); |
| 242 EXPECT_EQ(1, NumShutdownRequests()); | 244 EXPECT_EQ(1, NumShutdownRequests()); |
| 243 } | 245 } |
| 244 | 246 |
| 245 // Test that we lock the screen and deal with unlocking correctly. | 247 // Test that we lock the screen and deal with unlocking correctly. |
| 246 TEST_F(PowerButtonControllerTest, LockAndUnlock) { | 248 TEST_F(PowerButtonControllerTest, LockAndUnlock) { |
| 247 controller_->set_has_legacy_power_button_for_test(false); | 249 controller_->set_has_legacy_power_button_for_test(false); |
| 248 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 250 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 249 state_controller_->OnLockStateChanged(false); | 251 state_controller_->OnLockStateChanged(false); |
| 250 EXPECT_FALSE(animator_api_->BlackLayerIsVisible()); | 252 EXPECT_FALSE(animator_api_->BlackLayerIsVisible()); |
| 251 | 253 |
| 252 // We should initially be showing the screen locker containers, since they | 254 // We should initially be showing the screen locker containers, since they |
| 253 // also contain login-related windows that we want to show during the | 255 // also contain login-related windows that we want to show during the |
| 254 // logging-in animation. | 256 // logging-in animation. |
| 255 EXPECT_TRUE( | 257 EXPECT_TRUE( |
| 256 animator_api_->ContainersAreAnimated( | 258 animator_api_->ContainersAreAnimated( |
| 257 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | 259 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 258 internal::SessionStateAnimator::ANIMATION_RESTORE)); | 260 internal::SessionStateAnimator::ANIMATION_RESTORE)); |
| 259 | 261 |
| 260 // Press the power button and check that the lock timer is started and that we | 262 // Press the power button and check that the lock timer is started and that we |
| 261 // start scaling the non-screen-locker containers. | 263 // start scaling the non-screen-locker containers. |
| 262 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 264 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 263 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 265 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| 264 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 266 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
| 265 EXPECT_TRUE( | 267 EXPECT_TRUE( |
| 266 animator_api_->ContainersAreAnimated( | 268 animator_api_->ContainersAreAnimated( |
| 267 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 269 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 268 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); | 270 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); |
| 269 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 271 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); |
| 270 | 272 |
| 271 // Release the button before the lock timer fires. | 273 // Release the button before the lock timer fires. |
| 272 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 274 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| 273 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 275 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| 274 EXPECT_TRUE( | 276 EXPECT_TRUE( |
| 275 animator_api_->ContainersAreAnimated( | 277 animator_api_->ContainersAreAnimated( |
| 276 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 278 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 277 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE)); | 279 internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE)); |
| 278 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 280 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); |
| 279 EXPECT_TRUE(animator_api_->hide_black_layer_timer_is_running()); | 281 EXPECT_TRUE(animator_api_->hide_black_layer_timer_is_running()); |
| 280 animator_api_->TriggerHideBlackLayerTimeout(); | 282 animator_api_->TriggerHideBlackLayerTimeout(); |
| 281 EXPECT_FALSE(animator_api_->BlackLayerIsVisible()); | 283 EXPECT_FALSE(animator_api_->BlackLayerIsVisible()); |
| 282 | 284 |
| 283 // Press the button and fire the lock timer. We should request that the | 285 // Press the button and fire the lock timer. We should request that the |
| 284 // screen be locked, but we should still be in the slow-close animation. | 286 // screen be locked, but we should still be in the slow-close animation. |
| 285 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 287 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 286 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 288 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| 287 EXPECT_EQ(0, delegate_->num_lock_requests()); | 289 EXPECT_EQ(0, delegate_->num_lock_requests()); |
| 288 test_api_->trigger_lock_timeout(); | 290 test_api_->trigger_lock_timeout(); |
| 289 EXPECT_EQ(1, delegate_->num_lock_requests()); | 291 EXPECT_EQ(1, delegate_->num_lock_requests()); |
| 290 EXPECT_TRUE( | 292 EXPECT_TRUE( |
| 291 animator_api_->ContainersAreAnimated( | 293 animator_api_->ContainersAreAnimated( |
| 292 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 294 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 293 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); | 295 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); |
| 294 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 296 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); |
| 295 | 297 |
| 296 // Notify that we locked successfully. | 298 // Notify that we locked successfully. |
| 297 state_controller_->OnStartingLock(); | 299 state_controller_->OnStartingLock(); |
| 298 EXPECT_TRUE( | 300 EXPECT_TRUE( |
| 299 animator_api_->ContainersAreAnimated( | 301 animator_api_->ContainersAreAnimated( |
| 300 internal::SessionStateAnimator::LAUNCHER, | 302 internal::SessionStateAnimator::LAUNCHER, |
| 301 internal::SessionStateAnimator::ANIMATION_HIDE)); | 303 internal::SessionStateAnimator::ANIMATION_HIDE)); |
| 302 EXPECT_TRUE( | 304 EXPECT_TRUE( |
| 303 animator_api_->ContainersAreAnimated( | 305 animator_api_->ContainersAreAnimated( |
| 304 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 306 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 305 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); | 307 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); |
| 306 EXPECT_TRUE( | 308 EXPECT_TRUE( |
| 307 animator_api_->ContainersAreAnimated( | 309 animator_api_->ContainersAreAnimated( |
| 308 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | 310 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 309 internal::SessionStateAnimator::ANIMATION_HIDE)); | 311 internal::SessionStateAnimator::ANIMATION_HIDE)); |
| 310 | 312 |
| 311 // Notify that the lock window is visible. We should make it fade in. | 313 // Notify that the lock window is visible. We should make it fade in. |
| 312 state_controller_->OnLockStateChanged(true); | 314 state_controller_->OnLockStateChanged(true); |
| 313 EXPECT_TRUE( | 315 EXPECT_TRUE( |
| 314 animator_api_->ContainersAreAnimated( | 316 animator_api_->ContainersAreAnimated( |
| 315 internal::SessionStateAnimator::kAllLockScreenContainersMask, | 317 internal::SessionStateAnimator::kAllLockScreenContainersMask, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 350 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); |
| 349 | 351 |
| 350 // When the lock-to-shutdown timeout fires, we should start the shutdown | 352 // When the lock-to-shutdown timeout fires, we should start the shutdown |
| 351 // timer. | 353 // timer. |
| 352 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); | 354 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); |
| 353 test_api_->trigger_lock_to_shutdown_timeout(); | 355 test_api_->trigger_lock_to_shutdown_timeout(); |
| 354 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 356 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
| 355 EXPECT_TRUE( | 357 EXPECT_TRUE( |
| 356 animator_api_->ContainersAreAnimated( | 358 animator_api_->ContainersAreAnimated( |
| 357 internal::SessionStateAnimator::kAllContainersMask, | 359 internal::SessionStateAnimator::kAllContainersMask, |
| 358 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); | 360 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); |
| 359 | 361 |
| 360 // Fire the shutdown timeout and check that we request shutdown. | 362 // Fire the shutdown timeout and check that we request shutdown. |
| 361 test_api_->trigger_shutdown_timeout(); | 363 test_api_->trigger_shutdown_timeout(); |
| 362 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 364 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 363 EXPECT_EQ(0, NumShutdownRequests()); | 365 EXPECT_EQ(0, NumShutdownRequests()); |
| 364 test_api_->trigger_real_shutdown_timeout(); | 366 test_api_->trigger_real_shutdown_timeout(); |
| 365 EXPECT_EQ(1, NumShutdownRequests()); | 367 EXPECT_EQ(1, NumShutdownRequests()); |
| 366 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 368 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); |
| 367 } | 369 } |
| 368 | 370 |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 462 EXPECT_EQ(0, delegate_->num_lock_requests()); | 464 EXPECT_EQ(0, delegate_->num_lock_requests()); |
| 463 | 465 |
| 464 // If we're logged in as a regular user, we should start the lock timer and | 466 // If we're logged in as a regular user, we should start the lock timer and |
| 465 // the pre-lock animation. | 467 // the pre-lock animation. |
| 466 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 468 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 467 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 469 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
| 468 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 470 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| 469 EXPECT_TRUE( | 471 EXPECT_TRUE( |
| 470 animator_api_->ContainersAreAnimated( | 472 animator_api_->ContainersAreAnimated( |
| 471 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 473 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 472 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); | 474 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); |
| 473 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 475 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); |
| 474 | 476 |
| 475 // If the button is released immediately, we shouldn't lock the screen. | 477 // If the button is released immediately, we shouldn't lock the screen. |
| 476 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 478 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
| 477 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 479 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| 478 EXPECT_TRUE( | 480 EXPECT_TRUE( |
| 479 animator_api_->ContainersAreAnimated( | 481 animator_api_->ContainersAreAnimated( |
| 480 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 482 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 481 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE)); | 483 internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE)); |
| 482 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 484 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); |
| 483 EXPECT_TRUE(animator_api_->hide_black_layer_timer_is_running()); | 485 EXPECT_TRUE(animator_api_->hide_black_layer_timer_is_running()); |
| 484 animator_api_->TriggerHideBlackLayerTimeout(); | 486 animator_api_->TriggerHideBlackLayerTimeout(); |
| 485 EXPECT_FALSE(animator_api_->BlackLayerIsVisible()); | 487 EXPECT_FALSE(animator_api_->BlackLayerIsVisible()); |
| 486 EXPECT_EQ(0, delegate_->num_lock_requests()); | 488 EXPECT_EQ(0, delegate_->num_lock_requests()); |
| 487 | 489 |
| 488 // Press the button again and let the lock timeout fire. We should request | 490 // Press the button again and let the lock timeout fire. We should request |
| 489 // that the screen be locked. | 491 // that the screen be locked. |
| 490 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 492 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
| 491 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 493 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 | 542 |
| 541 // When the screen is locked without going through the usual power-button | 543 // When the screen is locked without going through the usual power-button |
| 542 // slow-close path (e.g. via the wrench menu), test that we still show the | 544 // slow-close path (e.g. via the wrench menu), test that we still show the |
| 543 // fast-close animation and display the black layer. | 545 // fast-close animation and display the black layer. |
| 544 TEST_F(PowerButtonControllerTest, LockWithoutButton) { | 546 TEST_F(PowerButtonControllerTest, LockWithoutButton) { |
| 545 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 547 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 546 state_controller_->OnStartingLock(); | 548 state_controller_->OnStartingLock(); |
| 547 EXPECT_TRUE( | 549 EXPECT_TRUE( |
| 548 animator_api_->ContainersAreAnimated( | 550 animator_api_->ContainersAreAnimated( |
| 549 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 551 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 550 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); | 552 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); |
| 551 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 553 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); |
| 552 } | 554 } |
| 553 | 555 |
| 554 // When we hear that the process is exiting but we haven't had a chance to | 556 // When we hear that the process is exiting but we haven't had a chance to |
| 555 // display an animation, we should just blank the screen. | 557 // display an animation, we should just blank the screen. |
| 556 TEST_F(PowerButtonControllerTest, ShutdownWithoutButton) { | 558 TEST_F(PowerButtonControllerTest, ShutdownWithoutButton) { |
| 557 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 559 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 558 state_controller_->OnAppTerminating(); | 560 state_controller_->OnAppTerminating(); |
| 559 EXPECT_TRUE( | 561 EXPECT_TRUE( |
| 560 animator_api_->ContainersAreAnimated( | 562 animator_api_->ContainersAreAnimated( |
| 561 internal::SessionStateAnimator::kAllContainersMask, | 563 internal::SessionStateAnimator::kAllContainersMask, |
| 562 internal::SessionStateAnimator::ANIMATION_HIDE)); | 564 internal::SessionStateAnimator::ANIMATION_HIDE)); |
| 563 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 565 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); |
| 564 GenerateMouseMoveEvent(); | 566 GenerateMouseMoveEvent(); |
| 565 EXPECT_FALSE(cursor_visible()); | 567 EXPECT_FALSE(cursor_visible()); |
| 566 } | 568 } |
| 567 | 569 |
| 568 // Test that we display the fast-close animation and shut down when we get an | 570 // Test that we display the fast-close animation and shut down when we get an |
| 569 // outside request to shut down (e.g. from the login or lock screen). | 571 // outside request to shut down (e.g. from the login or lock screen). |
| 570 TEST_F(PowerButtonControllerTest, RequestShutdownFromLoginScreen) { | 572 TEST_F(PowerButtonControllerTest, RequestShutdownFromLoginScreen) { |
| 571 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | 573 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); |
| 572 state_controller_->RequestShutdown(); | 574 state_controller_->RequestShutdown(); |
| 573 EXPECT_TRUE( | 575 EXPECT_TRUE( |
| 574 animator_api_->ContainersAreAnimated( | 576 animator_api_->ContainersAreAnimated( |
| 575 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 577 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 576 internal::SessionStateAnimator::ANIMATION_HIDE)); | 578 internal::SessionStateAnimator::ANIMATION_HIDE)); |
| 577 EXPECT_TRUE( | 579 EXPECT_TRUE( |
| 578 animator_api_->ContainersAreAnimated( | 580 animator_api_->ContainersAreAnimated( |
| 579 internal::SessionStateAnimator::kAllLockScreenContainersMask, | 581 internal::SessionStateAnimator::kAllLockScreenContainersMask, |
| 580 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); | 582 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); |
| 581 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 583 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); |
| 582 GenerateMouseMoveEvent(); | 584 GenerateMouseMoveEvent(); |
| 583 EXPECT_FALSE(cursor_visible()); | 585 EXPECT_FALSE(cursor_visible()); |
| 584 | 586 |
| 585 EXPECT_EQ(0, NumShutdownRequests()); | 587 EXPECT_EQ(0, NumShutdownRequests()); |
| 586 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 588 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 587 test_api_->trigger_real_shutdown_timeout(); | 589 test_api_->trigger_real_shutdown_timeout(); |
| 588 EXPECT_EQ(1, NumShutdownRequests()); | 590 EXPECT_EQ(1, NumShutdownRequests()); |
| 589 } | 591 } |
| 590 | 592 |
| 591 TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) { | 593 TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) { |
| 592 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 594 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 593 state_controller_->OnLockStateChanged(true); | 595 state_controller_->OnLockStateChanged(true); |
| 594 state_controller_->RequestShutdown(); | 596 state_controller_->RequestShutdown(); |
| 595 EXPECT_TRUE( | 597 EXPECT_TRUE( |
| 596 animator_api_->ContainersAreAnimated( | 598 animator_api_->ContainersAreAnimated( |
| 597 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 599 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 598 internal::SessionStateAnimator::ANIMATION_HIDE)); | 600 internal::SessionStateAnimator::ANIMATION_HIDE)); |
| 599 EXPECT_TRUE( | 601 EXPECT_TRUE( |
| 600 animator_api_->ContainersAreAnimated( | 602 animator_api_->ContainersAreAnimated( |
| 601 internal::SessionStateAnimator::kAllLockScreenContainersMask, | 603 internal::SessionStateAnimator::kAllLockScreenContainersMask, |
| 602 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); | 604 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); |
| 603 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 605 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); |
| 604 GenerateMouseMoveEvent(); | 606 GenerateMouseMoveEvent(); |
| 605 EXPECT_FALSE(cursor_visible()); | 607 EXPECT_FALSE(cursor_visible()); |
| 606 | 608 |
| 607 EXPECT_EQ(0, NumShutdownRequests()); | 609 EXPECT_EQ(0, NumShutdownRequests()); |
| 608 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 610 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 609 test_api_->trigger_real_shutdown_timeout(); | 611 test_api_->trigger_real_shutdown_timeout(); |
| 610 EXPECT_EQ(1, NumShutdownRequests()); | 612 EXPECT_EQ(1, NumShutdownRequests()); |
| 611 } | 613 } |
| 612 | 614 |
| 613 TEST_F(PowerButtonControllerTest, RequestAndCancelShutdownFromLockScreen) { | 615 TEST_F(PowerButtonControllerTest, RequestAndCancelShutdownFromLockScreen) { |
| 614 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 616 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 615 state_controller_->OnLockStateChanged(true); | 617 state_controller_->OnLockStateChanged(true); |
| 616 | 618 |
| 617 // Press the power button and check that we start the shutdown timer. | 619 // Press the power button and check that we start the shutdown timer. |
| 618 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 620 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 619 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 621 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| 620 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 622 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
| 621 EXPECT_TRUE( | 623 EXPECT_TRUE( |
| 622 animator_api_->ContainersAreAnimated( | 624 animator_api_->ContainersAreAnimated( |
| 623 internal::SessionStateAnimator::kAllContainersMask, | 625 internal::SessionStateAnimator::kAllContainersMask, |
| 624 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); | 626 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); |
| 625 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 627 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); |
| 626 | 628 |
| 627 // Release the power button before the shutdown timer fires. | 629 // Release the power button before the shutdown timer fires. |
| 628 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 630 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| 629 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 631 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
| 630 EXPECT_TRUE( | 632 EXPECT_TRUE( |
| 631 animator_api_->ContainersAreAnimated( | 633 animator_api_->ContainersAreAnimated( |
| 632 internal::SessionStateAnimator::kAllLockScreenContainersMask, | 634 internal::SessionStateAnimator::kAllLockScreenContainersMask, |
| 633 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE)); | 635 internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE)); |
| 634 EXPECT_TRUE( | 636 EXPECT_TRUE( |
| 635 animator_api_->ContainersAreAnimated( | 637 animator_api_->ContainersAreAnimated( |
| 636 internal::SessionStateAnimator::DESKTOP_BACKGROUND, | 638 internal::SessionStateAnimator::DESKTOP_BACKGROUND, |
| 637 internal::SessionStateAnimator::ANIMATION_RESTORE)); | 639 internal::SessionStateAnimator::ANIMATION_RESTORE)); |
| 638 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 640 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); |
| 639 } | 641 } |
| 640 | 642 |
| 641 // Test that the black layer is resized in response to root window resizes. | 643 // Test that the black layer is resized in response to root window resizes. |
| 642 TEST_F(PowerButtonControllerTest, ResizeBlackLayer) { | 644 TEST_F(PowerButtonControllerTest, ResizeBlackLayer) { |
| 643 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 645 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 662 | 664 |
| 663 // After increasing the brightness to 10%, we should start the timer like | 665 // After increasing the brightness to 10%, we should start the timer like |
| 664 // usual. | 666 // usual. |
| 665 controller_->OnScreenBrightnessChanged(10.0); | 667 controller_->OnScreenBrightnessChanged(10.0); |
| 666 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 668 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 667 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 669 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| 668 } | 670 } |
| 669 | 671 |
| 670 } // namespace test | 672 } // namespace test |
| 671 } // namespace ash | 673 } // namespace ash |
| OLD | NEW |