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

Side by Side Diff: ui/aura_shell/shell_accelerator_controller_unittest.cc

Issue 8689003: Register global accelerators and add placeholders for handling them. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments Created 9 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 | Annotate | Revision Log
« no previous file with comments | « ui/aura_shell/shell_accelerator_controller.cc ('k') | no next file » | 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 (c) 2011 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 "ui/aura_shell/shell.h"
6 #include "ui/aura_shell/shell_accelerator_controller.h"
7 #include "ui/aura_shell/test/aura_shell_test_base.h"
8
9 namespace aura_shell {
10 namespace test {
11
12 namespace {
13 class TestTarget : public ui::AcceleratorTarget {
14 public:
15 TestTarget() : accelerator_pressed_(false) {};
16 virtual ~TestTarget() {};
17
18 bool accelerator_pressed() const {
19 return accelerator_pressed_;
20 }
21
22 void set_accelerator_pressed(bool accelerator_pressed) {
23 accelerator_pressed_ = accelerator_pressed;
24 }
25
26 // Overridden from ui::AcceleratorTarget:
27 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) OVERRIDE;
28
29 private:
30 bool accelerator_pressed_;
31 };
32
33 bool TestTarget::AcceleratorPressed(const ui::Accelerator& accelerator) {
34 set_accelerator_pressed(true);
35 return true;
36 }
37
38 } // namespace
39
40 class ShellAcceleratorControllerTest : public AuraShellTestBase {
41 public:
42 ShellAcceleratorControllerTest() {};
43 virtual ~ShellAcceleratorControllerTest() {};
44
45 static ShellAcceleratorController* GetController();
46
47 // testing::Test:
48 // virtual void SetUp() OVERRIDE;
49 // virtual void TearDown() OVERRIDE;
50 };
51
52 ShellAcceleratorController* ShellAcceleratorControllerTest::GetController() {
53 return Shell::GetInstance()->accelerator_controller();
54 }
55
56 // void ShellAcceleratorControllerTest::SetUp() {
57 // AuraShellTestBase::SetUp();
58 // }
59
60 // void ShellAcceleratorControllerTest::TearDown() {
61 // AuraShellTestBase::TearDown();
62 // }
63
64 TEST_F(ShellAcceleratorControllerTest, Register) {
65 const ui::Accelerator accelerator_a(ui::VKEY_A, false, false, false);
66 TestTarget target;
67 GetController()->Register(accelerator_a, &target);
68
69 // The registered accelerator is processed.
70 EXPECT_TRUE(GetController()->Process(accelerator_a));
71 EXPECT_TRUE(target.accelerator_pressed());
72 }
73
74 TEST_F(ShellAcceleratorControllerTest, RegisterMultipleTarget) {
75 const ui::Accelerator accelerator_a(ui::VKEY_A, false, false, false);
76 TestTarget target1;
77 GetController()->Register(accelerator_a, &target1);
78 TestTarget target2;
79 GetController()->Register(accelerator_a, &target2);
80
81 // If multiple targets are registered with the same accelerator, the target
82 // registered later processes the accelerator.
83 EXPECT_TRUE(GetController()->Process(accelerator_a));
84 EXPECT_FALSE(target1.accelerator_pressed());
85 EXPECT_TRUE(target2.accelerator_pressed());
86 }
87
88 TEST_F(ShellAcceleratorControllerTest, Unregister) {
89 const ui::Accelerator accelerator_a(ui::VKEY_A, false, false, false);
90 TestTarget target;
91 GetController()->Register(accelerator_a, &target);
92 const ui::Accelerator accelerator_b(ui::VKEY_B, false, false, false);
93 GetController()->Register(accelerator_b, &target);
94
95 // Unregistering a different accelerator does not affect the other
96 // accelerator.
97 GetController()->Unregister(accelerator_b, &target);
98 EXPECT_TRUE(GetController()->Process(accelerator_a));
99 EXPECT_TRUE(target.accelerator_pressed());
100
101 // The unregistered accelerator is no longer processed.
102 target.set_accelerator_pressed(false);
103 GetController()->Unregister(accelerator_a, &target);
104 EXPECT_FALSE(GetController()->Process(accelerator_a));
105 EXPECT_FALSE(target.accelerator_pressed());
106 }
107
108 TEST_F(ShellAcceleratorControllerTest, UnregisterAll) {
109 const ui::Accelerator accelerator_a(ui::VKEY_A, false, false, false);
110 TestTarget target1;
111 GetController()->Register(accelerator_a, &target1);
112 const ui::Accelerator accelerator_b(ui::VKEY_B, false, false, false);
113 GetController()->Register(accelerator_b, &target1);
114 const ui::Accelerator accelerator_c(ui::VKEY_C, false, false, false);
115 TestTarget target2;
116 GetController()->Register(accelerator_c, &target2);
117 GetController()->UnregisterAll(&target1);
118
119 // All the accelerators registered for |target1| are no longer processed.
120 EXPECT_FALSE(GetController()->Process(accelerator_a));
121 EXPECT_FALSE(GetController()->Process(accelerator_b));
122 EXPECT_FALSE(target1.accelerator_pressed());
123
124 // UnregisterAll with a different target does not affect the other target.
125 EXPECT_TRUE(GetController()->Process(accelerator_c));
126 EXPECT_TRUE(target2.accelerator_pressed());
127 }
128
129 TEST_F(ShellAcceleratorControllerTest, Process) {
130 const ui::Accelerator accelerator_a(ui::VKEY_A, false, false, false);
131 TestTarget target1;
132 GetController()->Register(accelerator_a, &target1);
133
134 // The registered accelerator is processed.
135 EXPECT_TRUE(GetController()->Process(accelerator_a));
136 EXPECT_TRUE(target1.accelerator_pressed());
137
138 // The non-registered accelerator is not processed.
139 const ui::Accelerator accelerator_b(ui::VKEY_B, false, false, false);
140 EXPECT_FALSE(GetController()->Process(accelerator_b));
141 }
142
143 TEST_F(ShellAcceleratorControllerTest, GlobalAccelerators) {
144 // TODO(mazda): Uncomment the followings once they are implemented.
145 // CycleBackward
146 // EXPECT_TRUE(GetController()->Process(
147 // ui::Accelerator(ui::VKEY_TAB, true, false, true)));
148 // CycleForwrard
149 // EXPECT_TRUE(GetController()->Process(
150 // ui::Accelerator(ui::VKEY_TAB, false, false, true)));
151 // TakeScreenshot
152 // EXPECT_TRUE(GetController()->Process(
153 // ui::Accelerator(ui::VKEY_F5, false, true, false)));
154 // EXPECT_TRUE(GetController()->Process(
155 // ui::Accelerator(ui::VKEY_PRINT, false, false, false)));
156 #if !defined(NDEBUG)
157 // TODO(mazda): Callig RotateScreen in unit test causes a crash because of
158 // "pure virtual method called" for some reasons. Need to investigate.
159 // RotateScreen
160 // EXPECT_TRUE(GetController()->Process(
161 // ui::Accelerator(ui::VKEY_HOME, false, true, false)));
162 #if !defined(OS_LINUX)
163 // ToggleDesktopFullScreen (not implemented yet on Linux)
164 EXPECT_TRUE(GetController()->Process(
165 ui::Accelerator(ui::VKEY_F11, false, true, false)));
166 #endif
167 #endif
168 }
169
170 } // namespace test
171 } // namespace aura_shell
OLDNEW
« no previous file with comments | « ui/aura_shell/shell_accelerator_controller.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698