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