| 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" | |
| 7 #include "ash/wm/session_state_controller.h" | |
| 8 | 6 |
| 9 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 10 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
| 11 #include "ash/wm/cursor_manager.h" | 9 #include "ash/wm/cursor_manager.h" |
| 12 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/time.h" | 11 #include "base/time.h" |
| 14 #include "ui/aura/env.h" | 12 #include "ui/aura/env.h" |
| 15 #include "ui/aura/root_window.h" | 13 #include "ui/aura/root_window.h" |
| 16 #include "ui/aura/test/event_generator.h" | 14 #include "ui/aura/test/event_generator.h" |
| 17 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
| 18 #include "ui/gfx/size.h" | 16 #include "ui/gfx/size.h" |
| 19 | 17 |
| 20 namespace ash { | 18 namespace ash { |
| 21 namespace test { | 19 namespace test { |
| 22 namespace { | 20 namespace { |
| 23 bool cursor_visible() { | 21 bool cursor_visible() { |
| 24 return ash::Shell::GetInstance()->cursor_manager()->cursor_visible(); | 22 return ash::Shell::GetInstance()->cursor_manager()->cursor_visible(); |
| 25 } | 23 } |
| 26 } | 24 } |
| 27 | 25 |
| 28 // Fake implementation of PowerButtonControllerDelegate that just logs requests | 26 // Fake implementation of PowerButtonControllerDelegate that just logs requests |
| 29 // to lock the screen and shut down the device. | 27 // to lock the screen and shut down the device. |
| 30 class TestPowerButtonControllerDelegate : | 28 class TestPowerButtonControllerDelegate : public PowerButtonControllerDelegate { |
| 31 public SessionStateControllerDelegate { | |
| 32 public: | 29 public: |
| 33 TestPowerButtonControllerDelegate() | 30 TestPowerButtonControllerDelegate() |
| 34 : num_lock_requests_(0), | 31 : num_lock_requests_(0), |
| 35 num_shutdown_requests_(0) {} | 32 num_shutdown_requests_(0) {} |
| 36 | 33 |
| 37 int num_lock_requests() const { return num_lock_requests_; } | 34 int num_lock_requests() const { return num_lock_requests_; } |
| 38 int num_shutdown_requests() const { return num_shutdown_requests_; } | 35 int num_shutdown_requests() const { return num_shutdown_requests_; } |
| 39 | 36 |
| 40 // PowerButtonControllerDelegate implementation. | 37 // PowerButtonControllerDelegate implementation. |
| 41 virtual void RequestLockScreen() OVERRIDE { | 38 virtual void RequestLockScreen() OVERRIDE { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 54 | 51 |
| 55 class PowerButtonControllerTest : public AshTestBase { | 52 class PowerButtonControllerTest : public AshTestBase { |
| 56 public: | 53 public: |
| 57 PowerButtonControllerTest() : controller_(NULL), delegate_(NULL) {} | 54 PowerButtonControllerTest() : controller_(NULL), delegate_(NULL) {} |
| 58 virtual ~PowerButtonControllerTest() {} | 55 virtual ~PowerButtonControllerTest() {} |
| 59 | 56 |
| 60 void SetUp() OVERRIDE { | 57 void SetUp() OVERRIDE { |
| 61 AshTestBase::SetUp(); | 58 AshTestBase::SetUp(); |
| 62 delegate_ = new TestPowerButtonControllerDelegate; | 59 delegate_ = new TestPowerButtonControllerDelegate; |
| 63 controller_ = Shell::GetInstance()->power_button_controller(); | 60 controller_ = Shell::GetInstance()->power_button_controller(); |
| 64 state_controller_ = Shell::GetInstance()->session_state_controller(); | 61 controller_->set_delegate(delegate_); // transfers ownership |
| 65 state_controller_->SetDelegate(delegate_); // transfers ownership | 62 test_api_.reset(new PowerButtonController::TestApi(controller_)); |
| 66 test_api_.reset(new SessionStateController::TestApi(state_controller_)); | |
| 67 animator_api_.reset( | |
| 68 new internal::SessionStateAnimator::TestApi(state_controller_-> | |
| 69 animator_.get())); | |
| 70 } | 63 } |
| 71 | 64 |
| 72 protected: | 65 protected: |
| 73 void GenerateMouseMoveEvent() { | 66 void GenerateMouseMoveEvent() { |
| 74 aura::test::EventGenerator generator( | 67 aura::test::EventGenerator generator( |
| 75 Shell::GetPrimaryRootWindow()); | 68 Shell::GetPrimaryRootWindow()); |
| 76 generator.MoveMouseTo(10, 10); | 69 generator.MoveMouseTo(10, 10); |
| 77 } | 70 } |
| 78 | 71 |
| 79 PowerButtonController* controller_; // not owned | 72 PowerButtonController* controller_; // not owned |
| 80 SessionStateController* state_controller_; // not owned | |
| 81 TestPowerButtonControllerDelegate* delegate_; // not owned | 73 TestPowerButtonControllerDelegate* delegate_; // not owned |
| 82 | 74 scoped_ptr<PowerButtonController::TestApi> test_api_; |
| 83 scoped_ptr<SessionStateController::TestApi> test_api_; | |
| 84 scoped_ptr<internal::SessionStateAnimator::TestApi> animator_api_; | |
| 85 | 75 |
| 86 private: | 76 private: |
| 87 DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerTest); | 77 DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerTest); |
| 88 }; | 78 }; |
| 89 | 79 |
| 90 // Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't | 80 // Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't |
| 91 // correctly report power button releases. We should lock immediately the first | 81 // correctly report power button releases. We should lock immediately the first |
| 92 // time the button is pressed and shut down when it's pressed from the locked | 82 // time the button is pressed and shut down when it's pressed from the locked |
| 93 // state. | 83 // state. |
| 94 TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) { | 84 TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) { |
| 95 controller_->set_has_legacy_power_button_for_test(true); | 85 controller_->set_has_legacy_power_button_for_test(true); |
| 96 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 86 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 97 state_controller_->OnLockStateChanged(false); | 87 controller_->OnLockStateChanged(false); |
| 98 | 88 |
| 99 // We should request that the screen be locked immediately after seeing the | 89 // We should request that the screen be locked immediately after seeing the |
| 100 // power button get pressed. | 90 // power button get pressed. |
| 101 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 91 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 102 EXPECT_TRUE( | 92 EXPECT_TRUE( |
| 103 animator_api_->ContainersAreAnimated( | 93 test_api_->ContainersAreAnimated( |
| 104 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 94 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 105 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); | 95 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); |
| 106 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 96 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
| 107 EXPECT_FALSE(animator_api_->hide_black_layer_timer_is_running()); | 97 EXPECT_FALSE(test_api_->hide_black_layer_timer_is_running()); |
| 108 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 98 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| 109 EXPECT_EQ(1, delegate_->num_lock_requests()); | 99 EXPECT_EQ(1, delegate_->num_lock_requests()); |
| 110 | 100 |
| 111 // Notify that we locked successfully. | 101 // Notify that we locked successfully. |
| 112 state_controller_->OnStartingLock(); | 102 controller_->OnStartingLock(); |
| 113 EXPECT_TRUE( | 103 EXPECT_TRUE( |
| 114 animator_api_->ContainersAreAnimated( | 104 test_api_->ContainersAreAnimated( |
| 115 internal::SessionStateAnimator::LAUNCHER, | 105 internal::SessionStateAnimator::LAUNCHER, |
| 116 internal::SessionStateAnimator::ANIMATION_HIDE)); | 106 internal::SessionStateAnimator::ANIMATION_HIDE)); |
| 117 EXPECT_TRUE( | 107 EXPECT_TRUE( |
| 118 animator_api_->ContainersAreAnimated( | 108 test_api_->ContainersAreAnimated( |
| 119 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 109 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 120 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); | 110 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); |
| 121 EXPECT_TRUE( | 111 EXPECT_TRUE( |
| 122 animator_api_->ContainersAreAnimated( | 112 test_api_->ContainersAreAnimated( |
| 123 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | 113 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 124 internal::SessionStateAnimator::ANIMATION_HIDE)); | 114 internal::SessionStateAnimator::ANIMATION_HIDE)); |
| 125 | 115 |
| 126 // Notify that the lock window is visible. We should make it fade in. | 116 // Notify that the lock window is visible. We should make it fade in. |
| 127 state_controller_->OnLockStateChanged(true); | 117 controller_->OnLockStateChanged(true); |
| 128 EXPECT_TRUE( | 118 EXPECT_TRUE( |
| 129 animator_api_->ContainersAreAnimated( | 119 test_api_->ContainersAreAnimated( |
| 130 internal::SessionStateAnimator::kAllLockScreenContainersMask, | 120 internal::SessionStateAnimator::kAllLockScreenContainersMask, |
| 131 internal::SessionStateAnimator::ANIMATION_FADE_IN)); | 121 internal::SessionStateAnimator::ANIMATION_FADE_IN)); |
| 132 | 122 |
| 133 // We shouldn't progress towards the shutdown state, however. | 123 // We shouldn't progress towards the shutdown state, however. |
| 134 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); | 124 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
| 135 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 125 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
| 136 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 126 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| 137 | 127 |
| 138 // Hold the button again and check that we start shutting down. | 128 // Hold the button again and check that we start shutting down. |
| 139 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 129 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 140 EXPECT_EQ(0, delegate_->num_shutdown_requests()); | 130 EXPECT_EQ(0, delegate_->num_shutdown_requests()); |
| 141 | 131 |
| 142 // Previously we're checking that the all containers group was animated which | 132 // Previously we're checking that the all containers group was animated which |
| 143 // was in fact checking that | 133 // was in fact checking that |
| 144 // 1. All user session containers have transform (including wallpaper). | 134 // 1. All user session containers have transform (including wallpaper). |
| 145 // They're in this state after lock. | 135 // They're in this state after lock. |
| 146 // 2. Screen locker and related containers are in fact animating | 136 // 2. Screen locker and related containers are in fact animating |
| 147 // (as shutdown is in progress). | 137 // (as shutdown is in progress). |
| 148 // With http://crbug.com/144737 we no longer animate user session wallpaper | 138 // With http://crbug.com/144737 we no longer animate user session wallpaper |
| 149 // during lock so it makes sense only to check that screen lock and related | 139 // during lock so it makes sense only to check that screen lock and related |
| 150 // containers are animated during shutdown. | 140 // containers are animated during shutdown. |
| 151 EXPECT_TRUE( | 141 EXPECT_TRUE( |
| 152 animator_api_->ContainersAreAnimated( | 142 test_api_->ContainersAreAnimated( |
| 153 internal::SessionStateAnimator::kAllLockScreenContainersMask, | 143 internal::SessionStateAnimator::kAllLockScreenContainersMask, |
| 154 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); | 144 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); |
| 155 // Make sure a mouse move event won't show the cursor. | 145 // Make sure a mouse move event won't show the cursor. |
| 156 GenerateMouseMoveEvent(); | 146 GenerateMouseMoveEvent(); |
| 157 EXPECT_FALSE(cursor_visible()); | 147 EXPECT_FALSE(cursor_visible()); |
| 158 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 148 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 159 test_api_->trigger_real_shutdown_timeout(); | 149 test_api_->trigger_real_shutdown_timeout(); |
| 160 EXPECT_EQ(1, delegate_->num_shutdown_requests()); | 150 EXPECT_EQ(1, delegate_->num_shutdown_requests()); |
| 161 } | 151 } |
| 162 | 152 |
| 163 // Test that we start shutting down immediately if the power button is pressed | 153 // Test that we start shutting down immediately if the power button is pressed |
| 164 // while we're not logged in on an unofficial system. | 154 // while we're not logged in on an unofficial system. |
| 165 TEST_F(PowerButtonControllerTest, LegacyNotLoggedIn) { | 155 TEST_F(PowerButtonControllerTest, LegacyNotLoggedIn) { |
| 166 controller_->set_has_legacy_power_button_for_test(true); | 156 controller_->set_has_legacy_power_button_for_test(true); |
| 167 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | 157 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); |
| 168 state_controller_->OnLockStateChanged(false); | 158 controller_->OnLockStateChanged(false); |
| 169 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 159 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 170 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 160 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 171 } | 161 } |
| 172 | 162 |
| 173 // Test that we start shutting down immediately if the power button is pressed | 163 // Test that we start shutting down immediately if the power button is pressed |
| 174 // while we're logged in as a guest on an unofficial system. | 164 // while we're logged in as a guest on an unofficial system. |
| 175 TEST_F(PowerButtonControllerTest, LegacyGuest) { | 165 TEST_F(PowerButtonControllerTest, LegacyGuest) { |
| 176 controller_->set_has_legacy_power_button_for_test(true); | 166 controller_->set_has_legacy_power_button_for_test(true); |
| 177 state_controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST); | 167 controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST); |
| 178 state_controller_->OnLockStateChanged(false); | 168 controller_->OnLockStateChanged(false); |
| 179 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 169 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 180 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 170 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 181 } | 171 } |
| 182 | 172 |
| 183 // When we hold the power button while the user isn't logged in, we should shut | 173 // When we hold the power button while the user isn't logged in, we should shut |
| 184 // down the machine directly. | 174 // down the machine directly. |
| 185 TEST_F(PowerButtonControllerTest, ShutdownWhenNotLoggedIn) { | 175 TEST_F(PowerButtonControllerTest, ShutdownWhenNotLoggedIn) { |
| 186 controller_->set_has_legacy_power_button_for_test(false); | 176 controller_->set_has_legacy_power_button_for_test(false); |
| 187 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | 177 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); |
| 188 state_controller_->OnLockStateChanged(false); | 178 controller_->OnLockStateChanged(false); |
| 189 EXPECT_FALSE(animator_api_->BlackLayerIsVisible()); | 179 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); |
| 190 | 180 |
| 191 // Press the power button and check that we start the shutdown timer. | 181 // Press the power button and check that we start the shutdown timer. |
| 192 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 182 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 193 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 183 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| 194 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 184 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
| 195 EXPECT_TRUE( | 185 EXPECT_TRUE( |
| 196 animator_api_->ContainersAreAnimated( | 186 test_api_->ContainersAreAnimated( |
| 197 internal::SessionStateAnimator::kAllContainersMask, | 187 internal::SessionStateAnimator::kAllContainersMask, |
| 198 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); | 188 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); |
| 199 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 189 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
| 200 | 190 |
| 201 // Release the power button before the shutdown timer fires. | 191 // Release the power button before the shutdown timer fires. |
| 202 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 192 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| 203 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 193 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
| 204 EXPECT_TRUE( | 194 EXPECT_TRUE( |
| 205 animator_api_->ContainersAreAnimated( | 195 test_api_->ContainersAreAnimated( |
| 206 internal::SessionStateAnimator::kAllContainersMask, | 196 internal::SessionStateAnimator::kAllContainersMask, |
| 207 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE)); | 197 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE)); |
| 208 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 198 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
| 209 | 199 |
| 210 // We should re-hide the black layer after waiting long enough for | 200 // We should re-hide the black layer after waiting long enough for |
| 211 // the animation to finish. | 201 // the animation to finish. |
| 212 EXPECT_TRUE(animator_api_->hide_black_layer_timer_is_running()); | 202 EXPECT_TRUE(test_api_->hide_black_layer_timer_is_running()); |
| 213 animator_api_->TriggerHideBlackLayerTimeout(); | 203 test_api_->TriggerHideBlackLayerTimeout(); |
| 214 EXPECT_FALSE(animator_api_->BlackLayerIsVisible()); | 204 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); |
| 215 | 205 |
| 216 // Press the button again and make the shutdown timeout fire this time. | 206 // Press the button again and make the shutdown timeout fire this time. |
| 217 // Check that we start the timer for actually requesting the shutdown. | 207 // Check that we start the timer for actually requesting the shutdown. |
| 218 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 208 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 219 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 209 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
| 220 test_api_->trigger_shutdown_timeout(); | 210 test_api_->trigger_shutdown_timeout(); |
| 221 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 211 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 222 EXPECT_EQ(0, delegate_->num_shutdown_requests()); | 212 EXPECT_EQ(0, delegate_->num_shutdown_requests()); |
| 223 EXPECT_TRUE( | 213 EXPECT_TRUE( |
| 224 animator_api_->ContainersAreAnimated( | 214 test_api_->ContainersAreAnimated( |
| 225 internal::SessionStateAnimator::LAUNCHER | | 215 internal::SessionStateAnimator::LAUNCHER | |
| 226 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 216 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 227 internal::SessionStateAnimator::ANIMATION_HIDE)); | 217 internal::SessionStateAnimator::ANIMATION_HIDE)); |
| 228 EXPECT_TRUE( | 218 EXPECT_TRUE( |
| 229 animator_api_->ContainersAreAnimated( | 219 test_api_->ContainersAreAnimated( |
| 230 internal::SessionStateAnimator::kAllLockScreenContainersMask, | 220 internal::SessionStateAnimator::kAllLockScreenContainersMask, |
| 231 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); | 221 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); |
| 232 | 222 |
| 233 // When the timout fires, we should request a shutdown. | 223 // When the timout fires, we should request a shutdown. |
| 234 test_api_->trigger_real_shutdown_timeout(); | 224 test_api_->trigger_real_shutdown_timeout(); |
| 235 EXPECT_EQ(1, delegate_->num_shutdown_requests()); | 225 EXPECT_EQ(1, delegate_->num_shutdown_requests()); |
| 236 } | 226 } |
| 237 | 227 |
| 238 // Test that we lock the screen and deal with unlocking correctly. | 228 // Test that we lock the screen and deal with unlocking correctly. |
| 239 TEST_F(PowerButtonControllerTest, LockAndUnlock) { | 229 TEST_F(PowerButtonControllerTest, LockAndUnlock) { |
| 240 controller_->set_has_legacy_power_button_for_test(false); | 230 controller_->set_has_legacy_power_button_for_test(false); |
| 241 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 231 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 242 state_controller_->OnLockStateChanged(false); | 232 controller_->OnLockStateChanged(false); |
| 243 EXPECT_FALSE(animator_api_->BlackLayerIsVisible()); | 233 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); |
| 244 | 234 |
| 245 // We should initially be showing the screen locker containers, since they | 235 // We should initially be showing the screen locker containers, since they |
| 246 // also contain login-related windows that we want to show during the | 236 // also contain login-related windows that we want to show during the |
| 247 // logging-in animation. | 237 // logging-in animation. |
| 248 EXPECT_TRUE( | 238 EXPECT_TRUE( |
| 249 animator_api_->ContainersAreAnimated( | 239 test_api_->ContainersAreAnimated( |
| 250 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | 240 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 251 internal::SessionStateAnimator::ANIMATION_RESTORE)); | 241 internal::SessionStateAnimator::ANIMATION_RESTORE)); |
| 252 | 242 |
| 253 // Press the power button and check that the lock timer is started and that we | 243 // Press the power button and check that the lock timer is started and that we |
| 254 // start scaling the non-screen-locker containers. | 244 // start scaling the non-screen-locker containers. |
| 255 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 245 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 256 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 246 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| 257 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 247 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
| 258 EXPECT_TRUE( | 248 EXPECT_TRUE( |
| 259 animator_api_->ContainersAreAnimated( | 249 test_api_->ContainersAreAnimated( |
| 260 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 250 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 261 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); | 251 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); |
| 262 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 252 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
| 263 | 253 |
| 264 // Release the button before the lock timer fires. | 254 // Release the button before the lock timer fires. |
| 265 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 255 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| 266 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 256 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| 267 EXPECT_TRUE( | 257 EXPECT_TRUE( |
| 268 animator_api_->ContainersAreAnimated( | 258 test_api_->ContainersAreAnimated( |
| 269 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 259 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 270 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE)); | 260 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE)); |
| 271 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 261 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
| 272 EXPECT_TRUE(animator_api_->hide_black_layer_timer_is_running()); | 262 EXPECT_TRUE(test_api_->hide_black_layer_timer_is_running()); |
| 273 animator_api_->TriggerHideBlackLayerTimeout(); | 263 test_api_->TriggerHideBlackLayerTimeout(); |
| 274 EXPECT_FALSE(animator_api_->BlackLayerIsVisible()); | 264 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); |
| 275 | 265 |
| 276 // Press the button and fire the lock timer. We should request that the | 266 // Press the button and fire the lock timer. We should request that the |
| 277 // screen be locked, but we should still be in the slow-close animation. | 267 // screen be locked, but we should still be in the slow-close animation. |
| 278 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 268 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 279 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 269 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| 280 EXPECT_EQ(0, delegate_->num_lock_requests()); | 270 EXPECT_EQ(0, delegate_->num_lock_requests()); |
| 281 test_api_->trigger_lock_timeout(); | 271 test_api_->trigger_lock_timeout(); |
| 282 EXPECT_EQ(1, delegate_->num_lock_requests()); | 272 EXPECT_EQ(1, delegate_->num_lock_requests()); |
| 283 EXPECT_TRUE( | 273 EXPECT_TRUE( |
| 284 animator_api_->ContainersAreAnimated( | 274 test_api_->ContainersAreAnimated( |
| 285 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 275 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 286 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); | 276 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); |
| 287 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 277 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
| 288 | 278 |
| 289 // Notify that we locked successfully. | 279 // Notify that we locked successfully. |
| 290 state_controller_->OnStartingLock(); | 280 controller_->OnStartingLock(); |
| 291 EXPECT_TRUE( | 281 EXPECT_TRUE( |
| 292 animator_api_->ContainersAreAnimated( | 282 test_api_->ContainersAreAnimated( |
| 293 internal::SessionStateAnimator::LAUNCHER, | 283 internal::SessionStateAnimator::LAUNCHER, |
| 294 internal::SessionStateAnimator::ANIMATION_HIDE)); | 284 internal::SessionStateAnimator::ANIMATION_HIDE)); |
| 295 EXPECT_TRUE( | 285 EXPECT_TRUE( |
| 296 animator_api_->ContainersAreAnimated( | 286 test_api_->ContainersAreAnimated( |
| 297 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 287 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 298 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); | 288 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); |
| 299 EXPECT_TRUE( | 289 EXPECT_TRUE( |
| 300 animator_api_->ContainersAreAnimated( | 290 test_api_->ContainersAreAnimated( |
| 301 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | 291 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 302 internal::SessionStateAnimator::ANIMATION_HIDE)); | 292 internal::SessionStateAnimator::ANIMATION_HIDE)); |
| 303 | 293 |
| 304 // Notify that the lock window is visible. We should make it fade in. | 294 // Notify that the lock window is visible. We should make it fade in. |
| 305 state_controller_->OnLockStateChanged(true); | 295 controller_->OnLockStateChanged(true); |
| 306 EXPECT_TRUE( | 296 EXPECT_TRUE( |
| 307 animator_api_->ContainersAreAnimated( | 297 test_api_->ContainersAreAnimated( |
| 308 internal::SessionStateAnimator::kAllLockScreenContainersMask, | 298 internal::SessionStateAnimator::kAllLockScreenContainersMask, |
| 309 internal::SessionStateAnimator::ANIMATION_FADE_IN)); | 299 internal::SessionStateAnimator::ANIMATION_FADE_IN)); |
| 310 | 300 |
| 311 // When we release the power button, the lock-to-shutdown timer should be | 301 // When we release the power button, the lock-to-shutdown timer should be |
| 312 // stopped. | 302 // stopped. |
| 313 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); | 303 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); |
| 314 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 304 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| 315 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); | 305 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
| 316 | 306 |
| 317 // Notify that the screen has been unlocked. We should show the | 307 // Notify that the screen has been unlocked. We should show the |
| 318 // non-screen-locker windows and hide the black layer. | 308 // non-screen-locker windows and hide the black layer. |
| 319 state_controller_->OnLockStateChanged(false); | 309 controller_->OnLockStateChanged(false); |
| 320 EXPECT_TRUE( | 310 EXPECT_TRUE( |
| 321 animator_api_->ContainersAreAnimated( | 311 test_api_->ContainersAreAnimated( |
| 322 internal::SessionStateAnimator::DESKTOP_BACKGROUND | | 312 internal::SessionStateAnimator::DESKTOP_BACKGROUND | |
| 323 internal::SessionStateAnimator::LAUNCHER | | 313 internal::SessionStateAnimator::LAUNCHER | |
| 324 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 314 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 325 internal::SessionStateAnimator::ANIMATION_RESTORE)); | 315 internal::SessionStateAnimator::ANIMATION_RESTORE)); |
| 326 EXPECT_FALSE(animator_api_->BlackLayerIsVisible()); | 316 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); |
| 327 } | 317 } |
| 328 | 318 |
| 329 // Hold the power button down from the unlocked state to eventual shutdown. | 319 // Hold the power button down from the unlocked state to eventual shutdown. |
| 330 TEST_F(PowerButtonControllerTest, LockToShutdown) { | 320 TEST_F(PowerButtonControllerTest, LockToShutdown) { |
| 331 controller_->set_has_legacy_power_button_for_test(false); | 321 controller_->set_has_legacy_power_button_for_test(false); |
| 332 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 322 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 333 state_controller_->OnLockStateChanged(false); | 323 controller_->OnLockStateChanged(false); |
| 334 | 324 |
| 335 // Hold the power button and lock the screen. | 325 // Hold the power button and lock the screen. |
| 336 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 326 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 337 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 327 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| 338 test_api_->trigger_lock_timeout(); | 328 test_api_->trigger_lock_timeout(); |
| 339 state_controller_->OnStartingLock(); | 329 controller_->OnStartingLock(); |
| 340 state_controller_->OnLockStateChanged(true); | 330 controller_->OnLockStateChanged(true); |
| 341 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 331 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
| 342 | 332 |
| 343 // When the lock-to-shutdown timeout fires, we should start the shutdown | 333 // When the lock-to-shutdown timeout fires, we should start the shutdown |
| 344 // timer. | 334 // timer. |
| 345 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); | 335 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); |
| 346 test_api_->trigger_lock_to_shutdown_timeout(); | 336 test_api_->trigger_lock_to_shutdown_timeout(); |
| 347 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 337 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
| 348 EXPECT_TRUE( | 338 EXPECT_TRUE( |
| 349 animator_api_->ContainersAreAnimated( | 339 test_api_->ContainersAreAnimated( |
| 350 internal::SessionStateAnimator::kAllContainersMask, | 340 internal::SessionStateAnimator::kAllContainersMask, |
| 351 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); | 341 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); |
| 352 | 342 |
| 353 // Fire the shutdown timeout and check that we request shutdown. | 343 // Fire the shutdown timeout and check that we request shutdown. |
| 354 test_api_->trigger_shutdown_timeout(); | 344 test_api_->trigger_shutdown_timeout(); |
| 355 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 345 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 356 EXPECT_EQ(0, delegate_->num_shutdown_requests()); | 346 EXPECT_EQ(0, delegate_->num_shutdown_requests()); |
| 357 test_api_->trigger_real_shutdown_timeout(); | 347 test_api_->trigger_real_shutdown_timeout(); |
| 358 EXPECT_EQ(1, delegate_->num_shutdown_requests()); | 348 EXPECT_EQ(1, delegate_->num_shutdown_requests()); |
| 359 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 349 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
| 360 } | 350 } |
| 361 | 351 |
| 362 // Test that we handle the case where lock requests are ignored. | 352 // Test that we handle the case where lock requests are ignored. |
| 363 TEST_F(PowerButtonControllerTest, LockFail) { | 353 TEST_F(PowerButtonControllerTest, LockFail) { |
| 364 // We require animations to have a duration for this test. | 354 // We require animations to have a duration for this test. |
| 365 ui::LayerAnimator::set_disable_animations_for_test(false); | 355 ui::LayerAnimator::set_disable_animations_for_test(false); |
| 366 | 356 |
| 367 controller_->set_has_legacy_power_button_for_test(false); | 357 controller_->set_has_legacy_power_button_for_test(false); |
| 368 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 358 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 369 state_controller_->OnLockStateChanged(false); | 359 controller_->OnLockStateChanged(false); |
| 370 | 360 |
| 371 // Hold the power button and lock the screen. | 361 // Hold the power button and lock the screen. |
| 372 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 362 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 373 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 363 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| 374 EXPECT_TRUE( | 364 EXPECT_TRUE( |
| 375 animator_api_->ContainersAreAnimated( | 365 test_api_->ContainersAreAnimated( |
| 376 internal::SessionStateAnimator::DESKTOP_BACKGROUND | | 366 internal::SessionStateAnimator::DESKTOP_BACKGROUND | |
| 377 internal::SessionStateAnimator::LAUNCHER | | 367 internal::SessionStateAnimator::LAUNCHER | |
| 378 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 368 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 379 internal::SessionStateAnimator::ANIMATION_RESTORE)); | 369 internal::SessionStateAnimator::ANIMATION_RESTORE)); |
| 380 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 370 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
| 381 test_api_->trigger_lock_timeout(); | 371 test_api_->trigger_lock_timeout(); |
| 382 EXPECT_EQ(1, delegate_->num_lock_requests()); | 372 EXPECT_EQ(1, delegate_->num_lock_requests()); |
| 383 EXPECT_TRUE(test_api_->lock_fail_timer_is_running()); | 373 EXPECT_TRUE(test_api_->lock_fail_timer_is_running()); |
| 384 | 374 |
| 385 // We shouldn't start the lock-to-shutdown timer until the screen has actually | 375 // We shouldn't start the lock-to-shutdown timer until the screen has actually |
| 386 // been locked. | 376 // been locked. |
| 387 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); | 377 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
| 388 | 378 |
| 389 // Act as if the request timed out. We should restore the windows. | 379 // Act as if the request timed out. We should restore the windows. |
| 390 test_api_->trigger_lock_fail_timeout(); | 380 test_api_->trigger_lock_fail_timeout(); |
| 391 EXPECT_TRUE( | 381 EXPECT_TRUE( |
| 392 animator_api_->ContainersAreAnimated( | 382 test_api_->ContainersAreAnimated( |
| 393 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 383 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 394 internal::SessionStateAnimator::ANIMATION_RESTORE)); | 384 internal::SessionStateAnimator::ANIMATION_RESTORE)); |
| 395 EXPECT_FALSE(animator_api_->BlackLayerIsVisible()); | 385 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); |
| 396 } | 386 } |
| 397 | 387 |
| 398 // Test that we start the timer to hide the black layer when the power | 388 // Test that we start the timer to hide the black layer when the power |
| 399 // button is released, but that we cancel the timer if the button is pressed | 389 // button is released, but that we cancel the timer if the button is pressed |
| 400 // again before the timer has fired. | 390 // again before the timer has fired. |
| 401 TEST_F(PowerButtonControllerTest, CancelHideBackground) { | 391 TEST_F(PowerButtonControllerTest, CancelHideBackground) { |
| 402 controller_->set_has_legacy_power_button_for_test(false); | 392 controller_->set_has_legacy_power_button_for_test(false); |
| 403 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | 393 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); |
| 404 state_controller_->OnLockStateChanged(false); | 394 controller_->OnLockStateChanged(false); |
| 405 | 395 |
| 406 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 396 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 407 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 397 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| 408 EXPECT_TRUE(animator_api_->hide_black_layer_timer_is_running()); | 398 EXPECT_TRUE(test_api_->hide_black_layer_timer_is_running()); |
| 409 | 399 |
| 410 // We should cancel the timer if we get another button-down event. | 400 // We should cancel the timer if we get another button-down event. |
| 411 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 401 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 412 EXPECT_FALSE(animator_api_->hide_black_layer_timer_is_running()); | 402 EXPECT_FALSE(test_api_->hide_black_layer_timer_is_running()); |
| 413 } | 403 } |
| 414 | 404 |
| 415 // Test the basic operation of the lock button. | 405 // Test the basic operation of the lock button. |
| 416 TEST_F(PowerButtonControllerTest, LockButtonBasic) { | 406 TEST_F(PowerButtonControllerTest, LockButtonBasic) { |
| 417 controller_->set_has_legacy_power_button_for_test(false); | 407 controller_->set_has_legacy_power_button_for_test(false); |
| 418 // The lock button shouldn't do anything if we aren't logged in. | 408 // The lock button shouldn't do anything if we aren't logged in. |
| 419 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | 409 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); |
| 420 state_controller_->OnLockStateChanged(false); | 410 controller_->OnLockStateChanged(false); |
| 421 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 411 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
| 422 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 412 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| 423 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 413 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
| 424 EXPECT_EQ(0, delegate_->num_lock_requests()); | 414 EXPECT_EQ(0, delegate_->num_lock_requests()); |
| 425 | 415 |
| 426 // Ditto for when we're logged in as a guest. | 416 // Ditto for when we're logged in as a guest. |
| 427 state_controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST); | 417 controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST); |
| 428 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 418 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
| 429 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 419 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| 430 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 420 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
| 431 EXPECT_EQ(0, delegate_->num_lock_requests()); | 421 EXPECT_EQ(0, delegate_->num_lock_requests()); |
| 432 | 422 |
| 433 // If we're logged in as a regular user, we should start the lock timer and | 423 // If we're logged in as a regular user, we should start the lock timer and |
| 434 // the pre-lock animation. | 424 // the pre-lock animation. |
| 435 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 425 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 436 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 426 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
| 437 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 427 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| 438 EXPECT_TRUE( | 428 EXPECT_TRUE( |
| 439 animator_api_->ContainersAreAnimated( | 429 test_api_->ContainersAreAnimated( |
| 440 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 430 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 441 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); | 431 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); |
| 442 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 432 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
| 443 | 433 |
| 444 // If the button is released immediately, we shouldn't lock the screen. | 434 // If the button is released immediately, we shouldn't lock the screen. |
| 445 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 435 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
| 446 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 436 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| 447 EXPECT_TRUE( | 437 EXPECT_TRUE( |
| 448 animator_api_->ContainersAreAnimated( | 438 test_api_->ContainersAreAnimated( |
| 449 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 439 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 450 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE)); | 440 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE)); |
| 451 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 441 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
| 452 EXPECT_TRUE(animator_api_->hide_black_layer_timer_is_running()); | 442 EXPECT_TRUE(test_api_->hide_black_layer_timer_is_running()); |
| 453 animator_api_->TriggerHideBlackLayerTimeout(); | 443 test_api_->TriggerHideBlackLayerTimeout(); |
| 454 EXPECT_FALSE(animator_api_->BlackLayerIsVisible()); | 444 EXPECT_FALSE(test_api_->BlackLayerIsVisible()); |
| 455 EXPECT_EQ(0, delegate_->num_lock_requests()); | 445 EXPECT_EQ(0, delegate_->num_lock_requests()); |
| 456 | 446 |
| 457 // Press the button again and let the lock timeout fire. We should request | 447 // Press the button again and let the lock timeout fire. We should request |
| 458 // that the screen be locked. | 448 // that the screen be locked. |
| 459 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 449 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
| 460 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 450 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| 461 test_api_->trigger_lock_timeout(); | 451 test_api_->trigger_lock_timeout(); |
| 462 EXPECT_EQ(1, delegate_->num_lock_requests()); | 452 EXPECT_EQ(1, delegate_->num_lock_requests()); |
| 463 | 453 |
| 464 // Pressing the lock button while we have a pending lock request shouldn't do | 454 // Pressing the lock button while we have a pending lock request shouldn't do |
| 465 // anything. | 455 // anything. |
| 466 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 456 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
| 467 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 457 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
| 468 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 458 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| 469 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 459 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
| 470 | 460 |
| 471 // Pressing the button also shouldn't do anything after the screen is locked. | 461 // Pressing the button also shouldn't do anything after the screen is locked. |
| 472 state_controller_->OnStartingLock(); | 462 controller_->OnStartingLock(); |
| 473 state_controller_->OnLockStateChanged(true); | 463 controller_->OnLockStateChanged(true); |
| 474 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 464 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
| 475 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 465 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| 476 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 466 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
| 477 } | 467 } |
| 478 | 468 |
| 479 // Test that the power button takes priority over the lock button. | 469 // Test that the power button takes priority over the lock button. |
| 480 TEST_F(PowerButtonControllerTest, PowerButtonPreemptsLockButton) { | 470 TEST_F(PowerButtonControllerTest, PowerButtonPreemptsLockButton) { |
| 481 controller_->set_has_legacy_power_button_for_test(false); | 471 controller_->set_has_legacy_power_button_for_test(false); |
| 482 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 472 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 483 state_controller_->OnLockStateChanged(false); | 473 controller_->OnLockStateChanged(false); |
| 484 | 474 |
| 485 // While the lock button is down, hold the power button. | 475 // While the lock button is down, hold the power button. |
| 486 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 476 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
| 487 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 477 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| 488 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 478 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 489 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 479 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| 490 | 480 |
| 491 // The lock timer shouldn't be stopped when the lock button is released. | 481 // The lock timer shouldn't be stopped when the lock button is released. |
| 492 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 482 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
| 493 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 483 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 504 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 494 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| 505 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 495 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| 506 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 496 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
| 507 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 497 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| 508 } | 498 } |
| 509 | 499 |
| 510 // When the screen is locked without going through the usual power-button | 500 // When the screen is locked without going through the usual power-button |
| 511 // slow-close path (e.g. via the wrench menu), test that we still show the | 501 // slow-close path (e.g. via the wrench menu), test that we still show the |
| 512 // fast-close animation and display the black layer. | 502 // fast-close animation and display the black layer. |
| 513 TEST_F(PowerButtonControllerTest, LockWithoutButton) { | 503 TEST_F(PowerButtonControllerTest, LockWithoutButton) { |
| 514 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 504 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 515 state_controller_->OnStartingLock(); | 505 controller_->OnStartingLock(); |
| 516 EXPECT_TRUE( | 506 EXPECT_TRUE( |
| 517 animator_api_->ContainersAreAnimated( | 507 test_api_->ContainersAreAnimated( |
| 518 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 508 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 519 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); | 509 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); |
| 520 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 510 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
| 521 } | 511 } |
| 522 | 512 |
| 523 // When we hear that the process is exiting but we haven't had a chance to | 513 // When we hear that the process is exiting but we haven't had a chance to |
| 524 // display an animation, we should just blank the screen. | 514 // display an animation, we should just blank the screen. |
| 525 TEST_F(PowerButtonControllerTest, ShutdownWithoutButton) { | 515 TEST_F(PowerButtonControllerTest, ShutdownWithoutButton) { |
| 526 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 516 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 527 state_controller_->OnAppTerminating(); | 517 controller_->OnAppTerminating(); |
| 528 EXPECT_TRUE( | 518 EXPECT_TRUE( |
| 529 animator_api_->ContainersAreAnimated( | 519 test_api_->ContainersAreAnimated( |
| 530 internal::SessionStateAnimator::kAllContainersMask, | 520 internal::SessionStateAnimator::kAllContainersMask, |
| 531 internal::SessionStateAnimator::ANIMATION_HIDE)); | 521 internal::SessionStateAnimator::ANIMATION_HIDE)); |
| 532 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 522 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
| 533 GenerateMouseMoveEvent(); | 523 GenerateMouseMoveEvent(); |
| 534 EXPECT_FALSE(cursor_visible()); | 524 EXPECT_FALSE(cursor_visible()); |
| 535 } | 525 } |
| 536 | 526 |
| 537 // Test that we display the fast-close animation and shut down when we get an | 527 // Test that we display the fast-close animation and shut down when we get an |
| 538 // outside request to shut down (e.g. from the login or lock screen). | 528 // outside request to shut down (e.g. from the login or lock screen). |
| 539 TEST_F(PowerButtonControllerTest, RequestShutdownFromLoginScreen) { | 529 TEST_F(PowerButtonControllerTest, RequestShutdownFromLoginScreen) { |
| 540 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | 530 controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); |
| 541 state_controller_->RequestShutdown(); | 531 controller_->RequestShutdown(); |
| 542 EXPECT_TRUE( | 532 EXPECT_TRUE( |
| 543 animator_api_->ContainersAreAnimated( | 533 test_api_->ContainersAreAnimated( |
| 544 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 534 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 545 internal::SessionStateAnimator::ANIMATION_HIDE)); | 535 internal::SessionStateAnimator::ANIMATION_HIDE)); |
| 546 EXPECT_TRUE( | 536 EXPECT_TRUE( |
| 547 animator_api_->ContainersAreAnimated( | 537 test_api_->ContainersAreAnimated( |
| 548 internal::SessionStateAnimator::kAllLockScreenContainersMask, | 538 internal::SessionStateAnimator::kAllLockScreenContainersMask, |
| 549 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); | 539 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); |
| 550 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 540 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
| 551 GenerateMouseMoveEvent(); | 541 GenerateMouseMoveEvent(); |
| 552 EXPECT_FALSE(cursor_visible()); | 542 EXPECT_FALSE(cursor_visible()); |
| 553 | 543 |
| 554 EXPECT_EQ(0, delegate_->num_shutdown_requests()); | 544 EXPECT_EQ(0, delegate_->num_shutdown_requests()); |
| 555 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 545 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 556 test_api_->trigger_real_shutdown_timeout(); | 546 test_api_->trigger_real_shutdown_timeout(); |
| 557 EXPECT_EQ(1, delegate_->num_shutdown_requests()); | 547 EXPECT_EQ(1, delegate_->num_shutdown_requests()); |
| 558 } | 548 } |
| 559 | 549 |
| 560 TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) { | 550 TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) { |
| 561 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 551 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 562 state_controller_->OnLockStateChanged(true); | 552 controller_->OnLockStateChanged(true); |
| 563 state_controller_->RequestShutdown(); | 553 controller_->RequestShutdown(); |
| 564 EXPECT_TRUE( | 554 EXPECT_TRUE( |
| 565 animator_api_->ContainersAreAnimated( | 555 test_api_->ContainersAreAnimated( |
| 566 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 556 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 567 internal::SessionStateAnimator::ANIMATION_HIDE)); | 557 internal::SessionStateAnimator::ANIMATION_HIDE)); |
| 568 EXPECT_TRUE( | 558 EXPECT_TRUE( |
| 569 animator_api_->ContainersAreAnimated( | 559 test_api_->ContainersAreAnimated( |
| 570 internal::SessionStateAnimator::kAllLockScreenContainersMask, | 560 internal::SessionStateAnimator::kAllLockScreenContainersMask, |
| 571 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); | 561 internal::SessionStateAnimator::ANIMATION_FAST_CLOSE)); |
| 572 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 562 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
| 573 GenerateMouseMoveEvent(); | 563 GenerateMouseMoveEvent(); |
| 574 EXPECT_FALSE(cursor_visible()); | 564 EXPECT_FALSE(cursor_visible()); |
| 575 | 565 |
| 576 EXPECT_EQ(0, delegate_->num_shutdown_requests()); | 566 EXPECT_EQ(0, delegate_->num_shutdown_requests()); |
| 577 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 567 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
| 578 test_api_->trigger_real_shutdown_timeout(); | 568 test_api_->trigger_real_shutdown_timeout(); |
| 579 EXPECT_EQ(1, delegate_->num_shutdown_requests()); | 569 EXPECT_EQ(1, delegate_->num_shutdown_requests()); |
| 580 } | 570 } |
| 581 | 571 |
| 582 TEST_F(PowerButtonControllerTest, RequestAndCancelShutdownFromLockScreen) { | 572 TEST_F(PowerButtonControllerTest, RequestAndCancelShutdownFromLockScreen) { |
| 583 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 573 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 584 state_controller_->OnLockStateChanged(true); | 574 controller_->OnLockStateChanged(true); |
| 585 | 575 |
| 586 // Press the power button and check that we start the shutdown timer. | 576 // Press the power button and check that we start the shutdown timer. |
| 587 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 577 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 588 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 578 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| 589 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 579 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
| 590 EXPECT_TRUE( | 580 EXPECT_TRUE( |
| 591 animator_api_->ContainersAreAnimated( | 581 test_api_->ContainersAreAnimated( |
| 592 internal::SessionStateAnimator::kAllContainersMask, | 582 internal::SessionStateAnimator::kAllContainersMask, |
| 593 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); | 583 internal::SessionStateAnimator::ANIMATION_SLOW_CLOSE)); |
| 594 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 584 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
| 595 | 585 |
| 596 // Release the power button before the shutdown timer fires. | 586 // Release the power button before the shutdown timer fires. |
| 597 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 587 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| 598 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 588 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
| 599 EXPECT_TRUE( | 589 EXPECT_TRUE( |
| 600 animator_api_->ContainersAreAnimated( | 590 test_api_->ContainersAreAnimated( |
| 601 internal::SessionStateAnimator::kAllLockScreenContainersMask, | 591 internal::SessionStateAnimator::kAllLockScreenContainersMask, |
| 602 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE)); | 592 internal::SessionStateAnimator::ANIMATION_UNDO_SLOW_CLOSE)); |
| 603 EXPECT_TRUE( | 593 EXPECT_TRUE( |
| 604 animator_api_->ContainersAreAnimated( | 594 test_api_->ContainersAreAnimated( |
| 605 internal::SessionStateAnimator::DESKTOP_BACKGROUND, | 595 internal::SessionStateAnimator::DESKTOP_BACKGROUND, |
| 606 internal::SessionStateAnimator::ANIMATION_RESTORE)); | 596 internal::SessionStateAnimator::ANIMATION_RESTORE)); |
| 607 EXPECT_TRUE(animator_api_->BlackLayerIsVisible()); | 597 EXPECT_TRUE(test_api_->BlackLayerIsVisible()); |
| 608 } | 598 } |
| 609 | 599 |
| 610 // Test that the black layer is resized in response to root window resizes. | 600 // Test that the black layer is resized in response to root window resizes. |
| 611 TEST_F(PowerButtonControllerTest, ResizeBlackLayer) { | 601 TEST_F(PowerButtonControllerTest, ResizeBlackLayer) { |
| 612 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 602 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 613 EXPECT_EQ(Shell::GetPrimaryRootWindow()->bounds().ToString(), | 603 EXPECT_EQ(Shell::GetPrimaryRootWindow()->bounds().ToString(), |
| 614 animator_api_->GetBlackLayerBounds().ToString()); | 604 test_api_->GetBlackLayerBounds().ToString()); |
| 615 | 605 |
| 616 const gfx::Size kNewSize(400, 300); | 606 const gfx::Size kNewSize(400, 300); |
| 617 Shell::GetPrimaryRootWindow()->SetHostSize(kNewSize); | 607 Shell::GetPrimaryRootWindow()->SetHostSize(kNewSize); |
| 618 EXPECT_EQ(gfx::Rect(kNewSize).ToString(), | 608 EXPECT_EQ(gfx::Rect(kNewSize).ToString(), |
| 619 animator_api_->GetBlackLayerBounds().ToString()); | 609 test_api_->GetBlackLayerBounds().ToString()); |
| 620 } | 610 } |
| 621 | 611 |
| 622 // Test that we ignore power button presses when the screen is turned off. | 612 // Test that we ignore power button presses when the screen is turned off. |
| 623 TEST_F(PowerButtonControllerTest, IgnorePowerButtonIfScreenIsOff) { | 613 TEST_F(PowerButtonControllerTest, IgnorePowerButtonIfScreenIsOff) { |
| 624 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 614 controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
| 625 | 615 |
| 626 // When the screen brightness is at 0%, we shouldn't do anything in response | 616 // When the screen brightness is at 0%, we shouldn't do anything in response |
| 627 // to power button presses. | 617 // to power button presses. |
| 628 controller_->OnScreenBrightnessChanged(0.0); | 618 controller_->OnScreenBrightnessChanged(0.0); |
| 629 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 619 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 630 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 620 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
| 631 | 621 |
| 632 // After increasing the brightness to 10%, we should start the timer like | 622 // After increasing the brightness to 10%, we should start the timer like |
| 633 // usual. | 623 // usual. |
| 634 controller_->OnScreenBrightnessChanged(10.0); | 624 controller_->OnScreenBrightnessChanged(10.0); |
| 635 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 625 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 636 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 626 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
| 637 } | 627 } |
| 638 | 628 |
| 639 } // namespace test | 629 } // namespace test |
| 640 } // namespace ash | 630 } // namespace ash |
| OLD | NEW |