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

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

Issue 2521103002: Ignore OnKeyEvent for VKEY_POWER because it is handled by PowerButtonEvent (Closed)
Patch Set: add tests 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/wm/lock_state_controller.h" 16 #include "ash/wm/lock_state_controller.h"
17 #include "ash/wm/power_button_controller.h" 17 #include "ash/wm/power_button_controller.h"
18 #include "base/command_line.h" 18 #include "base/command_line.h"
19 #include "base/compiler_specific.h" 19 #include "base/compiler_specific.h"
20 #include "base/run_loop.h" 20 #include "base/run_loop.h"
21 #include "base/test/simple_test_tick_clock.h" 21 #include "base/test/simple_test_tick_clock.h"
22 #include "chromeos/dbus/dbus_thread_manager.h" 22 #include "chromeos/dbus/dbus_thread_manager.h"
23 #include "chromeos/dbus/fake_power_manager_client.h" 23 #include "chromeos/dbus/fake_power_manager_client.h"
24 #include "ui/events/event.h"
24 #include "ui/events/test/event_generator.h" 25 #include "ui/events/test/event_generator.h"
25 26
26 namespace ash { 27 namespace ash {
27 namespace test { 28 namespace test {
28 29
29 namespace { 30 namespace {
30 31
31 // A non-zero brightness used for test. 32 // A non-zero brightness used for test.
32 constexpr int kNonZeroBrightness = 10; 33 constexpr int kNonZeroBrightness = 10;
33 34
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 293
293 generator_->MoveMouseBy(1, 1); 294 generator_->MoveMouseBy(1, 1);
294 EXPECT_TRUE(GetBacklightsForcedOff()); 295 EXPECT_TRUE(GetBacklightsForcedOff());
295 296
296 generator_->EnterPenPointerMode(); 297 generator_->EnterPenPointerMode();
297 generator_->MoveMouseBy(1, 1); 298 generator_->MoveMouseBy(1, 1);
298 EXPECT_TRUE(GetBacklightsForcedOff()); 299 EXPECT_TRUE(GetBacklightsForcedOff());
299 generator_->ExitPenPointerMode(); 300 generator_->ExitPenPointerMode();
300 } 301 }
301 302
303 // Tests that a single set of power button pressed-and-released operation should
304 // cause only one SetBacklightsForcedOff call.
305 TEST_F(TabletPowerButtonControllerTest, IgnorePowerOnKeyEvent) {
306 ui::KeyEvent power_key_pressed(ui::ET_KEY_PRESSED, ui::VKEY_POWER,
307 ui::EF_NONE);
308 ui::KeyEvent power_key_released(ui::ET_KEY_RELEASED, ui::VKEY_POWER,
309 ui::EF_NONE);
310
311 int expectation =
312 power_manager_client_->num_set_backlights_forced_off_calls() + 1;
Daniel Erat 2016/11/22 00:48:19 does this count really not start out at zero? it l
Qiang(Joe) Xu 2016/11/22 01:02:50 It should start with zero. Thanks for pointing out
313 // There can be multiple |power_key_pressed| and |power_key_released| events
314 // depends on the duration of holding.
315 tablet_controller_->OnKeyEvent(&power_key_pressed);
316 PressPowerButton();
317 tablet_controller_->OnKeyEvent(&power_key_pressed);
318 tablet_controller_->OnKeyEvent(&power_key_pressed);
319 tablet_controller_->OnKeyEvent(&power_key_released);
Daniel Erat 2016/11/22 00:48:19 are there really multiple release events? i'd expe
Qiang(Joe) Xu 2016/11/22 01:02:51 Yes, there are multiple release events. I made the
320 ReleasePowerButton();
321 tablet_controller_->OnKeyEvent(&power_key_released);
322 EXPECT_EQ(power_manager_client_->num_set_backlights_forced_off_calls(),
Daniel Erat 2016/11/22 00:48:19 nit: the order should be EXPECT_EQ(expected, actua
Qiang(Joe) Xu 2016/11/22 01:02:50 Done.
323 expectation);
324 }
325
302 } // namespace test 326 } // namespace test
303 } // namespace ash 327 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698