Change DtmfSenderHandler to handle events on the signaling thread.
[chromium-blink-merge.git] / athena / input / input_manager_unittest.cc
blob242724a1480823fa9e4a3e391a6b5215ee8e61ca
1 // Copyright 2014 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.
5 #include "athena/input/input_manager_impl.h"
7 #include "athena/input/public/accelerator_manager.h"
8 #include "athena/test/base/athena_test_base.h"
9 #include "base/run_loop.h"
10 #include "ui/events/test/event_generator.h"
12 namespace athena {
13 namespace {
15 class TestPowerButtonObserver : public PowerButtonObserver {
16 public:
17 TestPowerButtonObserver() : count_(0), state_(RELEASED) {
18 InputManager::Get()->AddPowerButtonObserver(this);
20 ~TestPowerButtonObserver() override {
21 InputManager::Get()->RemovePowerButtonObserver(this);
24 int count() const { return count_; }
25 State state() const { return state_; }
27 bool WaitForLongPress() {
28 run_loop_.Run();
29 return state_ == LONG_PRESSED;
32 private:
33 virtual void OnPowerButtonStateChanged(
34 PowerButtonObserver::State state) override {
35 state_ = state;
36 count_++;
37 if (state == LONG_PRESSED) {
38 DCHECK(run_loop_.running());
39 run_loop_.Quit();
42 base::RunLoop run_loop_;
43 int count_;
44 State state_;
46 DISALLOW_COPY_AND_ASSIGN(TestPowerButtonObserver);
49 } // namespace
51 namespace test {
53 class ScopedPowerButtonTimeoutShortener {
54 public:
55 ScopedPowerButtonTimeoutShortener()
56 : original_timeout_(
57 GetInputManagerImpl()->SetPowerButtonTimeoutMsForTest(1)) {}
58 ~ScopedPowerButtonTimeoutShortener() {
59 GetInputManagerImpl()->SetPowerButtonTimeoutMsForTest(original_timeout_);
62 private:
63 InputManagerImpl* GetInputManagerImpl() {
64 return static_cast<InputManagerImpl*>(InputManager::Get());
67 int original_timeout_;
68 DISALLOW_COPY_AND_ASSIGN(ScopedPowerButtonTimeoutShortener);
71 } // namespace test
73 typedef test::AthenaTestBase InputManagerTest;
75 // This fails on bots. crbug.com/424109.
76 // Investigate once crbug.com/424093 is fixed.
77 TEST_F(InputManagerTest, DISABLED_PowerButton) {
78 test::ScopedPowerButtonTimeoutShortener shortener;
79 TestPowerButtonObserver observer;
81 ui::test::EventGenerator generator(root_window());
82 generator.PressKey(ui::VKEY_P, ui::EF_NONE);
83 EXPECT_EQ(0, observer.count());
85 // Test short press.
86 generator.PressKey(ui::VKEY_P, ui::EF_ALT_DOWN);
87 EXPECT_EQ(1, observer.count());
88 EXPECT_EQ(PowerButtonObserver::PRESSED, observer.state());
89 generator.ReleaseKey(ui::VKEY_P, ui::EF_ALT_DOWN);
90 EXPECT_EQ(2, observer.count());
91 EXPECT_EQ(PowerButtonObserver::RELEASED, observer.state());
93 // Test long press.
94 generator.PressKey(ui::VKEY_P, ui::EF_ALT_DOWN);
95 EXPECT_EQ(3, observer.count());
96 EXPECT_EQ(PowerButtonObserver::PRESSED, observer.state());
98 EXPECT_TRUE(observer.WaitForLongPress());
99 EXPECT_EQ(4, observer.count());
100 EXPECT_EQ(PowerButtonObserver::LONG_PRESSED, observer.state());
102 generator.ReleaseKey(ui::VKEY_P, ui::EF_ALT_DOWN);
103 EXPECT_EQ(5, observer.count());
104 EXPECT_EQ(PowerButtonObserver::RELEASED, observer.state());
107 } // namespace athena