OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/system/chromeos/power/tablet_power_button_controller.h" | |
6 | |
7 #include <memory> | |
8 | |
9 #include "ash/common/ash_switches.h" | |
10 #include "ash/common/session/session_state_delegate.h" | |
11 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" | |
12 #include "ash/common/wm_shell.h" | |
13 #include "ash/shell.h" | |
14 #include "ash/test/ash_test_base.h" | |
15 #include "ash/test/lock_state_controller_test_api.h" | |
16 #include "ash/test/test_shell_delegate.h" | |
17 #include "ash/wm/lock_state_controller.h" | |
18 #include "ash/wm/power_button_controller.h" | |
19 #include "base/command_line.h" | |
20 #include "base/compiler_specific.h" | |
21 #include "base/memory/ptr_util.h" | |
22 #include "base/run_loop.h" | |
23 #include "base/test/simple_test_tick_clock.h" | |
24 #include "chromeos/dbus/dbus_thread_manager.h" | |
25 #include "chromeos/dbus/fake_power_manager_client.h" | |
26 #include "ui/events/event.h" | |
27 #include "ui/events/test/event_generator.h" | |
28 | |
29 namespace ash { | |
30 namespace test { | |
31 | |
32 namespace { | |
33 | |
34 // A non-zero brightness used for test. | |
35 constexpr int kNonZeroBrightness = 10; | |
36 | |
37 void CopyResult(bool* dest, bool src) { | |
38 *dest = src; | |
39 } | |
40 | |
41 } // namespace | |
42 | |
43 class TabletPowerButtonControllerTest : public AshTestBase { | |
44 public: | |
45 TabletPowerButtonControllerTest() {} | |
46 ~TabletPowerButtonControllerTest() override {} | |
47 | |
48 void SetUp() override { | |
49 // This also initializes DBusThreadManager. | |
50 std::unique_ptr<chromeos::DBusThreadManagerSetter> dbus_setter = | |
51 chromeos::DBusThreadManager::GetSetterForTesting(); | |
52 power_manager_client_ = new chromeos::FakePowerManagerClient(); | |
53 dbus_setter->SetPowerManagerClient(base::WrapUnique(power_manager_client_)); | |
54 base::CommandLine::ForCurrentProcess()->AppendSwitch( | |
55 switches::kAshEnableTouchView); | |
56 AshTestBase::SetUp(); | |
57 | |
58 lock_state_controller_ = Shell::GetInstance()->lock_state_controller(); | |
59 tablet_controller_ = Shell::GetInstance() | |
60 ->power_button_controller() | |
61 ->tablet_power_button_controller_for_test(); | |
62 test_api_ = base::MakeUnique<TabletPowerButtonController::TestApi>( | |
63 tablet_controller_); | |
64 lock_state_test_api_ = | |
65 base::MakeUnique<LockStateControllerTestApi>(lock_state_controller_); | |
66 tick_clock_ = new base::SimpleTestTickClock; | |
67 tablet_controller_->SetTickClockForTesting( | |
68 std::unique_ptr<base::TickClock>(tick_clock_)); | |
69 shell_delegate_ = | |
70 static_cast<TestShellDelegate*>(WmShell::Get()->delegate()); | |
71 generator_ = &AshTestBase::GetEventGenerator(); | |
72 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); | |
73 EXPECT_FALSE(GetBacklightsForcedOff()); | |
74 } | |
75 | |
76 void TearDown() override { | |
77 generator_ = nullptr; | |
78 const bool is_mash = WmShell::Get()->IsRunningInMash(); | |
79 AshTestBase::TearDown(); | |
80 // Mash shuts down dbus after each test. | |
81 if (!is_mash) | |
82 chromeos::DBusThreadManager::Shutdown(); | |
83 } | |
84 | |
85 protected: | |
86 void PressPowerButton() { | |
87 tablet_controller_->OnPowerButtonEvent(true, base::TimeTicks::Now()); | |
88 } | |
89 | |
90 void ReleasePowerButton() { | |
91 tablet_controller_->OnPowerButtonEvent(false, base::TimeTicks::Now()); | |
92 } | |
93 | |
94 void UnlockScreen() { | |
95 lock_state_controller_->OnLockStateChanged(false); | |
96 WmShell::Get()->GetSessionStateDelegate()->UnlockScreen(); | |
97 } | |
98 | |
99 void Initialize(LoginStatus status) { | |
100 lock_state_controller_->OnLoginStateChanged(status); | |
101 SetUserLoggedIn(status != LoginStatus::NOT_LOGGED_IN); | |
102 lock_state_controller_->OnLockStateChanged(false); | |
103 } | |
104 | |
105 void EnableMaximizeMode(bool enabled) { | |
106 WmShell::Get()->maximize_mode_controller()->EnableMaximizeModeWindowManager( | |
107 enabled); | |
108 } | |
109 | |
110 bool GetLockedState() { | |
111 return WmShell::Get()->GetSessionStateDelegate()->IsScreenLocked(); | |
112 } | |
113 | |
114 bool GetBacklightsForcedOff() WARN_UNUSED_RESULT { | |
115 bool forced_off = false; | |
116 power_manager_client_->GetBacklightsForcedOff( | |
117 base::Bind(&CopyResult, base::Unretained(&forced_off))); | |
118 base::RunLoop().RunUntilIdle(); | |
119 return forced_off; | |
120 } | |
121 | |
122 // Ownership is passed on to chromeos::DBusThreadManager. | |
123 chromeos::FakePowerManagerClient* power_manager_client_; | |
124 | |
125 LockStateController* lock_state_controller_; // Not owned. | |
126 TabletPowerButtonController* tablet_controller_; // Not owned. | |
127 std::unique_ptr<TabletPowerButtonController::TestApi> test_api_; | |
128 std::unique_ptr<LockStateControllerTestApi> lock_state_test_api_; | |
129 base::SimpleTestTickClock* tick_clock_; // Not owned. | |
130 TestShellDelegate* shell_delegate_; // Not owned. | |
131 ui::test::EventGenerator* generator_ = nullptr; | |
132 | |
133 DISALLOW_COPY_AND_ASSIGN(TabletPowerButtonControllerTest); | |
134 }; | |
135 | |
136 TEST_F(TabletPowerButtonControllerTest, LockScreenIfRequired) { | |
137 Initialize(LoginStatus::USER); | |
138 SetShouldLockScreenAutomatically(true); | |
139 EXPECT_FALSE(GetLockedState()); | |
140 | |
141 // On User logged in status, power-button-press-release should lock screen if | |
142 // automatic screen-locking was requested. | |
143 PressPowerButton(); | |
144 ReleasePowerButton(); | |
145 EXPECT_TRUE(GetLockedState()); | |
146 | |
147 // On locked state, power-button-press-release should do nothing. | |
148 PressPowerButton(); | |
149 ReleasePowerButton(); | |
150 EXPECT_TRUE(GetLockedState()); | |
151 | |
152 // Unlock the sceen. | |
153 UnlockScreen(); | |
154 ASSERT_FALSE(GetLockedState()); | |
155 | |
156 // power-button-press-release should not lock the screen if automatic | |
157 // screen-locking wasn't requested. | |
158 SetShouldLockScreenAutomatically(false); | |
159 PressPowerButton(); | |
160 ReleasePowerButton(); | |
161 EXPECT_FALSE(GetLockedState()); | |
162 } | |
163 | |
164 // Tests that shutdown animation is not started if the power button is released | |
165 // quickly. | |
166 TEST_F(TabletPowerButtonControllerTest, | |
167 ReleasePowerButtonBeforeStartingShutdownAnimation) { | |
168 PressPowerButton(); | |
169 EXPECT_TRUE(test_api_->ShutdownTimerIsRunning()); | |
170 EXPECT_FALSE(GetBacklightsForcedOff()); | |
171 ReleasePowerButton(); | |
172 power_manager_client_->SendBrightnessChanged(0, false); | |
173 EXPECT_FALSE(test_api_->ShutdownTimerIsRunning()); | |
174 EXPECT_TRUE(GetBacklightsForcedOff()); | |
175 | |
176 PressPowerButton(); | |
177 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); | |
178 EXPECT_TRUE(test_api_->ShutdownTimerIsRunning()); | |
179 EXPECT_FALSE(GetBacklightsForcedOff()); | |
180 ReleasePowerButton(); | |
181 EXPECT_FALSE(test_api_->ShutdownTimerIsRunning()); | |
182 EXPECT_FALSE(GetBacklightsForcedOff()); | |
183 } | |
184 | |
185 // Tests that the shutdown animation is started when the power button is | |
186 // released after the timer fires. | |
187 TEST_F(TabletPowerButtonControllerTest, | |
188 ReleasePowerButtonDuringShutdownAnimation) { | |
189 PressPowerButton(); | |
190 test_api_->TriggerShutdownTimeout(); | |
191 EXPECT_TRUE(lock_state_test_api_->shutdown_timer_is_running()); | |
192 ReleasePowerButton(); | |
193 EXPECT_FALSE(lock_state_test_api_->shutdown_timer_is_running()); | |
194 EXPECT_FALSE(GetBacklightsForcedOff()); | |
195 | |
196 // Test again when backlights is forced off. | |
197 PressPowerButton(); | |
198 ReleasePowerButton(); | |
199 power_manager_client_->SendBrightnessChanged(0, false); | |
200 EXPECT_TRUE(GetBacklightsForcedOff()); | |
201 | |
202 PressPowerButton(); | |
203 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); | |
204 EXPECT_FALSE(GetBacklightsForcedOff()); | |
205 test_api_->TriggerShutdownTimeout(); | |
206 EXPECT_TRUE(lock_state_test_api_->shutdown_timer_is_running()); | |
207 ReleasePowerButton(); | |
208 EXPECT_FALSE(lock_state_test_api_->shutdown_timer_is_running()); | |
209 EXPECT_FALSE(GetBacklightsForcedOff()); | |
210 } | |
211 | |
212 // Tests tapping power button when screen is idle off. | |
213 TEST_F(TabletPowerButtonControllerTest, TappingPowerButtonWhenScreenIsIdleOff) { | |
214 power_manager_client_->SendBrightnessChanged(0, false); | |
215 PressPowerButton(); | |
216 EXPECT_FALSE(GetBacklightsForcedOff()); | |
217 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); | |
218 ReleasePowerButton(); | |
219 EXPECT_FALSE(GetBacklightsForcedOff()); | |
220 } | |
221 | |
222 // Tests tapping power button when device is suspended without backlights forced | |
223 // off. | |
224 TEST_F(TabletPowerButtonControllerTest, | |
225 TappingPowerButtonWhenSuspendedWithoutBacklightsForcedOff) { | |
226 power_manager_client_->SendSuspendImminent(); | |
227 power_manager_client_->SendBrightnessChanged(0, false); | |
228 // There is a power button pressed here, but PowerButtonEvent is sent later. | |
229 power_manager_client_->SendSuspendDone(); | |
230 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); | |
231 | |
232 // Send the power button event after a short delay and check that backlights | |
233 // are not forced off. | |
234 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(500)); | |
235 power_manager_client_->SendPowerButtonEvent(true, tick_clock_->NowTicks()); | |
236 EXPECT_TRUE(test_api_->ShutdownTimerIsRunning()); | |
237 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks()); | |
238 EXPECT_FALSE(test_api_->ShutdownTimerIsRunning()); | |
239 EXPECT_FALSE(GetBacklightsForcedOff()); | |
240 | |
241 // Send the power button event after a longer delay and check that backlights | |
242 // are forced off. | |
243 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(1600)); | |
244 power_manager_client_->SendPowerButtonEvent(true, tick_clock_->NowTicks()); | |
245 EXPECT_TRUE(test_api_->ShutdownTimerIsRunning()); | |
246 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks()); | |
247 power_manager_client_->SendBrightnessChanged(0, false); | |
248 EXPECT_FALSE(test_api_->ShutdownTimerIsRunning()); | |
249 EXPECT_TRUE(GetBacklightsForcedOff()); | |
250 } | |
251 | |
252 // Tests tapping power button when device is suspended with backlights forced | |
253 // off. | |
254 TEST_F(TabletPowerButtonControllerTest, | |
255 TappingPowerButtonWhenSuspendedWithBacklightsForcedOff) { | |
256 PressPowerButton(); | |
257 ReleasePowerButton(); | |
258 power_manager_client_->SendBrightnessChanged(0, false); | |
259 EXPECT_TRUE(GetBacklightsForcedOff()); | |
260 power_manager_client_->SendSuspendImminent(); | |
261 // There is a power button pressed here, but PowerButtonEvent is sent later. | |
262 // Because of backlights forced off, resuming system will not restore | |
263 // brightness. | |
264 power_manager_client_->SendSuspendDone(); | |
265 | |
266 // Send the power button event after a short delay and check that backlights | |
267 // are not forced off. | |
268 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(500)); | |
269 power_manager_client_->SendPowerButtonEvent(true, tick_clock_->NowTicks()); | |
270 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); | |
271 EXPECT_TRUE(test_api_->ShutdownTimerIsRunning()); | |
272 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks()); | |
273 EXPECT_FALSE(test_api_->ShutdownTimerIsRunning()); | |
274 EXPECT_FALSE(GetBacklightsForcedOff()); | |
275 | |
276 // Send the power button event after a longer delay and check that backlights | |
277 // are forced off. | |
278 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(1600)); | |
279 power_manager_client_->SendPowerButtonEvent(true, tick_clock_->NowTicks()); | |
280 EXPECT_TRUE(test_api_->ShutdownTimerIsRunning()); | |
281 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks()); | |
282 power_manager_client_->SendBrightnessChanged(0, false); | |
283 EXPECT_FALSE(test_api_->ShutdownTimerIsRunning()); | |
284 EXPECT_TRUE(GetBacklightsForcedOff()); | |
285 } | |
286 | |
287 // For convertible device working on laptop mode, tests keyboard/mouse event | |
288 // when screen is off. | |
289 TEST_F(TabletPowerButtonControllerTest, ConvertibleOnLaptopMode) { | |
290 EnableMaximizeMode(false); | |
291 | |
292 // KeyEvent should SetBacklightsForcedOff(false). | |
293 PressPowerButton(); | |
294 ReleasePowerButton(); | |
295 power_manager_client_->SendBrightnessChanged(0, false); | |
296 EXPECT_TRUE(GetBacklightsForcedOff()); | |
297 generator_->PressKey(ui::VKEY_L, ui::EF_NONE); | |
298 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); | |
299 EXPECT_FALSE(GetBacklightsForcedOff()); | |
300 | |
301 // Regular mouse event should SetBacklightsForcedOff(false). | |
302 PressPowerButton(); | |
303 ReleasePowerButton(); | |
304 power_manager_client_->SendBrightnessChanged(0, false); | |
305 EXPECT_TRUE(GetBacklightsForcedOff()); | |
306 generator_->MoveMouseBy(1, 1); | |
307 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); | |
308 EXPECT_FALSE(GetBacklightsForcedOff()); | |
309 | |
310 // Synthesized mouse event should not SetBacklightsForcedOff(false). | |
311 PressPowerButton(); | |
312 ReleasePowerButton(); | |
313 power_manager_client_->SendBrightnessChanged(0, false); | |
314 EXPECT_TRUE(GetBacklightsForcedOff()); | |
315 generator_->set_flags(ui::EF_IS_SYNTHESIZED); | |
316 generator_->MoveMouseBy(1, 1); | |
317 generator_->set_flags(ui::EF_NONE); | |
318 EXPECT_TRUE(GetBacklightsForcedOff()); | |
319 } | |
320 | |
321 // For convertible device working on tablet mode, keyboard/mouse event should | |
322 // not SetBacklightsForcedOff(false) when screen is off. | |
323 TEST_F(TabletPowerButtonControllerTest, ConvertibleOnMaximizeMode) { | |
324 EnableMaximizeMode(true); | |
325 | |
326 PressPowerButton(); | |
327 ReleasePowerButton(); | |
328 power_manager_client_->SendBrightnessChanged(0, false); | |
329 EXPECT_TRUE(GetBacklightsForcedOff()); | |
330 generator_->PressKey(ui::VKEY_L, ui::EF_NONE); | |
331 EXPECT_TRUE(GetBacklightsForcedOff()); | |
332 | |
333 generator_->MoveMouseBy(1, 1); | |
334 EXPECT_TRUE(GetBacklightsForcedOff()); | |
335 } | |
336 | |
337 // Tests that a single set of power button pressed-and-released operation should | |
338 // cause only one SetBacklightsForcedOff call. | |
339 TEST_F(TabletPowerButtonControllerTest, IgnorePowerOnKeyEvent) { | |
340 ui::KeyEvent power_key_pressed(ui::ET_KEY_PRESSED, ui::VKEY_POWER, | |
341 ui::EF_NONE); | |
342 ui::KeyEvent power_key_released(ui::ET_KEY_RELEASED, ui::VKEY_POWER, | |
343 ui::EF_NONE); | |
344 | |
345 // There are two |power_key_pressed| events and |power_key_released| events | |
346 // generated for each pressing and releasing, and multiple repeating pressed | |
347 // events depending on holding. | |
348 tablet_controller_->OnKeyEvent(&power_key_pressed); | |
349 tablet_controller_->OnKeyEvent(&power_key_pressed); | |
350 PressPowerButton(); | |
351 tablet_controller_->OnKeyEvent(&power_key_pressed); | |
352 tablet_controller_->OnKeyEvent(&power_key_pressed); | |
353 tablet_controller_->OnKeyEvent(&power_key_pressed); | |
354 ReleasePowerButton(); | |
355 tablet_controller_->OnKeyEvent(&power_key_released); | |
356 tablet_controller_->OnKeyEvent(&power_key_released); | |
357 EXPECT_EQ(1, power_manager_client_->num_set_backlights_forced_off_calls()); | |
358 } | |
359 | |
360 // Tests that under (1) tablet power button pressed/released, (2) keyboard/mouse | |
361 // events on laptop mode when screen is off, requesting/stopping backlights | |
362 // forced off should also set corresponding touch screen state in local pref. | |
363 TEST_F(TabletPowerButtonControllerTest, TouchScreenState) { | |
364 // Tests tablet power button. | |
365 EXPECT_TRUE(shell_delegate_->IsTouchscreenEnabledInPrefs(true)); | |
366 PressPowerButton(); | |
367 ReleasePowerButton(); | |
368 power_manager_client_->SendBrightnessChanged(0, false); | |
369 EXPECT_FALSE(shell_delegate_->IsTouchscreenEnabledInPrefs(true)); | |
370 | |
371 PressPowerButton(); | |
372 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); | |
373 ReleasePowerButton(); | |
374 EXPECT_TRUE(shell_delegate_->IsTouchscreenEnabledInPrefs(true)); | |
375 | |
376 EnableMaximizeMode(false); | |
377 // KeyEvent on laptop mode when screen is off. | |
378 PressPowerButton(); | |
379 ReleasePowerButton(); | |
380 power_manager_client_->SendBrightnessChanged(0, false); | |
381 EXPECT_TRUE(GetBacklightsForcedOff()); | |
382 EXPECT_FALSE(shell_delegate_->IsTouchscreenEnabledInPrefs(true)); | |
383 generator_->PressKey(ui::VKEY_L, ui::EF_NONE); | |
384 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); | |
385 EXPECT_TRUE(shell_delegate_->IsTouchscreenEnabledInPrefs(true)); | |
386 | |
387 // MouseEvent on laptop mode when screen is off. | |
388 PressPowerButton(); | |
389 ReleasePowerButton(); | |
390 power_manager_client_->SendBrightnessChanged(0, false); | |
391 EXPECT_TRUE(GetBacklightsForcedOff()); | |
392 EXPECT_FALSE(shell_delegate_->IsTouchscreenEnabledInPrefs(true)); | |
393 generator_->MoveMouseBy(1, 1); | |
394 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); | |
395 EXPECT_TRUE(shell_delegate_->IsTouchscreenEnabledInPrefs(true)); | |
396 } | |
397 | |
398 // When user switches convertible device between laptop mode and tablet mode, | |
399 // power button may be pressed and held, which may cause unwanted shutdown. | |
400 TEST_F(TabletPowerButtonControllerTest, | |
401 EnterOrLeaveMaximizeModeWhilePressingPowerButton) { | |
402 Initialize(LoginStatus::USER); | |
403 SetShouldLockScreenAutomatically(true); | |
404 EXPECT_FALSE(GetLockedState()); | |
405 | |
406 power_manager_client_->SendPowerButtonEvent(true, tick_clock_->NowTicks()); | |
407 EXPECT_TRUE(test_api_->ShutdownTimerIsRunning()); | |
408 tablet_controller_->OnMaximizeModeStarted(); | |
409 EXPECT_FALSE(test_api_->ShutdownTimerIsRunning()); | |
410 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(1500)); | |
411 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks()); | |
412 EXPECT_FALSE(GetLockedState()); | |
413 EXPECT_FALSE(GetBacklightsForcedOff()); | |
414 | |
415 power_manager_client_->SendPowerButtonEvent(true, tick_clock_->NowTicks()); | |
416 test_api_->TriggerShutdownTimeout(); | |
417 EXPECT_TRUE(lock_state_test_api_->shutdown_timer_is_running()); | |
418 tablet_controller_->OnMaximizeModeStarted(); | |
419 EXPECT_FALSE(lock_state_test_api_->shutdown_timer_is_running()); | |
420 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(2500)); | |
421 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks()); | |
422 EXPECT_FALSE(GetLockedState()); | |
423 EXPECT_FALSE(GetBacklightsForcedOff()); | |
424 | |
425 power_manager_client_->SendPowerButtonEvent(true, tick_clock_->NowTicks()); | |
426 EXPECT_TRUE(test_api_->ShutdownTimerIsRunning()); | |
427 tablet_controller_->OnMaximizeModeEnded(); | |
428 EXPECT_FALSE(test_api_->ShutdownTimerIsRunning()); | |
429 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(3500)); | |
430 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks()); | |
431 EXPECT_FALSE(GetLockedState()); | |
432 EXPECT_FALSE(GetBacklightsForcedOff()); | |
433 | |
434 power_manager_client_->SendPowerButtonEvent(true, tick_clock_->NowTicks()); | |
435 test_api_->TriggerShutdownTimeout(); | |
436 EXPECT_TRUE(lock_state_test_api_->shutdown_timer_is_running()); | |
437 tablet_controller_->OnMaximizeModeEnded(); | |
438 EXPECT_FALSE(lock_state_test_api_->shutdown_timer_is_running()); | |
439 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(4500)); | |
440 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks()); | |
441 EXPECT_FALSE(GetLockedState()); | |
442 EXPECT_FALSE(GetBacklightsForcedOff()); | |
443 } | |
444 | |
445 // Tests that repeated power button releases are ignored (crbug.com/675291). | |
446 TEST_F(TabletPowerButtonControllerTest, IgnoreRepeatedPowerButtonReleases) { | |
447 // Advance a long duration from initialized last resume time in | |
448 // |tablet_controller_| to avoid cross interference. | |
449 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(2000)); | |
450 | |
451 // Set backlights forced off for starting point. | |
452 PressPowerButton(); | |
453 ReleasePowerButton(); | |
454 power_manager_client_->SendBrightnessChanged(0, false); | |
455 EXPECT_TRUE(GetBacklightsForcedOff()); | |
456 | |
457 // Test that a pressing-releasing operation after a short duration, backlights | |
458 // forced off is stopped since we don't drop request for power button pressed. | |
459 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(200)); | |
460 power_manager_client_->SendPowerButtonEvent(true, tick_clock_->NowTicks()); | |
461 power_manager_client_->SendBrightnessChanged(kNonZeroBrightness, false); | |
462 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks()); | |
463 EXPECT_FALSE(GetBacklightsForcedOff()); | |
464 | |
465 // Test that after another short duration, backlights will not be forced off | |
466 // since this immediately following forcing off request needs to be dropped. | |
467 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(200)); | |
468 power_manager_client_->SendPowerButtonEvent(true, tick_clock_->NowTicks()); | |
469 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks()); | |
470 EXPECT_FALSE(GetBacklightsForcedOff()); | |
471 | |
472 // Test that after another long duration, backlights should be forced off. | |
473 tick_clock_->Advance(base::TimeDelta::FromMilliseconds(800)); | |
474 power_manager_client_->SendPowerButtonEvent(true, tick_clock_->NowTicks()); | |
475 power_manager_client_->SendPowerButtonEvent(false, tick_clock_->NowTicks()); | |
476 power_manager_client_->SendBrightnessChanged(0, false); | |
477 EXPECT_TRUE(GetBacklightsForcedOff()); | |
478 } | |
479 | |
480 } // namespace test | |
481 } // namespace ash | |
OLD | NEW |