OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/base/accelerators/accelerator_manager.h" | 5 #include "ui/base/accelerators/accelerator_manager.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "ui/events/event_constants.h" | 9 #include "ui/events/event_constants.h" |
10 #include "ui/events/keycodes/keyboard_codes.h" | 10 #include "ui/events/keycodes/keyboard_codes.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 &target); | 144 &target); |
145 | 145 |
146 // The registered accelerator is processed. | 146 // The registered accelerator is processed. |
147 const int last_count = target.accelerator_pressed_count(); | 147 const int last_count = target.accelerator_pressed_count(); |
148 EXPECT_TRUE(manager_.Process(accelerator)) << text; | 148 EXPECT_TRUE(manager_.Process(accelerator)) << text; |
149 EXPECT_EQ(last_count + 1, target.accelerator_pressed_count()) << text; | 149 EXPECT_EQ(last_count + 1, target.accelerator_pressed_count()) << text; |
150 | 150 |
151 // The non-registered accelerators are not processed. | 151 // The non-registered accelerators are not processed. |
152 accelerator.set_type(ET_UNKNOWN); | 152 accelerator.set_type(ET_UNKNOWN); |
153 EXPECT_FALSE(manager_.Process(accelerator)) << text; // different type | 153 EXPECT_FALSE(manager_.Process(accelerator)) << text; // different type |
154 accelerator.set_type(ET_TRANSLATED_KEY_PRESS); | |
155 EXPECT_FALSE(manager_.Process(accelerator)) << text; // different type | |
156 accelerator.set_type(ET_KEY_RELEASED); | 154 accelerator.set_type(ET_KEY_RELEASED); |
157 EXPECT_FALSE(manager_.Process(accelerator)) << text; // different type | 155 EXPECT_FALSE(manager_.Process(accelerator)) << text; // different type |
158 accelerator.set_type(ET_TRANSLATED_KEY_RELEASE); | |
159 EXPECT_FALSE(manager_.Process(accelerator)) << text; // different type | |
160 | 156 |
161 EXPECT_FALSE(manager_.Process(GetAccelerator(VKEY_UNKNOWN, mask))) | 157 EXPECT_FALSE(manager_.Process(GetAccelerator(VKEY_UNKNOWN, mask))) |
162 << text; // different vkey | 158 << text; // different vkey |
163 EXPECT_FALSE(manager_.Process(GetAccelerator(VKEY_B, mask))) | 159 EXPECT_FALSE(manager_.Process(GetAccelerator(VKEY_B, mask))) |
164 << text; // different vkey | 160 << text; // different vkey |
165 EXPECT_FALSE(manager_.Process(GetAccelerator(VKEY_SHIFT, mask))) | 161 EXPECT_FALSE(manager_.Process(GetAccelerator(VKEY_SHIFT, mask))) |
166 << text; // different vkey | 162 << text; // different vkey |
167 | 163 |
168 for (int test_mask = 0; test_mask < 2 * 2 * 2; ++test_mask) { | 164 for (int test_mask = 0; test_mask < 2 * 2 * 2; ++test_mask) { |
169 if (test_mask == mask) | 165 if (test_mask == mask) |
170 continue; | 166 continue; |
171 const Accelerator test_accelerator(GetAccelerator(VKEY_A, test_mask)); | 167 const Accelerator test_accelerator(GetAccelerator(VKEY_A, test_mask)); |
172 const base::string16 test_text = test_accelerator.GetShortcutText(); | 168 const base::string16 test_text = test_accelerator.GetShortcutText(); |
173 EXPECT_FALSE(manager_.Process(test_accelerator)) | 169 EXPECT_FALSE(manager_.Process(test_accelerator)) |
174 << text << ", " << test_text; // different modifiers | 170 << text << ", " << test_text; // different modifiers |
175 } | 171 } |
176 | 172 |
177 EXPECT_EQ(last_count + 1, target.accelerator_pressed_count()) << text; | 173 EXPECT_EQ(last_count + 1, target.accelerator_pressed_count()) << text; |
178 manager_.UnregisterAll(&target); | 174 manager_.UnregisterAll(&target); |
179 } | 175 } |
180 } | 176 } |
181 | 177 |
182 } // namespace test | 178 } // namespace test |
183 } // namespace ui | 179 } // namespace ui |
OLD | NEW |