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

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

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

Powered by Google App Engine
This is Rietveld 408576698