Chromium Code Reviews| 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 "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 Loading... | |
| 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 Loading... | |
| 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 } // namespace | |
| 1166 | |
| 1167 // Tests the four combinations of the TOGGLE_CAPS_LOCK accelerator. | |
| 1168 TEST_F(ToggleCapsLockTest, ToggleCapsLockAccelerators) { | |
|
James Cook
2017/02/08 22:39:08
nit: Could the test itself live in the anonymous n
afakhry
2017/02/09 00:28:30
The test can be placed in the anonymous namespace,
James Cook
2017/02/09 01:22:21
Putting it in an anonymous namespace reduces the a
| |
| 1169 chromeos::input_method::InputMethodManager* input_method_manager = | |
| 1170 chromeos::input_method::InputMethodManager::Get(); | |
| 1171 ASSERT_TRUE(input_method_manager); | |
| 1172 EXPECT_FALSE(input_method_manager->GetImeKeyboard()->CapsLockIsEnabled()); | |
| 1173 | |
| 1174 // 1. Press Alt, Press Search, Release Search, Release Alt. | |
| 1175 EXPECT_FALSE( | |
| 1176 ProcessInController(ui::Accelerator(ui::VKEY_MENU, ui::EF_COMMAND_DOWN))); | |
| 1177 EXPECT_TRUE( | |
| 1178 ProcessInController(ReleaseAccelerator(ui::VKEY_LWIN, ui::EF_ALT_DOWN))); | |
| 1179 EXPECT_TRUE(input_method_manager->GetImeKeyboard()->CapsLockIsEnabled()); | |
| 1180 input_method_manager->GetImeKeyboard()->SetCapsLockEnabled(false); | |
| 1181 EXPECT_FALSE(input_method_manager->GetImeKeyboard()->CapsLockIsEnabled()); | |
|
James Cook
2017/02/08 22:39:08
nit: I don't think you need to check that caps-loc
afakhry
2017/02/09 00:28:30
Me being extra cautious! Done.
| |
| 1182 | |
| 1183 // 2. Press Search, Press Alt, Release Search, Release Alt. | |
| 1184 EXPECT_FALSE( | |
| 1185 ProcessInController(ui::Accelerator(ui::VKEY_LWIN, ui::EF_ALT_DOWN))); | |
| 1186 EXPECT_TRUE( | |
| 1187 ProcessInController(ReleaseAccelerator(ui::VKEY_LWIN, ui::EF_ALT_DOWN))); | |
| 1188 EXPECT_TRUE(input_method_manager->GetImeKeyboard()->CapsLockIsEnabled()); | |
| 1189 input_method_manager->GetImeKeyboard()->SetCapsLockEnabled(false); | |
| 1190 EXPECT_FALSE(input_method_manager->GetImeKeyboard()->CapsLockIsEnabled()); | |
| 1191 | |
| 1192 // 3. Press Alt, Press Search, Release Alt, Release Search. | |
| 1193 EXPECT_FALSE( | |
| 1194 ProcessInController(ui::Accelerator(ui::VKEY_MENU, ui::EF_COMMAND_DOWN))); | |
|
James Cook
2017/02/08 22:39:08
optional: I wonder if this test would read better
afakhry
2017/02/09 00:28:30
Great suggestion, actually it helped me fixed the
| |
| 1195 EXPECT_TRUE(ProcessInController( | |
| 1196 ReleaseAccelerator(ui::VKEY_MENU, ui::EF_COMMAND_DOWN))); | |
| 1197 EXPECT_TRUE(input_method_manager->GetImeKeyboard()->CapsLockIsEnabled()); | |
| 1198 input_method_manager->GetImeKeyboard()->SetCapsLockEnabled(false); | |
| 1199 EXPECT_FALSE(input_method_manager->GetImeKeyboard()->CapsLockIsEnabled()); | |
| 1200 | |
| 1201 // 4. Press Search, Press Alt, Release Alt, Release Search. | |
| 1202 EXPECT_FALSE( | |
| 1203 ProcessInController(ui::Accelerator(ui::VKEY_LWIN, ui::EF_ALT_DOWN))); | |
| 1204 EXPECT_TRUE(ProcessInController( | |
| 1205 ReleaseAccelerator(ui::VKEY_MENU, ui::EF_COMMAND_DOWN))); | |
| 1206 EXPECT_TRUE(input_method_manager->GetImeKeyboard()->CapsLockIsEnabled()); | |
| 1207 } | |
|
James Cook
2017/02/08 22:39:08
Nice test. I like how you documented each block.
afakhry
2017/02/09 00:28:30
Thanks.
| |
| 1208 | |
| 1209 namespace { | |
| 1210 | |
| 1124 class PreferredReservedAcceleratorsTest : public test::AshTestBase { | 1211 class PreferredReservedAcceleratorsTest : public test::AshTestBase { |
| 1125 public: | 1212 public: |
| 1126 PreferredReservedAcceleratorsTest() {} | 1213 PreferredReservedAcceleratorsTest() {} |
| 1127 ~PreferredReservedAcceleratorsTest() override {} | 1214 ~PreferredReservedAcceleratorsTest() override {} |
| 1128 | 1215 |
| 1129 // test::AshTestBase: | 1216 // test::AshTestBase: |
| 1130 void SetUp() override { | 1217 void SetUp() override { |
| 1131 AshTestBase::SetUp(); | 1218 AshTestBase::SetUp(); |
| 1132 Shell::GetInstance()->lock_state_controller()->set_animator_for_test( | 1219 Shell::GetInstance()->lock_state_controller()->set_animator_for_test( |
| 1133 new test::TestSessionStateAnimator); | 1220 new test::TestSessionStateAnimator); |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1442 // Expect no notifications from the new accelerators. | 1529 // Expect no notifications from the new accelerators. |
| 1443 EXPECT_TRUE(IsMessageCenterEmpty()); | 1530 EXPECT_TRUE(IsMessageCenterEmpty()); |
| 1444 | 1531 |
| 1445 // If the action is LOCK_SCREEN, we must reset the state by unlocking the | 1532 // If the action is LOCK_SCREEN, we must reset the state by unlocking the |
| 1446 // screen before we proceed testing the rest of accelerators. | 1533 // screen before we proceed testing the rest of accelerators. |
| 1447 ResetStateIfNeeded(); | 1534 ResetStateIfNeeded(); |
| 1448 } | 1535 } |
| 1449 } | 1536 } |
| 1450 | 1537 |
| 1451 } // namespace ash | 1538 } // namespace ash |
| OLD | NEW |