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