Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(366)

Side by Side Diff: ash/wm/session_state_controller_impl2_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698