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/session_state_controller_impl2.h" | 5 #include "ash/wm/session_state_controller_impl2.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/shell_window_ids.h" |
9 #include "ash/test/ash_test_base.h" | 10 #include "ash/test/ash_test_base.h" |
10 #include "ash/test/test_shell_delegate.h" | 11 #include "ash/test/test_shell_delegate.h" |
11 #include "ash/wm/cursor_manager.h" | 12 #include "ash/wm/cursor_manager.h" |
12 #include "ash/wm/power_button_controller.h" | 13 #include "ash/wm/power_button_controller.h" |
13 #include "ash/wm/session_state_animator.h" | 14 #include "ash/wm/session_state_animator.h" |
14 #include "ash/wm/session_state_controller.h" | 15 #include "ash/wm/session_state_controller.h" |
15 #include "base/command_line.h" | 16 #include "base/command_line.h" |
16 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
17 #include "base/time.h" | 18 #include "base/time.h" |
18 #include "ui/aura/env.h" | 19 #include "ui/aura/env.h" |
19 #include "ui/aura/root_window.h" | 20 #include "ui/aura/root_window.h" |
20 #include "ui/aura/test/event_generator.h" | 21 #include "ui/aura/test/event_generator.h" |
| 22 #include "ui/compositor/scoped_layer_animation_settings.h" |
21 #include "ui/gfx/rect.h" | 23 #include "ui/gfx/rect.h" |
22 #include "ui/gfx/size.h" | 24 #include "ui/gfx/size.h" |
23 | 25 |
24 namespace ash { | 26 namespace ash { |
| 27 |
| 28 using internal::SessionStateAnimator; |
| 29 |
25 namespace test { | 30 namespace test { |
| 31 |
26 namespace { | 32 namespace { |
| 33 |
27 bool cursor_visible() { | 34 bool cursor_visible() { |
28 return ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible(); | 35 return ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible(); |
29 } | 36 } |
30 | 37 |
31 void CheckCalledCallback(bool* flag) { | 38 void CheckCalledCallback(bool* flag) { |
32 (*flag) = true; | 39 if (flag) |
| 40 (*flag) = true; |
33 } | 41 } |
| 42 |
| 43 aura::Window* GetBackground() { |
| 44 aura::RootWindow* root_window = Shell::GetPrimaryRootWindow(); |
| 45 return Shell::GetContainer(root_window, |
| 46 internal::kShellWindowId_DesktopBackgroundContainer); |
34 } | 47 } |
35 | 48 |
| 49 bool IsBackgroundHidden() { |
| 50 return !GetBackground()->IsVisible(); |
| 51 } |
| 52 |
| 53 void ShowBackground() { |
| 54 ui::ScopedLayerAnimationSettings settings( |
| 55 GetBackground()->layer()->GetAnimator()); |
| 56 settings.SetTransitionDuration(base::TimeDelta()); |
| 57 GetBackground()->Show(); |
| 58 } |
| 59 |
| 60 void HideBackground() { |
| 61 ui::ScopedLayerAnimationSettings settings( |
| 62 GetBackground()->layer()->GetAnimator()); |
| 63 settings.SetTransitionDuration(base::TimeDelta()); |
| 64 GetBackground()->Hide(); |
| 65 } |
| 66 |
| 67 } // namespace |
| 68 |
36 // Fake implementation of PowerButtonControllerDelegate that just logs requests | 69 // Fake implementation of PowerButtonControllerDelegate that just logs requests |
37 // to lock the screen and shut down the device. | 70 // to lock the screen and shut down the device. |
38 class TestSessionStateControllerDelegate : | 71 class TestSessionStateControllerDelegate : |
39 public SessionStateControllerDelegate { | 72 public SessionStateControllerDelegate { |
40 public: | 73 public: |
41 TestSessionStateControllerDelegate() | 74 TestSessionStateControllerDelegate() |
42 : num_lock_requests_(0), | 75 : num_lock_requests_(0), |
43 num_shutdown_requests_(0) {} | 76 num_shutdown_requests_(0) {} |
44 | 77 |
45 int num_lock_requests() const { return num_lock_requests_; } | 78 int num_lock_requests() const { return num_lock_requests_; } |
(...skipping 17 matching lines...) Expand all Loading... |
63 class SessionStateControllerImpl2Test : public AshTestBase { | 96 class SessionStateControllerImpl2Test : public AshTestBase { |
64 public: | 97 public: |
65 SessionStateControllerImpl2Test() : controller_(NULL), delegate_(NULL) {} | 98 SessionStateControllerImpl2Test() : controller_(NULL), delegate_(NULL) {} |
66 virtual ~SessionStateControllerImpl2Test() {} | 99 virtual ~SessionStateControllerImpl2Test() {} |
67 | 100 |
68 void SetUp() OVERRIDE { | 101 void SetUp() OVERRIDE { |
69 CommandLine::ForCurrentProcess()->AppendSwitch( | 102 CommandLine::ForCurrentProcess()->AppendSwitch( |
70 ash::switches::kAshNewLockAnimationsEnabled); | 103 ash::switches::kAshNewLockAnimationsEnabled); |
71 | 104 |
72 AshTestBase::SetUp(); | 105 AshTestBase::SetUp(); |
| 106 |
| 107 // We would control animations in a fine way: |
| 108 ui::LayerAnimator::set_disable_animations_for_test(false); |
| 109 animator_helper_ = ui::LayerAnimator::CreateAnimatorHelperForTest(); |
| 110 |
73 delegate_ = new TestSessionStateControllerDelegate; | 111 delegate_ = new TestSessionStateControllerDelegate; |
74 controller_ = Shell::GetInstance()->power_button_controller(); | 112 controller_ = Shell::GetInstance()->power_button_controller(); |
75 state_controller_ = static_cast<SessionStateControllerImpl2*>( | 113 state_controller_ = static_cast<SessionStateControllerImpl2*>( |
76 Shell::GetInstance()->session_state_controller()); | 114 Shell::GetInstance()->session_state_controller()); |
77 state_controller_->SetDelegate(delegate_); // transfers ownership | 115 state_controller_->SetDelegate(delegate_); // transfers ownership |
78 test_api_.reset( | 116 test_api_.reset( |
79 new SessionStateControllerImpl2::TestApi(state_controller_)); | 117 new SessionStateControllerImpl2::TestApi(state_controller_)); |
80 animator_api_.reset( | 118 animator_api_.reset( |
81 new internal::SessionStateAnimator::TestApi(state_controller_-> | 119 new SessionStateAnimator::TestApi(state_controller_-> |
82 animator_.get())); | 120 animator_.get())); |
83 shell_delegate_ = reinterpret_cast<TestShellDelegate*>( | 121 shell_delegate_ = reinterpret_cast<TestShellDelegate*>( |
84 ash::Shell::GetInstance()->delegate()); | 122 ash::Shell::GetInstance()->delegate()); |
85 } | 123 } |
86 | 124 |
| 125 void TearDown() { |
| 126 animator_helper_->ForwardWhileRunning(); |
| 127 AshTestBase::TearDown(); |
| 128 } |
| 129 |
87 protected: | 130 protected: |
88 void GenerateMouseMoveEvent() { | 131 void GenerateMouseMoveEvent() { |
89 aura::test::EventGenerator generator( | 132 aura::test::EventGenerator generator( |
90 Shell::GetPrimaryRootWindow()); | 133 Shell::GetPrimaryRootWindow()); |
91 generator.MoveMouseTo(10, 10); | 134 generator.MoveMouseTo(10, 10); |
92 } | 135 } |
93 | 136 |
94 int NumShutdownRequests() { | 137 int NumShutdownRequests() { |
95 return delegate_->num_shutdown_requests() + | 138 return delegate_->num_shutdown_requests() + |
96 shell_delegate_->num_exit_requests(); | 139 shell_delegate_->num_exit_requests(); |
97 } | 140 } |
98 | 141 |
| 142 void Forward(SessionStateAnimator::AnimationSpeed speed) { |
| 143 animator_helper_->Forward(SessionStateAnimator::GetDuration(speed)); |
| 144 } |
| 145 |
| 146 void ForwardPartially(SessionStateAnimator::AnimationSpeed speed, |
| 147 float factor) { |
| 148 base::TimeDelta duration = SessionStateAnimator::GetDuration(speed); |
| 149 base::TimeDelta partial_duration = |
| 150 base::TimeDelta::FromInternalValue(duration.ToInternalValue() * factor); |
| 151 animator_helper_->Forward(partial_duration); |
| 152 } |
| 153 |
| 154 void ExpectLockPartOneAnimationStarted() { |
| 155 EXPECT_TRUE(animator_helper_->IsAnimating()); |
| 156 EXPECT_TRUE( |
| 157 animator_api_->ContainersAreAnimated( |
| 158 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 159 SessionStateAnimator::ANIMATION_LIFT)); |
| 160 EXPECT_TRUE( |
| 161 animator_api_->ContainersAreAnimated( |
| 162 SessionStateAnimator::LAUNCHER, |
| 163 SessionStateAnimator::ANIMATION_FADE_OUT)); |
| 164 EXPECT_TRUE( |
| 165 animator_api_->ContainersAreAnimated( |
| 166 SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 167 SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); |
| 168 EXPECT_TRUE(test_api_->is_animating_lock()); |
| 169 } |
| 170 |
| 171 void ExpectLockPartOneAnimationUndo() { |
| 172 EXPECT_TRUE( |
| 173 animator_api_->ContainersAreAnimated( |
| 174 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 175 SessionStateAnimator::ANIMATION_DROP)); |
| 176 EXPECT_TRUE( |
| 177 animator_api_->ContainersAreAnimated( |
| 178 SessionStateAnimator::LAUNCHER, |
| 179 SessionStateAnimator::ANIMATION_FADE_IN)); |
| 180 } |
| 181 |
| 182 void ExpectLockPartOneAnimationFinished() { |
| 183 EXPECT_FALSE(animator_helper_->IsAnimating()); |
| 184 EXPECT_TRUE( |
| 185 animator_api_->ContainersAreAnimated( |
| 186 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 187 SessionStateAnimator::ANIMATION_LIFT)); |
| 188 EXPECT_TRUE( |
| 189 animator_api_->ContainersAreAnimated( |
| 190 SessionStateAnimator::LAUNCHER, |
| 191 SessionStateAnimator::ANIMATION_FADE_OUT)); |
| 192 EXPECT_TRUE( |
| 193 animator_api_->ContainersAreAnimated( |
| 194 SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 195 SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); |
| 196 } |
| 197 |
| 198 void ExpectLockPartTwoAnimationStarted() { |
| 199 EXPECT_TRUE(animator_helper_->IsAnimating()); |
| 200 EXPECT_TRUE( |
| 201 animator_api_->ContainersAreAnimated( |
| 202 SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 203 SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN)); |
| 204 } |
| 205 |
| 206 void ExpectLockPartTwoAnimationFinished() { |
| 207 EXPECT_FALSE(animator_helper_->IsAnimating()); |
| 208 EXPECT_TRUE( |
| 209 animator_api_->ContainersAreAnimated( |
| 210 SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 211 SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN)); |
| 212 } |
| 213 |
| 214 void ExpectUnlockPartOneAnimationStarted() { |
| 215 EXPECT_TRUE(animator_helper_->IsAnimating()); |
| 216 EXPECT_TRUE( |
| 217 animator_api_->ContainersAreAnimated( |
| 218 SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 219 SessionStateAnimator::ANIMATION_LIFT)); |
| 220 } |
| 221 |
| 222 void ExpectUnlockPartOneAnimationFinished() { |
| 223 EXPECT_FALSE(animator_helper_->IsAnimating()); |
| 224 EXPECT_TRUE( |
| 225 animator_api_->ContainersAreAnimated( |
| 226 SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 227 SessionStateAnimator::ANIMATION_LIFT)); |
| 228 } |
| 229 |
| 230 void ExpectUnlockPartTwoAnimationStarted() { |
| 231 EXPECT_TRUE(animator_helper_->IsAnimating()); |
| 232 EXPECT_TRUE( |
| 233 animator_api_->ContainersAreAnimated( |
| 234 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 235 SessionStateAnimator::ANIMATION_DROP)); |
| 236 EXPECT_TRUE( |
| 237 animator_api_->ContainersAreAnimated( |
| 238 SessionStateAnimator::LAUNCHER, |
| 239 SessionStateAnimator::ANIMATION_FADE_IN)); |
| 240 } |
| 241 |
| 242 void ExpectUnlockPartTwoAnimationFinished() { |
| 243 EXPECT_FALSE(animator_helper_->IsAnimating()); |
| 244 EXPECT_TRUE( |
| 245 animator_api_->ContainersAreAnimated( |
| 246 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 247 SessionStateAnimator::ANIMATION_DROP)); |
| 248 EXPECT_TRUE( |
| 249 animator_api_->ContainersAreAnimated( |
| 250 SessionStateAnimator::LAUNCHER, |
| 251 SessionStateAnimator::ANIMATION_FADE_IN)); |
| 252 } |
| 253 |
| 254 void ExpectShutdownAnimationStarted() { |
| 255 EXPECT_TRUE(animator_helper_->IsAnimating()); |
| 256 EXPECT_TRUE( |
| 257 animator_api_->RootWindowIsAnimated( |
| 258 SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); |
| 259 } |
| 260 |
| 261 void ExpectShutdownAnimationFinished() { |
| 262 EXPECT_FALSE(animator_helper_->IsAnimating()); |
| 263 EXPECT_TRUE( |
| 264 animator_api_->RootWindowIsAnimated( |
| 265 SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); |
| 266 } |
| 267 |
| 268 void ExpectShutdownAnimationUndo() { |
| 269 EXPECT_TRUE(animator_helper_->IsAnimating()); |
| 270 EXPECT_TRUE( |
| 271 animator_api_->RootWindowIsAnimated( |
| 272 SessionStateAnimator::ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS)); |
| 273 } |
| 274 |
| 275 void ExpectBackgroundIsShowing() { |
| 276 EXPECT_TRUE(animator_helper_->IsAnimating()); |
| 277 EXPECT_TRUE( |
| 278 animator_api_->ContainersAreAnimated( |
| 279 SessionStateAnimator::DESKTOP_BACKGROUND, |
| 280 SessionStateAnimator::ANIMATION_FADE_IN)); |
| 281 } |
| 282 |
| 283 void ExpectBackgroundIsHiding() { |
| 284 EXPECT_TRUE(animator_helper_->IsAnimating()); |
| 285 EXPECT_TRUE( |
| 286 animator_api_->ContainersAreAnimated( |
| 287 SessionStateAnimator::DESKTOP_BACKGROUND, |
| 288 SessionStateAnimator::ANIMATION_FADE_OUT)); |
| 289 } |
| 290 |
| 291 void ExpectUnlockedState() { |
| 292 EXPECT_FALSE(animator_helper_->IsAnimating()); |
| 293 EXPECT_FALSE(shell_delegate_->IsScreenLocked()); |
| 294 |
| 295 aura::Window::Windows containers; |
| 296 |
| 297 SessionStateAnimator::GetContainers( |
| 298 SessionStateAnimator::LAUNCHER | |
| 299 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS, |
| 300 &containers); |
| 301 for (aura::Window::Windows::const_iterator it = containers.begin(); |
| 302 it != containers.end(); ++it) { |
| 303 aura::Window* window = *it; |
| 304 ui::Layer* layer = window->layer(); |
| 305 EXPECT_EQ(1.0, layer->opacity()); |
| 306 EXPECT_EQ(0.0, layer->layer_brightness()); |
| 307 EXPECT_EQ(0.0, layer->layer_saturation()); |
| 308 EXPECT_EQ(gfx::Transform(), layer->transform()); |
| 309 } |
| 310 } |
| 311 |
| 312 void ExpectLockedState() { |
| 313 EXPECT_FALSE(animator_helper_->IsAnimating()); |
| 314 EXPECT_TRUE(shell_delegate_->IsScreenLocked()); |
| 315 |
| 316 aura::Window::Windows containers; |
| 317 |
| 318 SessionStateAnimator::GetContainers( |
| 319 SessionStateAnimator::LOCK_SCREEN_RELATED_CONTAINERS | |
| 320 SessionStateAnimator::LOCK_SCREEN_CONTAINERS, |
| 321 &containers); |
| 322 for (aura::Window::Windows::const_iterator it = containers.begin(); |
| 323 it != containers.end(); ++it) { |
| 324 aura::Window* window = *it; |
| 325 ui::Layer* layer = window->layer(); |
| 326 EXPECT_EQ(1.0, layer->opacity()); |
| 327 EXPECT_EQ(0.0, layer->layer_brightness()); |
| 328 EXPECT_EQ(0.0, layer->layer_saturation()); |
| 329 EXPECT_EQ(gfx::Transform(), layer->transform()); |
| 330 } |
| 331 } |
| 332 |
| 333 void PressPowerButton() { |
| 334 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); |
| 335 animator_helper_->Ping(); |
| 336 } |
| 337 |
| 338 void ReleasePowerButton() { |
| 339 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); |
| 340 animator_helper_->Ping(); |
| 341 } |
| 342 |
| 343 void PressLockButton() { |
| 344 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); |
| 345 } |
| 346 |
| 347 void ReleaseLockButton() { |
| 348 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); |
| 349 } |
| 350 |
| 351 void SystemLocks() { |
| 352 state_controller_->OnLockStateChanged(true); |
| 353 shell_delegate_->LockScreen(); |
| 354 animator_helper_->Ping(); |
| 355 } |
| 356 |
| 357 void SuccessfulAuthentication(bool* call_flag) { |
| 358 base::Closure closure = base::Bind(&CheckCalledCallback, call_flag); |
| 359 state_controller_->OnLockScreenHide(closure); |
| 360 animator_helper_->Ping(); |
| 361 } |
| 362 |
| 363 void SystemUnlocks() { |
| 364 state_controller_->OnLockStateChanged(false); |
| 365 shell_delegate_->UnlockScreen(); |
| 366 animator_helper_->Ping(); |
| 367 } |
| 368 |
| 369 void Initialize(bool legacy_button, user::LoginStatus status) { |
| 370 controller_->set_has_legacy_power_button_for_test(legacy_button); |
| 371 state_controller_->OnLoginStateChanged(status); |
| 372 SetUserLoggedIn(status != user::LOGGED_IN_NONE); |
| 373 if (status == user::LOGGED_IN_GUEST) |
| 374 SetCanLockScreen(false); |
| 375 state_controller_->OnLockStateChanged(false); |
| 376 } |
| 377 |
99 PowerButtonController* controller_; // not owned | 378 PowerButtonController* controller_; // not owned |
100 SessionStateControllerImpl2* state_controller_; // not owned | 379 SessionStateControllerImpl2* state_controller_; // not owned |
101 TestSessionStateControllerDelegate* delegate_; // not owned | 380 TestSessionStateControllerDelegate* delegate_; // not owned |
102 TestShellDelegate* shell_delegate_; // not owned | 381 TestShellDelegate* shell_delegate_; // not owned |
103 | 382 |
104 scoped_ptr<SessionStateControllerImpl2::TestApi> test_api_; | 383 scoped_ptr<SessionStateControllerImpl2::TestApi> test_api_; |
105 scoped_ptr<internal::SessionStateAnimator::TestApi> animator_api_; | 384 scoped_ptr<SessionStateAnimator::TestApi> animator_api_; |
| 385 scoped_ptr<ui::test::AnimationContainerTestHelper> animator_helper_; |
106 | 386 |
107 private: | 387 private: |
108 DISALLOW_COPY_AND_ASSIGN(SessionStateControllerImpl2Test); | 388 DISALLOW_COPY_AND_ASSIGN(SessionStateControllerImpl2Test); |
109 }; | 389 }; |
110 | 390 |
111 // Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't | 391 // Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't |
112 // correctly report power button releases. We should lock immediately the first | 392 // correctly report power button releases. We should lock immediately the first |
113 // time the button is pressed and shut down when it's pressed from the locked | 393 // time the button is pressed and shut down when it's pressed from the locked |
114 // state. | 394 // state. |
115 TEST_F(SessionStateControllerImpl2Test, LegacyLockAndShutDown) { | 395 TEST_F(SessionStateControllerImpl2Test, LegacyLockAndShutDown) { |
116 controller_->set_has_legacy_power_button_for_test(true); | 396 Initialize(true, user::LOGGED_IN_USER); |
117 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 397 |
118 state_controller_->OnLockStateChanged(false); | 398 ExpectUnlockedState(); |
119 | 399 |
120 // We should request that the screen be locked immediately after seeing the | 400 // We should request that the screen be locked immediately after seeing the |
121 // power button get pressed. | 401 // power button get pressed. |
122 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 402 PressPowerButton(); |
123 EXPECT_TRUE( | |
124 animator_api_->ContainersAreAnimated( | |
125 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | |
126 internal::SessionStateAnimator::LAUNCHER, | |
127 internal::SessionStateAnimator::ANIMATION_LIFT)); | |
128 | 403 |
129 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 404 ExpectLockPartOneAnimationStarted(); |
| 405 |
| 406 EXPECT_FALSE(test_api_->is_lock_undoable()); |
| 407 |
| 408 Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| 409 |
| 410 ExpectLockPartOneAnimationFinished(); |
130 EXPECT_EQ(1, delegate_->num_lock_requests()); | 411 EXPECT_EQ(1, delegate_->num_lock_requests()); |
131 | 412 |
132 // Notify that we locked successfully. | 413 // Notify that we locked successfully. |
133 state_controller_->OnStartingLock(); | 414 state_controller_->OnStartingLock(); |
| 415 // We had that animation already. |
| 416 EXPECT_FALSE(animator_helper_->IsAnimating()); |
134 | 417 |
135 EXPECT_TRUE( | 418 SystemLocks(); |
136 animator_api_->ContainersAreAnimated( | |
137 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | |
138 internal::SessionStateAnimator::LAUNCHER, | |
139 internal::SessionStateAnimator::ANIMATION_LIFT)); | |
140 EXPECT_TRUE( | |
141 animator_api_->ContainersAreAnimated( | |
142 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | |
143 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); | |
144 | 419 |
145 | 420 ExpectLockPartTwoAnimationStarted(); |
146 // Notify that the lock window is visible. We should make it fade in. | 421 Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
147 state_controller_->OnLockStateChanged(true); | 422 ExpectLockPartTwoAnimationFinished(); |
148 shell_delegate_->LockScreen(); | |
149 | |
150 EXPECT_TRUE( | |
151 animator_api_->ContainersAreAnimated( | |
152 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | |
153 internal::SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN)); | |
154 | 423 |
155 // We shouldn't progress towards the shutdown state, however. | 424 // We shouldn't progress towards the shutdown state, however. |
156 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); | 425 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
157 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 426 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
158 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 427 |
| 428 ReleasePowerButton(); |
159 | 429 |
160 // Hold the button again and check that we start shutting down. | 430 // Hold the button again and check that we start shutting down. |
161 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 431 PressPowerButton(); |
| 432 |
| 433 ExpectShutdownAnimationStarted(); |
| 434 |
162 EXPECT_EQ(0, NumShutdownRequests()); | 435 EXPECT_EQ(0, NumShutdownRequests()); |
163 | |
164 EXPECT_TRUE( | |
165 animator_api_->RootWindowIsAnimated( | |
166 internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); | |
167 // Make sure a mouse move event won't show the cursor. | 436 // Make sure a mouse move event won't show the cursor. |
168 GenerateMouseMoveEvent(); | 437 GenerateMouseMoveEvent(); |
169 EXPECT_FALSE(cursor_visible()); | 438 EXPECT_FALSE(cursor_visible()); |
| 439 |
170 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 440 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
171 test_api_->trigger_real_shutdown_timeout(); | 441 test_api_->trigger_real_shutdown_timeout(); |
172 EXPECT_EQ(1, NumShutdownRequests()); | 442 EXPECT_EQ(1, NumShutdownRequests()); |
173 } | 443 } |
174 | 444 |
175 // Test that we start shutting down immediately if the power button is pressed | 445 // Test that we start shutting down immediately if the power button is pressed |
176 // while we're not logged in on an unofficial system. | 446 // while we're not logged in on an unofficial system. |
177 TEST_F(SessionStateControllerImpl2Test, LegacyNotLoggedIn) { | 447 TEST_F(SessionStateControllerImpl2Test, LegacyNotLoggedIn) { |
178 controller_->set_has_legacy_power_button_for_test(true); | 448 Initialize(true, user::LOGGED_IN_NONE); |
179 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | 449 |
180 state_controller_->OnLockStateChanged(false); | 450 PressPowerButton(); |
181 SetUserLoggedIn(false); | 451 ExpectShutdownAnimationStarted(); |
182 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 452 |
183 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 453 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
184 } | 454 } |
185 | 455 |
186 // Test that we start shutting down immediately if the power button is pressed | 456 // Test that we start shutting down immediately if the power button is pressed |
187 // while we're logged in as a guest on an unofficial system. | 457 // while we're logged in as a guest on an unofficial system. |
188 TEST_F(SessionStateControllerImpl2Test, LegacyGuest) { | 458 TEST_F(SessionStateControllerImpl2Test, LegacyGuest) { |
189 controller_->set_has_legacy_power_button_for_test(true); | 459 Initialize(true, user::LOGGED_IN_GUEST); |
190 state_controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST); | 460 |
191 state_controller_->OnLockStateChanged(false); | 461 PressPowerButton(); |
192 SetCanLockScreen(false); | 462 ExpectShutdownAnimationStarted(); |
193 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 463 |
194 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 464 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
195 } | 465 } |
196 | 466 |
197 // When we hold the power button while the user isn't logged in, we should shut | 467 // When we hold the power button while the user isn't logged in, we should shut |
198 // down the machine directly. | 468 // down the machine directly. |
199 TEST_F(SessionStateControllerImpl2Test, ShutdownWhenNotLoggedIn) { | 469 TEST_F(SessionStateControllerImpl2Test, ShutdownWhenNotLoggedIn) { |
200 controller_->set_has_legacy_power_button_for_test(false); | 470 Initialize(false, user::LOGGED_IN_NONE); |
201 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | |
202 state_controller_->OnLockStateChanged(false); | |
203 SetUserLoggedIn(false); | |
204 | 471 |
205 // Press the power button and check that we start the shutdown timer. | 472 // Press the power button and check that we start the shutdown timer. |
206 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 473 PressPowerButton(); |
207 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 474 EXPECT_FALSE(test_api_->is_animating_lock()); |
208 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 475 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
209 EXPECT_TRUE( | 476 ExpectShutdownAnimationStarted(); |
210 animator_api_->RootWindowIsAnimated( | 477 |
211 internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); | 478 ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN, 0.5); |
212 | 479 |
213 // Release the power button before the shutdown timer fires. | 480 // Release the power button before the shutdown timer fires. |
214 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 481 ReleasePowerButton(); |
| 482 |
215 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 483 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
216 EXPECT_TRUE( | 484 ExpectShutdownAnimationUndo(); |
217 animator_api_->RootWindowIsAnimated( | 485 |
218 internal::SessionStateAnimator::ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS)); | 486 ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_REVERT, 0.5); |
219 | 487 |
220 // Press the button again and make the shutdown timeout fire this time. | 488 // Press the button again and make the shutdown timeout fire this time. |
221 // Check that we start the timer for actually requesting the shutdown. | 489 // Check that we start the timer for actually requesting the shutdown. |
222 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 490 PressPowerButton(); |
| 491 |
223 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 492 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
| 493 |
| 494 Forward(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| 495 ExpectShutdownAnimationFinished(); |
224 test_api_->trigger_shutdown_timeout(); | 496 test_api_->trigger_shutdown_timeout(); |
| 497 |
225 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 498 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
226 EXPECT_EQ(0, NumShutdownRequests()); | 499 EXPECT_EQ(0, NumShutdownRequests()); |
227 EXPECT_TRUE( | |
228 animator_api_->RootWindowIsAnimated( | |
229 internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); | |
230 | 500 |
231 // When the timout fires, we should request a shutdown. | 501 // When the timout fires, we should request a shutdown. |
232 test_api_->trigger_real_shutdown_timeout(); | 502 test_api_->trigger_real_shutdown_timeout(); |
| 503 |
233 EXPECT_EQ(1, NumShutdownRequests()); | 504 EXPECT_EQ(1, NumShutdownRequests()); |
234 } | 505 } |
235 | 506 |
236 // Test that we lock the screen and deal with unlocking correctly. | 507 // Test that we lock the screen and deal with unlocking correctly. |
237 TEST_F(SessionStateControllerImpl2Test, LockAndUnlock) { | 508 TEST_F(SessionStateControllerImpl2Test, LockAndUnlock) { |
238 controller_->set_has_legacy_power_button_for_test(false); | 509 Initialize(false, user::LOGGED_IN_USER); |
239 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 510 |
240 state_controller_->OnLockStateChanged(false); | 511 ExpectUnlockedState(); |
241 | |
242 // We should initially be showing the screen locker containers, since they | |
243 // also contain login-related windows that we want to show during the | |
244 // logging-in animation. | |
245 EXPECT_TRUE( | |
246 animator_api_->ContainersAreAnimated( | |
247 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | |
248 internal::SessionStateAnimator::ANIMATION_RESTORE)); | |
249 | 512 |
250 // Press the power button and check that the lock timer is started and that we | 513 // Press the power button and check that the lock timer is started and that we |
251 // start lifting the non-screen-locker containers. | 514 // start lifting the non-screen-locker containers. |
252 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 515 PressPowerButton(); |
253 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 516 |
254 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 517 ExpectLockPartOneAnimationStarted(); |
255 EXPECT_TRUE( | 518 EXPECT_TRUE(test_api_->is_lock_undoable()); |
256 animator_api_->ContainersAreAnimated( | |
257 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | |
258 internal::SessionStateAnimator::LAUNCHER, | |
259 internal::SessionStateAnimator::ANIMATION_LIFT)); | |
260 | |
261 // Release the button before the lock timer fires. | |
262 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | |
263 EXPECT_FALSE(test_api_->lock_timer_is_running()); | |
264 EXPECT_TRUE( | |
265 animator_api_->ContainersAreAnimated( | |
266 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | |
267 internal::SessionStateAnimator::LAUNCHER, | |
268 internal::SessionStateAnimator::ANIMATION_DROP)); | |
269 | |
270 // Press the button and fire the lock timer. We should request that the | |
271 // screen be locked, but we should still be in the lift animation. | |
272 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | |
273 EXPECT_TRUE(test_api_->lock_timer_is_running()); | |
274 EXPECT_EQ(0, delegate_->num_lock_requests()); | 519 EXPECT_EQ(0, delegate_->num_lock_requests()); |
275 test_api_->trigger_lock_timeout(); | 520 |
| 521 Forward(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); |
| 522 ExpectLockPartOneAnimationFinished(); |
| 523 |
276 EXPECT_EQ(1, delegate_->num_lock_requests()); | 524 EXPECT_EQ(1, delegate_->num_lock_requests()); |
277 EXPECT_TRUE( | |
278 animator_api_->ContainersAreAnimated( | |
279 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | |
280 internal::SessionStateAnimator::LAUNCHER, | |
281 internal::SessionStateAnimator::ANIMATION_LIFT)); | |
282 | 525 |
283 // Notify that we locked successfully. | 526 // Notify that we locked successfully. |
284 state_controller_->OnStartingLock(); | 527 state_controller_->OnStartingLock(); |
285 EXPECT_TRUE( | 528 // We had that animation already. |
286 animator_api_->ContainersAreAnimated( | 529 EXPECT_FALSE(animator_helper_->IsAnimating()); |
287 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | 530 |
288 internal::SessionStateAnimator::LAUNCHER, | 531 SystemLocks(); |
289 internal::SessionStateAnimator::ANIMATION_LIFT)); | 532 |
290 EXPECT_TRUE( | 533 ExpectLockPartTwoAnimationStarted(); |
291 animator_api_->ContainersAreAnimated( | 534 Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
292 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | 535 ExpectLockPartTwoAnimationFinished(); |
293 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); | |
294 | |
295 // Notify that the lock window is visible. We should make it raise in. | |
296 state_controller_->OnLockStateChanged(true); | |
297 shell_delegate_->LockScreen(); | |
298 EXPECT_TRUE( | |
299 animator_api_->ContainersAreAnimated( | |
300 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | |
301 internal::SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN)); | |
302 | 536 |
303 // When we release the power button, the lock-to-shutdown timer should be | 537 // When we release the power button, the lock-to-shutdown timer should be |
304 // stopped. | 538 // stopped. |
| 539 ExpectLockedState(); |
305 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); | 540 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); |
306 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 541 ReleasePowerButton(); |
| 542 ExpectLockedState(); |
307 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); | 543 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
308 | 544 |
309 // Notify that the screen has been unlocked. We should show the | 545 // Notify that the screen has been unlocked. We should show the |
310 // non-screen-locker windows. | 546 // non-screen-locker windows. |
311 state_controller_->OnLockStateChanged(false); | |
312 shell_delegate_->UnlockScreen(); | |
313 bool called = false; | 547 bool called = false; |
314 base::Closure closure = base::Bind(&CheckCalledCallback, &called); | 548 SuccessfulAuthentication(&called); |
315 state_controller_->OnLockScreenHide(closure); | 549 |
316 EXPECT_TRUE( | 550 ExpectUnlockPartOneAnimationStarted(); |
317 animator_api_->ContainersAreAnimated( | 551 EXPECT_FALSE(called); |
318 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | 552 Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
319 internal::SessionStateAnimator::ANIMATION_LIFT)); | 553 ExpectUnlockPartOneAnimationFinished(); |
| 554 |
320 EXPECT_TRUE(called); | 555 EXPECT_TRUE(called); |
321 EXPECT_TRUE( | 556 |
322 animator_api_->ContainersAreAnimated( | 557 SystemUnlocks(); |
323 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | 558 |
324 internal::SessionStateAnimator::LAUNCHER, | 559 ExpectUnlockPartTwoAnimationStarted(); |
325 internal::SessionStateAnimator::ANIMATION_DROP)); | 560 Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| 561 ExpectUnlockPartTwoAnimationFinished(); |
| 562 |
| 563 ExpectUnlockedState(); |
| 564 } |
| 565 |
| 566 // Test that we deal with cancelling lock correctly. |
| 567 TEST_F(SessionStateControllerImpl2Test, LockAndCancel) { |
| 568 Initialize(false, user::LOGGED_IN_USER); |
| 569 |
| 570 ExpectUnlockedState(); |
| 571 |
| 572 // Press the power button and check that the lock timer is started and that we |
| 573 // start lifting the non-screen-locker containers. |
| 574 PressPowerButton(); |
| 575 |
| 576 ExpectLockPartOneAnimationStarted(); |
| 577 EXPECT_TRUE(test_api_->is_lock_undoable()); |
| 578 |
| 579 // forward only half way through |
| 580 ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5); |
| 581 |
| 582 // Release the button before the lock timer fires. |
| 583 ReleasePowerButton(); |
| 584 ExpectLockPartOneAnimationUndo(); |
| 585 |
| 586 Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| 587 |
| 588 ExpectUnlockedState(); |
| 589 EXPECT_EQ(0, delegate_->num_lock_requests()); |
| 590 } |
| 591 |
| 592 // Test that we deal with cancelling lock correctly. |
| 593 TEST_F(SessionStateControllerImpl2Test, LockAndCancelAndLockAgain) { |
| 594 Initialize(false, user::LOGGED_IN_USER); |
| 595 |
| 596 ExpectUnlockedState(); |
| 597 |
| 598 // Press the power button and check that the lock timer is started and that we |
| 599 // start lifting the non-screen-locker containers. |
| 600 PressPowerButton(); |
| 601 |
| 602 ExpectLockPartOneAnimationStarted(); |
| 603 EXPECT_TRUE(test_api_->is_lock_undoable()); |
| 604 |
| 605 // forward only half way through |
| 606 ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5); |
| 607 |
| 608 // Release the button before the lock timer fires. |
| 609 ReleasePowerButton(); |
| 610 ExpectLockPartOneAnimationUndo(); |
| 611 |
| 612 ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, 0.5); |
| 613 |
| 614 PressPowerButton(); |
| 615 ExpectLockPartOneAnimationStarted(); |
| 616 EXPECT_TRUE(test_api_->is_lock_undoable()); |
| 617 |
| 618 ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.6); |
| 619 |
| 620 EXPECT_EQ(0, delegate_->num_lock_requests()); |
| 621 ExpectLockPartOneAnimationStarted(); |
| 622 |
| 623 ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.6); |
| 624 ExpectLockPartOneAnimationFinished(); |
| 625 EXPECT_EQ(1, delegate_->num_lock_requests()); |
326 } | 626 } |
327 | 627 |
328 // Hold the power button down from the unlocked state to eventual shutdown. | 628 // Hold the power button down from the unlocked state to eventual shutdown. |
329 TEST_F(SessionStateControllerImpl2Test, LockToShutdown) { | 629 TEST_F(SessionStateControllerImpl2Test, LockToShutdown) { |
330 controller_->set_has_legacy_power_button_for_test(false); | 630 Initialize(false, user::LOGGED_IN_USER); |
331 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | |
332 state_controller_->OnLockStateChanged(false); | |
333 | 631 |
334 // Hold the power button and lock the screen. | 632 // Hold the power button and lock the screen. |
335 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 633 PressPowerButton(); |
336 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 634 EXPECT_TRUE(test_api_->is_animating_lock()); |
337 test_api_->trigger_lock_timeout(); | 635 |
338 state_controller_->OnStartingLock(); | 636 Forward(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); |
339 state_controller_->OnLockStateChanged(true); | 637 SystemLocks(); |
340 shell_delegate_->LockScreen(); | 638 Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
341 | 639 |
342 // When the lock-to-shutdown timeout fires, we should start the shutdown | 640 // When the lock-to-shutdown timeout fires, we should start the shutdown |
343 // timer. | 641 // timer. |
344 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); | 642 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running()); |
| 643 |
345 test_api_->trigger_lock_to_shutdown_timeout(); | 644 test_api_->trigger_lock_to_shutdown_timeout(); |
| 645 |
| 646 ExpectShutdownAnimationStarted(); |
346 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 647 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
347 EXPECT_TRUE( | |
348 animator_api_->ContainersAreAnimated( | |
349 internal::SessionStateAnimator::LOCK_SCREEN_CONTAINERS, | |
350 internal::SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN)); | |
351 | 648 |
352 // Fire the shutdown timeout and check that we request shutdown. | 649 // Fire the shutdown timeout and check that we request shutdown. |
| 650 Forward(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| 651 ExpectShutdownAnimationFinished(); |
353 test_api_->trigger_shutdown_timeout(); | 652 test_api_->trigger_shutdown_timeout(); |
| 653 |
354 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 654 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
355 EXPECT_EQ(0, NumShutdownRequests()); | 655 EXPECT_EQ(0, NumShutdownRequests()); |
356 test_api_->trigger_real_shutdown_timeout(); | 656 test_api_->trigger_real_shutdown_timeout(); |
357 EXPECT_EQ(1, NumShutdownRequests()); | 657 EXPECT_EQ(1, NumShutdownRequests()); |
358 } | 658 } |
359 | 659 |
360 | |
361 // Hold the power button down from the unlocked state to eventual shutdown, | 660 // Hold the power button down from the unlocked state to eventual shutdown, |
362 // then release the button while system does locking. | 661 // then release the button while system does locking. |
363 TEST_F(SessionStateControllerImpl2Test, CancelLockToShutdown) { | 662 TEST_F(SessionStateControllerImpl2Test, CancelLockToShutdown) { |
364 controller_->set_has_legacy_power_button_for_test(false); | 663 Initialize(false, user::LOGGED_IN_USER); |
365 | 664 |
366 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 665 PressPowerButton(); |
367 state_controller_->OnLockStateChanged(false); | |
368 | 666 |
369 // Hold the power button and lock the screen. | 667 // Hold the power button and lock the screen. |
370 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 668 EXPECT_TRUE(test_api_->is_animating_lock()); |
371 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 669 |
372 test_api_->trigger_lock_timeout(); | 670 Forward(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); |
373 state_controller_->OnStartingLock(); | 671 SystemLocks(); |
| 672 ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, 0.5); |
374 | 673 |
375 // Power button is released while system attempts to lock. | 674 // Power button is released while system attempts to lock. |
376 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 675 ReleasePowerButton(); |
377 state_controller_->OnLockStateChanged(true); | 676 |
378 shell_delegate_->LockScreen(); | 677 Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
379 | 678 |
380 EXPECT_FALSE(state_controller_->ShutdownRequested()); | 679 EXPECT_FALSE(state_controller_->ShutdownRequested()); |
381 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); | 680 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
382 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 681 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
383 } | 682 } |
384 | 683 |
385 // Test that we handle the case where lock requests are ignored. | 684 // Test that we handle the case where lock requests are ignored. |
386 TEST_F(SessionStateControllerImpl2Test, Lock) { | 685 TEST_F(SessionStateControllerImpl2Test, Lock) { |
387 // We require animations to have a duration for this test. | 686 // We require animations to have a duration for this test. |
388 ui::LayerAnimator::set_disable_animations_for_test(false); | 687 ui::LayerAnimator::set_disable_animations_for_test(false); |
389 | 688 |
390 controller_->set_has_legacy_power_button_for_test(false); | 689 Initialize(false, user::LOGGED_IN_USER); |
391 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | |
392 state_controller_->OnLockStateChanged(false); | |
393 | 690 |
394 // Hold the power button and lock the screen. | 691 // Hold the power button and lock the screen. |
395 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 692 PressPowerButton(); |
396 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 693 ExpectLockPartOneAnimationStarted(); |
397 EXPECT_TRUE( | 694 |
398 animator_api_->ContainersAreAnimated( | 695 Forward(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); |
399 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | 696 |
400 internal::SessionStateAnimator::LAUNCHER, | |
401 internal::SessionStateAnimator::ANIMATION_LIFT)); | |
402 test_api_->trigger_lock_timeout(); | |
403 EXPECT_EQ(1, delegate_->num_lock_requests()); | 697 EXPECT_EQ(1, delegate_->num_lock_requests()); |
404 EXPECT_TRUE(test_api_->lock_fail_timer_is_running()); | 698 EXPECT_TRUE(test_api_->lock_fail_timer_is_running()); |
405 | |
406 // We shouldn't start the lock-to-shutdown timer until the screen has actually | 699 // We shouldn't start the lock-to-shutdown timer until the screen has actually |
407 // been locked. | 700 // been locked and this was animated. |
408 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); | 701 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); |
409 | 702 |
410 // Act as if the request timed out. We should restore the windows. | 703 // Act as if the request timed out. We should restore the windows. |
411 test_api_->trigger_lock_fail_timeout(); | 704 test_api_->trigger_lock_fail_timeout(); |
412 EXPECT_TRUE( | 705 |
413 animator_api_->ContainersAreAnimated( | 706 ExpectUnlockPartTwoAnimationStarted(); |
414 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | 707 Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
415 internal::SessionStateAnimator::LAUNCHER, | 708 ExpectUnlockPartTwoAnimationFinished(); |
416 internal::SessionStateAnimator::ANIMATION_DROP)); | 709 ExpectUnlockedState(); |
| 710 } |
| 711 |
| 712 // Test the basic operation of the lock button (not logged in). |
| 713 TEST_F(SessionStateControllerImpl2Test, LockButtonBasicNotLoggedIn) { |
| 714 // The lock button shouldn't do anything if we aren't logged in. |
| 715 Initialize(false, user::LOGGED_IN_NONE); |
| 716 |
| 717 PressLockButton(); |
| 718 EXPECT_FALSE(test_api_->is_animating_lock()); |
| 719 ReleaseLockButton(); |
| 720 EXPECT_EQ(0, delegate_->num_lock_requests()); |
| 721 } |
| 722 |
| 723 // Test the basic operation of the lock button (guest). |
| 724 TEST_F(SessionStateControllerImpl2Test, LockButtonBasicGuest) { |
| 725 // The lock button shouldn't do anything when we're logged in as a guest. |
| 726 Initialize(false, user::LOGGED_IN_GUEST); |
| 727 |
| 728 PressLockButton(); |
| 729 EXPECT_FALSE(test_api_->is_animating_lock()); |
| 730 ReleaseLockButton(); |
| 731 EXPECT_EQ(0, delegate_->num_lock_requests()); |
417 } | 732 } |
418 | 733 |
419 // Test the basic operation of the lock button. | 734 // Test the basic operation of the lock button. |
420 TEST_F(SessionStateControllerImpl2Test, LockButtonBasic) { | 735 TEST_F(SessionStateControllerImpl2Test, LockButtonBasic) { |
421 controller_->set_has_legacy_power_button_for_test(false); | |
422 // The lock button shouldn't do anything if we aren't logged in. | |
423 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | |
424 state_controller_->OnLockStateChanged(false); | |
425 SetUserLoggedIn(false); | |
426 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | |
427 EXPECT_FALSE(test_api_->lock_timer_is_running()); | |
428 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | |
429 EXPECT_EQ(0, delegate_->num_lock_requests()); | |
430 | |
431 // Ditto for when we're logged in as a guest. | |
432 state_controller_->OnLoginStateChanged(user::LOGGED_IN_GUEST); | |
433 SetUserLoggedIn(true); | |
434 SetCanLockScreen(false); | |
435 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | |
436 EXPECT_FALSE(test_api_->lock_timer_is_running()); | |
437 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | |
438 EXPECT_EQ(0, delegate_->num_lock_requests()); | |
439 | |
440 // If we're logged in as a regular user, we should start the lock timer and | 736 // If we're logged in as a regular user, we should start the lock timer and |
441 // the pre-lock animation. | 737 // the pre-lock animation. |
442 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 738 Initialize(false, user::LOGGED_IN_USER); |
443 SetCanLockScreen(true); | 739 |
444 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 740 PressLockButton(); |
445 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 741 ExpectLockPartOneAnimationStarted(); |
446 EXPECT_TRUE( | 742 ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5); |
447 animator_api_->ContainersAreAnimated( | |
448 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | |
449 internal::SessionStateAnimator::LAUNCHER, | |
450 internal::SessionStateAnimator::ANIMATION_LIFT)); | |
451 | 743 |
452 // If the button is released immediately, we shouldn't lock the screen. | 744 // If the button is released immediately, we shouldn't lock the screen. |
453 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 745 ReleaseLockButton(); |
454 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 746 ExpectLockPartOneAnimationUndo(); |
455 EXPECT_TRUE( | 747 Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
456 animator_api_->ContainersAreAnimated( | 748 |
457 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | 749 ExpectUnlockedState(); |
458 internal::SessionStateAnimator::LAUNCHER, | |
459 internal::SessionStateAnimator::ANIMATION_DROP)); | |
460 EXPECT_EQ(0, delegate_->num_lock_requests()); | 750 EXPECT_EQ(0, delegate_->num_lock_requests()); |
461 | 751 |
462 // Press the button again and let the lock timeout fire. We should request | 752 // Press the button again and let the lock timeout fire. We should request |
463 // that the screen be locked. | 753 // that the screen be locked. |
464 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 754 PressLockButton(); |
465 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 755 ExpectLockPartOneAnimationStarted(); |
466 test_api_->trigger_lock_timeout(); | 756 Forward(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); |
467 EXPECT_EQ(1, delegate_->num_lock_requests()); | 757 EXPECT_EQ(1, delegate_->num_lock_requests()); |
468 | 758 |
469 // Pressing the lock button while we have a pending lock request shouldn't do | 759 // Pressing the lock button while we have a pending lock request shouldn't do |
470 // anything. | 760 // anything. |
471 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 761 ReleaseLockButton(); |
472 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 762 PressLockButton(); |
473 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 763 ExpectLockPartOneAnimationFinished(); |
474 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 764 ReleaseLockButton(); |
475 | 765 |
476 // Pressing the button also shouldn't do anything after the screen is locked. | 766 // Pressing the button also shouldn't do anything after the screen is locked. |
477 state_controller_->OnStartingLock(); | 767 SystemLocks(); |
478 state_controller_->OnLockStateChanged(true); | 768 ExpectLockPartTwoAnimationStarted(); |
479 shell_delegate_->LockScreen(); | 769 |
480 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 770 PressLockButton(); |
481 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 771 ReleaseLockButton(); |
482 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 772 ExpectLockPartTwoAnimationStarted(); |
| 773 |
| 774 Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| 775 ExpectLockPartTwoAnimationFinished(); |
| 776 |
| 777 PressLockButton(); |
| 778 ReleaseLockButton(); |
| 779 ExpectLockPartTwoAnimationFinished(); |
483 } | 780 } |
484 | 781 |
485 // Test that the power button takes priority over the lock button. | 782 // Test that the power button takes priority over the lock button. |
486 TEST_F(SessionStateControllerImpl2Test, PowerButtonPreemptsLockButton) { | 783 TEST_F(SessionStateControllerImpl2Test, PowerButtonPreemptsLockButton) { |
487 controller_->set_has_legacy_power_button_for_test(false); | 784 Initialize(false, user::LOGGED_IN_USER); |
488 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | |
489 state_controller_->OnLockStateChanged(false); | |
490 | 785 |
491 // While the lock button is down, hold the power button. | 786 // While the lock button is down, hold the power button. |
492 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 787 PressLockButton(); |
493 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 788 ExpectLockPartOneAnimationStarted(); |
494 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 789 PressPowerButton(); |
495 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 790 ExpectLockPartOneAnimationStarted(); |
| 791 |
| 792 ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5); |
496 | 793 |
497 // The lock timer shouldn't be stopped when the lock button is released. | 794 // The lock timer shouldn't be stopped when the lock button is released. |
498 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 795 ReleaseLockButton(); |
499 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 796 ExpectLockPartOneAnimationStarted(); |
500 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 797 ReleasePowerButton(); |
501 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 798 ExpectLockPartOneAnimationUndo(); |
| 799 |
| 800 Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| 801 ExpectUnlockedState(); |
502 | 802 |
503 // Now press the power button first and then the lock button. | 803 // Now press the power button first and then the lock button. |
504 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 804 PressPowerButton(); |
505 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 805 ExpectLockPartOneAnimationStarted(); |
506 controller_->OnLockButtonEvent(true, base::TimeTicks::Now()); | 806 PressLockButton(); |
507 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 807 ExpectLockPartOneAnimationStarted(); |
| 808 |
| 809 ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5); |
508 | 810 |
509 // Releasing the power button should stop the lock timer. | 811 // Releasing the power button should stop the lock timer. |
510 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 812 ReleasePowerButton(); |
511 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 813 ExpectLockPartOneAnimationUndo(); |
512 controller_->OnLockButtonEvent(false, base::TimeTicks::Now()); | 814 ReleaseLockButton(); |
513 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 815 ExpectLockPartOneAnimationUndo(); |
514 } | 816 } |
515 | 817 |
516 // When the screen is locked without going through the usual power-button | 818 // When the screen is locked without going through the usual power-button |
517 // slow-close path (e.g. via the wrench menu), test that we still show the | 819 // slow-close path (e.g. via the wrench menu), test that we still show the |
518 // fast-close animation. | 820 // fast-close animation. |
519 TEST_F(SessionStateControllerImpl2Test, LockWithoutButton) { | 821 TEST_F(SessionStateControllerImpl2Test, LockWithoutButton) { |
520 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 822 Initialize(false, user::LOGGED_IN_USER); |
521 state_controller_->OnStartingLock(); | 823 state_controller_->OnStartingLock(); |
522 EXPECT_TRUE( | 824 |
523 animator_api_->ContainersAreAnimated( | 825 ExpectLockPartOneAnimationStarted(); |
524 internal::SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS | | 826 EXPECT_FALSE(test_api_->is_lock_undoable()); |
525 internal::SessionStateAnimator::LAUNCHER, | |
526 internal::SessionStateAnimator::ANIMATION_LIFT)); | |
527 } | 827 } |
528 | 828 |
529 // When we hear that the process is exiting but we haven't had a chance to | 829 // When we hear that the process is exiting but we haven't had a chance to |
530 // display an animation, we should just blank the screen. | 830 // display an animation, we should just blank the screen. |
531 TEST_F(SessionStateControllerImpl2Test, ShutdownWithoutButton) { | 831 TEST_F(SessionStateControllerImpl2Test, ShutdownWithoutButton) { |
532 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 832 Initialize(false, user::LOGGED_IN_USER); |
533 state_controller_->OnAppTerminating(); | 833 state_controller_->OnAppTerminating(); |
| 834 |
534 EXPECT_TRUE( | 835 EXPECT_TRUE( |
535 animator_api_->ContainersAreAnimated( | 836 animator_api_->ContainersAreAnimated( |
536 internal::SessionStateAnimator::kAllContainersMask, | 837 SessionStateAnimator::kAllContainersMask, |
537 internal::SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); | 838 SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); |
538 GenerateMouseMoveEvent(); | 839 GenerateMouseMoveEvent(); |
539 EXPECT_FALSE(cursor_visible()); | 840 EXPECT_FALSE(cursor_visible()); |
540 } | 841 } |
541 | 842 |
542 // Test that we display the fast-close animation and shut down when we get an | 843 // Test that we display the fast-close animation and shut down when we get an |
543 // outside request to shut down (e.g. from the login or lock screen). | 844 // outside request to shut down (e.g. from the login or lock screen). |
544 TEST_F(SessionStateControllerImpl2Test, RequestShutdownFromLoginScreen) { | 845 TEST_F(SessionStateControllerImpl2Test, RequestShutdownFromLoginScreen) { |
545 state_controller_->OnLoginStateChanged(user::LOGGED_IN_NONE); | 846 Initialize(false, user::LOGGED_IN_NONE); |
546 state_controller_->OnLockStateChanged(false); | 847 |
547 SetUserLoggedIn(false); | |
548 state_controller_->RequestShutdown(); | 848 state_controller_->RequestShutdown(); |
549 EXPECT_TRUE( | 849 |
550 animator_api_->RootWindowIsAnimated( | 850 ExpectShutdownAnimationStarted(); |
551 internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); | 851 Forward(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| 852 |
552 GenerateMouseMoveEvent(); | 853 GenerateMouseMoveEvent(); |
553 EXPECT_FALSE(cursor_visible()); | 854 EXPECT_FALSE(cursor_visible()); |
554 | 855 |
555 EXPECT_EQ(0, NumShutdownRequests()); | 856 EXPECT_EQ(0, NumShutdownRequests()); |
556 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 857 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
557 test_api_->trigger_real_shutdown_timeout(); | 858 test_api_->trigger_real_shutdown_timeout(); |
558 EXPECT_EQ(1, NumShutdownRequests()); | 859 EXPECT_EQ(1, NumShutdownRequests()); |
559 } | 860 } |
560 | 861 |
561 TEST_F(SessionStateControllerImpl2Test, RequestShutdownFromLockScreen) { | 862 TEST_F(SessionStateControllerImpl2Test, RequestShutdownFromLockScreen) { |
562 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 863 Initialize(false, user::LOGGED_IN_USER); |
563 state_controller_->OnLockStateChanged(true); | 864 |
564 shell_delegate_->LockScreen(); | 865 SystemLocks(); |
| 866 Forward(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| 867 ExpectLockPartTwoAnimationFinished(); |
| 868 |
565 state_controller_->RequestShutdown(); | 869 state_controller_->RequestShutdown(); |
566 EXPECT_TRUE( | 870 |
567 animator_api_->RootWindowIsAnimated( | 871 ExpectShutdownAnimationStarted(); |
568 internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); | 872 Forward(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| 873 |
569 GenerateMouseMoveEvent(); | 874 GenerateMouseMoveEvent(); |
570 EXPECT_FALSE(cursor_visible()); | 875 EXPECT_FALSE(cursor_visible()); |
571 | 876 |
572 EXPECT_EQ(0, NumShutdownRequests()); | 877 EXPECT_EQ(0, NumShutdownRequests()); |
573 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); | 878 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); |
574 test_api_->trigger_real_shutdown_timeout(); | 879 test_api_->trigger_real_shutdown_timeout(); |
575 EXPECT_EQ(1, NumShutdownRequests()); | 880 EXPECT_EQ(1, NumShutdownRequests()); |
576 } | 881 } |
577 | 882 |
578 TEST_F(SessionStateControllerImpl2Test, | 883 TEST_F(SessionStateControllerImpl2Test, |
579 RequestAndCancelShutdownFromLockScreen) { | 884 RequestAndCancelShutdownFromLockScreen) { |
580 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 885 Initialize(false, user::LOGGED_IN_USER); |
581 state_controller_->OnLockStateChanged(true); | 886 |
582 shell_delegate_->LockScreen(); | 887 SystemLocks(); |
| 888 Forward(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); |
| 889 ExpectLockedState(); |
583 | 890 |
584 // Press the power button and check that we start the shutdown timer. | 891 // Press the power button and check that we start the shutdown timer. |
585 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 892 PressPowerButton(); |
586 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 893 EXPECT_FALSE(test_api_->is_animating_lock()); |
587 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); | 894 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); |
588 EXPECT_TRUE( | 895 |
589 animator_api_->RootWindowIsAnimated( | 896 ExpectShutdownAnimationStarted(); |
590 internal::SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS)); | 897 |
| 898 ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN, 0.5); |
591 | 899 |
592 // Release the power button before the shutdown timer fires. | 900 // Release the power button before the shutdown timer fires. |
593 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | 901 ReleasePowerButton(); |
| 902 |
594 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); | 903 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); |
595 EXPECT_TRUE( | 904 |
596 animator_api_->RootWindowIsAnimated( | 905 ExpectShutdownAnimationUndo(); |
597 internal::SessionStateAnimator::ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS)); | 906 Forward(SessionStateAnimator::ANIMATION_SPEED_REVERT); |
| 907 ExpectLockedState(); |
598 } | 908 } |
599 | 909 |
600 // Test that we ignore power button presses when the screen is turned off. | 910 // Test that we ignore power button presses when the screen is turned off. |
601 TEST_F(SessionStateControllerImpl2Test, IgnorePowerButtonIfScreenIsOff) { | 911 TEST_F(SessionStateControllerImpl2Test, IgnorePowerButtonIfScreenIsOff) { |
602 state_controller_->OnLoginStateChanged(user::LOGGED_IN_USER); | 912 Initialize(false, user::LOGGED_IN_USER); |
603 | 913 |
604 // When the screen brightness is at 0%, we shouldn't do anything in response | 914 // When the screen brightness is at 0%, we shouldn't do anything in response |
605 // to power button presses. | 915 // to power button presses. |
606 controller_->OnScreenBrightnessChanged(0.0); | 916 controller_->OnScreenBrightnessChanged(0.0); |
607 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 917 |
608 EXPECT_FALSE(test_api_->lock_timer_is_running()); | 918 PressPowerButton(); |
| 919 EXPECT_FALSE(test_api_->is_animating_lock()); |
| 920 ReleasePowerButton(); |
609 | 921 |
610 // After increasing the brightness to 10%, we should start the timer like | 922 // After increasing the brightness to 10%, we should start the timer like |
611 // usual. | 923 // usual. |
612 controller_->OnScreenBrightnessChanged(10.0); | 924 controller_->OnScreenBrightnessChanged(10.0); |
613 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | 925 |
614 EXPECT_TRUE(test_api_->lock_timer_is_running()); | 926 PressPowerButton(); |
| 927 EXPECT_TRUE(test_api_->is_animating_lock()); |
| 928 } |
| 929 |
| 930 // Test that hidden background appears and revers correctly on lock/cancel. |
| 931 TEST_F(SessionStateControllerImpl2Test, TestHiddenBackgroundLockCancel) { |
| 932 Initialize(false, user::LOGGED_IN_USER); |
| 933 HideBackground(); |
| 934 |
| 935 EXPECT_TRUE(IsBackgroundHidden()); |
| 936 ExpectUnlockedState(); |
| 937 PressPowerButton(); |
| 938 |
| 939 ExpectLockPartOneAnimationStarted(); |
| 940 EXPECT_FALSE(IsBackgroundHidden()); |
| 941 ExpectBackgroundIsShowing(); |
| 942 |
| 943 // Forward only half way through. |
| 944 ForwardPartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5); |
| 945 |
| 946 // Release the button before the lock timer fires. |
| 947 ReleasePowerButton(); |
| 948 ExpectLockPartOneAnimationUndo(); |
| 949 ExpectBackgroundIsHiding(); |
| 950 EXPECT_FALSE(IsBackgroundHidden()); |
| 951 |
| 952 Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| 953 |
| 954 ExpectUnlockedState(); |
| 955 EXPECT_TRUE(IsBackgroundHidden()); |
| 956 } |
| 957 |
| 958 // Test that hidden background appears and revers correctly on lock/unlock. |
| 959 TEST_F(SessionStateControllerImpl2Test, TestHiddenBackgroundLockUnlock) { |
| 960 Initialize(false, user::LOGGED_IN_USER); |
| 961 HideBackground(); |
| 962 |
| 963 EXPECT_TRUE(IsBackgroundHidden()); |
| 964 ExpectUnlockedState(); |
| 965 |
| 966 // Press the power button and check that the lock timer is started and that we |
| 967 // start lifting the non-screen-locker containers. |
| 968 PressPowerButton(); |
| 969 |
| 970 ExpectLockPartOneAnimationStarted(); |
| 971 EXPECT_FALSE(IsBackgroundHidden()); |
| 972 ExpectBackgroundIsShowing(); |
| 973 |
| 974 Forward(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); |
| 975 |
| 976 ExpectLockPartOneAnimationFinished(); |
| 977 |
| 978 SystemLocks(); |
| 979 |
| 980 ExpectLockPartTwoAnimationStarted(); |
| 981 Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| 982 ExpectLockPartTwoAnimationFinished(); |
| 983 |
| 984 ExpectLockedState(); |
| 985 |
| 986 SuccessfulAuthentication(NULL); |
| 987 |
| 988 ExpectUnlockPartOneAnimationStarted(); |
| 989 Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| 990 ExpectUnlockPartOneAnimationFinished(); |
| 991 |
| 992 SystemUnlocks(); |
| 993 |
| 994 ExpectUnlockPartTwoAnimationStarted(); |
| 995 ExpectBackgroundIsHiding(); |
| 996 EXPECT_FALSE(IsBackgroundHidden()); |
| 997 |
| 998 Forward(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); |
| 999 ExpectUnlockPartTwoAnimationFinished(); |
| 1000 EXPECT_TRUE(IsBackgroundHidden()); |
| 1001 |
| 1002 ExpectUnlockedState(); |
615 } | 1003 } |
616 | 1004 |
617 } // namespace test | 1005 } // namespace test |
618 } // namespace ash | 1006 } // namespace ash |
OLD | NEW |