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

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

Issue 2533373002: Enabled/disable touch screen in TabletPowerButtonController (Closed)
Patch Set: nits Created 4 years 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/chromeos/power/tablet_power_button_controller.h" 5 #include "ash/system/chromeos/power/tablet_power_button_controller.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "ash/common/ash_switches.h" 9 #include "ash/common/ash_switches.h"
10 #include "ash/common/session/session_state_delegate.h" 10 #include "ash/common/session/session_state_delegate.h"
11 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" 11 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
12 #include "ash/common/wm_shell.h" 12 #include "ash/common/wm_shell.h"
13 #include "ash/shell.h" 13 #include "ash/shell.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_shell_delegate.h"
16 #include "ash/wm/lock_state_controller.h" 17 #include "ash/wm/lock_state_controller.h"
17 #include "ash/wm/power_button_controller.h" 18 #include "ash/wm/power_button_controller.h"
18 #include "base/command_line.h" 19 #include "base/command_line.h"
19 #include "base/compiler_specific.h" 20 #include "base/compiler_specific.h"
20 #include "base/run_loop.h" 21 #include "base/run_loop.h"
21 #include "base/test/simple_test_tick_clock.h" 22 #include "base/test/simple_test_tick_clock.h"
22 #include "chromeos/dbus/dbus_thread_manager.h" 23 #include "chromeos/dbus/dbus_thread_manager.h"
23 #include "chromeos/dbus/fake_power_manager_client.h" 24 #include "chromeos/dbus/fake_power_manager_client.h"
24 #include "ui/events/event.h" 25 #include "ui/events/event.h"
25 #include "ui/events/test/event_generator.h" 26 #include "ui/events/test/event_generator.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 58
58 lock_state_controller_ = Shell::GetInstance()->lock_state_controller(); 59 lock_state_controller_ = Shell::GetInstance()->lock_state_controller();
59 tablet_controller_ = Shell::GetInstance() 60 tablet_controller_ = Shell::GetInstance()
60 ->power_button_controller() 61 ->power_button_controller()
61 ->tablet_power_button_controller_for_test(); 62 ->tablet_power_button_controller_for_test();
62 test_api_ = base::MakeUnique<TabletPowerButtonController::TestApi>( 63 test_api_ = base::MakeUnique<TabletPowerButtonController::TestApi>(
63 tablet_controller_); 64 tablet_controller_);
64 tick_clock_ = new base::SimpleTestTickClock; 65 tick_clock_ = new base::SimpleTestTickClock;
65 tablet_controller_->SetTickClockForTesting( 66 tablet_controller_->SetTickClockForTesting(
66 std::unique_ptr<base::TickClock>(tick_clock_)); 67 std::unique_ptr<base::TickClock>(tick_clock_));
68 shell_delegate_ =
69 static_cast<TestShellDelegate*>(WmShell::Get()->delegate());
67 generator_ = &AshTestBase::GetEventGenerator(); 70 generator_ = &AshTestBase::GetEventGenerator();
68 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); 71 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false);
69 EXPECT_FALSE(GetBacklightsForcedOff()); 72 EXPECT_FALSE(GetBacklightsForcedOff());
70 } 73 }
71 74
72 void TearDown() override { 75 void TearDown() override {
73 generator_ = nullptr; 76 generator_ = nullptr;
74 AshTestBase::TearDown(); 77 AshTestBase::TearDown();
75 chromeos::DBusThreadManager::Shutdown(); 78 chromeos::DBusThreadManager::Shutdown();
76 } 79 }
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 return forced_off; 115 return forced_off;
113 } 116 }
114 117
115 // Ownership is passed on to chromeos::DBusThreadManager. 118 // Ownership is passed on to chromeos::DBusThreadManager.
116 chromeos::FakePowerManagerClient* power_manager_client_; 119 chromeos::FakePowerManagerClient* power_manager_client_;
117 120
118 LockStateController* lock_state_controller_; // Not owned. 121 LockStateController* lock_state_controller_; // Not owned.
119 TabletPowerButtonController* tablet_controller_; // Not owned. 122 TabletPowerButtonController* tablet_controller_; // Not owned.
120 std::unique_ptr<TabletPowerButtonController::TestApi> test_api_; 123 std::unique_ptr<TabletPowerButtonController::TestApi> test_api_;
121 base::SimpleTestTickClock* tick_clock_; // Not owned. 124 base::SimpleTestTickClock* tick_clock_; // Not owned.
125 TestShellDelegate* shell_delegate_; // Not owned.
122 ui::test::EventGenerator* generator_ = nullptr; 126 ui::test::EventGenerator* generator_ = nullptr;
123 127
124 DISALLOW_COPY_AND_ASSIGN(TabletPowerButtonControllerTest); 128 DISALLOW_COPY_AND_ASSIGN(TabletPowerButtonControllerTest);
125 }; 129 };
126 130
127 TEST_F(TabletPowerButtonControllerTest, LockScreenIfRequired) { 131 TEST_F(TabletPowerButtonControllerTest, LockScreenIfRequired) {
128 Initialize(LoginStatus::USER); 132 Initialize(LoginStatus::USER);
129 SetShouldLockScreenAutomatically(true); 133 SetShouldLockScreenAutomatically(true);
130 EXPECT_FALSE(GetLockedState()); 134 EXPECT_FALSE(GetLockedState());
131 135
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 PressPowerButton(); 353 PressPowerButton();
350 tablet_controller_->OnKeyEvent(&power_key_pressed); 354 tablet_controller_->OnKeyEvent(&power_key_pressed);
351 tablet_controller_->OnKeyEvent(&power_key_pressed); 355 tablet_controller_->OnKeyEvent(&power_key_pressed);
352 tablet_controller_->OnKeyEvent(&power_key_pressed); 356 tablet_controller_->OnKeyEvent(&power_key_pressed);
353 ReleasePowerButton(); 357 ReleasePowerButton();
354 tablet_controller_->OnKeyEvent(&power_key_released); 358 tablet_controller_->OnKeyEvent(&power_key_released);
355 tablet_controller_->OnKeyEvent(&power_key_released); 359 tablet_controller_->OnKeyEvent(&power_key_released);
356 EXPECT_EQ(1, power_manager_client_->num_set_backlights_forced_off_calls()); 360 EXPECT_EQ(1, power_manager_client_->num_set_backlights_forced_off_calls());
357 } 361 }
358 362
363 // Tests that under (1) tablet power button pressed/released, (2) keyboard/mouse
364 // events on laptop mode when screen is off, requesting/stopping backlights
365 // forced off should also set corresponding touch screen state in local pref.
366 TEST_F(TabletPowerButtonControllerTest, TouchScreenState) {
367 // Tests tablet power button.
368 EXPECT_TRUE(shell_delegate_->IsTouchscreenEnabledInPrefs(true));
369 PressPowerButton();
370 ReleasePowerButton();
371 power_manager_client_->SendBrightnessChanged(0, false);
372 EXPECT_FALSE(shell_delegate_->IsTouchscreenEnabledInPrefs(true));
373
374 PressPowerButton();
375 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false);
376 ReleasePowerButton();
377 EXPECT_TRUE(shell_delegate_->IsTouchscreenEnabledInPrefs(true));
378
379 EnableMaximizeMode(false);
380 // KeyEvent on laptop mode when screen is off.
381 PressPowerButton();
382 ReleasePowerButton();
383 power_manager_client_->SendBrightnessChanged(0, false);
384 EXPECT_TRUE(GetBacklightsForcedOff());
385 EXPECT_FALSE(shell_delegate_->IsTouchscreenEnabledInPrefs(true));
386 generator_->PressKey(ui::VKEY_L, ui::EF_NONE);
387 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false);
388 EXPECT_TRUE(shell_delegate_->IsTouchscreenEnabledInPrefs(true));
389
390 // MouseEvent on laptop mode when screen is off.
391 PressPowerButton();
392 ReleasePowerButton();
393 power_manager_client_->SendBrightnessChanged(0, false);
394 EXPECT_TRUE(GetBacklightsForcedOff());
395 EXPECT_FALSE(shell_delegate_->IsTouchscreenEnabledInPrefs(true));
396 generator_->MoveMouseBy(1, 1);
397 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false);
398 EXPECT_TRUE(shell_delegate_->IsTouchscreenEnabledInPrefs(true));
399 }
400
359 } // namespace test 401 } // namespace test
360 } // namespace ash 402 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/chromeos/power/tablet_power_button_controller.cc ('k') | ash/test/test_shell_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698