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

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

Issue 9348089: Make power button controller restore to original transformation on the layer. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: udpate. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/wm/power_button_controller.h" 5 #include "ash/wm/power_button_controller.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/test/aura_shell_test_base.h" 8 #include "ash/test/aura_shell_test_base.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/time.h" 10 #include "base/time.h"
11 #include "ui/aura/root_window.h" 11 #include "ui/aura/root_window.h"
12 #include "ui/aura/window.h"
12 13
13 namespace ash { 14 namespace ash {
14 namespace test { 15 namespace test {
15 16
16 // Fake implementation of PowerButtonControllerDelegate that just logs requests 17 // Fake implementation of PowerButtonControllerDelegate that just logs requests
17 // to lock the screen and shut down the device. 18 // to lock the screen and shut down the device.
18 class TestPowerButtonControllerDelegate : public PowerButtonControllerDelegate { 19 class TestPowerButtonControllerDelegate : public PowerButtonControllerDelegate {
19 public: 20 public:
20 TestPowerButtonControllerDelegate() 21 TestPowerButtonControllerDelegate()
21 : num_lock_requests_(0), 22 : num_lock_requests_(0),
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 // Notify that the screen has been unlocked. We should show the 266 // Notify that the screen has been unlocked. We should show the
266 // non-screen-locker windows and hide the background layer. 267 // non-screen-locker windows and hide the background layer.
267 controller_->OnLockStateChange(false); 268 controller_->OnLockStateChange(false);
268 EXPECT_TRUE( 269 EXPECT_TRUE(
269 test_api_->ContainerGroupIsAnimated( 270 test_api_->ContainerGroupIsAnimated(
270 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, 271 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
271 PowerButtonController::ANIMATION_RESTORE)); 272 PowerButtonController::ANIMATION_RESTORE));
272 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible()); 273 EXPECT_FALSE(test_api_->BackgroundLayerIsVisible());
273 } 274 }
274 275
276 // Test that we restore transformation that are non empty.
Daniel Erat 2012/02/15 05:50:03 s/transformation/transformations/
alicet1 2012/02/15 20:48:53 Done.
277 TEST_F(PowerButtonControllerTest, LockAndUnlockTransformed) {
278 controller_->set_has_legacy_power_button_for_test(false);
279 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/);
280 controller_->OnLockStateChange(false);
281
282 // Get current transformation on the containers.
283 aura::Window::Windows windows;
284 test_api_->GetContainerWindows(
285 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
286 &windows);
287
288 // Set a random transform to each container layer.
289 ui::Transform expected_transform;
290 expected_transform.ConcatTranslate(180, 180);
291 for (aura::Window::Windows::iterator it = windows.begin();
292 it != windows.end();
293 ++it) {
294 (*it)->layer()->SetTransform(expected_transform);
295 }
296
297 // Press the power button and check that the lock timer is started and that we
298 // start scaling the non-screen-locker containers.
299 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
300 EXPECT_TRUE(test_api_->lock_timer_is_running());
301 EXPECT_FALSE(test_api_->shutdown_timer_is_running());
302 EXPECT_TRUE(
303 test_api_->ContainerGroupIsAnimated(
304 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
305 PowerButtonController::ANIMATION_SLOW_CLOSE));
306
307 // Check current transformation is different than before.
308 windows.clear();
309 test_api_->GetContainerWindows(
310 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
311 &windows);
312 for (aura::Window::Windows::iterator it = windows.begin();
313 it != windows.end();
314 ++it) {
315 EXPECT_FALSE(expected_transform == (*it)->layer()->GetTargetTransform());
Daniel Erat 2012/02/15 05:50:03 EXPECT_NE?
alicet1 2012/02/15 20:48:53 Done.
316 }
317
318 // Release the button before the lock timer fires.
319 controller_->OnPowerButtonEvent(false, base::TimeTicks::Now());
320 EXPECT_FALSE(test_api_->lock_timer_is_running());
321 EXPECT_TRUE(
322 test_api_->ContainerGroupIsAnimated(
323 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
324 PowerButtonController::ANIMATION_UNDO_SLOW_CLOSE));
325
326 // Get current transformation on the containers to compare,
327 // it shouldn't have changed.
328 windows.clear();
329 test_api_->GetContainerWindows(
330 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
331 &windows);
332 for (aura::Window::Windows::iterator it = windows.begin();
333 it != windows.end();
334 ++it) {
335 EXPECT_EQ(expected_transform, (*it)->layer()->GetTargetTransform());
336 }
337 }
338
275 // Hold the power button down from the unlocked state to eventual shutdown. 339 // Hold the power button down from the unlocked state to eventual shutdown.
276 TEST_F(PowerButtonControllerTest, LockToShutdown) { 340 TEST_F(PowerButtonControllerTest, LockToShutdown) {
277 controller_->set_has_legacy_power_button_for_test(false); 341 controller_->set_has_legacy_power_button_for_test(false);
278 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/); 342 controller_->OnLoginStateChange(true /*logged_in*/, false /*is_guest*/);
279 controller_->OnLockStateChange(false); 343 controller_->OnLockStateChange(false);
280 344
281 // Hold the power button and lock the screen. 345 // Hold the power button and lock the screen.
282 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); 346 controller_->OnPowerButtonEvent(true, base::TimeTicks::Now());
283 EXPECT_TRUE(test_api_->lock_timer_is_running()); 347 EXPECT_TRUE(test_api_->lock_timer_is_running());
284 test_api_->trigger_lock_timeout(); 348 test_api_->trigger_lock_timeout();
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 controller_->OnStartingLock(); 523 controller_->OnStartingLock();
460 EXPECT_TRUE( 524 EXPECT_TRUE(
461 test_api_->ContainerGroupIsAnimated( 525 test_api_->ContainerGroupIsAnimated(
462 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS, 526 PowerButtonController::ALL_BUT_SCREEN_LOCKER_AND_RELATED_CONTAINERS,
463 PowerButtonController::ANIMATION_FAST_CLOSE)); 527 PowerButtonController::ANIMATION_FAST_CLOSE));
464 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible()); 528 EXPECT_TRUE(test_api_->BackgroundLayerIsVisible());
465 } 529 }
466 530
467 } // namespace test 531 } // namespace test
468 } // namespace ash 532 } // namespace ash
OLDNEW
« ash/wm/power_button_controller.cc ('K') | « ash/wm/power_button_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698