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

Side by Side Diff: athena/input/input_manager_unittest.cc

Issue 863033002: Delete athena/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 11 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
« no previous file with comments | « athena/input/input_manager_impl.cc ('k') | athena/input/power_button_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "athena/input/input_manager_impl.h"
6
7 #include "athena/input/public/accelerator_manager.h"
8 #include "athena/test/base/athena_test_base.h"
9 #include "athena/util/switches.h"
10 #include "base/command_line.h"
11 #include "base/run_loop.h"
12 #include "ui/events/test/event_generator.h"
13
14 namespace athena {
15 namespace {
16
17 class TestPowerButtonObserver : public PowerButtonObserver {
18 public:
19 TestPowerButtonObserver() : count_(0), state_(RELEASED) {
20 InputManager::Get()->AddPowerButtonObserver(this);
21 }
22 ~TestPowerButtonObserver() override {
23 InputManager::Get()->RemovePowerButtonObserver(this);
24 }
25
26 int count() const { return count_; }
27 State state() const { return state_; }
28
29 bool WaitForLongPress() {
30 run_loop_.Run();
31 return state_ == LONG_PRESSED;
32 }
33
34 private:
35 virtual void OnPowerButtonStateChanged(
36 PowerButtonObserver::State state) override {
37 state_ = state;
38 count_++;
39 if (state == LONG_PRESSED) {
40 DCHECK(run_loop_.running());
41 run_loop_.Quit();
42 }
43 }
44 base::RunLoop run_loop_;
45 int count_;
46 State state_;
47
48 DISALLOW_COPY_AND_ASSIGN(TestPowerButtonObserver);
49 };
50
51 class InputManagerTest : public test::AthenaTestBase {
52 public:
53 InputManagerTest() {}
54 ~InputManagerTest() override {}
55
56 void SetUp() override {
57 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
58 command_line->AppendSwitch(switches::kEnableDebugAccelerators);
59 test::AthenaTestBase::SetUp();
60 }
61
62 private:
63 DISALLOW_COPY_AND_ASSIGN(InputManagerTest);
64 };
65
66 } // namespace
67
68 namespace test {
69
70 class ScopedPowerButtonTimeoutShortener {
71 public:
72 ScopedPowerButtonTimeoutShortener()
73 : original_timeout_(
74 GetInputManagerImpl()->SetPowerButtonTimeoutMsForTest(1)) {}
75 ~ScopedPowerButtonTimeoutShortener() {
76 GetInputManagerImpl()->SetPowerButtonTimeoutMsForTest(original_timeout_);
77 }
78
79 private:
80 InputManagerImpl* GetInputManagerImpl() {
81 return static_cast<InputManagerImpl*>(InputManager::Get());
82 }
83
84 int original_timeout_;
85 DISALLOW_COPY_AND_ASSIGN(ScopedPowerButtonTimeoutShortener);
86 };
87
88 } // namespace test
89
90 TEST_F(InputManagerTest, PowerButton) {
91 test::ScopedPowerButtonTimeoutShortener shortener;
92 TestPowerButtonObserver observer;
93
94 ui::test::EventGenerator generator(root_window());
95 generator.PressKey(ui::VKEY_P, ui::EF_NONE);
96 EXPECT_EQ(0, observer.count());
97
98 // Test short press.
99 generator.PressKey(ui::VKEY_P, ui::EF_ALT_DOWN);
100 EXPECT_EQ(1, observer.count());
101 EXPECT_EQ(PowerButtonObserver::PRESSED, observer.state());
102 generator.ReleaseKey(ui::VKEY_P, ui::EF_ALT_DOWN);
103 EXPECT_EQ(2, observer.count());
104 EXPECT_EQ(PowerButtonObserver::RELEASED, observer.state());
105
106 // Test long press.
107 generator.PressKey(ui::VKEY_P, ui::EF_ALT_DOWN);
108 EXPECT_EQ(3, observer.count());
109 EXPECT_EQ(PowerButtonObserver::PRESSED, observer.state());
110
111 EXPECT_TRUE(observer.WaitForLongPress());
112 EXPECT_EQ(4, observer.count());
113 EXPECT_EQ(PowerButtonObserver::LONG_PRESSED, observer.state());
114
115 generator.ReleaseKey(ui::VKEY_P, ui::EF_ALT_DOWN);
116 EXPECT_EQ(5, observer.count());
117 EXPECT_EQ(PowerButtonObserver::RELEASED, observer.state());
118 }
119
120 } // namespace athena
OLDNEW
« no previous file with comments | « athena/input/input_manager_impl.cc ('k') | athena/input/power_button_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698