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_lock_state_controller.h" |
6 #include "ash/wm/session_state_animator.h" | 7 #include "ash/wm/session_state_animator.h" |
7 #include "ash/wm/session_state_controller.h" | |
8 #include "ash/wm/session_state_controller_impl.h" | 8 #include "ash/wm/session_state_controller_impl.h" |
9 | |
10 #include "ash/ash_switches.h" | 9 #include "ash/ash_switches.h" |
11 #include "ash/session_state_delegate.h" | 10 #include "ash/session_state_delegate.h" |
12 #include "ash/shell.h" | 11 #include "ash/shell.h" |
13 #include "ash/test/ash_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
14 #include "ash/test/test_shell_delegate.h" | 13 #include "ash/test/test_shell_delegate.h" |
15 #include "base/command_line.h" | 14 #include "base/command_line.h" |
16 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
17 #include "base/time.h" | 16 #include "base/time.h" |
18 #include "ui/aura/env.h" | 17 #include "ui/aura/env.h" |
19 #include "ui/aura/root_window.h" | 18 #include "ui/aura/root_window.h" |
20 #include "ui/aura/test/event_generator.h" | 19 #include "ui/aura/test/event_generator.h" |
21 #include "ui/compositor/scoped_animation_duration_scale_mode.h" | 20 #include "ui/compositor/scoped_animation_duration_scale_mode.h" |
22 #include "ui/gfx/rect.h" | 21 #include "ui/gfx/rect.h" |
23 #include "ui/gfx/size.h" | 22 #include "ui/gfx/size.h" |
24 | 23 |
25 namespace ash { | 24 namespace ash { |
26 namespace test { | 25 namespace test { |
27 namespace { | 26 namespace { |
28 bool cursor_visible() { | 27 bool cursor_visible() { |
29 return ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible(); | 28 return ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible(); |
30 } | 29 } |
31 } | 30 } |
32 | 31 |
33 // Fake implementation of PowerButtonControllerDelegate that just logs requests | 32 // Fake implementation of PowerButtonControllerDelegate that just logs requests |
34 // to lock the screen and shut down the device. | 33 // to lock the screen and shut down the device. |
35 class TestPowerButtonControllerDelegate : | 34 class TestPowerButtonControllerDelegate : |
36 public SessionStateControllerDelegate { | 35 public SessionLockStateControllerDelegate { |
37 public: | 36 public: |
38 TestPowerButtonControllerDelegate() | 37 TestPowerButtonControllerDelegate() |
39 : num_lock_requests_(0), | 38 : num_lock_requests_(0), |
40 num_shutdown_requests_(0) {} | 39 num_shutdown_requests_(0) {} |
41 | 40 |
42 int num_lock_requests() const { return num_lock_requests_; } | 41 int num_lock_requests() const { return num_lock_requests_; } |
43 int num_shutdown_requests() const { return num_shutdown_requests_; } | 42 int num_shutdown_requests() const { return num_shutdown_requests_; } |
44 | 43 |
45 // PowerButtonControllerDelegate implementation. | 44 // PowerButtonControllerDelegate implementation. |
46 virtual void RequestLockScreen() OVERRIDE { | 45 virtual void RequestLockScreen() OVERRIDE { |
(...skipping 15 matching lines...) Expand all Loading... |
62 PowerButtonControllerTest() : controller_(NULL), delegate_(NULL) {} | 61 PowerButtonControllerTest() : controller_(NULL), delegate_(NULL) {} |
63 virtual ~PowerButtonControllerTest() {} | 62 virtual ~PowerButtonControllerTest() {} |
64 | 63 |
65 virtual void SetUp() OVERRIDE { | 64 virtual void SetUp() OVERRIDE { |
66 CommandLine::ForCurrentProcess()->AppendSwitch( | 65 CommandLine::ForCurrentProcess()->AppendSwitch( |
67 ash::switches::kAshDisableNewLockAnimations); | 66 ash::switches::kAshDisableNewLockAnimations); |
68 | 67 |
69 AshTestBase::SetUp(); | 68 AshTestBase::SetUp(); |
70 delegate_ = new TestPowerButtonControllerDelegate; | 69 delegate_ = new TestPowerButtonControllerDelegate; |
71 controller_ = Shell::GetInstance()->power_button_controller(); | 70 controller_ = Shell::GetInstance()->power_button_controller(); |
72 state_controller_ = static_cast<SessionStateControllerImpl*>( | 71 lock_state_controller_ = static_cast<SessionStateControllerImpl*>( |
73 Shell::GetInstance()->session_state_controller()); | 72 Shell::GetInstance()->session_lock_state_controller()); |
74 state_controller_->SetDelegate(delegate_); // transfers ownership | 73 lock_state_controller_->SetDelegate(delegate_); // transfers ownership |
75 test_api_.reset(new SessionStateControllerImpl::TestApi(state_controller_)); | 74 test_api_.reset(new SessionStateControllerImpl::TestApi( |
76 animator_api_.reset( | 75 lock_state_controller_)); |
77 new internal::SessionStateAnimator::TestApi(state_controller_-> | 76 animator_api_.reset(new internal::SessionStateAnimator::TestApi( |
78 animator_.get())); | 77 lock_state_controller_->animator_.get())); |
79 shell_delegate_ = reinterpret_cast<TestShellDelegate*>( | 78 shell_delegate_ = reinterpret_cast<TestShellDelegate*>( |
80 ash::Shell::GetInstance()->delegate()); | 79 ash::Shell::GetInstance()->delegate()); |
81 state_delegate_ = Shell::GetInstance()->session_state_delegate(); | 80 state_delegate_ = Shell::GetInstance()->session_state_delegate(); |
82 } | 81 } |
83 | 82 |
84 protected: | 83 protected: |
85 void GenerateMouseMoveEvent() { | 84 void GenerateMouseMoveEvent() { |
86 aura::test::EventGenerator generator( | 85 aura::test::EventGenerator generator( |
87 Shell::GetPrimaryRootWindow()); | 86 Shell::GetPrimaryRootWindow()); |
88 generator.MoveMouseTo(10, 10); | 87 generator.MoveMouseTo(10, 10); |
89 } | 88 } |
90 | 89 |
91 int NumShutdownRequests() { | 90 int NumShutdownRequests() { |
92 return delegate_->num_shutdown_requests() + | 91 return delegate_->num_shutdown_requests() + |
93 shell_delegate_->num_exit_requests(); | 92 shell_delegate_->num_exit_requests(); |
94 } | 93 } |
95 | 94 |
96 PowerButtonController* controller_; // not owned | 95 PowerButtonController* controller_; // not owned |
97 SessionStateControllerImpl* state_controller_; // not owned | 96 SessionStateControllerImpl* lock_state_controller_; // not owned |
98 TestPowerButtonControllerDelegate* delegate_; // not owned | 97 TestPowerButtonControllerDelegate* delegate_; // not owned |
99 TestShellDelegate* shell_delegate_; // not owned | 98 TestShellDelegate* shell_delegate_; // not owned |
100 SessionStateDelegate* state_delegate_; // not owned | 99 SessionStateDelegate* state_delegate_; // not owned |
101 | 100 |
102 scoped_ptr<SessionStateControllerImpl::TestApi> test_api_; | 101 scoped_ptr<SessionStateControllerImpl::TestApi> test_api_; |
103 scoped_ptr<internal::SessionStateAnimator::TestApi> animator_api_; | 102 scoped_ptr<internal::SessionStateAnimator::TestApi> animator_api_; |
104 | 103 |
105 private: | 104 private: |
106 DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerTest); | 105 DISALLOW_COPY_AND_ASSIGN(PowerButtonControllerTest); |
107 }; | 106 }; |
108 | 107 |
109 // Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't | 108 // Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't |
110 // correctly report power button releases. We should lock immediately the first | 109 // correctly report power button releases. We should lock immediately the first |
111 // time the button is pressed and shut down when it's pressed from the locked | 110 // time the button is pressed and shut down when it's pressed from the locked |
112 // state. | 111 // state. |
113 TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) { | 112 TEST_F(PowerButtonControllerTest, LegacyLockAndShutDown) { |
114 controller_->set_has_legacy_power_button_for_test(true); | 113 controller_->set_has_legacy_power_button_for_test(true); |
115 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 114 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
116 state_controller_->OnLockStateChanged(false); | 115 lock_state_controller_->OnLockStateChanged(false); |
117 | 116 |
118 // We should request that the screen be locked immediately after seeing the | 117 // We should request that the screen be locked immediately after seeing the |
119 // power button get pressed. | 118 // power button get pressed. |
120 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 119 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
121 EXPECT_TRUE( | 120 EXPECT_TRUE( |
122 animator_api_->ContainersAreAnimated( | 121 animator_api_->ContainersAreAnimated( |
123 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 122 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
124 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); | 123 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); |
125 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 124 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
126 EXPECT_EQ(1, delegate_->num_lock_requests()); | 125 EXPECT_EQ(1, delegate_->num_lock_requests()); |
127 | 126 |
128 // Notify that we locked successfully. | 127 // Notify that we locked successfully. |
129 state_controller_->OnStartingLock(); | 128 lock_state_controller_->OnStartingLock(); |
130 EXPECT_TRUE( | 129 EXPECT_TRUE( |
131 animator_api_->ContainersAreAnimated( | 130 animator_api_->ContainersAreAnimated( |
132 internal::SessionStateAnimator::LAUNCHER, | 131 internal::SessionStateAnimator::LAUNCHER, |
133 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); | 132 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); |
134 EXPECT_TRUE( | 133 EXPECT_TRUE( |
135 animator_api_->ContainersAreAnimated( | 134 animator_api_->ContainersAreAnimated( |
136 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 135 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
137 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); | 136 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); |
138 EXPECT_TRUE( | 137 EXPECT_TRUE( |
139 animator_api_->ContainersAreAnimated( | 138 animator_api_->ContainersAreAnimated( |
140 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | 139 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
141 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); | 140 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); |
142 | 141 |
143 // Notify that the lock window is visible. We should make it fade in. | 142 // Notify that the lock window is visible. We should make it fade in. |
144 state_controller_->OnLockStateChanged(true); | 143 lock_state_controller_->OnLockStateChanged(true); |
145 state_delegate_->LockScreen(); | 144 state_delegate_->LockScreen(); |
146 EXPECT_TRUE( | 145 EXPECT_TRUE( |
147 animator_api_->ContainersAreAnimated( | 146 animator_api_->ContainersAreAnimated( |
148 internal::SessionStateAnimator::kAllLockScreenContainersMask, | 147 internal::SessionStateAnimator::kAllLockScreenContainersMask, |
149 internal::SessionStateAnimator::ANIMATION_FADE_IN)); | 148 internal::SessionStateAnimator::ANIMATION_FADE_IN)); |
150 | 149 |
151 // We shouldn't progress towards the shutdown state, however. | 150 // We shouldn't progress towards the shutdown state, however. |
152 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); | 151 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
153 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 152 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
154 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 153 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
(...skipping 20 matching lines...) Expand all Loading... |
175 EXPECT_FALSE(cursor_visible()); | 174 EXPECT_FALSE(cursor_visible()); |
176 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 175 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
177 test_api_->trigger_real_shutdown_timeout(); | 176 test_api_->trigger_real_shutdown_timeout(); |
178 EXPECT_EQ(1, NumShutdownRequests()); | 177 EXPECT_EQ(1, NumShutdownRequests()); |
179 } | 178 } |
180 | 179 |
181 // 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 |
182 // while we're not logged in on an unofficial system. | 181 // while we're not logged in on an unofficial system. |
183 TEST_F(PowerButtonControllerTest, LegacyNotLoggedIn) { | 182 TEST_F(PowerButtonControllerTest, LegacyNotLoggedIn) { |
184 controller_->set_has_legacy_power_button_for_test(true); | 183 controller_->set_has_legacy_power_button_for_test(true); |
185 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | 184 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); |
186 state_controller_->OnLockStateChanged(false); | 185 lock_state_controller_->OnLockStateChanged(false); |
187 SetUserLoggedIn(false); | 186 SetUserLoggedIn(false); |
188 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 187 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
189 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 188 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
190 } | 189 } |
191 | 190 |
192 // Test that we start shutting down immediately if the power button is pressed | 191 // Test that we start shutting down immediately if the power button is pressed |
193 // while we're logged in as a guest on an unofficial system. | 192 // while we're logged in as a guest on an unofficial system. |
194 TEST_F(PowerButtonControllerTest, LegacyGuest) { | 193 TEST_F(PowerButtonControllerTest, LegacyGuest) { |
195 controller_->set_has_legacy_power_button_for_test(true); | 194 controller_->set_has_legacy_power_button_for_test(true); |
196 state_controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST); | 195 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST); |
197 state_controller_->OnLockStateChanged(false); | 196 lock_state_controller_->OnLockStateChanged(false); |
198 SetCanLockScreen(false); | 197 SetCanLockScreen(false); |
199 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 198 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
200 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 199 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
201 } | 200 } |
202 | 201 |
203 // When we hold the power button while the user isn't logged in, we should shut | 202 // When we hold the power button while the user isn't logged in, we should shut |
204 // down the machine directly. | 203 // down the machine directly. |
205 TEST_F(PowerButtonControllerTest, ShutdownWhenNotLoggedIn) { | 204 TEST_F(PowerButtonControllerTest, ShutdownWhenNotLoggedIn) { |
206 controller_->set_has_legacy_power_button_for_test(false); | 205 controller_->set_has_legacy_power_button_for_test(false); |
207 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | 206 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); |
208 state_controller_->OnLockStateChanged(false); | 207 lock_state_controller_->OnLockStateChanged(false); |
209 SetUserLoggedIn(false); | 208 SetUserLoggedIn(false); |
210 | 209 |
211 // Press the power button and check that we start the shutdown timer. | 210 // Press the power button and check that we start the shutdown timer. |
212 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 211 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
213 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 212 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
214 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 213 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
215 EXPECT_TRUE( | 214 EXPECT_TRUE( |
216 animator_api_->ContainersAreAnimated( | 215 animator_api_->ContainersAreAnimated( |
217 internal::SessionStateAnimator::kAllContainersMask, | 216 internal::SessionStateAnimator::kAllContainersMask, |
218 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); | 217 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); |
(...skipping 24 matching lines...) Expand all Loading... |
243 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); | 242 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); |
244 | 243 |
245 // When the timout fires, we should request a shutdown. | 244 // When the timout fires, we should request a shutdown. |
246 test_api_->trigger_real_shutdown_timeout(); | 245 test_api_->trigger_real_shutdown_timeout(); |
247 EXPECT_EQ(1, NumShutdownRequests()); | 246 EXPECT_EQ(1, NumShutdownRequests()); |
248 } | 247 } |
249 | 248 |
250 // Test that we lock the screen and deal with unlocking correctly. | 249 // Test that we lock the screen and deal with unlocking correctly. |
251 TEST_F(PowerButtonControllerTest, LockAndUnlock) { | 250 TEST_F(PowerButtonControllerTest, LockAndUnlock) { |
252 controller_->set_has_legacy_power_button_for_test(false); | 251 controller_->set_has_legacy_power_button_for_test(false); |
253 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 252 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
254 state_controller_->OnLockStateChanged(false); | 253 lock_state_controller_->OnLockStateChanged(false); |
255 | 254 |
256 // We should initially be showing the screen locker containers, since they | 255 // We should initially be showing the screen locker containers, since they |
257 // also contain login-related windows that we want to show during the | 256 // also contain login-related windows that we want to show during the |
258 // logging-in animation. | 257 // logging-in animation. |
259 EXPECT_TRUE( | 258 EXPECT_TRUE( |
260 animator_api_->ContainersAreAnimated( | 259 animator_api_->ContainersAreAnimated( |
261 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | 260 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
262 internal::SessionStateAnimator::ANIMATION_RESTORE)); | 261 internal::SessionStateAnimator::ANIMATION_RESTORE)); |
263 | 262 |
264 // Press the power button and check that the lock timer is started and that we | 263 // Press the power button and check that the lock timer is started and that we |
(...skipping 20 matching lines...) Expand all Loading... |
285 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 284 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
286 EXPECT_EQ(0, delegate_->num_lock_requests()); | 285 EXPECT_EQ(0, delegate_->num_lock_requests()); |
287 test_api_->trigger_lock_timeout(); | 286 test_api_->trigger_lock_timeout(); |
288 EXPECT_EQ(1, delegate_->num_lock_requests()); | 287 EXPECT_EQ(1, delegate_->num_lock_requests()); |
289 EXPECT_TRUE( | 288 EXPECT_TRUE( |
290 animator_api_->ContainersAreAnimated( | 289 animator_api_->ContainersAreAnimated( |
291 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 290 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
292 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); | 291 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); |
293 | 292 |
294 // Notify that we locked successfully. | 293 // Notify that we locked successfully. |
295 state_controller_->OnStartingLock(); | 294 lock_state_controller_->OnStartingLock(); |
296 EXPECT_TRUE( | 295 EXPECT_TRUE( |
297 animator_api_->ContainersAreAnimated( | 296 animator_api_->ContainersAreAnimated( |
298 internal::SessionStateAnimator::LAUNCHER, | 297 internal::SessionStateAnimator::LAUNCHER, |
299 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); | 298 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); |
300 EXPECT_TRUE( | 299 EXPECT_TRUE( |
301 animator_api_->ContainersAreAnimated( | 300 animator_api_->ContainersAreAnimated( |
302 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 301 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
303 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); | 302 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); |
304 EXPECT_TRUE( | 303 EXPECT_TRUE( |
305 animator_api_->ContainersAreAnimated( | 304 animator_api_->ContainersAreAnimated( |
306 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | 305 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
307 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); | 306 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); |
308 | 307 |
309 // Notify that the lock window is visible. We should make it fade in. | 308 // Notify that the lock window is visible. We should make it fade in. |
310 state_controller_->OnLockStateChanged(true); | 309 lock_state_controller_->OnLockStateChanged(true); |
311 state_delegate_->LockScreen(); | 310 state_delegate_->LockScreen(); |
312 EXPECT_TRUE( | 311 EXPECT_TRUE( |
313 animator_api_->ContainersAreAnimated( | 312 animator_api_->ContainersAreAnimated( |
314 internal::SessionStateAnimator::kAllLockScreenContainersMask, | 313 internal::SessionStateAnimator::kAllLockScreenContainersMask, |
315 internal::SessionStateAnimator::ANIMATION_FADE_IN)); | 314 internal::SessionStateAnimator::ANIMATION_FADE_IN)); |
316 | 315 |
317 // When we release the power button, the lock-to-shutdown timer should be | 316 // When we release the power button, the lock-to-shutdown timer should be |
318 // stopped. | 317 // stopped. |
319 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); | 318 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); |
320 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 319 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
321 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); | 320 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
322 | 321 |
323 // Notify that the screen has been unlocked. We should show the | 322 // Notify that the screen has been unlocked. We should show the |
324 // non-screen-locker windows. | 323 // non-screen-locker windows. |
325 state_controller_->OnLockStateChanged(false); | 324 lock_state_controller_->OnLockStateChanged(false); |
326 state_delegate_->UnlockScreen(); | 325 state_delegate_->UnlockScreen(); |
327 EXPECT_TRUE( | 326 EXPECT_TRUE( |
328 animator_api_->ContainersAreAnimated( | 327 animator_api_->ContainersAreAnimated( |
329 internal::SessionStateAnimator::DESKTOP_BACKGROUND | | 328 internal::SessionStateAnimator::DESKTOP_BACKGROUND | |
330 internal::SessionStateAnimator::LAUNCHER | | 329 internal::SessionStateAnimator::LAUNCHER | |
331 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 330 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
332 internal::SessionStateAnimator::ANIMATION_RESTORE)); | 331 internal::SessionStateAnimator::ANIMATION_RESTORE)); |
333 } | 332 } |
334 | 333 |
335 // Hold the power button down from the unlocked state to eventual shutdown. | 334 // Hold the power button down from the unlocked state to eventual shutdown. |
336 TEST_F(PowerButtonControllerTest, LockToShutdown) { | 335 TEST_F(PowerButtonControllerTest, LockToShutdown) { |
337 controller_->set_has_legacy_power_button_for_test(false); | 336 controller_->set_has_legacy_power_button_for_test(false); |
338 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 337 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
339 state_controller_->OnLockStateChanged(false); | 338 lock_state_controller_->OnLockStateChanged(false); |
340 | 339 |
341 // Hold the power button and lock the screen. | 340 // Hold the power button and lock the screen. |
342 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 341 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
343 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 342 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
344 test_api_->trigger_lock_timeout(); | 343 test_api_->trigger_lock_timeout(); |
345 state_controller_->OnStartingLock(); | 344 lock_state_controller_->OnStartingLock(); |
346 state_controller_->OnLockStateChanged(true); | 345 lock_state_controller_->OnLockStateChanged(true); |
347 state_delegate_->LockScreen(); | 346 state_delegate_->LockScreen(); |
348 | 347 |
349 // When the lock-to-shutdown timeout fires, we should start the shutdown | 348 // When the lock-to-shutdown timeout fires, we should start the shutdown |
350 // timer. | 349 // timer. |
351 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); | 350 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); |
352 test_api_->trigger_lock_to_shutdown_timeout(); | 351 test_api_->trigger_lock_to_shutdown_timeout(); |
353 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 352 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
354 EXPECT_TRUE( | 353 EXPECT_TRUE( |
355 animator_api_->ContainersAreAnimated( | 354 animator_api_->ContainersAreAnimated( |
356 internal::SessionStateAnimator::kAllContainersMask, | 355 internal::SessionStateAnimator::kAllContainersMask, |
357 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); | 356 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); |
358 | 357 |
359 // Fire the shutdown timeout and check that we request shutdown. | 358 // Fire the shutdown timeout and check that we request shutdown. |
360 test_api_->trigger_shutdown_timeout(); | 359 test_api_->trigger_shutdown_timeout(); |
361 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 360 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
362 EXPECT_EQ(0, NumShutdownRequests()); | 361 EXPECT_EQ(0, NumShutdownRequests()); |
363 test_api_->trigger_real_shutdown_timeout(); | 362 test_api_->trigger_real_shutdown_timeout(); |
364 EXPECT_EQ(1, NumShutdownRequests()); | 363 EXPECT_EQ(1, NumShutdownRequests()); |
365 } | 364 } |
366 | 365 |
367 | 366 |
368 // Hold the power button down from the unlocked state to eventual shutdown, | 367 // Hold the power button down from the unlocked state to eventual shutdown, |
369 // then release the button while system does locking. | 368 // then release the button while system does locking. |
370 TEST_F(PowerButtonControllerTest, CancelLockToShutdown) { | 369 TEST_F(PowerButtonControllerTest, CancelLockToShutdown) { |
371 controller_->set_has_legacy_power_button_for_test(false); | 370 controller_->set_has_legacy_power_button_for_test(false); |
372 | 371 |
373 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 372 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
374 state_controller_->OnLockStateChanged(false); | 373 lock_state_controller_->OnLockStateChanged(false); |
375 | 374 |
376 // Hold the power button and lock the screen. | 375 // Hold the power button and lock the screen. |
377 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 376 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
378 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 377 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
379 test_api_->trigger_lock_timeout(); | 378 test_api_->trigger_lock_timeout(); |
380 state_controller_->OnStartingLock(); | 379 lock_state_controller_->OnStartingLock(); |
381 | 380 |
382 // Power button is released while system attempts to lock. | 381 // Power button is released while system attempts to lock. |
383 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 382 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
384 state_controller_->OnLockStateChanged(true); | 383 lock_state_controller_->OnLockStateChanged(true); |
385 state_delegate_->LockScreen(); | 384 state_delegate_->LockScreen(); |
386 | 385 |
387 EXPECT_FALSE(state_controller_->ShutdownRequested()); | 386 EXPECT_FALSE(lock_state_controller_->ShutdownRequested()); |
388 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); | 387 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
389 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 388 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
390 } | 389 } |
391 | 390 |
392 // Test that we handle the case where lock requests are ignored. | 391 // Test that we handle the case where lock requests are ignored. |
393 TEST_F(PowerButtonControllerTest, LockFail) { | 392 TEST_F(PowerButtonControllerTest, LockFail) { |
394 // We require animations to have a duration for this test. | 393 // We require animations to have a duration for this test. |
395 ui::ScopedAnimationDurationScaleMode normal_duration_mode( | 394 ui::ScopedAnimationDurationScaleMode normal_duration_mode( |
396 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); | 395 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION); |
397 | 396 |
398 controller_->set_has_legacy_power_button_for_test(false); | 397 controller_->set_has_legacy_power_button_for_test(false); |
399 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 398 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
400 state_controller_->OnLockStateChanged(false); | 399 lock_state_controller_->OnLockStateChanged(false); |
401 | 400 |
402 // Hold the power button and lock the screen. | 401 // Hold the power button and lock the screen. |
403 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 402 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
404 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 403 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
405 EXPECT_TRUE( | 404 EXPECT_TRUE( |
406 animator_api_->ContainersAreAnimated( | 405 animator_api_->ContainersAreAnimated( |
407 internal::SessionStateAnimator::DESKTOP_BACKGROUND | | 406 internal::SessionStateAnimator::DESKTOP_BACKGROUND | |
408 internal::SessionStateAnimator::LAUNCHER | | 407 internal::SessionStateAnimator::LAUNCHER | |
409 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 408 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
410 internal::SessionStateAnimator::ANIMATION_RESTORE)); | 409 internal::SessionStateAnimator::ANIMATION_RESTORE)); |
(...skipping 10 matching lines...) Expand all Loading... |
421 EXPECT_TRUE( | 420 EXPECT_TRUE( |
422 animator_api_->ContainersAreAnimated( | 421 animator_api_->ContainersAreAnimated( |
423 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 422 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
424 internal::SessionStateAnimator::ANIMATION_RESTORE)); | 423 internal::SessionStateAnimator::ANIMATION_RESTORE)); |
425 } | 424 } |
426 | 425 |
427 // Test the basic operation of the lock button. | 426 // Test the basic operation of the lock button. |
428 TEST_F(PowerButtonControllerTest, LockButtonBasic) { | 427 TEST_F(PowerButtonControllerTest, LockButtonBasic) { |
429 controller_->set_has_legacy_power_button_for_test(false); | 428 controller_->set_has_legacy_power_button_for_test(false); |
430 // The lock button shouldn't do anything if we aren't logged in. | 429 // The lock button shouldn't do anything if we aren't logged in. |
431 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | 430 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); |
432 state_controller_->OnLockStateChanged(false); | 431 lock_state_controller_->OnLockStateChanged(false); |
433 SetUserLoggedIn(false); | 432 SetUserLoggedIn(false); |
434 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 433 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
435 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 434 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
436 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 435 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
437 EXPECT_EQ(0, delegate_->num_lock_requests()); | 436 EXPECT_EQ(0, delegate_->num_lock_requests()); |
438 | 437 |
439 // Ditto for when we're logged in as a guest. | 438 // Ditto for when we're logged in as a guest. |
440 state_controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST); | 439 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST); |
441 SetUserLoggedIn(true); | 440 SetUserLoggedIn(true); |
442 SetCanLockScreen(false); | 441 SetCanLockScreen(false); |
443 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 442 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
444 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 443 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
445 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 444 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
446 EXPECT_EQ(0, delegate_->num_lock_requests()); | 445 EXPECT_EQ(0, delegate_->num_lock_requests()); |
447 | 446 |
448 // If we're logged in as a regular user, we should start the lock timer and | 447 // If we're logged in as a regular user, we should start the lock timer and |
449 // the pre-lock animation. | 448 // the pre-lock animation. |
450 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 449 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
451 SetCanLockScreen(true); | 450 SetCanLockScreen(true); |
452 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 451 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
453 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 452 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
454 EXPECT_TRUE( | 453 EXPECT_TRUE( |
455 animator_api_->ContainersAreAnimated( | 454 animator_api_->ContainersAreAnimated( |
456 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 455 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
457 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); | 456 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); |
458 | 457 |
459 // If the button is released immediately, we shouldn't lock the screen. | 458 // If the button is released immediately, we shouldn't lock the screen. |
460 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 459 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
(...skipping 12 matching lines...) Expand all Loading... |
473 EXPECT_EQ(1, delegate_->num_lock_requests()); | 472 EXPECT_EQ(1, delegate_->num_lock_requests()); |
474 | 473 |
475 // Pressing the lock button while we have a pending lock request shouldn't do | 474 // Pressing the lock button while we have a pending lock request shouldn't do |
476 // anything. | 475 // anything. |
477 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 476 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
478 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 477 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
479 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 478 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
480 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 479 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
481 | 480 |
482 // Pressing the button also shouldn't do anything after the screen is locked. | 481 // Pressing the button also shouldn't do anything after the screen is locked. |
483 state_controller_->OnStartingLock(); | 482 lock_state_controller_->OnStartingLock(); |
484 state_controller_->OnLockStateChanged(true); | 483 lock_state_controller_->OnLockStateChanged(true); |
485 state_delegate_->LockScreen(); | 484 state_delegate_->LockScreen(); |
486 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 485 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
487 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 486 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
488 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 487 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
489 } | 488 } |
490 | 489 |
491 // Test that the power button takes priority over the lock button. | 490 // Test that the power button takes priority over the lock button. |
492 TEST_F(PowerButtonControllerTest, PowerButtonPreemptsLockButton) { | 491 TEST_F(PowerButtonControllerTest, PowerButtonPreemptsLockButton) { |
493 controller_->set_has_legacy_power_button_for_test(false); | 492 controller_->set_has_legacy_power_button_for_test(false); |
494 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 493 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
495 state_controller_->OnLockStateChanged(false); | 494 lock_state_controller_->OnLockStateChanged(false); |
496 | 495 |
497 // While the lock button is down, hold the power button. | 496 // While the lock button is down, hold the power button. |
498 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 497 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
499 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 498 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
500 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 499 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
501 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 500 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
502 | 501 |
503 // The lock timer shouldn't be stopped when the lock button is released. | 502 // The lock timer shouldn't be stopped when the lock button is released. |
504 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 503 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
505 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 504 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
(...skipping 10 matching lines...) Expand all Loading... |
516 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 515 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
517 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 516 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
518 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 517 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
519 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 518 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
520 } | 519 } |
521 | 520 |
522 // When the screen is locked without going through the usual power-button | 521 // When the screen is locked without going through the usual power-button |
523 // slow-close path (e.g. via the wrench menu), test that we still show the | 522 // slow-close path (e.g. via the wrench menu), test that we still show the |
524 // fast-close animation. | 523 // fast-close animation. |
525 TEST_F(PowerButtonControllerTest, LockWithoutButton) { | 524 TEST_F(PowerButtonControllerTest, LockWithoutButton) { |
526 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 525 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
527 state_controller_->OnStartingLock(); | 526 lock_state_controller_->OnStartingLock(); |
528 EXPECT_TRUE( | 527 EXPECT_TRUE( |
529 animator_api_->ContainersAreAnimated( | 528 animator_api_->ContainersAreAnimated( |
530 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 529 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
531 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); | 530 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); |
532 } | 531 } |
533 | 532 |
534 // When we hear that the process is exiting but we haven't had a chance to | 533 // When we hear that the process is exiting but we haven't had a chance to |
535 // display an animation, we should just blank the screen. | 534 // display an animation, we should just blank the screen. |
536 TEST_F(PowerButtonControllerTest, ShutdownWithoutButton) { | 535 TEST_F(PowerButtonControllerTest, ShutdownWithoutButton) { |
537 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 536 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
538 state_controller_->OnAppTerminating(); | 537 lock_state_controller_->OnAppTerminating(); |
539 EXPECT_TRUE( | 538 EXPECT_TRUE( |
540 animator_api_->ContainersAreAnimated( | 539 animator_api_->ContainersAreAnimated( |
541 internal::SessionStateAnimator::kAllContainersMask, | 540 internal::SessionStateAnimator::kAllContainersMask, |
542 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); | 541 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); |
543 GenerateMouseMoveEvent(); | 542 GenerateMouseMoveEvent(); |
544 EXPECT_FALSE(cursor_visible()); | 543 EXPECT_FALSE(cursor_visible()); |
545 } | 544 } |
546 | 545 |
547 // Test that we display the fast-close animation and shut down when we get an | 546 // Test that we display the fast-close animation and shut down when we get an |
548 // outside request to shut down (e.g. from the login or lock screen). | 547 // outside request to shut down (e.g. from the login or lock screen). |
549 TEST_F(PowerButtonControllerTest, RequestShutdownFromLoginScreen) { | 548 TEST_F(PowerButtonControllerTest, RequestShutdownFromLoginScreen) { |
550 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | 549 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); |
551 state_controller_->OnLockStateChanged(false); | 550 lock_state_controller_->OnLockStateChanged(false); |
552 SetUserLoggedIn(false); | 551 SetUserLoggedIn(false); |
553 state_controller_->RequestShutdown(); | 552 lock_state_controller_->RequestShutdown(); |
554 EXPECT_TRUE( | 553 EXPECT_TRUE( |
555 animator_api_->ContainersAreAnimated( | 554 animator_api_->ContainersAreAnimated( |
556 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 555 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
557 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); | 556 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); |
558 EXPECT_TRUE( | 557 EXPECT_TRUE( |
559 animator_api_->ContainersAreAnimated( | 558 animator_api_->ContainersAreAnimated( |
560 internal::SessionStateAnimator::kAllLockScreenContainersMask, | 559 internal::SessionStateAnimator::kAllLockScreenContainersMask, |
561 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); | 560 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); |
562 GenerateMouseMoveEvent(); | 561 GenerateMouseMoveEvent(); |
563 EXPECT_FALSE(cursor_visible()); | 562 EXPECT_FALSE(cursor_visible()); |
564 | 563 |
565 EXPECT_EQ(0, NumShutdownRequests()); | 564 EXPECT_EQ(0, NumShutdownRequests()); |
566 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 565 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
567 test_api_->trigger_real_shutdown_timeout(); | 566 test_api_->trigger_real_shutdown_timeout(); |
568 EXPECT_EQ(1, NumShutdownRequests()); | 567 EXPECT_EQ(1, NumShutdownRequests()); |
569 } | 568 } |
570 | 569 |
571 TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) { | 570 TEST_F(PowerButtonControllerTest, RequestShutdownFromLockScreen) { |
572 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 571 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
573 state_controller_->OnLockStateChanged(true); | 572 lock_state_controller_->OnLockStateChanged(true); |
574 state_delegate_->LockScreen(); | 573 state_delegate_->LockScreen(); |
575 state_controller_->RequestShutdown(); | 574 lock_state_controller_->RequestShutdown(); |
576 EXPECT_TRUE( | 575 EXPECT_TRUE( |
577 animator_api_->ContainersAreAnimated( | 576 animator_api_->ContainersAreAnimated( |
578 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, | 577 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
579 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); | 578 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); |
580 EXPECT_TRUE( | 579 EXPECT_TRUE( |
581 animator_api_->ContainersAreAnimated( | 580 animator_api_->ContainersAreAnimated( |
582 internal::SessionStateAnimator::kAllLockScreenContainersMask, | 581 internal::SessionStateAnimator::kAllLockScreenContainersMask, |
583 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); | 582 internal::SessionStateAnimator::ANIMATION_FULL_CLOSE)); |
584 GenerateMouseMoveEvent(); | 583 GenerateMouseMoveEvent(); |
585 EXPECT_FALSE(cursor_visible()); | 584 EXPECT_FALSE(cursor_visible()); |
586 | 585 |
587 EXPECT_EQ(0, NumShutdownRequests()); | 586 EXPECT_EQ(0, NumShutdownRequests()); |
588 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 587 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
589 test_api_->trigger_real_shutdown_timeout(); | 588 test_api_->trigger_real_shutdown_timeout(); |
590 EXPECT_EQ(1, NumShutdownRequests()); | 589 EXPECT_EQ(1, NumShutdownRequests()); |
591 } | 590 } |
592 | 591 |
593 TEST_F(PowerButtonControllerTest, RequestAndCancelShutdownFromLockScreen) { | 592 TEST_F(PowerButtonControllerTest, RequestAndCancelShutdownFromLockScreen) { |
594 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 593 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
595 state_controller_->OnLockStateChanged(true); | 594 lock_state_controller_->OnLockStateChanged(true); |
596 state_delegate_->LockScreen(); | 595 state_delegate_->LockScreen(); |
597 | 596 |
598 // Press the power button and check that we start the shutdown timer. | 597 // Press the power button and check that we start the shutdown timer. |
599 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 598 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
600 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 599 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
601 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 600 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
602 EXPECT_TRUE( | 601 EXPECT_TRUE( |
603 animator_api_->ContainersAreAnimated( | 602 animator_api_->ContainersAreAnimated( |
604 internal::SessionStateAnimator::kAllContainersMask, | 603 internal::SessionStateAnimator::kAllContainersMask, |
605 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); | 604 internal::SessionStateAnimator::ANIMATION_PARTIAL_CLOSE)); |
606 | 605 |
607 // Release the power button before the shutdown timer fires. | 606 // Release the power button before the shutdown timer fires. |
608 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 607 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
609 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 608 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
610 EXPECT_TRUE( | 609 EXPECT_TRUE( |
611 animator_api_->ContainersAreAnimated( | 610 animator_api_->ContainersAreAnimated( |
612 internal::SessionStateAnimator::kAllLockScreenContainersMask, | 611 internal::SessionStateAnimator::kAllLockScreenContainersMask, |
613 internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE)); | 612 internal::SessionStateAnimator::ANIMATION_UNDO_PARTIAL_CLOSE)); |
614 EXPECT_TRUE( | 613 EXPECT_TRUE( |
615 animator_api_->ContainersAreAnimated( | 614 animator_api_->ContainersAreAnimated( |
616 internal::SessionStateAnimator::DESKTOP_BACKGROUND, | 615 internal::SessionStateAnimator::DESKTOP_BACKGROUND, |
617 internal::SessionStateAnimator::ANIMATION_RESTORE)); | 616 internal::SessionStateAnimator::ANIMATION_RESTORE)); |
618 } | 617 } |
619 | 618 |
620 // Test that we ignore power button presses when the screen is turned off. | 619 // Test that we ignore power button presses when the screen is turned off. |
621 TEST_F(PowerButtonControllerTest, IgnorePowerButtonIfScreenIsOff) { | 620 TEST_F(PowerButtonControllerTest, IgnorePowerButtonIfScreenIsOff) { |
622 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 621 lock_state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); |
623 | 622 |
624 // When the screen brightness is at 0%, we shouldn't do anything in response | 623 // When the screen brightness is at 0%, we shouldn't do anything in response |
625 // to power button presses. | 624 // to power button presses. |
626 controller_->OnScreenBrightnessChanged(0.0); | 625 controller_->OnScreenBrightnessChanged(0.0); |
627 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 626 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
628 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 627 EXPECT_FALSE(test_api_->lock_timer_is_running()); |
629 | 628 |
630 // After increasing the brightness to 10%, we should start the timer like | 629 // After increasing the brightness to 10%, we should start the timer like |
631 // usual. | 630 // usual. |
632 controller_->OnScreenBrightnessChanged(10.0); | 631 controller_->OnScreenBrightnessChanged(10.0); |
633 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 632 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
634 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 633 EXPECT_TRUE(test_api_->lock_timer_is_running()); |
635 } | 634 } |
636 | 635 |
637 } // namespace test | 636 } // namespace test |
638 } // namespace ash | 637 } // namespace ash |
OLD | NEW |