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

Side by Side Diff: ash/accelerators/accelerator_controller_unittest.cc

Issue 2686833005: Fix the toggle caps lock accelerator not always working. (Closed)
Patch Set: Nits Created 3 years, 10 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 | « no previous file | ash/common/accelerators/accelerator_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ash/common/accelerators/accelerator_controller.h" 5 #include "ash/common/accelerators/accelerator_controller.h"
6 6
7 #include "ash/common/accelerators/accelerator_table.h" 7 #include "ash/common/accelerators/accelerator_table.h"
8 #include "ash/common/accessibility_delegate.h" 8 #include "ash/common/accessibility_delegate.h"
9 #include "ash/common/accessibility_types.h" 9 #include "ash/common/accessibility_types.h"
10 #include "ash/common/ash_switches.h" 10 #include "ash/common/ash_switches.h"
(...skipping 20 matching lines...) Expand all
31 #include "ash/wm/window_util.h" 31 #include "ash/wm/window_util.h"
32 #include "base/command_line.h" 32 #include "base/command_line.h"
33 #include "base/test/user_action_tester.cc" 33 #include "base/test/user_action_tester.cc"
34 #include "services/ui/public/interfaces/window_manager_constants.mojom.h" 34 #include "services/ui/public/interfaces/window_manager_constants.mojom.h"
35 #include "ui/app_list/presenter/app_list.h" 35 #include "ui/app_list/presenter/app_list.h"
36 #include "ui/app_list/presenter/test/test_app_list_presenter.h" 36 #include "ui/app_list/presenter/test/test_app_list_presenter.h"
37 #include "ui/aura/client/aura_constants.h" 37 #include "ui/aura/client/aura_constants.h"
38 #include "ui/aura/test/test_window_delegate.h" 38 #include "ui/aura/test/test_window_delegate.h"
39 #include "ui/aura/test/test_windows.h" 39 #include "ui/aura/test/test_windows.h"
40 #include "ui/aura/window.h" 40 #include "ui/aura/window.h"
41 #include "ui/base/ime/chromeos/fake_ime_keyboard.h"
42 #include "ui/base/ime/chromeos/ime_keyboard.h"
43 #include "ui/base/ime/chromeos/input_method_manager.h"
44 #include "ui/base/ime/chromeos/mock_input_method_manager.h"
41 #include "ui/display/manager/display_manager.h" 45 #include "ui/display/manager/display_manager.h"
42 #include "ui/display/screen.h" 46 #include "ui/display/screen.h"
43 #include "ui/events/event.h" 47 #include "ui/events/event.h"
44 #include "ui/events/event_processor.h" 48 #include "ui/events/event_processor.h"
45 #include "ui/events/test/event_generator.h" 49 #include "ui/events/test/event_generator.h"
46 #include "ui/message_center/message_center.h" 50 #include "ui/message_center/message_center.h"
47 #include "ui/views/widget/widget.h" 51 #include "ui/views/widget/widget.h"
48 52
49 #if defined(USE_X11) 53 #if defined(USE_X11)
50 #include <X11/Xlib.h> 54 #include <X11/Xlib.h>
(...skipping 1063 matching lines...) Expand 10 before | Expand all | Expand 10 after
1114 EXPECT_FALSE( 1118 EXPECT_FALSE(
1115 GetController()->IsPreferred(ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE))); 1119 GetController()->IsPreferred(ui::Accelerator(ui::VKEY_TAB, ui::EF_NONE)));
1116 EXPECT_FALSE( 1120 EXPECT_FALSE(
1117 GetController()->IsReserved(ui::Accelerator(ui::VKEY_A, ui::EF_NONE))); 1121 GetController()->IsReserved(ui::Accelerator(ui::VKEY_A, ui::EF_NONE)));
1118 EXPECT_FALSE( 1122 EXPECT_FALSE(
1119 GetController()->IsPreferred(ui::Accelerator(ui::VKEY_A, ui::EF_NONE))); 1123 GetController()->IsPreferred(ui::Accelerator(ui::VKEY_A, ui::EF_NONE)));
1120 } 1124 }
1121 1125
1122 namespace { 1126 namespace {
1123 1127
1128 class TestInputMethodManager
1129 : public chromeos::input_method::MockInputMethodManager {
1130 public:
1131 TestInputMethodManager() = default;
1132 ~TestInputMethodManager() override = default;
1133
1134 // MockInputMethodManager:
1135 chromeos::input_method::ImeKeyboard* GetImeKeyboard() override {
1136 return &keyboard_;
1137 }
1138
1139 private:
1140 chromeos::input_method::FakeImeKeyboard keyboard_;
1141
1142 DISALLOW_COPY_AND_ASSIGN(TestInputMethodManager);
1143 };
1144
1145 class ToggleCapsLockTest : public AcceleratorControllerTest {
1146 public:
1147 ToggleCapsLockTest() = default;
1148 ~ToggleCapsLockTest() override = default;
1149
1150 void SetUp() override {
1151 AcceleratorControllerTest::SetUp();
1152 chromeos::input_method::InputMethodManager::Initialize(
1153 new TestInputMethodManager);
1154 }
1155
1156 void TearDown() override {
1157 chromeos::input_method::InputMethodManager::Shutdown();
1158 AcceleratorControllerTest::TearDown();
1159 }
1160
1161 private:
1162 DISALLOW_COPY_AND_ASSIGN(ToggleCapsLockTest);
1163 };
1164
1165 // Tests the four combinations of the TOGGLE_CAPS_LOCK accelerator.
1166 TEST_F(ToggleCapsLockTest, ToggleCapsLockAccelerators) {
1167 chromeos::input_method::InputMethodManager* input_method_manager =
1168 chromeos::input_method::InputMethodManager::Get();
1169 ASSERT_TRUE(input_method_manager);
1170 EXPECT_FALSE(input_method_manager->GetImeKeyboard()->CapsLockIsEnabled());
1171
1172 // 1. Press Alt, Press Search, Release Search, Release Alt.
1173 // Note when you press Alt then press search, the key_code at this point is
1174 // VKEY_LWIN (for search) and Alt is the modifier.
1175 const ui::Accelerator press_alt_then_search(ui::VKEY_LWIN, ui::EF_ALT_DOWN);
1176 EXPECT_FALSE(ProcessInController(press_alt_then_search));
1177 // When you release Search before Alt, the key_code is still VKEY_LWIN and
1178 // Alt is still the modifier.
1179 const ReleaseAccelerator release_search_before_alt(ui::VKEY_LWIN,
1180 ui::EF_ALT_DOWN);
1181 EXPECT_TRUE(ProcessInController(release_search_before_alt));
1182 EXPECT_TRUE(input_method_manager->GetImeKeyboard()->CapsLockIsEnabled());
1183 input_method_manager->GetImeKeyboard()->SetCapsLockEnabled(false);
1184
1185 // 2. Press Search, Press Alt, Release Search, Release Alt.
1186 const ui::Accelerator press_search_then_alt(ui::VKEY_MENU,
1187 ui::EF_COMMAND_DOWN);
1188 EXPECT_FALSE(ProcessInController(press_search_then_alt));
1189 EXPECT_TRUE(ProcessInController(release_search_before_alt));
1190 EXPECT_TRUE(input_method_manager->GetImeKeyboard()->CapsLockIsEnabled());
1191 input_method_manager->GetImeKeyboard()->SetCapsLockEnabled(false);
1192
1193 // 3. Press Alt, Press Search, Release Alt, Release Search.
1194 EXPECT_FALSE(ProcessInController(press_alt_then_search));
1195 const ReleaseAccelerator release_alt_before_search(ui::VKEY_MENU,
1196 ui::EF_COMMAND_DOWN);
1197 EXPECT_TRUE(ProcessInController(release_alt_before_search));
1198 EXPECT_TRUE(input_method_manager->GetImeKeyboard()->CapsLockIsEnabled());
1199 input_method_manager->GetImeKeyboard()->SetCapsLockEnabled(false);
1200
1201 // 4. Press Search, Press Alt, Release Alt, Release Search.
1202 EXPECT_FALSE(ProcessInController(press_search_then_alt));
1203 EXPECT_TRUE(ProcessInController(release_alt_before_search));
1204 EXPECT_TRUE(input_method_manager->GetImeKeyboard()->CapsLockIsEnabled());
1205 }
1206
1124 class PreferredReservedAcceleratorsTest : public test::AshTestBase { 1207 class PreferredReservedAcceleratorsTest : public test::AshTestBase {
1125 public: 1208 public:
1126 PreferredReservedAcceleratorsTest() {} 1209 PreferredReservedAcceleratorsTest() {}
1127 ~PreferredReservedAcceleratorsTest() override {} 1210 ~PreferredReservedAcceleratorsTest() override {}
1128 1211
1129 // test::AshTestBase: 1212 // test::AshTestBase:
1130 void SetUp() override { 1213 void SetUp() override {
1131 AshTestBase::SetUp(); 1214 AshTestBase::SetUp();
1132 Shell::GetInstance()->lock_state_controller()->set_animator_for_test( 1215 Shell::GetInstance()->lock_state_controller()->set_animator_for_test(
1133 new test::TestSessionStateAnimator); 1216 new test::TestSessionStateAnimator);
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 // Expect no notifications from the new accelerators. 1525 // Expect no notifications from the new accelerators.
1443 EXPECT_TRUE(IsMessageCenterEmpty()); 1526 EXPECT_TRUE(IsMessageCenterEmpty());
1444 1527
1445 // If the action is LOCK_SCREEN, we must reset the state by unlocking the 1528 // If the action is LOCK_SCREEN, we must reset the state by unlocking the
1446 // screen before we proceed testing the rest of accelerators. 1529 // screen before we proceed testing the rest of accelerators.
1447 ResetStateIfNeeded(); 1530 ResetStateIfNeeded();
1448 } 1531 }
1449 } 1532 }
1450 1533
1451 } // namespace ash 1534 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/common/accelerators/accelerator_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698