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

Side by Side Diff: ash/system/power/tablet_power_button_controller_unittest.cc

Issue 2906803002: Rename MaximizeMode to TabletMode (Closed)
Patch Set: updated filter Created 3 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/system/power/tablet_power_button_controller.h" 5 #include "ash/system/power/tablet_power_button_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "ash/ash_switches.h" 9 #include "ash/ash_switches.h"
10 #include "ash/public/cpp/config.h" 10 #include "ash/public/cpp/config.h"
11 #include "ash/session/session_controller.h" 11 #include "ash/session/session_controller.h"
12 #include "ash/shell.h" 12 #include "ash/shell.h"
13 #include "ash/shell_port.h" 13 #include "ash/shell_port.h"
14 #include "ash/test/ash_test_base.h" 14 #include "ash/test/ash_test_base.h"
15 #include "ash/test/lock_state_controller_test_api.h" 15 #include "ash/test/lock_state_controller_test_api.h"
16 #include "ash/test/test_session_controller_client.h" 16 #include "ash/test/test_session_controller_client.h"
17 #include "ash/test/test_shell_delegate.h" 17 #include "ash/test/test_shell_delegate.h"
18 #include "ash/wm/lock_state_controller.h" 18 #include "ash/wm/lock_state_controller.h"
19 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
20 #include "ash/wm/power_button_controller.h" 19 #include "ash/wm/power_button_controller.h"
20 #include "ash/wm/tablet_mode/tablet_mode_controller.h"
21 #include "base/command_line.h" 21 #include "base/command_line.h"
22 #include "base/compiler_specific.h" 22 #include "base/compiler_specific.h"
23 #include "base/memory/ptr_util.h" 23 #include "base/memory/ptr_util.h"
24 #include "base/run_loop.h" 24 #include "base/run_loop.h"
25 #include "base/test/simple_test_tick_clock.h" 25 #include "base/test/simple_test_tick_clock.h"
26 #include "chromeos/dbus/dbus_thread_manager.h" 26 #include "chromeos/dbus/dbus_thread_manager.h"
27 #include "chromeos/dbus/fake_power_manager_client.h" 27 #include "chromeos/dbus/fake_power_manager_client.h"
28 #include "ui/events/event.h" 28 #include "ui/events/event.h"
29 #include "ui/events/test/event_generator.h" 29 #include "ui/events/test/event_generator.h"
30 30
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 105
106 void UnlockScreen() { 106 void UnlockScreen() {
107 lock_state_controller_->OnLockStateChanged(false); 107 lock_state_controller_->OnLockStateChanged(false);
108 GetSessionControllerClient()->UnlockScreen(); 108 GetSessionControllerClient()->UnlockScreen();
109 } 109 }
110 110
111 void Initialize(LoginStatus status) { 111 void Initialize(LoginStatus status) {
112 SetUserLoggedIn(status != LoginStatus::NOT_LOGGED_IN); 112 SetUserLoggedIn(status != LoginStatus::NOT_LOGGED_IN);
113 } 113 }
114 114
115 void EnableMaximizeMode(bool enabled) { 115 void EnableTabletMode(bool enabled) {
116 Shell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( 116 Shell::Get()->tablet_mode_controller()->EnableTabletModeWindowManager(
117 enabled); 117 enabled);
118 } 118 }
119 119
120 bool GetLockedState() { 120 bool GetLockedState() {
121 // LockScreen is an async mojo call. Spin message loop to ensure it is 121 // LockScreen is an async mojo call. Spin message loop to ensure it is
122 // delivered. 122 // delivered.
123 SessionController* const session_controller = 123 SessionController* const session_controller =
124 Shell::Get()->session_controller(); 124 Shell::Get()->session_controller();
125 session_controller->FlushMojoForTest(); 125 session_controller->FlushMojoForTest();
126 return session_controller->IsScreenLocked(); 126 return session_controller->IsScreenLocked();
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
295 EXPECT_TRUE(test_api_->ShutdownTimerIsRunning()); 295 EXPECT_TRUE(test_api_->ShutdownTimerIsRunning());
296 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks()); 296 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks());
297 power_manager_client_->SendBrightnessChanged(0, false); 297 power_manager_client_->SendBrightnessChanged(0, false);
298 EXPECT_FALSE(test_api_->ShutdownTimerIsRunning()); 298 EXPECT_FALSE(test_api_->ShutdownTimerIsRunning());
299 EXPECT_TRUE(GetBacklightsForcedOff()); 299 EXPECT_TRUE(GetBacklightsForcedOff());
300 } 300 }
301 301
302 // For convertible device working on laptop mode, tests keyboard/mouse event 302 // For convertible device working on laptop mode, tests keyboard/mouse event
303 // when screen is off. 303 // when screen is off.
304 TEST_F(TabletPowerButtonControllerTest, ConvertibleOnLaptopMode) { 304 TEST_F(TabletPowerButtonControllerTest, ConvertibleOnLaptopMode) {
305 EnableMaximizeMode(false); 305 EnableTabletMode(false);
306 306
307 // KeyEvent should SetBacklightsForcedOff(false). 307 // KeyEvent should SetBacklightsForcedOff(false).
308 PressPowerButton(); 308 PressPowerButton();
309 ReleasePowerButton(); 309 ReleasePowerButton();
310 power_manager_client_->SendBrightnessChanged(0, false); 310 power_manager_client_->SendBrightnessChanged(0, false);
311 ASSERT_TRUE(GetBacklightsForcedOff()); 311 ASSERT_TRUE(GetBacklightsForcedOff());
312 generator_->PressKey(ui::VKEY_L, ui::EF_NONE); 312 generator_->PressKey(ui::VKEY_L, ui::EF_NONE);
313 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); 313 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false);
314 EXPECT_FALSE(GetBacklightsForcedOff()); 314 EXPECT_FALSE(GetBacklightsForcedOff());
315 315
(...skipping 12 matching lines...) Expand all
328 power_manager_client_->SendBrightnessChanged(0, false); 328 power_manager_client_->SendBrightnessChanged(0, false);
329 ASSERT_TRUE(GetBacklightsForcedOff()); 329 ASSERT_TRUE(GetBacklightsForcedOff());
330 generator_->set_flags(ui::EF_IS_SYNTHESIZED); 330 generator_->set_flags(ui::EF_IS_SYNTHESIZED);
331 generator_->MoveMouseBy(1, 1); 331 generator_->MoveMouseBy(1, 1);
332 generator_->set_flags(ui::EF_NONE); 332 generator_->set_flags(ui::EF_NONE);
333 EXPECT_TRUE(GetBacklightsForcedOff()); 333 EXPECT_TRUE(GetBacklightsForcedOff());
334 } 334 }
335 335
336 // For convertible device working on tablet mode, keyboard/mouse event should 336 // For convertible device working on tablet mode, keyboard/mouse event should
337 // not SetBacklightsForcedOff(false) when screen is off. 337 // not SetBacklightsForcedOff(false) when screen is off.
338 TEST_F(TabletPowerButtonControllerTest, ConvertibleOnMaximizeMode) { 338 TEST_F(TabletPowerButtonControllerTest, ConvertibleOnTabletMode) {
339 EnableMaximizeMode(true); 339 EnableTabletMode(true);
340 340
341 PressPowerButton(); 341 PressPowerButton();
342 ReleasePowerButton(); 342 ReleasePowerButton();
343 power_manager_client_->SendBrightnessChanged(0, false); 343 power_manager_client_->SendBrightnessChanged(0, false);
344 ASSERT_TRUE(GetBacklightsForcedOff()); 344 ASSERT_TRUE(GetBacklightsForcedOff());
345 generator_->PressKey(ui::VKEY_L, ui::EF_NONE); 345 generator_->PressKey(ui::VKEY_L, ui::EF_NONE);
346 EXPECT_TRUE(GetBacklightsForcedOff()); 346 EXPECT_TRUE(GetBacklightsForcedOff());
347 347
348 generator_->MoveMouseBy(1, 1); 348 generator_->MoveMouseBy(1, 1);
349 EXPECT_TRUE(GetBacklightsForcedOff()); 349 EXPECT_TRUE(GetBacklightsForcedOff());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 PressPowerButton(); 382 PressPowerButton();
383 ReleasePowerButton(); 383 ReleasePowerButton();
384 power_manager_client_->SendBrightnessChanged(0, false); 384 power_manager_client_->SendBrightnessChanged(0, false);
385 EXPECT_FALSE(shell_delegate_->IsTouchscreenEnabledInPrefs(true)); 385 EXPECT_FALSE(shell_delegate_->IsTouchscreenEnabledInPrefs(true));
386 386
387 PressPowerButton(); 387 PressPowerButton();
388 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); 388 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false);
389 ReleasePowerButton(); 389 ReleasePowerButton();
390 EXPECT_TRUE(shell_delegate_->IsTouchscreenEnabledInPrefs(true)); 390 EXPECT_TRUE(shell_delegate_->IsTouchscreenEnabledInPrefs(true));
391 391
392 EnableMaximizeMode(false); 392 EnableTabletMode(false);
393 // KeyEvent on laptop mode when screen is off. 393 // KeyEvent on laptop mode when screen is off.
394 PressPowerButton(); 394 PressPowerButton();
395 ReleasePowerButton(); 395 ReleasePowerButton();
396 power_manager_client_->SendBrightnessChanged(0, false); 396 power_manager_client_->SendBrightnessChanged(0, false);
397 ASSERT_TRUE(GetBacklightsForcedOff()); 397 ASSERT_TRUE(GetBacklightsForcedOff());
398 ASSERT_FALSE(shell_delegate_->IsTouchscreenEnabledInPrefs(true)); 398 ASSERT_FALSE(shell_delegate_->IsTouchscreenEnabledInPrefs(true));
399 generator_->PressKey(ui::VKEY_L, ui::EF_NONE); 399 generator_->PressKey(ui::VKEY_L, ui::EF_NONE);
400 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); 400 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false);
401 EXPECT_TRUE(shell_delegate_->IsTouchscreenEnabledInPrefs(true)); 401 EXPECT_TRUE(shell_delegate_->IsTouchscreenEnabledInPrefs(true));
402 402
403 // MouseEvent on laptop mode when screen is off. 403 // MouseEvent on laptop mode when screen is off.
404 PressPowerButton(); 404 PressPowerButton();
405 ReleasePowerButton(); 405 ReleasePowerButton();
406 power_manager_client_->SendBrightnessChanged(0, false); 406 power_manager_client_->SendBrightnessChanged(0, false);
407 ASSERT_TRUE(GetBacklightsForcedOff()); 407 ASSERT_TRUE(GetBacklightsForcedOff());
408 ASSERT_FALSE(shell_delegate_->IsTouchscreenEnabledInPrefs(true)); 408 ASSERT_FALSE(shell_delegate_->IsTouchscreenEnabledInPrefs(true));
409 generator_->MoveMouseBy(1, 1); 409 generator_->MoveMouseBy(1, 1);
410 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); 410 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false);
411 EXPECT_TRUE(shell_delegate_->IsTouchscreenEnabledInPrefs(true)); 411 EXPECT_TRUE(shell_delegate_->IsTouchscreenEnabledInPrefs(true));
412 } 412 }
413 413
414 // When user switches convertible device between laptop mode and tablet mode, 414 // When user switches convertible device between laptop mode and tablet mode,
415 // power button may be pressed and held, which may cause unwanted shutdown. 415 // power button may be pressed and held, which may cause unwanted shutdown.
416 TEST_F(TabletPowerButtonControllerTest, 416 TEST_F(TabletPowerButtonControllerTest,
417 EnterOrLeaveMaximizeModeWhilePressingPowerButton) { 417 EnterOrLeaveTabletModeWhilePressingPowerButton) {
418 Initialize(LoginStatus::USER); 418 Initialize(LoginStatus::USER);
419 SetShouldLockScreenAutomatically(true); 419 SetShouldLockScreenAutomatically(true);
420 ASSERT_FALSE(GetLockedState()); 420 ASSERT_FALSE(GetLockedState());
421 421
422 power_manager_client_->SendPowerButtonEvent(true, tick_clock_->NowTicks()); 422 power_manager_client_->SendPowerButtonEvent(true, tick_clock_->NowTicks());
423 EXPECT_TRUE(test_api_->ShutdownTimerIsRunning()); 423 EXPECT_TRUE(test_api_->ShutdownTimerIsRunning());
424 tablet_controller_->OnMaximizeModeStarted(); 424 tablet_controller_->OnTabletModeStarted();
425 EXPECT_FALSE(test_api_->ShutdownTimerIsRunning()); 425 EXPECT_FALSE(test_api_->ShutdownTimerIsRunning());
426 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(1500)); 426 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(1500));
427 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks()); 427 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks());
428 EXPECT_FALSE(GetLockedState()); 428 EXPECT_FALSE(GetLockedState());
429 EXPECT_FALSE(GetBacklightsForcedOff()); 429 EXPECT_FALSE(GetBacklightsForcedOff());
430 430
431 power_manager_client_->SendPowerButtonEvent(true, tick_clock_->NowTicks()); 431 power_manager_client_->SendPowerButtonEvent(true, tick_clock_->NowTicks());
432 test_api_->TriggerShutdownTimeout(); 432 test_api_->TriggerShutdownTimeout();
433 EXPECT_TRUE(lock_state_test_api_->shutdown_timer_is_running()); 433 EXPECT_TRUE(lock_state_test_api_->shutdown_timer_is_running());
434 tablet_controller_->OnMaximizeModeStarted(); 434 tablet_controller_->OnTabletModeStarted();
435 EXPECT_FALSE(lock_state_test_api_->shutdown_timer_is_running()); 435 EXPECT_FALSE(lock_state_test_api_->shutdown_timer_is_running());
436 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(2500)); 436 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(2500));
437 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks()); 437 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks());
438 EXPECT_FALSE(GetLockedState()); 438 EXPECT_FALSE(GetLockedState());
439 EXPECT_FALSE(GetBacklightsForcedOff()); 439 EXPECT_FALSE(GetBacklightsForcedOff());
440 440
441 power_manager_client_->SendPowerButtonEvent(true, tick_clock_->NowTicks()); 441 power_manager_client_->SendPowerButtonEvent(true, tick_clock_->NowTicks());
442 EXPECT_TRUE(test_api_->ShutdownTimerIsRunning()); 442 EXPECT_TRUE(test_api_->ShutdownTimerIsRunning());
443 tablet_controller_->OnMaximizeModeEnded(); 443 tablet_controller_->OnTabletModeEnded();
444 EXPECT_FALSE(test_api_->ShutdownTimerIsRunning()); 444 EXPECT_FALSE(test_api_->ShutdownTimerIsRunning());
445 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(3500)); 445 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(3500));
446 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks()); 446 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks());
447 EXPECT_FALSE(GetLockedState()); 447 EXPECT_FALSE(GetLockedState());
448 EXPECT_FALSE(GetBacklightsForcedOff()); 448 EXPECT_FALSE(GetBacklightsForcedOff());
449 449
450 power_manager_client_->SendPowerButtonEvent(true, tick_clock_->NowTicks()); 450 power_manager_client_->SendPowerButtonEvent(true, tick_clock_->NowTicks());
451 test_api_->TriggerShutdownTimeout(); 451 test_api_->TriggerShutdownTimeout();
452 EXPECT_TRUE(lock_state_test_api_->shutdown_timer_is_running()); 452 EXPECT_TRUE(lock_state_test_api_->shutdown_timer_is_running());
453 tablet_controller_->OnMaximizeModeEnded(); 453 tablet_controller_->OnTabletModeEnded();
454 EXPECT_FALSE(lock_state_test_api_->shutdown_timer_is_running()); 454 EXPECT_FALSE(lock_state_test_api_->shutdown_timer_is_running());
455 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(4500)); 455 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(4500));
456 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks()); 456 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks());
457 EXPECT_FALSE(GetLockedState()); 457 EXPECT_FALSE(GetLockedState());
458 EXPECT_FALSE(GetBacklightsForcedOff()); 458 EXPECT_FALSE(GetBacklightsForcedOff());
459 } 459 }
460 460
461 // Tests that repeated power button releases are ignored (crbug.com/675291). 461 // Tests that repeated power button releases are ignored (crbug.com/675291).
462 TEST_F(TabletPowerButtonControllerTest, IgnoreRepeatedPowerButtonReleases) { 462 TEST_F(TabletPowerButtonControllerTest, IgnoreRepeatedPowerButtonReleases) {
463 // Advance a long duration from initialized last resume time in 463 // Advance a long duration from initialized last resume time in
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 553
554 SendAccelerometerUpdate(); 554 SendAccelerometerUpdate();
555 tablet_controller_ = Shell::Get() 555 tablet_controller_ = Shell::Get()
556 ->power_button_controller() 556 ->power_button_controller()
557 ->tablet_power_button_controller_for_test(); 557 ->tablet_power_button_controller_for_test();
558 EXPECT_TRUE(tablet_controller_); 558 EXPECT_TRUE(tablet_controller_);
559 } 559 }
560 560
561 } // namespace test 561 } // namespace test
562 } // namespace ash 562 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698