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

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: Enabled LockStateControllerTests for Background hiding & addressed other comments. 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
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
702 // Test that we handle the case where lock requests are ignored. 645 // Test that we handle the case where lock requests are ignored.
703 // TODO(antrim): Reenable this: http://crbug.com/167048 646 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); 647 Initialize(false, user::LOGGED_IN_USER);
710 648
711 // Hold the power button and lock the screen. 649 // Hold the power button and lock the screen.
712 PressPowerButton(); 650 PressPowerButton();
713 ExpectPreLockAnimationStarted(); 651 ExpectPreLockAnimationStarted();
714 652
715 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); 653 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
716 654
717 EXPECT_EQ(1, delegate_->num_lock_requests()); 655 EXPECT_EQ(1, lock_state_controller_delegate_->num_lock_requests());
718 EXPECT_TRUE(test_api_->lock_fail_timer_is_running()); 656 EXPECT_TRUE(test_api_->lock_fail_timer_is_running());
719 // We shouldn't start the lock-to-shutdown timer until the screen has actually 657 // We shouldn't start the lock-to-shutdown timer until the screen has actually
720 // been locked and this was animated. 658 // been locked and this was animated.
721 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running()); 659 EXPECT_FALSE(test_api_->lock_to_shutdown_timer_is_running());
722 660
723 // Act as if the request timed out. We should restore the windows. 661 // Act as if the request timed out.
724 test_api_->trigger_lock_fail_timeout(); 662 EXPECT_DEATH(test_api_->trigger_lock_fail_timeout(), "");
725
726 ExpectUnlockAfterUIDestroyedAnimationStarted();
727 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
728 ExpectUnlockAfterUIDestroyedAnimationFinished();
729 ExpectUnlockedState();
730 } 663 }
731 664
732 // Test the basic operation of the lock button (not logged in). 665 // Test the basic operation of the lock button (not logged in).
733 TEST_F(LockStateControllerTest, LockButtonBasicNotLoggedIn) { 666 TEST_F(LockStateControllerTest, LockButtonBasicNotLoggedIn) {
734 // The lock button shouldn't do anything if we aren't logged in. 667 // The lock button shouldn't do anything if we aren't logged in.
735 Initialize(false, user::LOGGED_IN_NONE); 668 Initialize(false, user::LOGGED_IN_NONE);
736 669
737 PressLockButton(); 670 PressLockButton();
738 EXPECT_FALSE(test_api_->is_animating_lock()); 671 EXPECT_FALSE(test_api_->is_animating_lock());
739 ReleaseLockButton(); 672 ReleaseLockButton();
740 EXPECT_EQ(0, delegate_->num_lock_requests()); 673 EXPECT_EQ(0, lock_state_controller_delegate_->num_lock_requests());
741 } 674 }
742 675
743 // Test the basic operation of the lock button (guest). 676 // Test the basic operation of the lock button (guest).
744 TEST_F(LockStateControllerTest, LockButtonBasicGuest) { 677 TEST_F(LockStateControllerTest, LockButtonBasicGuest) {
745 // The lock button shouldn't do anything when we're logged in as a guest. 678 // The lock button shouldn't do anything when we're logged in as a guest.
746 Initialize(false, user::LOGGED_IN_GUEST); 679 Initialize(false, user::LOGGED_IN_GUEST);
747 680
748 PressLockButton(); 681 PressLockButton();
749 EXPECT_FALSE(test_api_->is_animating_lock()); 682 EXPECT_FALSE(test_api_->is_animating_lock());
750 ReleaseLockButton(); 683 ReleaseLockButton();
751 EXPECT_EQ(0, delegate_->num_lock_requests()); 684 EXPECT_EQ(0, lock_state_controller_delegate_->num_lock_requests());
752 } 685 }
753 686
754 // Test the basic operation of the lock button. 687 // Test the basic operation of the lock button.
755 // TODO(antrim): Reenable this: http://crbug.com/167048 688 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 689 // If we're logged in as a regular user, we should start the lock timer and
758 // the pre-lock animation. 690 // the pre-lock animation.
759 Initialize(false, user::LOGGED_IN_USER); 691 Initialize(false, user::LOGGED_IN_USER);
760 692
761 PressLockButton(); 693 PressLockButton();
762 ExpectPreLockAnimationStarted(); 694 ExpectPreLockAnimationStarted();
763 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f); 695 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
764 696
765 // If the button is released immediately, we shouldn't lock the screen. 697 // If the button is released immediately, we shouldn't lock the screen.
766 ReleaseLockButton(); 698 ReleaseLockButton();
767 ExpectPreLockAnimationCancel(); 699 ExpectPreLockAnimationCancel();
768 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); 700 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
769 701
770 ExpectUnlockedState(); 702 ExpectUnlockedState();
771 EXPECT_EQ(0, delegate_->num_lock_requests()); 703 EXPECT_EQ(0, lock_state_controller_delegate_->num_lock_requests());
772 704
773 // Press the button again and let the lock timeout fire. We should request 705 // Press the button again and let the lock timeout fire. We should request
774 // that the screen be locked. 706 // that the screen be locked.
775 PressLockButton(); 707 PressLockButton();
776 ExpectPreLockAnimationStarted(); 708 ExpectPreLockAnimationStarted();
777 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); 709 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
778 EXPECT_EQ(1, delegate_->num_lock_requests()); 710 EXPECT_EQ(1, lock_state_controller_delegate_->num_lock_requests());
779 711
780 // Pressing the lock button while we have a pending lock request shouldn't do 712 // Pressing the lock button while we have a pending lock request shouldn't do
781 // anything. 713 // anything.
782 ReleaseLockButton(); 714 ReleaseLockButton();
783 PressLockButton(); 715 PressLockButton();
784 ExpectPreLockAnimationFinished(); 716 ExpectPreLockAnimationFinished();
785 ReleaseLockButton(); 717 ReleaseLockButton();
786 718
787 // Pressing the button also shouldn't do anything after the screen is locked. 719 // Pressing the button also shouldn't do anything after the screen is locked.
788 SystemLocks(); 720 SystemLocks();
789 ExpectPostLockAnimationStarted(); 721 ExpectPostLockAnimationStarted();
790 722
791 PressLockButton(); 723 PressLockButton();
792 ReleaseLockButton(); 724 ReleaseLockButton();
793 ExpectPostLockAnimationStarted(); 725 ExpectPostLockAnimationStarted();
794 726
795 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); 727 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
796 ExpectPastLockAnimationFinished(); 728 ExpectPostLockAnimationFinished();
797 729
798 PressLockButton(); 730 PressLockButton();
799 ReleaseLockButton(); 731 ReleaseLockButton();
800 ExpectPastLockAnimationFinished(); 732 ExpectPostLockAnimationFinished();
801 } 733 }
802 734
803 // Test that the power button takes priority over the lock button. 735 // Test that the power button takes priority over the lock button.
804 // TODO(antrim): Reenable this: http://crbug.com/167048 736 TEST_F(LockStateControllerTest, PowerButtonPreemptsLockButton) {
805 TEST_F(LockStateControllerTest,
806 DISABLED_PowerButtonPreemptsLockButton) {
807 Initialize(false, user::LOGGED_IN_USER); 737 Initialize(false, user::LOGGED_IN_USER);
808 738
809 // While the lock button is down, hold the power button. 739 // While the lock button is down, hold the power button.
810 PressLockButton(); 740 PressLockButton();
811 ExpectPreLockAnimationStarted(); 741 ExpectPreLockAnimationStarted();
742
743 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.1f);
744 ExpectPreLockAnimationRunning();
745
812 PressPowerButton(); 746 PressPowerButton();
813 ExpectPreLockAnimationStarted(); 747 ExpectPreLockAnimationRunning();
814 748
815 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f); 749 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.1f);
750 ExpectPreLockAnimationRunning();
816 751
817 // The lock timer shouldn't be stopped when the lock button is released. 752 // The lock timer shouldn't be stopped when the lock button is released.
818 ReleaseLockButton(); 753 ReleaseLockButton();
819 ExpectPreLockAnimationStarted(); 754 ExpectPreLockAnimationRunning();
755
820 ReleasePowerButton(); 756 ReleasePowerButton();
821 ExpectPreLockAnimationCancel(); 757 ExpectPreLockAnimationCancel();
822 758
823 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); 759 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
824 ExpectUnlockedState(); 760 ExpectUnlockedState();
825 761
826 // Now press the power button first and then the lock button. 762 // Now press the power button first and then the lock button.
827 PressPowerButton(); 763 PressPowerButton();
828 ExpectPreLockAnimationStarted(); 764 ExpectPreLockAnimationStarted();
765
766 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.1f);
767
829 PressLockButton(); 768 PressLockButton();
830 ExpectPreLockAnimationStarted(); 769 ExpectPreLockAnimationRunning();
831 770
832 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f); 771 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.1f);
833 772
834 // Releasing the power button should stop the lock timer. 773 // Releasing the power button should stop the lock timer.
835 ReleasePowerButton(); 774 ReleasePowerButton();
836 ExpectPreLockAnimationCancel(); 775 ExpectPreLockAnimationCancel();
776
777 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.1f);
778
837 ReleaseLockButton(); 779 ReleaseLockButton();
838 ExpectPreLockAnimationCancel(); 780 ExpectPreLockAnimationCancel();
839 } 781 }
840 782
841 // When the screen is locked without going through the usual power-button 783 // 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 784 // slow-close path (e.g. via the wrench menu), test that we still show the
843 // fast-close animation. 785 // fast-close animation.
844 TEST_F(LockStateControllerTest, LockWithoutButton) { 786 TEST_F(LockStateControllerTest, LockWithoutButton) {
845 Initialize(false, user::LOGGED_IN_USER); 787 Initialize(false, user::LOGGED_IN_USER);
846 lock_state_controller_->OnStartingLock(); 788 lock_state_controller_->OnStartingLock();
847 789
848 ExpectPreLockAnimationStarted(); 790 ExpectPreLockAnimationStarted();
849 EXPECT_FALSE(test_api_->is_lock_cancellable()); 791 EXPECT_FALSE(test_api_->is_lock_cancellable());
792 EXPECT_LT(0u, test_animator_->GetAnimationCount());
850 793
851 // TODO(antrim): After time-faking is fixed, let the pre-lock animation 794 test_animator_->CompleteAllAnimations(true);
852 // complete here and check that delegate_->num_lock_requests() is 0 to 795 EXPECT_EQ(0, lock_state_controller_delegate_->num_lock_requests());
853 // prevent http://crbug.com/172487 from regressing.
854 } 796 }
855 797
856 // When we hear that the process is exiting but we haven't had a chance to 798 // 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. 799 // display an animation, we should just blank the screen.
858 TEST_F(LockStateControllerTest, ShutdownWithoutButton) { 800 TEST_F(LockStateControllerTest, ShutdownWithoutButton) {
859 Initialize(false, user::LOGGED_IN_USER); 801 Initialize(false, user::LOGGED_IN_USER);
860 lock_state_controller_->OnAppTerminating(); 802 lock_state_controller_->OnAppTerminating();
861 803
862 EXPECT_TRUE( 804 EXPECT_TRUE(
863 animator_api_->ContainersAreAnimated( 805 test_animator_->AreContainersAnimated(
864 SessionStateAnimator::kAllContainersMask, 806 SessionStateAnimator::kAllNonRootContainersMask,
865 SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY)); 807 SessionStateAnimator::ANIMATION_HIDE_IMMEDIATELY));
866 GenerateMouseMoveEvent(); 808 GenerateMouseMoveEvent();
867 EXPECT_FALSE(cursor_visible()); 809 EXPECT_FALSE(cursor_visible());
868 } 810 }
869 811
870 // Test that we display the fast-close animation and shut down when we get an 812 // 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). 813 // outside request to shut down (e.g. from the login or lock screen).
872 TEST_F(LockStateControllerTest, RequestShutdownFromLoginScreen) { 814 TEST_F(LockStateControllerTest, RequestShutdownFromLoginScreen) {
873 Initialize(false, user::LOGGED_IN_NONE); 815 Initialize(false, user::LOGGED_IN_NONE);
874 CreateWindowForLockscreen();
875 816
876 lock_state_controller_->RequestShutdown(); 817 lock_state_controller_->RequestShutdown();
877 818
878 ExpectShutdownAnimationStarted(); 819 ExpectShutdownAnimationStarted();
879 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); 820 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
880 821
881 GenerateMouseMoveEvent(); 822 GenerateMouseMoveEvent();
882 EXPECT_FALSE(cursor_visible()); 823 EXPECT_FALSE(cursor_visible());
883 824
884 EXPECT_EQ(0, NumShutdownRequests()); 825 EXPECT_EQ(0, NumShutdownRequests());
885 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 826 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
886 test_api_->trigger_real_shutdown_timeout(); 827 test_api_->trigger_real_shutdown_timeout();
887 EXPECT_EQ(1, NumShutdownRequests()); 828 EXPECT_EQ(1, NumShutdownRequests());
888 } 829 }
889 830
890 TEST_F(LockStateControllerTest, RequestShutdownFromLockScreen) { 831 TEST_F(LockStateControllerTest, RequestShutdownFromLockScreen) {
891 Initialize(false, user::LOGGED_IN_USER); 832 Initialize(false, user::LOGGED_IN_USER);
892 833
893 SystemLocks(); 834 SystemLocks();
894 CreateWindowForLockscreen(); 835
895 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); 836 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
896 ExpectPastLockAnimationFinished(); 837 ExpectPostLockAnimationFinished();
897 838
898 lock_state_controller_->RequestShutdown(); 839 lock_state_controller_->RequestShutdown();
899 840
900 ExpectShutdownAnimationStarted(); 841 ExpectShutdownAnimationStarted();
901 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); 842 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
902 843
903 GenerateMouseMoveEvent(); 844 GenerateMouseMoveEvent();
904 EXPECT_FALSE(cursor_visible()); 845 EXPECT_FALSE(cursor_visible());
905 846
906 EXPECT_EQ(0, NumShutdownRequests()); 847 EXPECT_EQ(0, NumShutdownRequests());
907 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running()); 848 EXPECT_TRUE(test_api_->real_shutdown_timer_is_running());
908 test_api_->trigger_real_shutdown_timeout(); 849 test_api_->trigger_real_shutdown_timeout();
909 EXPECT_EQ(1, NumShutdownRequests()); 850 EXPECT_EQ(1, NumShutdownRequests());
910 } 851 }
911 852
912 // TODO(antrim): Reenable this: http://crbug.com/167048 853 TEST_F(LockStateControllerTest, RequestAndCancelShutdownFromLockScreen) {
913 TEST_F(LockStateControllerTest,
914 DISABLED_RequestAndCancelShutdownFromLockScreen) {
915 Initialize(false, user::LOGGED_IN_USER); 854 Initialize(false, user::LOGGED_IN_USER);
916 855
917 SystemLocks(); 856 SystemLocks();
918 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN); 857 Advance(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN);
919 ExpectLockedState(); 858 ExpectLockedState();
920 859
921 // Press the power button and check that we start the shutdown timer. 860 // Press the power button and check that we start the shutdown timer.
922 PressPowerButton(); 861 PressPowerButton();
923 EXPECT_FALSE(test_api_->is_animating_lock()); 862 EXPECT_FALSE(test_api_->is_animating_lock());
924 EXPECT_TRUE(test_api_->shutdown_timer_is_running()); 863 EXPECT_TRUE(test_api_->shutdown_timer_is_running());
925 864
926 ExpectShutdownAnimationStarted(); 865 ExpectShutdownAnimationStarted();
927 866
928 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN, 0.5f); 867 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_SHUTDOWN, 0.5f);
929 868
930 float grayscale_before_button_release =
931 Shell::GetPrimaryRootWindow()->layer()->layer_grayscale();
932
933 // Release the power button before the shutdown timer fires. 869 // Release the power button before the shutdown timer fires.
934 ReleasePowerButton(); 870 ReleasePowerButton();
935 871
936 EXPECT_FALSE(test_api_->shutdown_timer_is_running()); 872 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
937 873
938 ExpectShutdownAnimationCancel(); 874 ExpectShutdownAnimationCancel();
939 875
940 float grayscale_after_button_release = 876 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(); 877 ExpectLockedState();
947 } 878 }
948 879
949 // Test that we ignore power button presses when the screen is turned off. 880 // Test that we ignore power button presses when the screen is turned off.
950 TEST_F(LockStateControllerTest, IgnorePowerButtonIfScreenIsOff) { 881 TEST_F(LockStateControllerTest, IgnorePowerButtonIfScreenIsOff) {
951 Initialize(false, user::LOGGED_IN_USER); 882 Initialize(false, user::LOGGED_IN_USER);
952 883
953 // When the screen brightness is at 0%, we shouldn't do anything in response 884 // When the screen brightness is at 0%, we shouldn't do anything in response
954 // to power button presses. 885 // to power button presses.
955 controller_->OnScreenBrightnessChanged(0.0); 886 power_button_controller_->OnScreenBrightnessChanged(0.0);
956 PressPowerButton(); 887 PressPowerButton();
957 EXPECT_FALSE(test_api_->is_animating_lock()); 888 EXPECT_FALSE(test_api_->is_animating_lock());
958 ReleasePowerButton(); 889 ReleasePowerButton();
959 890
960 // After increasing the brightness to 10%, we should start the timer like 891 // After increasing the brightness to 10%, we should start the timer like
961 // usual. 892 // usual.
962 controller_->OnScreenBrightnessChanged(10.0); 893 power_button_controller_->OnScreenBrightnessChanged(10.0);
963 PressPowerButton(); 894 PressPowerButton();
964 EXPECT_TRUE(test_api_->is_animating_lock()); 895 EXPECT_TRUE(test_api_->is_animating_lock());
965 ReleasePowerButton(); 896 ReleasePowerButton();
966 } 897 }
967 898
968 #if defined(OS_CHROMEOS) 899 #if defined(OS_CHROMEOS)
969 TEST_F(LockStateControllerTest, HonorPowerButtonInDockedMode) { 900 TEST_F(LockStateControllerTest, HonorPowerButtonInDockedMode) {
970 ScopedVector<const ui::DisplayMode> modes; 901 ScopedVector<const ui::DisplayMode> modes;
971 modes.push_back(new ui::DisplayMode(gfx::Size(1, 1), false, 60.0f)); 902 modes.push_back(new ui::DisplayMode(gfx::Size(1, 1), false, 60.0f));
972 903
973 // Create two outputs, the first internal and the second external. 904 // Create two outputs, the first internal and the second external.
974 ui::DisplayConfigurator::DisplayStateList outputs; 905 ui::DisplayConfigurator::DisplayStateList outputs;
975 ui::DisplayConfigurator::DisplayState internal_output; 906 ui::DisplayConfigurator::DisplayState internal_output;
976 ui::TestDisplaySnapshot internal_display; 907 ui::TestDisplaySnapshot internal_display;
977 internal_display.set_type(ui::DISPLAY_CONNECTION_TYPE_INTERNAL); 908 internal_display.set_type(ui::DISPLAY_CONNECTION_TYPE_INTERNAL);
978 internal_display.set_modes(modes.get()); 909 internal_display.set_modes(modes.get());
979 internal_output.display = &internal_display; 910 internal_output.display = &internal_display;
980 outputs.push_back(internal_output); 911 outputs.push_back(internal_output);
981 912
982 ui::DisplayConfigurator::DisplayState external_output; 913 ui::DisplayConfigurator::DisplayState external_output;
983 ui::TestDisplaySnapshot external_display; 914 ui::TestDisplaySnapshot external_display;
984 external_display.set_type(ui::DISPLAY_CONNECTION_TYPE_HDMI); 915 external_display.set_type(ui::DISPLAY_CONNECTION_TYPE_HDMI);
985 external_display.set_modes(modes.get()); 916 external_display.set_modes(modes.get());
986 external_output.display = &external_display; 917 external_output.display = &external_display;
987 outputs.push_back(external_output); 918 outputs.push_back(external_output);
988 919
989 // When all of the displays are turned off (e.g. due to user inactivity), the 920 // When all of the displays are turned off (e.g. due to user inactivity), the
990 // power button should be ignored. 921 // power button should be ignored.
991 controller_->OnScreenBrightnessChanged(0.0); 922 power_button_controller_->OnScreenBrightnessChanged(0.0);
992 static_cast<ui::TestDisplaySnapshot*>(outputs[0].display) 923 static_cast<ui::TestDisplaySnapshot*>(outputs[0].display)
993 ->set_current_mode(NULL); 924 ->set_current_mode(NULL);
994 static_cast<ui::TestDisplaySnapshot*>(outputs[1].display) 925 static_cast<ui::TestDisplaySnapshot*>(outputs[1].display)
995 ->set_current_mode(NULL); 926 ->set_current_mode(NULL);
996 controller_->OnDisplayModeChanged(outputs); 927 power_button_controller_->OnDisplayModeChanged(outputs);
997 PressPowerButton(); 928 PressPowerButton();
998 EXPECT_FALSE(test_api_->is_animating_lock()); 929 EXPECT_FALSE(test_api_->is_animating_lock());
999 ReleasePowerButton(); 930 ReleasePowerButton();
1000 931
1001 // When the screen brightness is 0% but the external display is still turned 932 // 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 933 // on (indicating either docked mode or the user having manually decreased the
1003 // brightness to 0%), the power button should still be handled. 934 // brightness to 0%), the power button should still be handled.
1004 static_cast<ui::TestDisplaySnapshot*>(outputs[1].display) 935 static_cast<ui::TestDisplaySnapshot*>(outputs[1].display)
1005 ->set_current_mode(modes[0]); 936 ->set_current_mode(modes[0]);
1006 controller_->OnDisplayModeChanged(outputs); 937 power_button_controller_->OnDisplayModeChanged(outputs);
1007 PressPowerButton(); 938 PressPowerButton();
1008 EXPECT_TRUE(test_api_->is_animating_lock()); 939 EXPECT_TRUE(test_api_->is_animating_lock());
1009 ReleasePowerButton(); 940 ReleasePowerButton();
1010 } 941 }
1011 #endif 942 #endif
1012 943
1013 // Test that hidden background appears and revers correctly on lock/cancel. 944 // Test that hidden background appears and revers correctly on lock/cancel.
1014 // TODO(antrim): Reenable this: http://crbug.com/167048 945 TEST_F(LockStateControllerTest, TestHiddenBackgroundLockCancel) {
1015 TEST_F(LockStateControllerTest, DISABLED_TestHiddenBackgroundLockCancel) {
1016 Initialize(false, user::LOGGED_IN_USER); 946 Initialize(false, user::LOGGED_IN_USER);
1017 HideBackground(); 947 HideBackground();
1018 948
1019 EXPECT_TRUE(IsBackgroundHidden());
1020 ExpectUnlockedState(); 949 ExpectUnlockedState();
1021 PressPowerButton(); 950 PressPowerButton();
1022 951
1023 ExpectPreLockAnimationStarted(); 952 ExpectPreLockAnimationStarted();
1024 EXPECT_FALSE(IsBackgroundHidden());
1025 ExpectBackgroundIsShowing(); 953 ExpectBackgroundIsShowing();
1026 954
1027 // Forward only half way through. 955 // Forward only half way through.
1028 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f); 956 AdvancePartially(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE, 0.5f);
1029 957
1030 // Release the button before the lock timer fires. 958 // Release the button before the lock timer fires.
1031 ReleasePowerButton(); 959 ReleasePowerButton();
1032 ExpectPreLockAnimationCancel(); 960 ExpectPreLockAnimationCancel();
1033 ExpectBackgroundIsHiding(); 961 ExpectBackgroundIsHiding();
1034 EXPECT_FALSE(IsBackgroundHidden());
1035 962
1036 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); 963 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDO_MOVE_WINDOWS);
964
965 // When the CancelPrelockAnimation sequence finishes it queues up a
966 // restore background visibilty sequence when the background is hidden.
967 ExpectRestoringBackgroundVisibility();
968
969 Advance(SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE);
1037 970
1038 ExpectUnlockedState(); 971 ExpectUnlockedState();
1039 EXPECT_TRUE(IsBackgroundHidden());
1040 } 972 }
1041 973
1042 // Test that hidden background appears and revers correctly on lock/unlock. 974 // Test that hidden background appears and revers correctly on lock/unlock.
1043 // TODO(antrim): Reenable this: http://crbug.com/167048 975 TEST_F(LockStateControllerTest, TestHiddenBackgroundLockUnlock) {
1044 TEST_F(LockStateControllerTest, DISABLED_TestHiddenBackgroundLockUnlock) {
1045 Initialize(false, user::LOGGED_IN_USER); 976 Initialize(false, user::LOGGED_IN_USER);
1046 HideBackground(); 977 HideBackground();
1047 978
1048 EXPECT_TRUE(IsBackgroundHidden());
1049 ExpectUnlockedState(); 979 ExpectUnlockedState();
1050 980
1051 // Press the power button and check that the lock timer is started and that we 981 // Press the power button and check that the lock timer is started and that we
1052 // start lifting the non-screen-locker containers. 982 // start lifting the non-screen-locker containers.
1053 PressPowerButton(); 983 PressPowerButton();
1054 984
1055 ExpectPreLockAnimationStarted(); 985 ExpectPreLockAnimationStarted();
1056 EXPECT_FALSE(IsBackgroundHidden());
1057 ExpectBackgroundIsShowing(); 986 ExpectBackgroundIsShowing();
1058 987
1059 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE); 988 Advance(SessionStateAnimator::ANIMATION_SPEED_UNDOABLE);
1060 989
1061 ExpectPreLockAnimationFinished(); 990 ExpectPreLockAnimationFinished();
1062 991
1063 SystemLocks(); 992 SystemLocks();
1064 993
1065 ReleasePowerButton(); 994 ReleasePowerButton();
1066 995
1067 ExpectPostLockAnimationStarted(); 996 ExpectPostLockAnimationStarted();
1068 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); 997 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
1069 ExpectPastLockAnimationFinished(); 998 ExpectPostLockAnimationFinished();
1070 999
1071 ExpectLockedState(); 1000 ExpectLockedState();
1072 1001
1073 SuccessfulAuthentication(NULL); 1002 SuccessfulAuthentication(NULL);
1074 1003
1075 ExpectUnlockBeforeUIDestroyedAnimationStarted(); 1004 ExpectUnlockBeforeUIDestroyedAnimationStarted();
1076 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); 1005 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
1077 ExpectUnlockBeforeUIDestroyedAnimationFinished(); 1006 ExpectUnlockBeforeUIDestroyedAnimationFinished();
1078 1007
1079 SystemUnlocks(); 1008 SystemUnlocks();
1080 1009
1081 ExpectUnlockAfterUIDestroyedAnimationStarted(); 1010 ExpectUnlockAfterUIDestroyedAnimationStarted();
1082 ExpectBackgroundIsHiding(); 1011 ExpectBackgroundIsHiding();
1083 EXPECT_FALSE(IsBackgroundHidden());
1084 1012
1085 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS); 1013 Advance(SessionStateAnimator::ANIMATION_SPEED_MOVE_WINDOWS);
1014
1015 // When the StartUnlockAnimationAfterUIDestroyed sequence finishes it queues
1016 // up a restore background visibilty sequence when the background is hidden.
1017 ExpectRestoringBackgroundVisibility();
1018
1019 Advance(SessionStateAnimator::ANIMATION_SPEED_IMMEDIATE);
1020
1086 ExpectUnlockAfterUIDestroyedAnimationFinished(); 1021 ExpectUnlockAfterUIDestroyedAnimationFinished();
1087 EXPECT_TRUE(IsBackgroundHidden());
1088 1022
1089 ExpectUnlockedState(); 1023 ExpectUnlockedState();
1090 } 1024 }
1091 1025
1026 TEST_F(LockStateControllerTest, Screenshot) {
1027 test::TestScreenshotDelegate* delegate = GetScreenshotDelegate();
1028 delegate->set_can_take_screenshot(true);
1029
1030 EnableMaximizeMode(false);
1031
1032 // Screenshot handling should not be active when not in maximize mode.
1033 ASSERT_EQ(0, delegate->handle_take_screenshot_count());
1034 PressVolumeDown();
1035 PressPowerButton();
1036 ReleasePowerButton();
1037 ReleaseVolumeDown();
1038 EXPECT_EQ(0, delegate->handle_take_screenshot_count());
1039
1040 EnableMaximizeMode(true);
1041
1042 // Pressing power alone does not take a screenshot.
1043 PressPowerButton();
1044 ReleasePowerButton();
1045 EXPECT_EQ(0, delegate->handle_take_screenshot_count());
1046
1047 // Press & release volume then pressing power does not take a screenshot.
1048 ASSERT_EQ(0, delegate->handle_take_screenshot_count());
1049 PressVolumeDown();
1050 ReleaseVolumeDown();
1051 PressPowerButton();
1052 ReleasePowerButton();
1053 EXPECT_EQ(0, delegate->handle_take_screenshot_count());
1054
1055 // Pressing power and then volume does not take a screenshot.
1056 ASSERT_EQ(0, delegate->handle_take_screenshot_count());
1057 PressPowerButton();
1058 ReleasePowerButton();
1059 PressVolumeDown();
1060 ReleaseVolumeDown();
1061 EXPECT_EQ(0, delegate->handle_take_screenshot_count());
1062
1063 // Holding volume down and pressing power takes a screenshot.
1064 ASSERT_EQ(0, delegate->handle_take_screenshot_count());
1065 PressVolumeDown();
1066 PressPowerButton();
1067 ReleasePowerButton();
1068 ReleaseVolumeDown();
1069 EXPECT_EQ(1, delegate->handle_take_screenshot_count());
1070 }
1071
1072 // Tests that a lock action is cancellable when quick lock is turned on and
1073 // maximize mode is not active.
1074 TEST_F(LockStateControllerTest, QuickLockWhileNotInMaximizeMode) {
1075 Initialize(false, user::LOGGED_IN_USER);
1076 power_button_controller_->set_enable_quick_lock_for_test(true);
1077 EnableMaximizeMode(false);
1078
1079 PressPowerButton();
1080
1081 ExpectPreLockAnimationStarted();
1082 EXPECT_TRUE(test_api_->is_animating_lock());
1083 EXPECT_TRUE(lock_state_controller_->CanCancelLockAnimation());
1084
1085 ReleasePowerButton();
1086
1087 EXPECT_EQ(0, lock_state_controller_delegate_->num_lock_requests());
1088 }
1089
1090 // Tests that a lock action is not cancellable when quick lock is turned on and
1091 // maximize mode is active.
1092 TEST_F(LockStateControllerTest, QuickLockWhileInMaximizeMode) {
1093 Initialize(false, user::LOGGED_IN_USER);
1094 power_button_controller_->set_enable_quick_lock_for_test(true);
1095 EnableMaximizeMode(true);
1096
1097 PressPowerButton();
1098
1099 ExpectPreLockAnimationStarted();
1100 EXPECT_TRUE(test_api_->is_animating_lock());
1101 EXPECT_FALSE(lock_state_controller_->CanCancelLockAnimation());
1102
1103 ReleasePowerButton();
1104
1105 ExpectPreLockAnimationStarted();
1106
1107 test_animator_->CompleteAllAnimations(true);
1108 EXPECT_EQ(1, lock_state_controller_delegate_->num_lock_requests());
1109 }
1110
1092 } // namespace test 1111 } // namespace test
1093 } // namespace ash 1112 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698