Clear GCMProfileService::account_id_ in when signing out
[chromium-blink-merge.git] / athena / input / accelerator_manager_unittest.cc
blobcd74ee1613af07916797fd88b9fa4a5cbc234e02
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/public/accelerator_manager.h"
7 #include "athena/input/public/input_manager.h"
8 #include "athena/test/athena_test_base.h"
9 #include "ui/events/test/event_generator.h"
11 namespace athena {
12 namespace {
14 const int kInvalidCommandId = -1;
16 class TestHandler : public AcceleratorHandler {
17 public:
18 TestHandler() : fired_command_id_(kInvalidCommandId), enabled_(true) {}
19 virtual ~TestHandler() {}
21 void set_enabled(bool enabled) { enabled_ = enabled; }
23 int GetFiredCommandIdAndReset() {
24 int fired = fired_command_id_;
25 fired_command_id_ = kInvalidCommandId;
26 return fired;
29 private:
30 // AcceleratorHandler:
31 virtual bool IsCommandEnabled(int command_id) const OVERRIDE {
32 return enabled_;
34 virtual bool OnAcceleratorFired(int command_id,
35 const ui::Accelerator& accelerator) OVERRIDE {
36 fired_command_id_ = command_id;
37 return true;
40 int fired_command_id_;
41 bool enabled_;
43 DISALLOW_COPY_AND_ASSIGN(TestHandler);
46 } // namespace athena
48 typedef test::AthenaTestBase InputManagerTest;
50 TEST_F(InputManagerTest, Basic) {
51 enum TestCommandId {
52 COMMAND_A,
53 COMMAND_B,
54 COMMAND_C,
55 COMMAND_D,
56 COMMAND_E,
58 const AcceleratorData data[] = {
59 {TRIGGER_ON_PRESS, ui::VKEY_A, ui::EF_SHIFT_DOWN, COMMAND_A, AF_RESERVED},
60 {TRIGGER_ON_RELEASE, ui::VKEY_B, ui::EF_SHIFT_DOWN, COMMAND_B,
61 AF_RESERVED},
62 {TRIGGER_ON_PRESS, ui::VKEY_C, ui::EF_SHIFT_DOWN, COMMAND_C,
63 AF_RESERVED | AF_DEBUG},
64 {TRIGGER_ON_PRESS, ui::VKEY_D, ui::EF_SHIFT_DOWN, COMMAND_D,
65 AF_RESERVED | AF_NON_AUTO_REPEATABLE},
66 {TRIGGER_ON_PRESS, ui::VKEY_E, ui::EF_SHIFT_DOWN, COMMAND_E, AF_NONE},
68 AcceleratorManager* accelerator_manager =
69 InputManager::Get()->GetAcceleratorManager();
70 TestHandler test_handler;
71 accelerator_manager->RegisterAccelerators(
72 data, arraysize(data), &test_handler);
74 ui::test::EventGenerator generator(root_window());
75 generator.PressKey(ui::VKEY_A, ui::EF_NONE);
76 EXPECT_EQ(kInvalidCommandId, test_handler.GetFiredCommandIdAndReset());
78 // Trigger on press.
79 generator.PressKey(ui::VKEY_A, ui::EF_SHIFT_DOWN);
80 EXPECT_EQ(COMMAND_A, test_handler.GetFiredCommandIdAndReset());
81 generator.ReleaseKey(ui::VKEY_A, ui::EF_SHIFT_DOWN);
82 EXPECT_EQ(kInvalidCommandId, test_handler.GetFiredCommandIdAndReset());
84 // Trigger on release.
85 generator.PressKey(ui::VKEY_B, ui::EF_SHIFT_DOWN);
86 EXPECT_EQ(kInvalidCommandId, test_handler.GetFiredCommandIdAndReset());
87 generator.ReleaseKey(ui::VKEY_B, ui::EF_SHIFT_DOWN);
88 EXPECT_EQ(COMMAND_B, test_handler.GetFiredCommandIdAndReset());
90 // Disable command.
91 test_handler.set_enabled(false);
92 generator.PressKey(ui::VKEY_A, ui::EF_SHIFT_DOWN);
93 EXPECT_EQ(kInvalidCommandId, test_handler.GetFiredCommandIdAndReset());
94 test_handler.set_enabled(true);
95 generator.PressKey(ui::VKEY_A, ui::EF_SHIFT_DOWN);
96 EXPECT_EQ(COMMAND_A, test_handler.GetFiredCommandIdAndReset());
98 // Debug accelerators.
99 accelerator_manager->SetDebugAcceleratorsEnabled(false);
100 generator.PressKey(ui::VKEY_C, ui::EF_SHIFT_DOWN);
101 EXPECT_EQ(kInvalidCommandId, test_handler.GetFiredCommandIdAndReset());
102 accelerator_manager->SetDebugAcceleratorsEnabled(true);
103 generator.PressKey(ui::VKEY_C, ui::EF_SHIFT_DOWN);
104 EXPECT_EQ(COMMAND_C, test_handler.GetFiredCommandIdAndReset());
105 accelerator_manager->SetDebugAcceleratorsEnabled(false);
107 // Non auto repeatable
108 generator.PressKey(ui::VKEY_D, ui::EF_SHIFT_DOWN);
109 EXPECT_EQ(COMMAND_D, test_handler.GetFiredCommandIdAndReset());
110 generator.PressKey(ui::VKEY_D, ui::EF_SHIFT_DOWN | ui::EF_IS_REPEAT);
111 EXPECT_EQ(kInvalidCommandId, test_handler.GetFiredCommandIdAndReset());
113 // TODO(oshima): Add scenario where the key event is consumed by
114 // an app.
115 generator.PressKey(ui::VKEY_E, ui::EF_SHIFT_DOWN);
116 EXPECT_EQ(COMMAND_E, test_handler.GetFiredCommandIdAndReset());
119 } // namespace athena