Move render_view_context_menu.* and related files out of tab_contents.
[chromium-blink-merge.git] / ash / wm / lock_state_controller_unittest.cc
blob871682d3a221de3d76ae4e0d675f5794c28630d0
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/wm/lock_state_controller.h"
7 #include "ash/ash_switches.h"
8 #include "ash/session_state_delegate.h"
9 #include "ash/shell.h"
10 #include "ash/shell_window_ids.h"
11 #include "ash/test/ash_test_base.h"
12 #include "ash/test/test_shell_delegate.h"
13 #include "ash/wm/power_button_controller.h"
14 #include "ash/wm/session_state_animator.h"
15 #include "base/command_line.h"
16 #include "base/memory/scoped_ptr.h"
17 #include "base/time/time.h"
18 #include "ui/aura/env.h"
19 #include "ui/aura/test/event_generator.h"
20 #include "ui/aura/test/test_window_delegate.h"
21 #include "ui/aura/window_event_dispatcher.h"
22 #include "ui/compositor/layer_animator.h"
23 #include "ui/compositor/scoped_animation_duration_scale_mode.h"
24 #include "ui/compositor/scoped_layer_animation_settings.h"
25 #include "ui/gfx/rect.h"
26 #include "ui/gfx/size.h"
28 #if defined(OS_WIN)
29 #include "base/win/windows_version.h"
30 #endif
32 namespace ash {
34 using internal::SessionStateAnimator;
36 namespace test {
38 namespace {
40 bool cursor_visible() {
41 return ash::Shell::GetInstance()->cursor_manager()->IsCursorVisible();
44 void CheckCalledCallback(bool* flag) {
45 if (flag)
46 (*flag) = true;
49 aura::Window* GetContainer(int container ) {
50 aura::Window* root_window = Shell::GetPrimaryRootWindow();
51 return Shell::GetContainer(root_window, container);
54 bool IsBackgroundHidden() {
55 return !GetContainer(internal::kShellWindowId_DesktopBackgroundContainer)->
56 IsVisible();
59 void HideBackground() {
60 ui::ScopedLayerAnimationSettings settings(
61 GetContainer(internal::kShellWindowId_DesktopBackgroundContainer)->
62 layer()->GetAnimator());
63 settings.SetTransitionDuration(base::TimeDelta());
64 GetContainer(internal::kShellWindowId_DesktopBackgroundContainer)->Hide();
67 } // namespace
69 // Fake implementation of PowerButtonControllerDelegate that just logs requests
70 // to lock the screen and shut down the device.
71 class TestLockStateControllerDelegate : public LockStateControllerDelegate {
72 public:
73 TestLockStateControllerDelegate()
74 : num_lock_requests_(0),
75 num_shutdown_requests_(0) {}
77 int num_lock_requests() const { return num_lock_requests_; }
78 int num_shutdown_requests() const { return num_shutdown_requests_; }
80 // LockStateControllerDelegate implementation.
81 virtual void RequestLockScreen() OVERRIDE {
82 num_lock_requests_++;
84 virtual void RequestShutdown() OVERRIDE {
85 num_shutdown_requests_++;
88 private:
89 int num_lock_requests_;
90 int num_shutdown_requests_;
92 DISALLOW_COPY_AND_ASSIGN(TestLockStateControllerDelegate);
95 class LockStateControllerTest : public AshTestBase {
96 public:
97 LockStateControllerTest() : controller_(NULL), delegate_(NULL) {}
98 virtual ~LockStateControllerTest() {}
100 virtual void SetUp() OVERRIDE {
101 AshTestBase::SetUp();
103 // We would control animations in a fine way:
104 animation_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
105 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION));
106 // TODO(antrim) : restore
107 // animator_helper_ = ui::test::CreateLayerAnimatorHelperForTest();
109 // Temporary disable animations so that observer is always called, and
110 // no leaks happen during tests.
111 animation_duration_mode_.reset(new ui::ScopedAnimationDurationScaleMode(
112 ui::ScopedAnimationDurationScaleMode::ZERO_DURATION));
113 // TODO(antrim): once there is a way to mock time and run animations, make
114 // sure that animations are finished even in simple tests.
116 delegate_ = new TestLockStateControllerDelegate;
117 controller_ = Shell::GetInstance()->power_button_controller();
118 lock_state_controller_ = static_cast<LockStateController*>(
119 Shell::GetInstance()->lock_state_controller());
120 lock_state_controller_->SetDelegate(delegate_); // transfers ownership
121 test_api_.reset(new LockStateController::TestApi(lock_state_controller_));
122 animator_api_.reset(
123 new SessionStateAnimator::TestApi(lock_state_controller_->
124 animator_.get()));
125 shell_delegate_ = reinterpret_cast<TestShellDelegate*>(
126 ash::Shell::GetInstance()->delegate());
127 session_state_delegate_ = Shell::GetInstance()->session_state_delegate();
130 virtual void TearDown() {
131 // TODO(antrim) : restore
132 // animator_helper_->AdvanceUntilDone();
133 window_.reset();
134 AshTestBase::TearDown();
137 protected:
138 void GenerateMouseMoveEvent() {
139 aura::test::EventGenerator generator(
140 Shell::GetPrimaryRootWindow());
141 generator.MoveMouseTo(10, 10);
144 int NumShutdownRequests() {
145 return delegate_->num_shutdown_requests() +
146 shell_delegate_->num_exit_requests();
149 void Advance(SessionStateAnimator::AnimationSpeed speed) {
150 // TODO (antrim) : restore
151 // animator_helper_->Advance(SessionStateAnimator::GetDuration(speed));
154 void AdvancePartially(SessionStateAnimator::AnimationSpeed speed,
155 float factor) {
156 // TODO (antrim) : restore
157 // base::TimeDelta duration = SessionStateAnimator::GetDuration(speed);
158 // base::TimeDelta partial_duration =
159 // base::TimeDelta::FromInternalValue(duration.ToInternalValue() * factor);
160 // animator_helper_->Advance(partial_duration);
163 void ExpectPreLockAnimationStarted() {
164 //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating());
165 EXPECT_TRUE(
166 animator_api_->ContainersAreAnimated(
167 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
168 SessionStateAnimator::ANIMATION_LIFT));
169 EXPECT_TRUE(
170 animator_api_->ContainersAreAnimated(
171 SessionStateAnimator::LAUNCHER,
172 SessionStateAnimator::ANIMATION_FADE_OUT));
173 EXPECT_TRUE(
174 animator_api_->ContainersAreAnimated(
175 SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
176 SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY));
177 EXPECT_TRUE(test_api_->is_animating_lock());
180 void ExpectPreLockAnimationCancel() {
181 EXPECT_TRUE(
182 animator_api_->ContainersAreAnimated(
183 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
184 SessionStateAnimator::ANIMATION_DROP));
185 EXPECT_TRUE(
186 animator_api_->ContainersAreAnimated(
187 SessionStateAnimator::LAUNCHER,
188 SessionStateAnimator::ANIMATION_FADE_IN));
191 void ExpectPreLockAnimationFinished() {
192 //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating());
193 EXPECT_TRUE(
194 animator_api_->ContainersAreAnimated(
195 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
196 SessionStateAnimator::ANIMATION_LIFT));
197 EXPECT_TRUE(
198 animator_api_->ContainersAreAnimated(
199 SessionStateAnimator::LAUNCHER,
200 SessionStateAnimator::ANIMATION_FADE_OUT));
201 EXPECT_TRUE(
202 animator_api_->ContainersAreAnimated(
203 SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
204 SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY));
207 void ExpectPostLockAnimationStarted() {
208 //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating());
209 EXPECT_TRUE(
210 animator_api_->ContainersAreAnimated(
211 SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
212 SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN));
215 void ExpectPastLockAnimationFinished() {
216 //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating());
217 EXPECT_TRUE(
218 animator_api_->ContainersAreAnimated(
219 SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
220 SessionStateAnimator::ANIMATION_RAISE_TO_SCREEN));
223 void ExpectUnlockBeforeUIDestroyedAnimationStarted() {
224 //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating());
225 EXPECT_TRUE(
226 animator_api_->ContainersAreAnimated(
227 SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
228 SessionStateAnimator::ANIMATION_LIFT));
231 void ExpectUnlockBeforeUIDestroyedAnimationFinished() {
232 //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating());
233 EXPECT_TRUE(
234 animator_api_->ContainersAreAnimated(
235 SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
236 SessionStateAnimator::ANIMATION_LIFT));
239 void ExpectUnlockAfterUIDestroyedAnimationStarted() {
240 //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating());
241 EXPECT_TRUE(
242 animator_api_->ContainersAreAnimated(
243 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
244 SessionStateAnimator::ANIMATION_DROP));
245 EXPECT_TRUE(
246 animator_api_->ContainersAreAnimated(
247 SessionStateAnimator::LAUNCHER,
248 SessionStateAnimator::ANIMATION_FADE_IN));
251 void ExpectUnlockAfterUIDestroyedAnimationFinished() {
252 //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating());
253 EXPECT_TRUE(
254 animator_api_->ContainersAreAnimated(
255 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
256 SessionStateAnimator::ANIMATION_DROP));
257 EXPECT_TRUE(
258 animator_api_->ContainersAreAnimated(
259 SessionStateAnimator::LAUNCHER,
260 SessionStateAnimator::ANIMATION_FADE_IN));
263 void ExpectShutdownAnimationStarted() {
264 //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating());
265 EXPECT_TRUE(
266 animator_api_->RootWindowIsAnimated(
267 SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS));
270 void ExpectShutdownAnimationFinished() {
271 //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating());
272 EXPECT_TRUE(
273 animator_api_->RootWindowIsAnimated(
274 SessionStateAnimator::ANIMATION_GRAYSCALE_BRIGHTNESS));
277 void ExpectShutdownAnimationCancel() {
278 //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating());
279 EXPECT_TRUE(
280 animator_api_->RootWindowIsAnimated(
281 SessionStateAnimator::ANIMATION_UNDO_GRAYSCALE_BRIGHTNESS));
284 void ExpectBackgroundIsShowing() {
285 //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating());
286 EXPECT_TRUE(
287 animator_api_->ContainersAreAnimated(
288 SessionStateAnimator::DESKTOP_BACKGROUND,
289 SessionStateAnimator::ANIMATION_FADE_IN));
292 void ExpectBackgroundIsHiding() {
293 //TODO (antrim) : restore EXPECT_TRUE(animator_helper_->IsAnimating());
294 EXPECT_TRUE(
295 animator_api_->ContainersAreAnimated(
296 SessionStateAnimator::DESKTOP_BACKGROUND,
297 SessionStateAnimator::ANIMATION_FADE_OUT));
300 void ExpectUnlockedState() {
301 //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating());
302 EXPECT_FALSE(session_state_delegate_->IsScreenLocked());
304 aura::Window::Windows containers;
306 SessionStateAnimator::GetContainers(
307 SessionStateAnimator::LAUNCHER |
308 SessionStateAnimator::NON_LOCK_SCREEN_CONTAINERS,
309 &containers);
310 for (aura::Window::Windows::const_iterator it = containers.begin();
311 it != containers.end(); ++it) {
312 aura::Window* window = *it;
313 ui::Layer* layer = window->layer();
314 EXPECT_EQ(1.0f, layer->opacity());
315 EXPECT_EQ(0.0f, layer->layer_brightness());
316 EXPECT_EQ(0.0f, layer->layer_saturation());
317 EXPECT_EQ(gfx::Transform(), layer->transform());
321 void ExpectLockedState() {
322 //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating());
323 EXPECT_TRUE(session_state_delegate_->IsScreenLocked());
325 aura::Window::Windows containers;
327 SessionStateAnimator::GetContainers(
328 SessionStateAnimator::LOCK_SCREEN_RELATED_CONTAINERS |
329 SessionStateAnimator::LOCK_SCREEN_CONTAINERS,
330 &containers);
331 for (aura::Window::Windows::const_iterator it = containers.begin();
332 it != containers.end(); ++it) {
333 aura::Window* window = *it;
334 ui::Layer* layer = window->layer();
335 EXPECT_EQ(1.0f, layer->opacity());
336 EXPECT_EQ(0.0f, layer->layer_brightness());
337 EXPECT_EQ(0.0f, layer->layer_saturation());
338 EXPECT_EQ(gfx::Transform(), layer->transform());
342 void PressPowerButton() {
343 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
344 //TODO (antrim) : restore animator_helper_->Advance(base::TimeDelta());
347 void ReleasePowerButton() {
348 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
349 //TODO (antrim) : restore animator_helper_->Advance(base::TimeDelta());
352 void PressLockButton() {
353 controller_->OnLockButtonEvent(true, base::TimeTicks::Now());
356 void ReleaseLockButton() {
357 controller_->OnLockButtonEvent(false, base::TimeTicks::Now());
360 void SystemLocks() {
361 lock_state_controller_->OnLockStateChanged(true);
362 session_state_delegate_->LockScreen();
363 //TODO (antrim) : restore animator_helper_->Advance(base::TimeDelta());
366 void SuccessfulAuthentication(bool* call_flag) {
367 base::Closure closure = base::Bind(&CheckCalledCallback, call_flag);
368 lock_state_controller_->OnLockScreenHide(closure);
369 //TODO (antrim) : restore animator_helper_->Advance(base::TimeDelta());
372 void SystemUnlocks() {
373 lock_state_controller_->OnLockStateChanged(false);
374 session_state_delegate_->UnlockScreen();
375 //TODO (antrim) : restore animator_helper_->Advance(base::TimeDelta());
378 void Initialize(bool legacy_button, user::LoginStatus status) {
379 controller_->set_has_legacy_power_button_for_test(legacy_button);
380 lock_state_controller_->OnLoginStateChanged(status);
381 SetUserLoggedIn(status != user::LOGGED_IN_NONE);
382 if (status == user::LOGGED_IN_GUEST)
383 SetCanLockScreen(false);
384 lock_state_controller_->OnLockStateChanged(false);
387 void CreateWindowForLockscreen() {
388 window_.reset(new aura::Window(&window_delegate_));
389 window_->SetBounds(gfx::Rect(0, 0, 100, 100));
390 window_->SetType(ui::wm::WINDOW_TYPE_NORMAL);
391 window_->Init(aura::WINDOW_LAYER_TEXTURED);
392 window_->SetName("WINDOW");
393 aura::Window* container = Shell::GetContainer(Shell::GetPrimaryRootWindow(),
394 internal::kShellWindowId_LockScreenContainer);
395 ASSERT_TRUE(container);
396 container->AddChild(window_.get());
397 window_->Show();
400 PowerButtonController* controller_; // not owned
401 LockStateController* lock_state_controller_; // not owned
402 TestLockStateControllerDelegate* delegate_; // not owned
403 TestShellDelegate* shell_delegate_; // not owned
404 SessionStateDelegate* session_state_delegate_; // not owned
406 aura::test::TestWindowDelegate window_delegate_;
407 scoped_ptr<aura::Window> window_;
408 scoped_ptr<ui::ScopedAnimationDurationScaleMode> animation_duration_mode_;
409 scoped_ptr<LockStateController::TestApi> test_api_;
410 scoped_ptr<SessionStateAnimator::TestApi> animator_api_;
411 // TODO(antrim) : restore
412 // scoped_ptr<ui::test::AnimationContainerTestHelper> animator_helper_;
414 private:
415 DISALLOW_COPY_AND_ASSIGN(LockStateControllerTest);
418 // Test the lock-to-shutdown flow for non-Chrome-OS hardware that doesn't
419 // correctly report power button releases. We should lock immediately the first
420 // time the button is pressed and shut down when it's pressed from the locked
421 // state.
422 // TODO(antrim): Reenable this: http://crbug.com/167048
423 TEST_F(LockStateControllerTest, DISABLED_LegacyLockAndShutDown) {
424 Initialize(true, user::LOGGED_IN_USER);
426 ExpectUnlockedState();
428 // We should request that the screen be locked immediately after seeing the
429 // power button get pressed.
430 PressPowerButton();
432 ExpectPreLockAnimationStarted();
434 EXPECT_FALSE(test_api_->is_lock_cancellable());
436 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
438 ExpectPreLockAnimationFinished();
439 EXPECT_EQ(1, delegate_->num_lock_requests());
441 // Notify that we locked successfully.
442 lock_state_controller_->OnStartingLock();
443 // We had that animation already.
444 //TODO (antrim) : restore
445 // EXPECT_FALSE(animator_helper_->IsAnimating());
447 SystemLocks();
449 ExpectPostLockAnimationStarted();
450 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
451 ExpectPastLockAnimationFinished();
453 // We shouldn't progress towards the shutdown state, however.
454 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
455 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
457 ReleasePowerButton();
459 // Hold the button again and check that we start shutting down.
460 PressPowerButton();
462 ExpectShutdownAnimationStarted();
464 EXPECT_EQ(0, NumShutdownRequests());
465 // Make sure a mouse move event won't show the cursor.
466 GenerateMouseMoveEvent();
467 EXPECT_FALSE(cursor_visible());
469 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
470 test_api_->trigger_real_shutdown_timeout();
471 EXPECT_EQ(1, NumShutdownRequests());
474 // Test that we start shutting down immediately if the power button is pressed
475 // while we're not logged in on an unofficial system.
476 TEST_F(LockStateControllerTest, LegacyNotLoggedIn) {
477 Initialize(true, user::LOGGED_IN_NONE);
479 PressPowerButton();
480 ExpectShutdownAnimationStarted();
482 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
485 // Test that we start shutting down immediately if the power button is pressed
486 // while we're logged in as a guest on an unofficial system.
487 TEST_F(LockStateControllerTest, LegacyGuest) {
488 Initialize(true, user::LOGGED_IN_GUEST);
490 PressPowerButton();
491 ExpectShutdownAnimationStarted();
493 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
496 // When we hold the power button while the user isn't logged in, we should shut
497 // down the machine directly.
498 TEST_F(LockStateControllerTest, ShutdownWhenNotLoggedIn) {
499 Initialize(false, user::LOGGED_IN_NONE);
501 // Press the power button and check that we start the shutdown timer.
502 PressPowerButton();
503 EXPECT_FALSE(test_api_->is_animating_lock());
504 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
505 ExpectShutdownAnimationStarted();
507 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN, 0.5f);
509 // Release the power button before the shutdown timer fires.
510 ReleasePowerButton();
512 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
513 ExpectShutdownAnimationCancel();
515 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_REVERT, 0.5f);
517 // Press the button again and make the shutdown timeout fire this time.
518 // Check that we start the timer for actually requesting the shutdown.
519 PressPowerButton();
521 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
523 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
524 ExpectShutdownAnimationFinished();
525 test_api_->trigger_shutdown_timeout();
527 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
528 EXPECT_EQ(0, NumShutdownRequests());
530 // When the timout fires, we should request a shutdown.
531 test_api_->trigger_real_shutdown_timeout();
533 EXPECT_EQ(1, NumShutdownRequests());
536 // Test that we lock the screen and deal with unlocking correctly.
537 // TODO(antrim): Reenable this: http://crbug.com/167048
538 TEST_F(LockStateControllerTest, DISABLED_LockAndUnlock) {
539 Initialize(false, user::LOGGED_IN_USER);
541 ExpectUnlockedState();
543 // Press the power button and check that the lock timer is started and that we
544 // start lifting the non-screen-locker containers.
545 PressPowerButton();
547 ExpectPreLockAnimationStarted();
548 EXPECT_TRUE(test_api_->is_lock_cancellable());
549 EXPECT_EQ(0, delegate_->num_lock_requests());
551 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
552 ExpectPreLockAnimationFinished();
554 EXPECT_EQ(1, delegate_->num_lock_requests());
556 // Notify that we locked successfully.
557 lock_state_controller_->OnStartingLock();
558 // We had that animation already.
559 //TODO (antrim) : restore EXPECT_FALSE(animator_helper_->IsAnimating());
561 SystemLocks();
563 ExpectPostLockAnimationStarted();
564 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
565 ExpectPastLockAnimationFinished();
567 // When we release the power button, the lock-to-shutdown timer should be
568 // stopped.
569 ExpectLockedState();
570 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running());
571 ReleasePowerButton();
572 ExpectLockedState();
573 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
575 // Notify that the screen has been unlocked. We should show the
576 // non-screen-locker windows.
577 bool called = false;
578 SuccessfulAuthentication(&called);
580 ExpectUnlockBeforeUIDestroyedAnimationStarted();
581 EXPECT_FALSE(called);
582 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
583 ExpectUnlockBeforeUIDestroyedAnimationFinished();
585 EXPECT_TRUE(called);
587 SystemUnlocks();
589 ExpectUnlockAfterUIDestroyedAnimationStarted();
590 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
591 ExpectUnlockAfterUIDestroyedAnimationFinished();
593 ExpectUnlockedState();
596 // Test that we deal with cancelling lock correctly.
597 // TODO(antrim): Reenable this: http://crbug.com/167048
598 TEST_F(LockStateControllerTest, DISABLED_LockAndCancel) {
599 Initialize(false, user::LOGGED_IN_USER);
601 ExpectUnlockedState();
603 // Press the power button and check that the lock timer is started and that we
604 // start lifting the non-screen-locker containers.
605 PressPowerButton();
607 ExpectPreLockAnimationStarted();
608 EXPECT_TRUE(test_api_->is_lock_cancellable());
610 // forward only half way through
611 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
613 gfx::Transform transform_before_button_released =
614 GetContainer(internal::kShellWindowId_DefaultContainer)->
615 layer()->transform();
617 // Release the button before the lock timer fires.
618 ReleasePowerButton();
620 ExpectPreLockAnimationCancel();
622 gfx::Transform transform_after_button_released =
623 GetContainer(internal::kShellWindowId_DefaultContainer)->
624 layer()->transform();
625 // Expect no flickering, animation should proceed from mid-state.
626 EXPECT_EQ(transform_before_button_released, transform_after_button_released);
628 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
629 ExpectUnlockedState();
630 EXPECT_EQ(0, delegate_->num_lock_requests());
633 // Test that we deal with cancelling lock correctly.
634 // TODO(antrim): Reenable this: http://crbug.com/167048
635 TEST_F(LockStateControllerTest,
636 DISABLED_LockAndCancelAndLockAgain) {
637 Initialize(false, user::LOGGED_IN_USER);
639 ExpectUnlockedState();
641 // Press the power button and check that the lock timer is started and that we
642 // start lifting the non-screen-locker containers.
643 PressPowerButton();
645 ExpectPreLockAnimationStarted();
646 EXPECT_TRUE(test_api_->is_lock_cancellable());
648 // forward only half way through
649 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
651 // Release the button before the lock timer fires.
652 ReleasePowerButton();
653 ExpectPreLockAnimationCancel();
655 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, 0.5f);
657 PressPowerButton();
658 ExpectPreLockAnimationStarted();
659 EXPECT_TRUE(test_api_->is_lock_cancellable());
661 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.6f);
663 EXPECT_EQ(0, delegate_->num_lock_requests());
664 ExpectPreLockAnimationStarted();
666 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.6f);
667 ExpectPreLockAnimationFinished();
668 EXPECT_EQ(1, delegate_->num_lock_requests());
671 // Hold the power button down from the unlocked state to eventual shutdown.
672 // TODO(antrim): Reenable this: http://crbug.com/167048
673 TEST_F(LockStateControllerTest, DISABLED_LockToShutdown) {
674 Initialize(false, user::LOGGED_IN_USER);
676 // Hold the power button and lock the screen.
677 PressPowerButton();
678 EXPECT_TRUE(test_api_->is_animating_lock());
680 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
681 SystemLocks();
682 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
684 // When the lock-to-shutdown timeout fires, we should start the shutdown
685 // timer.
686 EXPECT_TRUE(test_api_->lock_to_shutdown_timer_is_running());
688 test_api_->trigger_lock_to_shutdown_timeout();
690 ExpectShutdownAnimationStarted();
691 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
693 // Fire the shutdown timeout and check that we request shutdown.
694 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
695 ExpectShutdownAnimationFinished();
696 test_api_->trigger_shutdown_timeout();
698 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
699 EXPECT_EQ(0, NumShutdownRequests());
700 test_api_->trigger_real_shutdown_timeout();
701 EXPECT_EQ(1, NumShutdownRequests());
704 // Hold the power button down from the unlocked state to eventual shutdown,
705 // then release the button while system does locking.
706 TEST_F(LockStateControllerTest, CancelLockToShutdown) {
707 Initialize(false, user::LOGGED_IN_USER);
709 PressPowerButton();
711 // Hold the power button and lock the screen.
712 EXPECT_TRUE(test_api_->is_animating_lock());
714 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
715 SystemLocks();
716 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS, 0.5f);
718 // Power button is released while system attempts to lock.
719 ReleasePowerButton();
721 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
723 EXPECT_FALSE(lock_state_controller_->ShutdownRequested());
724 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
725 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
728 // Test that we handle the case where lock requests are ignored.
729 // TODO(antrim): Reenable this: http://crbug.com/167048
730 TEST_F(LockStateControllerTest, DISABLED_Lock) {
731 // We require animations to have a duration for this test.
732 ui::ScopedAnimationDurationScaleMode normal_duration_mode(
733 ui::ScopedAnimationDurationScaleMode::NORMAL_DURATION);
735 Initialize(false, user::LOGGED_IN_USER);
737 // Hold the power button and lock the screen.
738 PressPowerButton();
739 ExpectPreLockAnimationStarted();
741 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
743 EXPECT_EQ(1, delegate_->num_lock_requests());
744 EXPECT_TRUE(test_api_->lock_fail_timer_is_running());
745 // We shouldn't start the lock-to-shutdown timer until the screen has actually
746 // been locked and this was animated.
747 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
749 // Act as if the request timed out. We should restore the windows.
750 test_api_->trigger_lock_fail_timeout();
752 ExpectUnlockAfterUIDestroyedAnimationStarted();
753 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
754 ExpectUnlockAfterUIDestroyedAnimationFinished();
755 ExpectUnlockedState();
758 // Test the basic operation of the lock button (not logged in).
759 TEST_F(LockStateControllerTest, LockButtonBasicNotLoggedIn) {
760 // The lock button shouldn't do anything if we aren't logged in.
761 Initialize(false, user::LOGGED_IN_NONE);
763 PressLockButton();
764 EXPECT_FALSE(test_api_->is_animating_lock());
765 ReleaseLockButton();
766 EXPECT_EQ(0, delegate_->num_lock_requests());
769 // Test the basic operation of the lock button (guest).
770 TEST_F(LockStateControllerTest, LockButtonBasicGuest) {
771 // The lock button shouldn't do anything when we're logged in as a guest.
772 Initialize(false, user::LOGGED_IN_GUEST);
774 PressLockButton();
775 EXPECT_FALSE(test_api_->is_animating_lock());
776 ReleaseLockButton();
777 EXPECT_EQ(0, delegate_->num_lock_requests());
780 // Test the basic operation of the lock button.
781 // TODO(antrim): Reenable this: http://crbug.com/167048
782 TEST_F(LockStateControllerTest, DISABLED_LockButtonBasic) {
783 // If we're logged in as a regular user, we should start the lock timer and
784 // the pre-lock animation.
785 Initialize(false, user::LOGGED_IN_USER);
787 PressLockButton();
788 ExpectPreLockAnimationStarted();
789 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
791 // If the button is released immediately, we shouldn't lock the screen.
792 ReleaseLockButton();
793 ExpectPreLockAnimationCancel();
794 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
796 ExpectUnlockedState();
797 EXPECT_EQ(0, delegate_->num_lock_requests());
799 // Press the button again and let the lock timeout fire. We should request
800 // that the screen be locked.
801 PressLockButton();
802 ExpectPreLockAnimationStarted();
803 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
804 EXPECT_EQ(1, delegate_->num_lock_requests());
806 // Pressing the lock button while we have a pending lock request shouldn't do
807 // anything.
808 ReleaseLockButton();
809 PressLockButton();
810 ExpectPreLockAnimationFinished();
811 ReleaseLockButton();
813 // Pressing the button also shouldn't do anything after the screen is locked.
814 SystemLocks();
815 ExpectPostLockAnimationStarted();
817 PressLockButton();
818 ReleaseLockButton();
819 ExpectPostLockAnimationStarted();
821 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
822 ExpectPastLockAnimationFinished();
824 PressLockButton();
825 ReleaseLockButton();
826 ExpectPastLockAnimationFinished();
829 // Test that the power button takes priority over the lock button.
830 // TODO(antrim): Reenable this: http://crbug.com/167048
831 TEST_F(LockStateControllerTest,
832 DISABLED_PowerButtonPreemptsLockButton) {
833 Initialize(false, user::LOGGED_IN_USER);
835 // While the lock button is down, hold the power button.
836 PressLockButton();
837 ExpectPreLockAnimationStarted();
838 PressPowerButton();
839 ExpectPreLockAnimationStarted();
841 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
843 // The lock timer shouldn't be stopped when the lock button is released.
844 ReleaseLockButton();
845 ExpectPreLockAnimationStarted();
846 ReleasePowerButton();
847 ExpectPreLockAnimationCancel();
849 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
850 ExpectUnlockedState();
852 // Now press the power button first and then the lock button.
853 PressPowerButton();
854 ExpectPreLockAnimationStarted();
855 PressLockButton();
856 ExpectPreLockAnimationStarted();
858 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
860 // Releasing the power button should stop the lock timer.
861 ReleasePowerButton();
862 ExpectPreLockAnimationCancel();
863 ReleaseLockButton();
864 ExpectPreLockAnimationCancel();
867 // When the screen is locked without going through the usual power-button
868 // slow-close path (e.g. via the wrench menu), test that we still show the
869 // fast-close animation.
870 TEST_F(LockStateControllerTest, LockWithoutButton) {
871 Initialize(false, user::LOGGED_IN_USER);
872 lock_state_controller_->OnStartingLock();
874 ExpectPreLockAnimationStarted();
875 EXPECT_FALSE(test_api_->is_lock_cancellable());
877 // TODO(antrim): After time-faking is fixed, let the pre-lock animation
878 // complete here and check that delegate_->num_lock_requests() is 0 to
879 // prevent http://crbug.com/172487 from regressing.
882 // When we hear that the process is exiting but we haven't had a chance to
883 // display an animation, we should just blank the screen.
884 TEST_F(LockStateControllerTest, ShutdownWithoutButton) {
885 Initialize(false, user::LOGGED_IN_USER);
886 lock_state_controller_->OnAppTerminating();
888 EXPECT_TRUE(
889 animator_api_->ContainersAreAnimated(
890 SessionStateAnimator::kAllContainersMask,
891 SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY));
892 GenerateMouseMoveEvent();
893 EXPECT_FALSE(cursor_visible());
896 // Test that we display the fast-close animation and shut down when we get an
897 // outside request to shut down (e.g. from the login or lock screen).
898 TEST_F(LockStateControllerTest, RequestShutdownFromLoginScreen) {
899 Initialize(false, user::LOGGED_IN_NONE);
900 CreateWindowForLockscreen();
902 lock_state_controller_->RequestShutdown();
904 ExpectShutdownAnimationStarted();
905 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
907 GenerateMouseMoveEvent();
908 EXPECT_FALSE(cursor_visible());
910 EXPECT_EQ(0, NumShutdownRequests());
911 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
912 test_api_->trigger_real_shutdown_timeout();
913 EXPECT_EQ(1, NumShutdownRequests());
916 TEST_F(LockStateControllerTest, RequestShutdownFromLockScreen) {
917 Initialize(false, user::LOGGED_IN_USER);
919 SystemLocks();
920 CreateWindowForLockscreen();
921 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
922 ExpectPastLockAnimationFinished();
924 lock_state_controller_->RequestShutdown();
926 ExpectShutdownAnimationStarted();
927 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
929 GenerateMouseMoveEvent();
930 EXPECT_FALSE(cursor_visible());
932 EXPECT_EQ(0, NumShutdownRequests());
933 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
934 test_api_->trigger_real_shutdown_timeout();
935 EXPECT_EQ(1, NumShutdownRequests());
938 // TODO(antrim): Reenable this: http://crbug.com/167048
939 TEST_F(LockStateControllerTest,
940 DISABLED_RequestAndCancelShutdownFromLockScreen) {
941 Initialize(false, user::LOGGED_IN_USER);
943 SystemLocks();
944 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
945 ExpectLockedState();
947 // Press the power button and check that we start the shutdown timer.
948 PressPowerButton();
949 EXPECT_FALSE(test_api_->is_animating_lock());
950 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
952 ExpectShutdownAnimationStarted();
954 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN, 0.5f);
956 float grayscale_before_button_release =
957 Shell::GetPrimaryRootWindow()->layer()->layer_grayscale();
959 // Release the power button before the shutdown timer fires.
960 ReleasePowerButton();
962 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
964 ExpectShutdownAnimationCancel();
966 float grayscale_after_button_release =
967 Shell::GetPrimaryRootWindow()->layer()->layer_grayscale();
968 // Expect no flickering in undo animation.
969 EXPECT_EQ(grayscale_before_button_release, grayscale_after_button_release);
971 Advance(SessionStateAnimator::ANIMATION_SPEED_REVERT);
972 ExpectLockedState();
975 // Test that we ignore power button presses when the screen is turned off.
976 TEST_F(LockStateControllerTest, IgnorePowerButtonIfScreenIsOff) {
977 Initialize(false, user::LOGGED_IN_USER);
979 // When the screen brightness is at 0%, we shouldn't do anything in response
980 // to power button presses.
981 controller_->OnScreenBrightnessChanged(0.0);
983 PressPowerButton();
984 EXPECT_FALSE(test_api_->is_animating_lock());
985 ReleasePowerButton();
987 // After increasing the brightness to 10%, we should start the timer like
988 // usual.
989 controller_->OnScreenBrightnessChanged(10.0);
991 PressPowerButton();
992 EXPECT_TRUE(test_api_->is_animating_lock());
995 // Test that hidden background appears and revers correctly on lock/cancel.
996 // TODO(antrim): Reenable this: http://crbug.com/167048
997 TEST_F(LockStateControllerTest, DISABLED_TestHiddenBackgroundLockCancel) {
998 Initialize(false, user::LOGGED_IN_USER);
999 HideBackground();
1001 EXPECT_TRUE(IsBackgroundHidden());
1002 ExpectUnlockedState();
1003 PressPowerButton();
1005 ExpectPreLockAnimationStarted();
1006 EXPECT_FALSE(IsBackgroundHidden());
1007 ExpectBackgroundIsShowing();
1009 // Forward only half way through.
1010 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
1012 // Release the button before the lock timer fires.
1013 ReleasePowerButton();
1014 ExpectPreLockAnimationCancel();
1015 ExpectBackgroundIsHiding();
1016 EXPECT_FALSE(IsBackgroundHidden());
1018 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
1020 ExpectUnlockedState();
1021 EXPECT_TRUE(IsBackgroundHidden());
1024 // Test that hidden background appears and revers correctly on lock/unlock.
1025 // TODO(antrim): Reenable this: http://crbug.com/167048
1026 TEST_F(LockStateControllerTest, DISABLED_TestHiddenBackgroundLockUnlock) {
1027 Initialize(false, user::LOGGED_IN_USER);
1028 HideBackground();
1030 EXPECT_TRUE(IsBackgroundHidden());
1031 ExpectUnlockedState();
1033 // Press the power button and check that the lock timer is started and that we
1034 // start lifting the non-screen-locker containers.
1035 PressPowerButton();
1037 ExpectPreLockAnimationStarted();
1038 EXPECT_FALSE(IsBackgroundHidden());
1039 ExpectBackgroundIsShowing();
1041 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
1043 ExpectPreLockAnimationFinished();
1045 SystemLocks();
1047 ReleasePowerButton();
1049 ExpectPostLockAnimationStarted();
1050 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
1051 ExpectPastLockAnimationFinished();
1053 ExpectLockedState();
1055 SuccessfulAuthentication(NULL);
1057 ExpectUnlockBeforeUIDestroyedAnimationStarted();
1058 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
1059 ExpectUnlockBeforeUIDestroyedAnimationFinished();
1061 SystemUnlocks();
1063 ExpectUnlockAfterUIDestroyedAnimationStarted();
1064 ExpectBackgroundIsHiding();
1065 EXPECT_FALSE(IsBackgroundHidden());
1067 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
1068 ExpectUnlockAfterUIDestroyedAnimationFinished();
1069 EXPECT_TRUE(IsBackgroundHidden());
1071 ExpectUnlockedState();
1074 } // namespace test
1075 } // namespace ash